filesystem: add option to decode loadables

This commit is contained in:
schneider 2011-07-19 01:21:05 +02:00
parent 43eddd123b
commit b49a49f31c
4 changed files with 19 additions and 6 deletions

View File

@ -37,7 +37,8 @@ void htonlp(uint32_t *v, uint8_t n)
}
}
void xxtea_cbcmac(uint32_t mac[4], uint32_t *data, uint32_t len, uint32_t key[4])
void xxtea_cbcmac(uint32_t mac[4], uint32_t *data,
uint32_t len, uint32_t const key[4])
{
if( len & 0x03 )
return;

View File

@ -1,7 +1,8 @@
#ifndef _XXTEA_H_
#define _XXTEA_H_
void xxtea_cbcmac(uint32_t mac[4], uint32_t *data, uint32_t len, uint32_t key[4]);
void xxtea_cbcmac(uint32_t mac[4], uint32_t *data,
uint32_t len, uint32_t const key[4]);
void xxtea_encode_words(uint32_t *v, int n, uint32_t const k[4]);
void xxtea_decode_words(uint32_t *v, int n, uint32_t const k[4]);

View File

@ -10,14 +10,16 @@
#include "filesystem/ff.h"
#include "filesystem/select.h"
#include "basic/xxtea.h"
const uint32_t signature_key[4] = {0,0,0,0};
const uint32_t decode_key[4] = {0,0,0,0};
extern void * sram_top;
/**************************************************************************/
void execute_file (const char * fname, uint8_t checksignature){
void execute_file (const char * fname, uint8_t checksignature, uint8_t decode){
FRESULT res;
FIL file;
UINT readbytes;
@ -45,18 +47,27 @@ void execute_file (const char * fname, uint8_t checksignature){
if(res){
return;
};
if( decode || checksignature )
if( readbytes & 0x03 )
return;
if( checksignature ){
uint32_t mac[4];
uint32_t *data = (uint32_t*)dst;
uint32_t len = readbytes/4;
xxtea_cbcmac(mac, (uint32_t*)dst, len-4, signature_key);
if( data[len-4] != mac[0] || data[len-3] != mac[1]
|| data[len-2] != mac[2] || data[len-1] != mac[3] ){
return;
}
}
if( decode ){
uint32_t *data = (uint32_t*)dst;
uint32_t len = readbytes/4;
xxtea_decode_words(data, len, decode_key);
}
//lcdPrintInt(readbytes);
//lcdPrintln(" bytes");
//lcdRefresh();
@ -75,6 +86,6 @@ void executeSelect(char *ext){
filename[2]=0;
if( selectFile(filename+2,ext) == 0)
execute_file(filename,0);
execute_file(filename,0,0);
};

View File

@ -1,7 +1,7 @@
#ifndef _EXECUTE_H_
#define _EXECUTE_H_
void execute_file (const char * fname, uint8_t checksignature);
void execute_file (const char * fname, uint8_t checksignature, uint8_t decode);
void executeSelect(char *ext);
#endif