From cdd117bfb94fec61913441a415f635e55747651a Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Tue, 14 Feb 2006 11:22:21 +0000 Subject: [PATCH] Rearranged debug options. committer: mfx 1139916141 +0000 --- src/main.cpp | 38 ++++++++++++++++++++++++-------------- src/options.h | 11 ++++++++--- src/p_exe.cpp | 4 ++-- src/p_w32pe.cpp | 3 ++- src/p_wcle.cpp | 4 ++-- src/packer.cpp | 18 +++++++++--------- 6 files changed, 47 insertions(+), 31 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index aa86909c..0d891761 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -443,7 +443,7 @@ static int do_option(int optc, const char *arg) set_cmd(CMD_DECOMPRESS); break; case 'D': - opt->debug++; + opt->debug.debug_level++; break; case 'f': opt->force++; @@ -537,6 +537,23 @@ static int do_option(int optc, const char *arg) e_method(opt->method, 10); break; + // debug + case 542: + if (!mfx_optarg || strlen(mfx_optarg) != 4) + e_optarg(arg); + memcpy(opt->debug.fake_stub_version, mfx_optarg, 4); + break; + case 543: + if (!mfx_optarg || strlen(mfx_optarg) != 4) + e_optarg(arg); + memcpy(opt->debug.fake_stub_year, mfx_optarg, 4); + break; + case 544: + if (!mfx_optarg || !mfx_optarg[0]) + e_optarg(arg); + opt->debug.dump_stub_loader = mfx_optarg; + break; + // misc case 512: opt->console = CON_FILE; @@ -550,16 +567,6 @@ static int do_option(int optc, const char *arg) case 516: opt->no_progress = true; break; - case 542: - if (!mfx_optarg || strlen(mfx_optarg) != 4) - e_optarg(arg); - memcpy(opt->fake_stub_version, mfx_optarg, 4); - break; - case 543: - if (!mfx_optarg || strlen(mfx_optarg) != 4) - e_optarg(arg); - memcpy(opt->fake_stub_year, mfx_optarg, 4); - break; case 519: opt->no_env = true; break; @@ -763,9 +770,6 @@ static const struct mfx_option longopts[] = {"version", 0, 0, 'V'+256}, // display version number // options - {"debug", 0x10, 0, 'D'}, - {"fake-stub-version",0x31, 0, 542}, // for internal debugging - {"fake-stub-year" ,0x31, 0, 543}, // for internal debugging {"force", 0, 0, 'f'}, // force overwrite of output files {"force-compress", 0, 0, 'f'}, // and compression of suspicious files {"info", 0, 0, 'i'}, // info mode @@ -781,6 +785,12 @@ static const struct mfx_option longopts[] = #endif {"verbose", 0, 0, 'v'}, // verbose mode + // debug options + {"debug", 0x10, 0, 'D'}, + {"dump-stub-loader" ,0x31, 0, 544}, // for internal debugging + {"fake-stub-version",0x31, 0, 542}, // for internal debugging + {"fake-stub-year" ,0x31, 0, 543}, // for internal debugging + // backup options {"backup", 0, 0, 'k'}, {"keep", 0, 0, 'k'}, diff --git a/src/options.h b/src/options.h index d4abf81b..905bb7f8 100644 --- a/src/options.h +++ b/src/options.h @@ -56,9 +56,6 @@ struct options_t { // other options int backup; int console; - int debug; - char fake_stub_version[4+1]; // for internal debugging - char fake_stub_year[4+1]; // for internal debugging int force; int info_mode; bool ignorewarn; @@ -69,6 +66,14 @@ struct options_t { int verbose; bool to_stdout; + // debug options + struct { + int debug_level; + const char *dump_stub_loader; + char fake_stub_version[4+1]; // for internal debugging + char fake_stub_year[4+1]; // for internal debugging + } debug; + // overlay handling enum { SKIP_OVERLAY = 0, diff --git a/src/p_exe.cpp b/src/p_exe.cpp index c113348c..c33666a1 100644 --- a/src/p_exe.cpp +++ b/src/p_exe.cpp @@ -411,7 +411,7 @@ void PackExe::pack(OutputFile *fo) throwCantPack("decompressor limit exceeded, send a bugreport"); #ifdef TESTING - if (opt->debug) + if (opt->debug.debug_level) { printf("image+relocs %d -> %d\n",ih_imagesize+relocsize,ph.c_len); printf("offsets: %d - %d\nmatches: %d - %d\nruns: %d - %d\n", @@ -527,7 +527,7 @@ void PackExe::pack(OutputFile *fo) // write header + write loader + compressed file #ifdef TESTING - if (opt->debug) + if (opt->debug.debug_level) printf("\n%d %d %d %d\n",(int)sizeof(oh),e_len,packedsize,d_len); #endif fo->write(&oh,sizeof(oh)); diff --git a/src/p_w32pe.cpp b/src/p_w32pe.cpp index 1085a70e..f5983eaf 100644 --- a/src/p_w32pe.cpp +++ b/src/p_w32pe.cpp @@ -2098,7 +2098,8 @@ void PackW32Pe::pack(OutputFile *fo) fo->write(obuf,clen); infoWriting("compressed data", clen); fo->write(loader,codesize); - //OutputFile::dump("loader.dat", loader, codesize); + if (opt->debug.dump_stub_loader) + OutputFile::dump(opt->debug.dump_stub_loader, loader, codesize); if ((ic = fo->getBytesWritten() & 3) != 0) fo->write(ibuf,4 - ic); fo->write(otls,sotls); diff --git a/src/p_wcle.cpp b/src/p_wcle.cpp index 1757f8ca..7bb31ac2 100644 --- a/src/p_wcle.cpp +++ b/src/p_wcle.cpp @@ -48,8 +48,8 @@ static const #define LE_STUB_EDI (1) #ifdef TESTING -# define dputc(x,y) do { if (opt->debug) putc(x,y); } while (0) -# define Opt_debug opt->debug +# define dputc(x,y) do { if (opt->debug.debug_level) putc(x,y); } while (0) +# define Opt_debug opt->debug.debug_level #else # define dputc(x,y) ((void)0) # define Opt_debug 0 diff --git a/src/packer.cpp b/src/packer.cpp index d30dcd93..dbf78cf9 100644 --- a/src/packer.cpp +++ b/src/packer.cpp @@ -812,8 +812,8 @@ int Packer::patchVersion(void *b, int blen) checkPatch(b, blen, boff, 14); unsigned char *p = (unsigned char *)b + boff + 9; - if (opt->fake_stub_version[0]) - memcpy(p, opt->fake_stub_version, 4); + if (opt->debug.fake_stub_version[0]) + memcpy(p, opt->debug.fake_stub_version, 4); else memcpy(p, UPX_VERSION_STRING4, 4); @@ -828,8 +828,8 @@ int Packer::patchVersionYear(void *b, int blen) checkPatch(b, blen, boff, 11); unsigned char *p = (unsigned char *)b + boff + 6; - if (opt->fake_stub_year[0]) - memcpy(p, opt->fake_stub_year, 4); + if (opt->debug.fake_stub_year[0]) + memcpy(p, opt->debug.fake_stub_year, 4); else memcpy(p, UPX_VERSION_YEAR, 4); @@ -1012,7 +1012,7 @@ char const *Packer::getIdentstr(unsigned *size, int small) static char identtiny[] = UPX_VERSION_STRING4; static int done; - if (!done && (opt->fake_stub_version[0] || opt->fake_stub_year[0])) + if (!done && (opt->debug.fake_stub_version[0] || opt->debug.fake_stub_year[0])) { struct strinfo_t { char *s; int size; }; static const strinfo_t strlist[] = { @@ -1024,10 +1024,10 @@ char const *Packer::getIdentstr(unsigned *size, int small) for (iter = strlist; iter->s; ++iter) { - if (opt->fake_stub_version[0]) - mem_replace(iter->s, iter->size, UPX_VERSION_STRING4, 4, opt->fake_stub_version); - if (opt->fake_stub_year[0]) - mem_replace(iter->s, iter->size, UPX_VERSION_YEAR, 4, opt->fake_stub_year); + if (opt->debug.fake_stub_version[0]) + mem_replace(iter->s, iter->size, UPX_VERSION_STRING4, 4, opt->debug.fake_stub_version); + if (opt->debug.fake_stub_year[0]) + mem_replace(iter->s, iter->size, UPX_VERSION_YEAR, 4, opt->debug.fake_stub_year); } done = 1; }