From b49a49f31c0aefcacd609f1554e0c3368f1c1fbf Mon Sep 17 00:00:00 2001 From: schneider Date: Tue, 19 Jul 2011 01:21:05 +0200 Subject: [PATCH] filesystem: add option to decode loadables --- firmware/basic/xxtea.c | 3 ++- firmware/basic/xxtea.h | 3 ++- firmware/filesystem/execute.c | 17 ++++++++++++++--- firmware/filesystem/execute.h | 2 +- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/firmware/basic/xxtea.c b/firmware/basic/xxtea.c index 91e0316..9ae81f8 100644 --- a/firmware/basic/xxtea.c +++ b/firmware/basic/xxtea.c @@ -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; diff --git a/firmware/basic/xxtea.h b/firmware/basic/xxtea.h index 4a08ce6..da93394 100644 --- a/firmware/basic/xxtea.h +++ b/firmware/basic/xxtea.h @@ -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]); diff --git a/firmware/filesystem/execute.c b/firmware/filesystem/execute.c index 071b910..ee387b0 100644 --- a/firmware/filesystem/execute.c +++ b/firmware/filesystem/execute.c @@ -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); }; diff --git a/firmware/filesystem/execute.h b/firmware/filesystem/execute.h index 2b4b0f1..8c52cae 100644 --- a/firmware/filesystem/execute.h +++ b/firmware/filesystem/execute.h @@ -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