#1 14 Apr 2015 14:37

carlos
Member
From: Chile
Registered: 04 Nov 2008
Posts: 244
Website

BHX 5.6 now with great encoding

When I create my program bhx it always encode binary data using 16 hexadecimal characters, that is write out 2 bytes for 1 byte.
For reduce the output I recommend create a cabinet with the file using lzx compression and then apply bhx.
But today I replaced the default hexadecimal encode with a encoding based on the encoding ZeroMQ Base-85 that uses 85 printable characters.
The result is awesome, this saves more bytes than base 16 encoding, and even more than base 64 encoding.

For example, the current bhx.exe size is: 12288 bytes.
Using the previous default hexadecimal it produced a script file (that includes the decoder) with size:
flat(hex): 26921 bytes
cab(hex): 11288 bytes
And now using the new 85 encoding produces a script file (that includes the decoder) with size:
flat(85): 17957 bytes
cab(85): 8182 bytes.

BHX v5.6
Encode a binary file in a batch script for rebuild it.

By default, the generated batch script name is mybin.cmd.
Is recommended convert your file in a cabinet
with compression, created with this command line:
Makecab /d compressiontype=lzx file file.cab
and use the generated cabinet as source.
This can save many bytes in the output script.

BHX source [/ne] [/o:out] [/y]

  source  Binary to encode.
  /ne     If the source file is a cabinet, not write code
          for expand it.
  /o:out  out is the output filename instead of mybin.cmd.
  /y      Overwrite the output file.
  /hex    Encode binary data using 16 hexadecimal characters.
          The default encoder uses 85 printable characters.

BHX /author
  display the author of the program.

This is the script for rebuild bhx 5.6 :
build_bhx.cmd

@Echo Off
SetLocal EnableExtensions
Call :Rebuild
If ErrorLevel 1 Echo Rebuild failed.
Goto :Eof

:Rebuild
Rem Script made using BHX 5.6 { consolesoft.com/p/bhx }
SetLocal EnableExtensions EnableDelayedExpansion
Set "bin=bhx.cab"
Set /A "size=4688"
For %%# In (
"bhx.exe"
"!bin!" "!bin!.da" "!bin!.tmp"
) Do If Exist "%%#" (Del /A /F /Q "%%#" >Nul 2>&1
If ErrorLevel 1 Exit /B 1 )
Set "fsrc=%~f0"
Findstr /B /N ":+res:!bin!:" "!fsrc!" >"!bin!.tmp"
(Set /P "inioff="
Set /P "endoff=") <"!bin!.tmp"
For /F "delims=:" %%# In ("!inioff!") Do Set "inioff=%%#"
For /F "delims=:" %%# In ("!endoff!") Do Set "endoff=%%#"
Set ".=ado="adodb.stream""
Set ".=!.! :set a=createobject(ado) :a.type=1 :a.open"
Set ".=!.! :set u=createobject(ado) :u.type=2 :u.open"
Set ".=!.! :set fs=createobject("scripting.filesystemobject")"
Set ".=!.! :set s=fs.opentextfile("!fsrc!",1,0,0)"
Set ".=!.! :e="0123456789abcdefghijklmnopqrstuvwxyzABCDEF"
Set ".=!.!GHIJKLMNOPQRSTUVWXYZ.-:+=^^`/*?&<>()[]{}~,$#"
Set ".=!.!" :max=!size! :wri=0 :n=array(0,0,0,0,0)"
Set ".=!.! :for i=1 to !inioff! step 1 :s.readline :next"
Set ".=!.! :do while i<!endoff! :d=replace(s.readline," ","")"
Set ".=!.! :for j=1 to len(d) step 5 :num85=mid(d,j,5)"
Set ".=!.! :v=0 :for k=1 to len(num85) step 1"
Set ".=!.! :v=v*85+instr(1,e,mid(num85,k,1))-1 :next"
Set ".=!.! :n(1)=Fix(v/16777216) :v=v-n(1)*16777216"
Set ".=!.! :n(2)=Fix(v/65536) :v=v-n(2)*65536"
Set ".=!.! :n(3)=Fix(v/256) :n(4)=v-n(3)*256"
Set ".=!.! :for m=1 to 4 step 1 :if (wri < max) then"
Set ".=!.! :u.writetext chrb(n(m)) :wri=wri+1 :end if :next"
Set ".=!.! :next :i=i+1 :loop"
Set ".=!.! :u.position=2 :u.copyto a :u.close :set u=nothing"
Set ".=!.! :a.savetofile "!bin!",2 :a.close :set a=nothing"
Set ".=!.! :s.close :set s=nothing :set fs=nothing"
Echo !.!>"!bin!.da"
Set "ret=1"
Cscript.exe /B /E:vbs "!bin!.da" >Nul
For %%# In ("!bin!") Do If "%%~z#"=="!size!" Set "ret=0"
If "0"=="!ret!" Expand.exe -r "!bin!" -F:* . >Nul
If ErrorLevel 1 Set "ret=1"
Del /A /F "!bin!" "!bin!.da" "!bin!.tmp" >Nul
Exit /B !ret!

:+res:bhx.cab:
o&BzG00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