diff --git a/src/stub/Makefile b/src/stub/Makefile index acd8d356..be274b90 100644 --- a/src/stub/Makefile +++ b/src/stub/Makefile @@ -161,9 +161,8 @@ endef # default tools tc.default.bin2h = python $(top_srcdir)/src/stub/scripts/bin2h.py --ident=auto-stub -##tc.default.bin2h-c = $(call tc,bin2h) --compress=upx-stub-deflate -##tc.default.bin2h-c = $(call tc,bin2h) --compress=upx-stub-lzma -tc.default.bin2h-c = $(call tc,bin2h) --compress=none +##tc.default.bin2h-c = $(call tc,bin2h) --compress=14,15,0 +tc.default.bin2h-c = $(call tc,bin2h) --compress=0 tc.default.brandelf = python $(top_srcdir)/src/stub/scripts/brandelf.py $(if $(tc_bfdname),--bfdname=$(tc_bfdname)) tc.default.gpp_inc = python $(top_srcdir)/src/stub/scripts/gpp_inc.py tc.default.gpp_mkdep = python $(top_srcdir)/src/stub/scripts/gpp_inc.py -o /dev/null diff --git a/src/stub/amd64-linux.elf-entry.h b/src/stub/amd64-linux.elf-entry.h index a75b7d44..676e94cb 100644 --- a/src/stub/amd64-linux.elf-entry.h +++ b/src/stub/amd64-linux.elf-entry.h @@ -1,4 +1,5 @@ -/* amd64-linux.elf-entry.h -- created from amd64-linux.elf-entry.bin, 12687 (0x318f) bytes +/* amd64-linux.elf-entry.h + created from amd64-linux.elf-entry.bin, 12687 (0x318f) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/amd64-linux.elf-fold.h b/src/stub/amd64-linux.elf-fold.h index 7324b653..927d306a 100644 --- a/src/stub/amd64-linux.elf-fold.h +++ b/src/stub/amd64-linux.elf-fold.h @@ -1,4 +1,5 @@ -/* amd64-linux.elf-fold.h -- created from amd64-linux.elf-fold.bin, 1775 (0x6ef) bytes +/* amd64-linux.elf-fold.h + created from amd64-linux.elf-fold.bin, 1775 (0x6ef) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/arm-linux.elf-entry.h b/src/stub/arm-linux.elf-entry.h index 13c64d6a..37372c9b 100644 --- a/src/stub/arm-linux.elf-entry.h +++ b/src/stub/arm-linux.elf-entry.h @@ -1,4 +1,5 @@ -/* arm-linux.elf-entry.h -- created from arm-linux.elf-entry.bin, 19530 (0x4c4a) bytes +/* arm-linux.elf-entry.h + created from arm-linux.elf-entry.bin, 19530 (0x4c4a) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/arm-linux.elf-fold.h b/src/stub/arm-linux.elf-fold.h index a2c82360..8f629fbc 100644 --- a/src/stub/arm-linux.elf-fold.h +++ b/src/stub/arm-linux.elf-fold.h @@ -1,4 +1,5 @@ -/* arm-linux.elf-fold.h -- created from arm-linux.elf-fold.bin, 2108 (0x83c) bytes +/* arm-linux.elf-fold.h + created from arm-linux.elf-fold.bin, 2108 (0x83c) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/arm.v4a-wince.pe.h b/src/stub/arm.v4a-wince.pe.h index 4e168bcf..1fae5a62 100644 --- a/src/stub/arm.v4a-wince.pe.h +++ b/src/stub/arm.v4a-wince.pe.h @@ -1,4 +1,5 @@ -/* arm.v4a-wince.pe.h -- created from arm.v4a-wince.pe.bin, 19616 (0x4ca0) bytes +/* arm.v4a-wince.pe.h + created from arm.v4a-wince.pe.bin, 19616 (0x4ca0) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/arm.v4t-wince.pe.h b/src/stub/arm.v4t-wince.pe.h index 1cd47d59..7b069794 100644 --- a/src/stub/arm.v4t-wince.pe.h +++ b/src/stub/arm.v4t-wince.pe.h @@ -1,4 +1,5 @@ -/* arm.v4t-wince.pe.h -- created from arm.v4t-wince.pe.bin, 9992 (0x2708) bytes +/* arm.v4t-wince.pe.h + created from arm.v4t-wince.pe.bin, 9992 (0x2708) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/armeb-linux.elf-entry.h b/src/stub/armeb-linux.elf-entry.h index 7e3c6c14..32fa309a 100644 --- a/src/stub/armeb-linux.elf-entry.h +++ b/src/stub/armeb-linux.elf-entry.h @@ -1,4 +1,5 @@ -/* armeb-linux.elf-entry.h -- created from armeb-linux.elf-entry.bin, 19529 (0x4c49) bytes +/* armeb-linux.elf-entry.h + created from armeb-linux.elf-entry.bin, 19529 (0x4c49) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/armeb-linux.elf-fold.h b/src/stub/armeb-linux.elf-fold.h index 3a724239..f704a339 100644 --- a/src/stub/armeb-linux.elf-fold.h +++ b/src/stub/armeb-linux.elf-fold.h @@ -1,4 +1,5 @@ -/* armeb-linux.elf-fold.h -- created from armeb-linux.elf-fold.bin, 2108 (0x83c) bytes +/* armeb-linux.elf-fold.h + created from armeb-linux.elf-fold.bin, 2108 (0x83c) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/i086-dos16.com.h b/src/stub/i086-dos16.com.h index 2026dfae..4b1ca3d8 100644 --- a/src/stub/i086-dos16.com.h +++ b/src/stub/i086-dos16.com.h @@ -1,4 +1,5 @@ -/* i086-dos16.com.h -- created from i086-dos16.com.bin, 9078 (0x2376) bytes +/* i086-dos16.com.h + created from i086-dos16.com.bin, 9078 (0x2376) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/i086-dos16.exe.h b/src/stub/i086-dos16.exe.h index be67da12..1be4d8db 100644 --- a/src/stub/i086-dos16.exe.h +++ b/src/stub/i086-dos16.exe.h @@ -1,4 +1,5 @@ -/* i086-dos16.exe.h -- created from i086-dos16.exe.bin, 19030 (0x4a56) bytes +/* i086-dos16.exe.h + created from i086-dos16.exe.bin, 19030 (0x4a56) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/i086-dos16.sys.h b/src/stub/i086-dos16.sys.h index 7996a02c..2a4cfe85 100644 --- a/src/stub/i086-dos16.sys.h +++ b/src/stub/i086-dos16.sys.h @@ -1,4 +1,5 @@ -/* i086-dos16.sys.h -- created from i086-dos16.sys.bin, 10474 (0x28ea) bytes +/* i086-dos16.sys.h + created from i086-dos16.sys.bin, 10474 (0x28ea) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/i386-bsd.elf-entry.h b/src/stub/i386-bsd.elf-entry.h index dfd5083c..ffd50a0e 100644 --- a/src/stub/i386-bsd.elf-entry.h +++ b/src/stub/i386-bsd.elf-entry.h @@ -1,4 +1,5 @@ -/* i386-bsd.elf-entry.h -- created from i386-bsd.elf-entry.bin, 52750 (0xce0e) bytes +/* i386-bsd.elf-entry.h + created from i386-bsd.elf-entry.bin, 52750 (0xce0e) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/i386-bsd.elf-fold.h b/src/stub/i386-bsd.elf-fold.h index 21e76d20..bfce2b61 100644 --- a/src/stub/i386-bsd.elf-fold.h +++ b/src/stub/i386-bsd.elf-fold.h @@ -1,4 +1,5 @@ -/* i386-bsd.elf-fold.h -- created from i386-bsd.elf-fold.bin, 1789 (0x6fd) bytes +/* i386-bsd.elf-fold.h + created from i386-bsd.elf-fold.bin, 1789 (0x6fd) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/i386-bsd.elf.execve-entry.h b/src/stub/i386-bsd.elf.execve-entry.h index e0de18ee..08c84ef6 100644 --- a/src/stub/i386-bsd.elf.execve-entry.h +++ b/src/stub/i386-bsd.elf.execve-entry.h @@ -1,4 +1,5 @@ -/* i386-bsd.elf.execve-entry.h -- created from i386-bsd.elf.execve-entry.bin, 53357 (0xd06d) bytes +/* i386-bsd.elf.execve-entry.h + created from i386-bsd.elf.execve-entry.bin, 53357 (0xd06d) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/i386-bsd.elf.execve-fold.h b/src/stub/i386-bsd.elf.execve-fold.h index 033a3834..7b891117 100644 --- a/src/stub/i386-bsd.elf.execve-fold.h +++ b/src/stub/i386-bsd.elf.execve-fold.h @@ -1,4 +1,5 @@ -/* i386-bsd.elf.execve-fold.h -- created from i386-bsd.elf.execve-fold.bin, 1031 (0x407) bytes +/* i386-bsd.elf.execve-fold.h + created from i386-bsd.elf.execve-fold.bin, 1031 (0x407) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/i386-dos32.djgpp2.h b/src/stub/i386-dos32.djgpp2.h index 6114a0f5..29ad9fd5 100644 --- a/src/stub/i386-dos32.djgpp2.h +++ b/src/stub/i386-dos32.djgpp2.h @@ -1,4 +1,5 @@ -/* i386-dos32.djgpp2.h -- created from i386-dos32.djgpp2.bin, 33548 (0x830c) bytes +/* i386-dos32.djgpp2.h + created from i386-dos32.djgpp2.bin, 33548 (0x830c) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/i386-dos32.tmt.h b/src/stub/i386-dos32.tmt.h index 358d0c03..bd465615 100644 --- a/src/stub/i386-dos32.tmt.h +++ b/src/stub/i386-dos32.tmt.h @@ -1,4 +1,5 @@ -/* i386-dos32.tmt.h -- created from i386-dos32.tmt.bin, 34553 (0x86f9) bytes +/* i386-dos32.tmt.h + created from i386-dos32.tmt.bin, 34553 (0x86f9) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/i386-dos32.watcom.le.h b/src/stub/i386-dos32.watcom.le.h index 2cce5031..1ae7adcb 100644 --- a/src/stub/i386-dos32.watcom.le.h +++ b/src/stub/i386-dos32.watcom.le.h @@ -1,4 +1,5 @@ -/* i386-dos32.watcom.le.h -- created from i386-dos32.watcom.le.bin, 35309 (0x89ed) bytes +/* i386-dos32.watcom.le.h + created from i386-dos32.watcom.le.bin, 35309 (0x89ed) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/i386-linux.elf-entry.h b/src/stub/i386-linux.elf-entry.h index ff507864..d35d7b4f 100644 --- a/src/stub/i386-linux.elf-entry.h +++ b/src/stub/i386-linux.elf-entry.h @@ -1,4 +1,5 @@ -/* i386-linux.elf-entry.h -- created from i386-linux.elf-entry.bin, 52744 (0xce08) bytes +/* i386-linux.elf-entry.h + created from i386-linux.elf-entry.bin, 52744 (0xce08) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/i386-linux.elf-fold.h b/src/stub/i386-linux.elf-fold.h index 8d1b9e85..99d5eda3 100644 --- a/src/stub/i386-linux.elf-fold.h +++ b/src/stub/i386-linux.elf-fold.h @@ -1,4 +1,5 @@ -/* i386-linux.elf-fold.h -- created from i386-linux.elf-fold.bin, 1691 (0x69b) bytes +/* i386-linux.elf-fold.h + created from i386-linux.elf-fold.bin, 1691 (0x69b) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/i386-linux.elf.execve-entry.h b/src/stub/i386-linux.elf.execve-entry.h index 18800bff..473a9693 100644 --- a/src/stub/i386-linux.elf.execve-entry.h +++ b/src/stub/i386-linux.elf.execve-entry.h @@ -1,4 +1,5 @@ -/* i386-linux.elf.execve-entry.h -- created from i386-linux.elf.execve-entry.bin, 53359 (0xd06f) bytes +/* i386-linux.elf.execve-entry.h + created from i386-linux.elf.execve-entry.bin, 53359 (0xd06f) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/i386-linux.elf.execve-fold.h b/src/stub/i386-linux.elf.execve-fold.h index f1a76a02..8912038c 100644 --- a/src/stub/i386-linux.elf.execve-fold.h +++ b/src/stub/i386-linux.elf.execve-fold.h @@ -1,4 +1,5 @@ -/* i386-linux.elf.execve-fold.h -- created from i386-linux.elf.execve-fold.bin, 931 (0x3a3) bytes +/* i386-linux.elf.execve-fold.h + created from i386-linux.elf.execve-fold.bin, 931 (0x3a3) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/i386-linux.elf.interp-entry.h b/src/stub/i386-linux.elf.interp-entry.h index 564495fd..03a89948 100644 --- a/src/stub/i386-linux.elf.interp-entry.h +++ b/src/stub/i386-linux.elf.interp-entry.h @@ -1,4 +1,5 @@ -/* i386-linux.elf.interp-entry.h -- created from i386-linux.elf.interp-entry.bin, 64126 (0xfa7e) bytes +/* i386-linux.elf.interp-entry.h + created from i386-linux.elf.interp-entry.bin, 64126 (0xfa7e) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/i386-linux.elf.interp-fold.h b/src/stub/i386-linux.elf.interp-fold.h index fd7fefc7..8b446be4 100644 --- a/src/stub/i386-linux.elf.interp-fold.h +++ b/src/stub/i386-linux.elf.interp-fold.h @@ -1,4 +1,5 @@ -/* i386-linux.elf.interp-fold.h -- created from i386-linux.elf.interp-fold.bin, 1519 (0x5ef) bytes +/* i386-linux.elf.interp-fold.h + created from i386-linux.elf.interp-fold.bin, 1519 (0x5ef) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/i386-linux.elf.shell-entry.h b/src/stub/i386-linux.elf.shell-entry.h index d24fd00e..2397914c 100644 --- a/src/stub/i386-linux.elf.shell-entry.h +++ b/src/stub/i386-linux.elf.shell-entry.h @@ -1,4 +1,5 @@ -/* i386-linux.elf.shell-entry.h -- created from i386-linux.elf.shell-entry.bin, 41479 (0xa207) bytes +/* i386-linux.elf.shell-entry.h + created from i386-linux.elf.shell-entry.bin, 41479 (0xa207) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/i386-linux.elf.shell-fold.h b/src/stub/i386-linux.elf.shell-fold.h index bc1885b7..94871d30 100644 --- a/src/stub/i386-linux.elf.shell-fold.h +++ b/src/stub/i386-linux.elf.shell-fold.h @@ -1,4 +1,5 @@ -/* i386-linux.elf.shell-fold.h -- created from i386-linux.elf.shell-fold.bin, 1194 (0x4aa) bytes +/* i386-linux.elf.shell-fold.h + created from i386-linux.elf.shell-fold.bin, 1194 (0x4aa) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/i386-linux.kernel.vmlinux-head.h b/src/stub/i386-linux.kernel.vmlinux-head.h index 05efbd59..ef5e3cce 100644 --- a/src/stub/i386-linux.kernel.vmlinux-head.h +++ b/src/stub/i386-linux.kernel.vmlinux-head.h @@ -1,4 +1,5 @@ -/* i386-linux.kernel.vmlinux-head.h -- created from i386-linux.kernel.vmlinux-head.bin, 39 (0x27) bytes +/* i386-linux.kernel.vmlinux-head.h + created from i386-linux.kernel.vmlinux-head.bin, 39 (0x27) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/i386-linux.kernel.vmlinux.h b/src/stub/i386-linux.kernel.vmlinux.h index 2efc32b6..d57b0f95 100644 --- a/src/stub/i386-linux.kernel.vmlinux.h +++ b/src/stub/i386-linux.kernel.vmlinux.h @@ -1,4 +1,5 @@ -/* i386-linux.kernel.vmlinux.h -- created from i386-linux.kernel.vmlinux.bin, 34465 (0x86a1) bytes +/* i386-linux.kernel.vmlinux.h + created from i386-linux.kernel.vmlinux.bin, 34465 (0x86a1) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/i386-linux.kernel.vmlinuz.h b/src/stub/i386-linux.kernel.vmlinuz.h index 49c1fe96..51b75631 100644 --- a/src/stub/i386-linux.kernel.vmlinuz.h +++ b/src/stub/i386-linux.kernel.vmlinuz.h @@ -1,4 +1,5 @@ -/* i386-linux.kernel.vmlinuz.h -- created from i386-linux.kernel.vmlinuz.bin, 35988 (0x8c94) bytes +/* i386-linux.kernel.vmlinuz.h + created from i386-linux.kernel.vmlinuz.bin, 35988 (0x8c94) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/i386-openbsd.elf-fold.h b/src/stub/i386-openbsd.elf-fold.h index 763d9080..9d9b48dd 100644 --- a/src/stub/i386-openbsd.elf-fold.h +++ b/src/stub/i386-openbsd.elf-fold.h @@ -1,4 +1,5 @@ -/* i386-openbsd.elf-fold.h -- created from i386-openbsd.elf-fold.bin, 2025 (0x7e9) bytes +/* i386-openbsd.elf-fold.h + created from i386-openbsd.elf-fold.bin, 2025 (0x7e9) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/i386-win32.pe.h b/src/stub/i386-win32.pe.h index 6d72e703..c5b2ee7a 100644 --- a/src/stub/i386-win32.pe.h +++ b/src/stub/i386-win32.pe.h @@ -1,4 +1,5 @@ -/* i386-win32.pe.h -- created from i386-win32.pe.bin, 42482 (0xa5f2) bytes +/* i386-win32.pe.h + created from i386-win32.pe.bin, 42482 (0xa5f2) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/m68k-atari.tos.h b/src/stub/m68k-atari.tos.h index 8cac44d2..91054248 100644 --- a/src/stub/m68k-atari.tos.h +++ b/src/stub/m68k-atari.tos.h @@ -1,4 +1,5 @@ -/* m68k-atari.tos.h -- created from m68k-atari.tos.bin, 25878 (0x6516) bytes +/* m68k-atari.tos.h + created from m68k-atari.tos.bin, 25878 (0x6516) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/mipsel.r3000-ps1.h b/src/stub/mipsel.r3000-ps1.h index 146388a6..5300be05 100644 --- a/src/stub/mipsel.r3000-ps1.h +++ b/src/stub/mipsel.r3000-ps1.h @@ -1,4 +1,5 @@ -/* mipsel.r3000-ps1.h -- created from mipsel.r3000-ps1.bin, 26795 (0x68ab) bytes +/* mipsel.r3000-ps1.h + created from mipsel.r3000-ps1.bin, 26795 (0x68ab) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/powerpc-darwin.macho-entry.h b/src/stub/powerpc-darwin.macho-entry.h index f3c78feb..c2cc4e3e 100644 --- a/src/stub/powerpc-darwin.macho-entry.h +++ b/src/stub/powerpc-darwin.macho-entry.h @@ -1,4 +1,5 @@ -/* powerpc-darwin.macho-entry.h -- created from powerpc-darwin.macho-entry.bin, 9698 (0x25e2) bytes +/* powerpc-darwin.macho-entry.h + created from powerpc-darwin.macho-entry.bin, 9698 (0x25e2) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/powerpc-darwin.macho-fold.h b/src/stub/powerpc-darwin.macho-fold.h index bfc49488..bb35f7e9 100644 --- a/src/stub/powerpc-darwin.macho-fold.h +++ b/src/stub/powerpc-darwin.macho-fold.h @@ -1,4 +1,5 @@ -/* powerpc-darwin.macho-fold.h -- created from powerpc-darwin.macho-fold.bin, 1660 (0x67c) bytes +/* powerpc-darwin.macho-fold.h + created from powerpc-darwin.macho-fold.bin, 1660 (0x67c) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/powerpc-linux.elf-entry.h b/src/stub/powerpc-linux.elf-entry.h index 0309eb63..c3f1a258 100644 --- a/src/stub/powerpc-linux.elf-entry.h +++ b/src/stub/powerpc-linux.elf-entry.h @@ -1,4 +1,5 @@ -/* powerpc-linux.elf-entry.h -- created from powerpc-linux.elf-entry.bin, 10127 (0x278f) bytes +/* powerpc-linux.elf-entry.h + created from powerpc-linux.elf-entry.bin, 10127 (0x278f) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/powerpc-linux.elf-fold.h b/src/stub/powerpc-linux.elf-fold.h index fa31d6fb..b9597a11 100644 --- a/src/stub/powerpc-linux.elf-fold.h +++ b/src/stub/powerpc-linux.elf-fold.h @@ -1,4 +1,5 @@ -/* powerpc-linux.elf-fold.h -- created from powerpc-linux.elf-fold.bin, 1944 (0x798) bytes +/* powerpc-linux.elf-fold.h + created from powerpc-linux.elf-fold.bin, 1944 (0x798) bytes This file is part of the UPX executable compressor. diff --git a/src/stub/scripts/bin2h.py b/src/stub/scripts/bin2h.py index 607e4c34..d9f0d2e0 100644 --- a/src/stub/scripts/bin2h.py +++ b/src/stub/scripts/bin2h.py @@ -32,9 +32,10 @@ import getopt, os, re, struct, sys, zlib class opts: - compress = None dry_run = 0 ident = None + methods = [ 0 ] + mname = "STUB_COMPRESS_METHOD" mode = "c" verbose = 0 @@ -44,7 +45,7 @@ class opts: # ************************************************************************/ def w_header_c(w, ifile, ofile, n): - w("/* %s -- created from %s, %d (0x%x) bytes\n" % (os.path.basename(ofile), os.path.basename(ifile), n, n)) + w("/* %s\n created from %s, %d (0x%x) bytes\n" % (os.path.basename(ofile), os.path.basename(ifile), n, n)) w("""\n\ This file is part of the UPX executable compressor. @@ -153,10 +154,74 @@ def encode_compressed_stub_header(method, idata, odata): else: h = "UPX#" + "\x00" + struct.pack("= len(idata): + odata = idata + method = 0 + assert len(odata) <= len(idata), "stub compression failed" + + if len(opts.methods) > 1: + if method_index == 0: + w("#if (%s == %d)\n\n" % (opts.mname, method)) + elif method_index < len(opts.methods) - 1: + w("\n#elif (%s == %d)\n\n" % (opts.mname, method)) + else: + w("\n#else\n\n") + + if opts.ident: + if opts.mode == "c": + w_checksum_c(w, opts.ident.upper(), odata) + w("unsigned char %s[%d] = {\n" % (opts.ident, len(odata))) + if opts.mode == "c": + w_data_c(w, odata) + elif opts.mode == "gas": + w_data_gas(w, odata) + elif opts.mode == "nasm": + w_data_nasm(w, odata) + else: + assert 0, opts.mode + if opts.ident: + if opts.mode == "c": + w("};\n") + + if len(opts.methods) > 1: + if method_index == len(opts.methods) - 1: + w("\n#endif\n") + + # /*********************************************************************** # // main # ************************************************************************/ @@ -170,7 +235,7 @@ def main(argv): if 0: pass elif opt in ["-q", "--quiet"]: opts.verbose = opts.verbose - 1 elif opt in ["-v", "--verbose"]: opts.verbose = opts.verbose + 1 - elif opt in ["--compress"]: opts.compress = optarg + elif opt in ["--compress"]: opts.methods = map(int, optarg.split(",")) elif opt in ["--dry-run"]: opts.dry_run = opts.dry_run + 1 elif opt in ["--ident"]: opts.ident = optarg elif opt in ["--mode"]: opts.mode = optarg.lower() @@ -190,44 +255,13 @@ def main(argv): sys.exit(1) # read ifile + ifile = os.path.normpath(ifile) ifp = open(ifile, "rb") idata = ifp.read() ifp.close() assert len(idata) == st.st_size - # compress - if opts.compress in [None, "none"]: - odata = idata - elif opts.compress in ["zlib"]: - # zlib with header and adler32 checksum - odata = zlib.compress(idata, 9) - assert zlib.decompress(odata) == idata - elif opts.compress in ["upx-stub-deflate"]: - odata = zlib.compress(idata, 9) - # strip zlib-header and zlib-trailer (adler32) - odata = odata[2:-4] - assert zlib.decompress(odata, -15) == idata - # encode upx stub header - M_DEFLATE = 15 - odata = encode_compressed_stub_header(M_DEFLATE, idata, odata) + odata - elif opts.compress in ["upx-stub-lzma"]: - import pylzma - odata = pylzma.compress(idata, eos=0) - ## FIXME: internal pylzma-0.3.0 error - ##assert pylzma.decompress(odata, maxlength=len(idata)) == idata - # strip lzma-header - prop = ord(odata[0]) - pb = (prop / 9) / 5; lp = (prop / 9) % 5; lc = prop % 9 - h = chr(((lc + lp) << 3) | pb) + chr((lp << 4) | lc) - odata = h + odata[5:] - # encode upx stub header - M_LZMA = 14 - odata = encode_compressed_stub_header(M_LZMA, idata, odata) + odata - else: - raise Exception, ("invalid --compress=", opts.compress) - assert len(odata) <= len(idata), "compression failed" - - # ident + # opts.ident if opts.ident in ["auto", "auto-stub"]: s = os.path.basename(ifile) s = re.sub(r"\.(bin|out)$", "", s) @@ -253,21 +287,9 @@ def main(argv): if opts.verbose >= 0: if opts.mode == "c": w_header_c(w, ifile, ofile, len(idata)) - if opts.ident: - if opts.mode == "c": - w_checksum_c(w, opts.ident.upper(), odata) - w("unsigned char %s[%d] = {\n" % (opts.ident, len(odata))) - if opts.mode == "c": - w_data_c(w, odata) - elif opts.mode == "gas": - w_data_gas(w, odata) - elif opts.mode == "nasm": - w_data_nasm(w, odata) - else: - assert 0, opts.mode - if opts.ident: - if opts.mode == "c": - w("};\n") + assert len(opts.methods) >= 1 + for i in range(len(opts.methods)): + write_stub(w, idata, i) if ofp: if ofp is sys.stdout: ofp.flush()