Index: kitsh/buildsrc/kitsh-0.0/cvfs_data.c ================================================================== --- kitsh/buildsrc/kitsh-0.0/cvfs_data.c +++ kitsh/buildsrc/kitsh-0.0/cvfs_data.c @@ -164,11 +164,11 @@ Tcl_SetResult(interp, "No such file or directory", TCL_STATIC); return(TCL_ERROR); } - if (finfo->type == CVFS_FILETYPE_OBSFUCATED_FILE || finfo->type == CVFS_FILETYPE_ENCRYPTED_FILE) { + if (finfo->type == CVFS_FILETYPE_ENCRYPTED_FILE) { cmd_decryptFile = getCmdDecryptFile(hashkey); if (cmd_decryptFile != NULL) { cmd_decryptFile(file, finfo); } Index: kitsh/buildsrc/kitsh-0.0/dir2c.tcl ================================================================== --- kitsh/buildsrc/kitsh-0.0/dir2c.tcl +++ kitsh/buildsrc/kitsh-0.0/dir2c.tcl @@ -122,11 +122,11 @@ "rotate_subst" { switch -- $target { "c" { set retval ".type = CVFS_KEYTYPE_ROTATE_SUBST,\n" append retval ".typedata.rotate_subst.rotate_length = $key(rotate_length),\n" - append retval ".typedata.rotate_subst.subst = [stringify $key(subst)]\n" + append retval ".typedata.rotate_subst.subst = (unsigned char *) [stringify $key(subst)]\n" return $retval } } } @@ -242,20 +242,21 @@ # define LOADED_CVFS_COMMON 1 typedef enum { CVFS_FILETYPE_FILE = 0, CVFS_FILETYPE_DIR = 1, - CVFS_FILETYPE_OBSFUCATED_FILE = 2, - CVFS_FILETYPE_ENCRYPTED_FILE = 3, + CVFS_FILETYPE_ENCRYPTED_FILE = 2, + CVFS_FILETYPE_COMPRESSED_FILE = 4, } cvfs_filetype_t; struct cvfs_data { const char * name; unsigned long index; unsigned long size; cvfs_filetype_t type; const unsigned char * data; + int free; }; typedef enum { CVFS_KEYTYPE_ROTATE_SUBST = 0, } cvfs_keytype_t; @@ -283,11 +284,10 @@ } return(h); } -#include static int cvfs_decrypt(unsigned char *out, const unsigned char *in, unsigned long in_out_length, struct cvfs_key *key) { unsigned long i; unsigned char in_ch, out_ch; int ch_idx; @@ -306,15 +306,17 @@ # endif /* !LOADED_CVFS_COMMON */} puts "" puts "static struct cvfs_data ${code_tag}_data\[\] = {" puts "\t{" +puts "\t\t/* Index 0 cannot be used because we use the value 0 to represent failure */" puts "\t\t.name = NULL," puts "\t\t.index = 0," puts "\t\t.type = 0," puts "\t\t.size = 0," puts "\t\t.data = NULL," +puts "\t\t.free = 0," puts "\t}," for {set idx 1} {$idx < [llength $files]} {incr idx} { set file [lindex $files $idx] set shortfile [shorten_file $startdir $file] @@ -329,11 +331,11 @@ fconfigure $fd -translation binary set data [read $fd] close $fd if {$obsfucate} { - set type "CVFS_FILETYPE_OBSFUCATED_FILE" + set type "CVFS_FILETYPE_ENCRYPTED_FILE" set data "(unsigned char *) [stringify [encrypt $data $obsfucation_key]]" } else { set type "CVFS_FILETYPE_FILE" set data "(unsigned char *) [stringify $data]" } @@ -349,10 +351,11 @@ puts "\t\t.name = \"$shortfile\"," puts "\t\t.index = $idx," puts "\t\t.type = $type," puts "\t\t.size = $size," puts "\t\t.data = $data," + puts "\t\t.free = 0," puts "\t}," } puts "};" puts "" @@ -504,22 +507,31 @@ puts "" if {$obsfucate} { puts "static void ${code_tag}_decryptFile(const char *path, struct cvfs_data *finfo) {" puts "\tstatic struct cvfs_key key = { [string map [list "\n" " "] [encrypt_key_export $obsfucation_key "c"]] };" - puts "\tunsigned char *new_data;" - puts "\tint decrypt_ret;" + puts "\tunsigned char *new_data, *old_data;" + puts "\tint decrypt_ret, free_old_data;" puts "" puts "\tnew_data = malloc(finfo->size);" puts "\tdecrypt_ret = cvfs_decrypt(new_data, finfo->data, finfo->size, &key);" puts "\tif (decrypt_ret != 0) {" puts "\t\tfree(new_data);" puts "" puts "\t\treturn;" puts "\t}" + puts "" + puts "\tfree_old_data = finfo->free;" + puts "\told_data = (void *) finfo->data;" + puts "" puts "\tfinfo->data = new_data;" + puts "\tfinfo->free = 1;" puts "\tfinfo->type = CVFS_FILETYPE_FILE;" + puts "" + puts "\tif (free_old_data) {" + puts "\t\tfree(old_data);" + puts "\t}" puts "\treturn;" puts "}" puts "" }