Artifacts Associated With Ticket bd6188edd4290bfdcff4a8ef9355f5280496eda5
Ticket change [4eaaa9b664] (rid 2628) by anonymous on 2020-04-20 16:03:24:
- comment initialized to:
<div>Dear Roy,</div><div><br /></div><div>thank you for great tcl2c.tcl and its framework.</div><div>I am learning each day and digging miself through the mechanisms.</div><div>Sorry to be a novice.</div><div>And sorry to use Microsoft compilers.</div><div><br /></div><div>The compiler MS-VC2015 (VC9) has a string constant size limit of 65535 characters.</div><div>A possibility to avoid this limit is to use an array of characters, which have a limit of size_z = 0x7CFFFFFF.</div><div><br /></div><div>The patch below changes dir2c.tcl to output each file within one character array named cvfs_data_$idx as follows:</div><div><br /></div><div><verbatim></div><div>/* Data of boot.tcl */<br />static unsigned char cvfs_data_2[] = {<br /> 0x70, 0x72, 0x6f, 0x63, 0x20, 0x74, 0x63, 0x6c, 0x49, 0x6e, 0x69, 0x74, 0x20, 0x7b, 0x7d, 0x20, <br />...</div><div>static struct cvfs_data cvfs_tcl_data[] = {<br /></div><div>...<br /></div><div> {<br /> /* name */ "boot.tcl",<br /> /* index */ 2,<br /> /* type */ CVFS_FILETYPE_FILE,<br /> /* size */ 2887,<br /> /* data */ cvfs_data_2,<br /> /* free */ 0,<br /> },<br /></verbatim><br /></div><div><br /></div><div>The patch allows to use this for all files or files larger than the character length limit.</div><div><br /></div><div>I may miss another disadvantage of this method. I suppose, it only avoids the implicite trailing zero byte.<br /></div><div><br /></div><div>Thank you,</div><div>Harald</div><div><br /></div><div>Patch:</div><div><verbatim></div><div>--- C:/Users/oehhar/AppData/Local/Temp/dir2c.tcl-revBASE.svn001.tmp.tcl Fri Apr 17 17:29:24 2020<br />+++ C:/oehhar/elmicron/projekte/el1005_scanlink_dll/source/c-vfs/dir2c.tcl Mon Apr 20 17:30:25 2020<br />@@ -66,26 +66,44 @@<br /> proc stringify {data} {<br /> set ret "\""<br /> for {set idx 0} {$idx < [string length $data]} {incr idx} {<br /> binary scan [string index $data $idx] H* char<br /> <br /> append ret "\\x${char}"<br /> <br />- if {($idx % 20) == 0 && $idx != 0} {<br />+ if {(($idx+1) % 20) == 0} {<br /> append ret "\"\n\""<br /> }<br /> }<br /> <br /> set ret [string trim $ret "\n\""]<br /> <br /> set ret "\"$ret\""<br /> <br /> return $ret<br /> }<br /> <br />+# Convert data to a character array<br />+proc character_array {data} {<br />+ set ret "\{\n\t"<br />+ for {set idx 0} {$idx < [string length $data]} {incr idx} {<br />+ binary scan [string index $data $idx] H* char<br />+ append ret "0x${char}, "<br />+<br />+ if {(($idx+1) % 16) == 0 } {<br />+ append ret "\n\t"<br />+ }<br />+ }<br />+ set ret [string trimright $ret "\n, \t"]<br />+<br />+ append ret "\n\}"<br />+<br />+ return $ret<br />+}<br />+<br /> # Encrypt the data<br /> proc random_byte {} {<br /> set value [expr {int(256 * rand())}]<br /> <br /> return $value<br /> }<br /> <br />@@ -303,64 +321,80 @@<br /> <br /> return(0);<br /> }<br /> <br /> # endif /* !LOADED_CVFS_COMMON */}<br /> puts ""<br /> <br />-puts "static struct cvfs_data ${code_tag}_data\[\] = {"<br />-puts "\t{"<br />-puts "\t\t/* Index 0 cannot be used because we use the value 0 to represent failure */"<br />-puts "\t\t/* name */ NULL,"<br />-puts "\t\t/* index */ 0,"<br />-puts "\t\t/* type */ 0,"<br />-puts "\t\t/* size */ 0,"<br />-puts "\t\t/* data */ NULL,"<br />-puts "\t\t/* free */ 0,"<br />-puts "\t},"<br />+# C struct data output buffer (must be delayed after definition of file data)<br />+set struct_data ""<br />+<br /> for {set idx 1} {$idx < [llength $files]} {incr idx} {<br /> set file [lindex $files $idx]<br /> set shortfile [shorten_file $startdir $file]<br /> <br /> unset -nocomplain finfo type<br /> file stat $file finfo<br /> <br /> switch -- $finfo(type) {<br /> "file" {<br /> set size $finfo(size)<br /> <br /> set fd [open $file]<br /> fconfigure $fd -translation binary<br />- set data [read $fd]<br />+ set data_in [read $fd]<br /> close $fd<br /> <br /> if {$obsfucate} {<br /> set type "CVFS_FILETYPE_ENCRYPTED_FILE"<br />- set data "(unsigned char *) [stringify [encrypt $data $obsfucation_key]]"<br />+ set data_in [encrypt $data $obsfucation_key]<br /> } else {<br /> set type "CVFS_FILETYPE_FILE"<br />- set data "(unsigned char *) [stringify $data]"<br /> }<br />+ # Microsoft VC9 compiler has a string limit of 65535 bytes<br />+ # so put all larger files into an array which has a higher<br />+ # string limit<br />+ #if {$size <= 65535} {<br />+ # set data "(unsigned char *) [stringify $data_in]"<br />+ #} else {<br />+ puts "/* Data of $shortfile */"<br />+ set variable_name cvfs_data_$idx<br />+ set data $variable_name<br />+ puts "static unsigned char ${variable_name}\[\] =\<br />+ [character_array $data_in];"<br />+ #}<br /> }<br /> "directory" {<br /> set type "CVFS_FILETYPE_DIR"<br /> set data "NULL"<br /> set size 0<br /> }<br /> }<br /> <br />- puts "\t{"<br />- puts "\t\t/* name */ \"$shortfile\","<br />- puts "\t\t/* index */ $idx,"<br />- puts "\t\t/* type */ $type,"<br />- puts "\t\t/* size */ $size,"<br />- puts "\t\t/* data */ $data,"<br />- puts "\t\t/* free */ 0,"<br />- puts "\t},"<br />+ append struct_data "\t{\n"\<br />+ "\t\t/* name */ \"$shortfile\",\n"\<br />+ "\t\t/* index */ $idx,\n"\<br />+ "\t\t/* type */ $type,\n"\<br />+ "\t\t/* size */ $size,\n"\<br />+ "\t\t/* data */ $data,\n"\<br />+ "\t\t/* free */ 0,\n"\<br />+ "\t},\n"<br /> }<br />+puts ""<br />+puts "static struct cvfs_data ${code_tag}_data\[\] = {"<br />+puts "\t{"<br />+puts "\t\t/* Index 0 cannot be used because we use the value 0 to represent failure */"<br />+puts "\t\t/* name */ NULL,"<br />+puts "\t\t/* index */ 0,"<br />+puts "\t\t/* type */ 0,"<br />+puts "\t\t/* size */ 0,"<br />+puts "\t\t/* data */ NULL,"<br />+puts "\t\t/* free */ 0,"<br />+puts "\t},"<br />+puts -nonewline $struct_data<br /> puts "};"<br /> puts ""<br /> <br /> puts "static unsigned long ${code_tag}_lookup_index(const char *path) {"<br /> puts "\tswitch (cvfs_hash((unsigned char *) path)) {"<br /> <br /> for {set idx 1} {$idx < [llength $files]} {incr idx} {<br /><br /></div><div></verbatim><br /></div>
- foundin initialized to: "trunk"
- login: "anonymous"
- private_contact initialized to: "0f366eb3e9e2fcab52b8ebacd197db9047186a5f"
- severity initialized to: "Minor"
- status initialized to: "Open"
- title initialized to:
dir2c: Output data as character array and not as string
- type initialized to: "Feature Request"
- comment initialized to:
Ticket change [5f15c8b012] (rid 2634) by anonymous on 2020-05-11 16:38:04:
- icomment:
Dear Roy, sorry, this patch also has an issue. The obfuscated version does not work any more (wrong variable data instead data_in). Here is a corrected total patch including ticket [127ac40147] <verbatim> --- C:/oehhar/elmicron/projekte/el1005_scanlink_dll/source/c-vfs/dir2c.tcl Mon May 11 07:31:09 2020 +++ C:/oehhar/elmicron/projekte/el1005_scanlink_dll/source/c-vfs/dir2c_ori.tcl Wed Jan 22 20:53:52 2020 @@ -70,7 +70,7 @@ append ret "\\x${char}" - if {(($idx+1) % 20) == 0} { + if {($idx % 20) == 0 && $idx != 0} { append ret "\"\n\"" } } @@ -82,24 +82,6 @@ return $ret } -# Convert data to a character array -proc character_array {data} { - set ret "\{\n\t" - for {set idx 0} {$idx < [string length $data]} {incr idx} { - binary scan [string index $data $idx] H* char - append ret "0x${char}, " - - if {(($idx+1) % 16) == 0 } { - append ret "\n\t" - } - } - set ret [string trimright $ret "\n, \t"] - - append ret "\n\}" - - return $ret -} - # Encrypt the data proc random_byte {} { set value [expr {int(256 * rand())}] @@ -325,9 +307,16 @@ # endif /* !LOADED_CVFS_COMMON */} puts "" -# C struct data output buffer (must be delayed after definition of file data) -set struct_data "" - +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] @@ -341,28 +330,15 @@ set fd [open $file] fconfigure $fd -translation binary - set data_in [read $fd] + set data [read $fd] close $fd if {$obsfucate} { set type "CVFS_FILETYPE_ENCRYPTED_FILE" - set data_in [encrypt $data_in $obsfucation_key] + set data "(unsigned char *) [stringify [encrypt $data $obsfucation_key]]" } else { set type "CVFS_FILETYPE_FILE" - } - # Microsoft VC9 compiler has a string limit of 65535 bytes - # so put all larger files into an array which has a higher - # string limit - # For instance, the extra variable is used for all files. - # this may be deactivated by removing "0 &" below - if { 0 & $size <= 65535} { - set data "(unsigned char *) [stringify $data_in]" - } else { - puts "/* Data of $shortfile */" - set variable_name cvfs_data_$idx - set data $variable_name - puts "static unsigned char ${variable_name}\[\] =\ - [character_array $data_in];" + set data "(unsigned char *) [stringify $data]" } } "directory" { @@ -372,27 +348,15 @@ } } - append struct_data "\t{\n"\ - "\t\t/* name */ \"$shortfile\",\n"\ - "\t\t/* index */ $idx,\n"\ - "\t\t/* size */ $size,\n"\ - "\t\t/* type */ $type,\n"\ - "\t\t/* data */ $data,\n"\ - "\t\t/* free */ 0,\n"\ - "\t},\n" + puts "\t{" + 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 "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}," -puts -nonewline $struct_data puts "};" puts "" </verbatim>
- login: "anonymous"
- mimetype: "text/x-fossil-wiki"
- priority changed to: "Immediate"
- resolution changed to: "Open"
- subsystem changed to: "Tcl"
- username: "oehhar"
- icomment:
Ticket change [2536b9c03b] (rid 2635) by anonymous on 2020-05-11 16:40:12:
- icomment:
I would love to be able to edit my own bad stuff. The diff was in the wrong direction. Here is the corrected diff: <verbatim> --- C:/oehhar/elmicron/projekte/el1005_scanlink_dll/source/c-vfs/dir2c_ori.tcl Wed Jan 22 20:53:52 2020 +++ C:/oehhar/elmicron/projekte/el1005_scanlink_dll/source/c-vfs/dir2c.tcl Mon May 11 07:31:09 2020 @@ -70,7 +70,7 @@ append ret "\\x${char}" - if {($idx % 20) == 0 && $idx != 0} { + if {(($idx+1) % 20) == 0} { append ret "\"\n\"" } } @@ -82,6 +82,24 @@ return $ret } +# Convert data to a character array +proc character_array {data} { + set ret "\{\n\t" + for {set idx 0} {$idx < [string length $data]} {incr idx} { + binary scan [string index $data $idx] H* char + append ret "0x${char}, " + + if {(($idx+1) % 16) == 0 } { + append ret "\n\t" + } + } + set ret [string trimright $ret "\n, \t"] + + append ret "\n\}" + + return $ret +} + # Encrypt the data proc random_byte {} { set value [expr {int(256 * rand())}] @@ -307,16 +325,9 @@ # 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}," +# C struct data output buffer (must be delayed after definition of file data) +set struct_data "" + for {set idx 1} {$idx < [llength $files]} {incr idx} { set file [lindex $files $idx] set shortfile [shorten_file $startdir $file] @@ -330,15 +341,28 @@ set fd [open $file] fconfigure $fd -translation binary - set data [read $fd] + set data_in [read $fd] close $fd if {$obsfucate} { set type "CVFS_FILETYPE_ENCRYPTED_FILE" - set data "(unsigned char *) [stringify [encrypt $data $obsfucation_key]]" + set data_in [encrypt $data_in $obsfucation_key] } else { set type "CVFS_FILETYPE_FILE" - set data "(unsigned char *) [stringify $data]" + } + # Microsoft VC9 compiler has a string limit of 65535 bytes + # so put all larger files into an array which has a higher + # string limit + # For instance, the extra variable is used for all files. + # this may be deactivated by removing "0 &" below + if { 0 & $size <= 65535} { + set data "(unsigned char *) [stringify $data_in]" + } else { + puts "/* Data of $shortfile */" + set variable_name cvfs_data_$idx + set data $variable_name + puts "static unsigned char ${variable_name}\[\] =\ + [character_array $data_in];" } } "directory" { @@ -348,15 +372,27 @@ } } - puts "\t{" - 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}," + append struct_data "\t{\n"\ + "\t\t/* name */ \"$shortfile\",\n"\ + "\t\t/* index */ $idx,\n"\ + "\t\t/* size */ $size,\n"\ + "\t\t/* type */ $type,\n"\ + "\t\t/* data */ $data,\n"\ + "\t\t/* free */ 0,\n"\ + "\t},\n" } +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}," +puts -nonewline $struct_data puts "};" puts "" </verbatim>
- login: "anonymous"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"
- icomment: