1
0
mirror of https://github.com/upx/upx synced 2025-09-28 19:06:07 +08:00

Renamed the options sub-structs for more consistency. Some portab fixes.

committer: mfx <mfx> 1058221575 +0000
This commit is contained in:
Markus F.X.J. Oberhumer 2003-07-14 22:26:15 +00:00
parent f9054529c1
commit 48ec581539
18 changed files with 127 additions and 124 deletions

View File

@ -329,7 +329,7 @@ ifeq ($(target),bc)
o = .obj o = .obj
a = .lib a = .lib
e = .exe e = .exe
CC = bcc32 -q -6 CC = bcc32 -q -3
CFLAGS = -w -w-aus -w-inl -g1 CFLAGS = -w -w-aus -w-inl -g1
CFLAGS_OUTPUT = -o$@ CFLAGS_OUTPUT = -o$@
LDFLAGS = -ls LDFLAGS = -ls

View File

@ -221,6 +221,7 @@ class BE16
unsigned char d[2]; unsigned char d[2];
public: public:
BE16() { }
BE16& operator = (const BE16 &v) { memcpy(d, v.d, sizeof(d)); return *this; } BE16& operator = (const BE16 &v) { memcpy(d, v.d, sizeof(d)); return *this; }
BE16& operator = (unsigned v) { set_be16(d, v); return *this; } BE16& operator = (unsigned v) { set_be16(d, v); return *this; }
@ -239,6 +240,7 @@ class BE32
unsigned char d[4]; unsigned char d[4];
public: public:
BE32() { }
BE32& operator = (const BE32 &v) { memcpy(d, v.d, sizeof(d)); return *this; } BE32& operator = (const BE32 &v) { memcpy(d, v.d, sizeof(d)); return *this; }
BE32& operator = (unsigned v) { set_be32(d, v); return *this; } BE32& operator = (unsigned v) { set_be32(d, v); return *this; }
@ -257,6 +259,7 @@ class LE16
unsigned char d[2]; unsigned char d[2];
public: public:
LE16() { }
LE16& operator = (const LE16 &v) { memcpy(d, v.d, sizeof(d)); return *this; } LE16& operator = (const LE16 &v) { memcpy(d, v.d, sizeof(d)); return *this; }
LE16& operator = (unsigned v) { set_le16(d, v); return *this; } LE16& operator = (unsigned v) { set_le16(d, v); return *this; }
@ -275,6 +278,7 @@ class LE32
unsigned char d[4]; unsigned char d[4];
public: public:
LE32() { }
LE32& operator = (const LE32 &v) { memcpy(d, v.d, sizeof(d)); return *this; } LE32& operator = (const LE32 &v) { memcpy(d, v.d, sizeof(d)); return *this; }
LE32& operator = (unsigned v) { set_le32(d, v); return *this; } LE32& operator = (unsigned v) { set_le32(d, v); return *this; }

View File

@ -142,7 +142,7 @@ console_t console_init =
}; };
void con_fprintf(FILE *f, const char *format, ...) void __acc_cdecl con_fprintf(FILE *f, const char *format, ...)
{ {
va_list args; va_list args;
char buf[80*25]; char buf[80*25];

View File

@ -53,18 +53,18 @@
# if (__BORLANDC__ < 0x550) # if (__BORLANDC__ < 0x550)
# error "need Borland C++ 5.5 or newer" # error "need Borland C++ 5.5 or newer"
# endif # endif
# define __UPX_CDECL __cdecl
# if (__BORLANDC__ >= 0x560) # if (__BORLANDC__ >= 0x560)
# pragma warn -use # pragma warn -use
# endif # endif
#elif (ACC_CC_DMC) #elif (ACC_CC_DMC)
# define __UPX_CDECL __cdecl # if (__DMC__ < 0x829)
# error "need Digital Mars C++ 8.29 or newer"
# endif
#elif (ACC_CC_INTELC) #elif (ACC_CC_INTELC)
# if (__INTEL_COMPILER < 450) # if (__INTEL_COMPILER < 450)
# error "need Intel C++ 4.5 or newer" # error "need Intel C++ 4.5 or newer"
# endif # endif
# if (ACC_CC_WIN32 || ACC_CC_WIN64) # if (ACC_OS_WIN32 || ACC_OS_WIN64)
# define __UPX_CDECL __cdecl
# elif defined(__linux__) # elif defined(__linux__)
# pragma warning(error: 424) // #424: extra ";" ignored # pragma warning(error: 424) // #424: extra ";" ignored
# pragma warning(disable: 193) // #193: zero used for undefined preprocessing identifier # pragma warning(disable: 193) // #193: zero used for undefined preprocessing identifier
@ -78,8 +78,9 @@
# if (_MSC_VER < 1100) # if (_MSC_VER < 1100)
# error "need Visual C++ 5.0 or newer" # error "need Visual C++ 5.0 or newer"
# endif # endif
# define __UPX_CDECL __cdecl #if 0
# pragma warning(disable: 4096) // __cdecl + '...' # pragma warning(disable: 4096) // W2: '__cdecl' must be used with '...'
#endif
# pragma warning(disable: 4097) // W3: typedef-name 'A' used as synonym for class-name 'B' # pragma warning(disable: 4097) // W3: typedef-name 'A' used as synonym for class-name 'B'
# pragma warning(disable: 4511) // W3: 'class': copy constructor could not be generated # pragma warning(disable: 4511) // W3: 'class': copy constructor could not be generated
# pragma warning(disable: 4512) // W4: 'class': assignment operator could not be generated # pragma warning(disable: 4512) // W4: 'class': assignment operator could not be generated
@ -94,10 +95,6 @@
# endif # endif
#endif #endif
#if !defined(__UPX_CDECL)
# define __UPX_CDECL
#endif
/************************************************************************* /*************************************************************************
// //
@ -453,26 +450,26 @@ void printClearLine(FILE *f = NULL);
void printErr(const char *iname, const Throwable *e); void printErr(const char *iname, const Throwable *e);
void printUnhandledException(const char *iname, const std::exception *e); void printUnhandledException(const char *iname, const std::exception *e);
#if defined(__GNUC__) #if defined(__GNUC__)
void printErr(const char *iname, const char *format, ...) void __acc_cdecl printErr(const char *iname, const char *format, ...)
__attribute__((format(printf,2,3))); __attribute__((format(printf,2,3)));
void printWarn(const char *iname, const char *format, ...) void __acc_cdecl printWarn(const char *iname, const char *format, ...)
__attribute__((format(printf,2,3))); __attribute__((format(printf,2,3)));
#else #else
void printErr(const char *iname, const char *format, ...); void __acc_cdecl printErr(const char *iname, const char *format, ...);
void printWarn(const char *iname, const char *format, ...); void __acc_cdecl printWarn(const char *iname, const char *format, ...);
#endif #endif
#if defined(__GNUC__) #if defined(__GNUC__)
void infoWarning(const char *format, ...) void __acc_cdecl infoWarning(const char *format, ...)
__attribute__((format(printf,1,2))); __attribute__((format(printf,1,2)));
void infoHeader(const char *format, ...) void __acc_cdecl infoHeader(const char *format, ...)
__attribute__((format(printf,1,2))); __attribute__((format(printf,1,2)));
void info(const char *format, ...) void __acc_cdecl info(const char *format, ...)
__attribute__((format(printf,1,2))); __attribute__((format(printf,1,2)));
#else #else
void infoWarning(const char *format, ...); void __acc_cdecl infoWarning(const char *format, ...);
void infoHeader(const char *format, ...); void __acc_cdecl infoHeader(const char *format, ...);
void info(const char *format, ...); void __acc_cdecl info(const char *format, ...);
#endif #endif
void infoHeader(); void infoHeader();
void infoWriting(const char *what, long size); void infoWriting(const char *what, long size);

View File

@ -123,10 +123,10 @@ console_t;
#if defined(__GNUC__) #if defined(__GNUC__)
void con_fprintf(FILE *f, const char *format, ...) void __acc_cdecl con_fprintf(FILE *f, const char *format, ...)
__attribute__((format(printf,2,3))); __attribute__((format(printf,2,3)));
#else #else
void con_fprintf(FILE *f, const char *format, ...); void __acc_cdecl con_fprintf(FILE *f, const char *format, ...);
#endif #endif

View File

@ -65,13 +65,13 @@ void init_options(struct options_t *o)
#endif #endif
o->verbose = 2; o->verbose = 2;
o->w32pe.compress_exports = 1; o->win32_pe.compress_exports = 1;
o->w32pe.compress_icons = 2; o->win32_pe.compress_icons = 2;
o->w32pe.compress_resources = -1; o->win32_pe.compress_resources = -1;
for (unsigned i = 0; i < TABLESIZE(opt->w32pe.compress_rt); i++) for (unsigned i = 0; i < TABLESIZE(o->win32_pe.compress_rt); i++)
opt->w32pe.compress_rt[i] = -1; o->win32_pe.compress_rt[i] = -1;
opt->w32pe.compress_rt[24] = false; // 24 == RT_MANIFEST o->win32_pe.compress_rt[24] = false; // 24 == RT_MANIFEST
o->w32pe.strip_relocs = -1; o->win32_pe.strip_relocs = -1;
} }
static struct options_t global_options; static struct options_t global_options;
@ -403,7 +403,7 @@ char* prepare_shortopts(char *buf, const char *n,
template <class T> template <class T>
int getoptvar(T *var, T minval, T maxval) int getoptvar(T *var, const T minval, const T maxval)
{ {
const char *p = mfx_optarg; const char *p = mfx_optarg;
char *endptr; char *endptr;
@ -594,7 +594,7 @@ static int do_option(int optc, const char *arg)
getoptvar(&opt->crp.max_match, 16u, ~0u); getoptvar(&opt->crp.max_match, 16u, ~0u);
break; break;
case 537: case 537:
if (getoptvar(&opt->crp.m_size, 10000u, (unsigned)999999u) != 0) if (getoptvar(&opt->crp.m_size, 10000u, 999999u) != 0)
e_optval("--crp-ms="); e_optval("--crp-ms=");
break; break;
// backup // backup
@ -647,41 +647,41 @@ static int do_option(int optc, const char *arg)
break; break;
// //
case 600: case 600:
opt->dos.force_stub = true; opt->dos_exe.force_stub = true;
break; break;
case 601: case 601:
opt->dos.no_reloc = true; opt->dos_exe.no_reloc = true;
break; break;
case 610: case 610:
opt->djgpp2.coff = true; opt->djgpp2_coff.coff = true;
break; break;
case 620: case 620:
opt->wcle.le = true; opt->watcom_le.le = true;
break; break;
case 630: case 630:
opt->w32pe.compress_exports = 1; opt->win32_pe.compress_exports = 1;
getoptvar(&opt->w32pe.compress_exports, 0, 1); getoptvar(&opt->win32_pe.compress_exports, 0, 1);
//printf("compress_exports: %d\n", opt->w32pe.compress_exports); //printf("compress_exports: %d\n", opt->win32_pe.compress_exports);
break; break;
case 631: case 631:
opt->w32pe.compress_icons = 1; opt->win32_pe.compress_icons = 1;
getoptvar(&opt->w32pe.compress_icons, 0, 2); getoptvar(&opt->win32_pe.compress_icons, 0, 2);
//printf("compress_icons: %d\n", opt->w32pe.compress_icons); //printf("compress_icons: %d\n", opt->win32_pe.compress_icons);
break; break;
case 632: case 632:
opt->w32pe.compress_resources = true; opt->win32_pe.compress_resources = true;
if (mfx_optarg && strcmp(mfx_optarg,"0") == 0) if (mfx_optarg && strcmp(mfx_optarg,"0") == 0)
opt->w32pe.compress_resources = false; opt->win32_pe.compress_resources = false;
//printf("compress_resources: %d\n", opt->w32pe.compress_resources); //printf("compress_resources: %d\n", opt->win32_pe.compress_resources);
break; break;
case 633: case 633:
opt->w32pe.strip_relocs = 1; opt->win32_pe.strip_relocs = 1;
if (mfx_optarg && strcmp(mfx_optarg,"0") == 0) if (mfx_optarg && strcmp(mfx_optarg,"0") == 0)
opt->w32pe.strip_relocs = 0; opt->win32_pe.strip_relocs = 0;
//printf("strip_relocs: %d\n", opt->w32pe.strip_relocs); //printf("strip_relocs: %d\n", opt->win32_pe.strip_relocs);
break; break;
case 650: case 650:
opt->tos.split_segments = true; opt->atari_tos.split_segments = true;
break; break;
case 660: case 660:
getoptvar(&opt->unix.blocksize, 8192u, ~0u); getoptvar(&opt->unix.blocksize, 8192u, ~0u);
@ -698,7 +698,7 @@ static int do_option(int optc, const char *arg)
opt->unix.ptinterp = true; opt->unix.ptinterp = true;
break; break;
case 670: case 670:
opt->ps1.no_align = true; opt->ps1_exe.no_align = true;
break; break;
case '\0': case '\0':
@ -1044,6 +1044,7 @@ void upx_sanity_check(void)
COMPILE_TIME_ASSERT(((((unsigned)1 << 31) + 1) >> 31) == 1); COMPILE_TIME_ASSERT(((((unsigned)1 << 31) + 1) >> 31) == 1);
COMPILE_TIME_ASSERT(((((acc_uint64l_t)1 << 63) + 1) >> 63) == 1); COMPILE_TIME_ASSERT(((((acc_uint64l_t)1 << 63) + 1) >> 63) == 1);
#if !defined(ACC_CC_WATCOMC)
struct foo1a_t { char c1; LE16 v[4]; } __attribute_packed; struct foo1a_t { char c1; LE16 v[4]; } __attribute_packed;
struct align_assertion_1a_t { foo1a_t d[3]; } __attribute_packed; struct align_assertion_1a_t { foo1a_t d[3]; } __attribute_packed;
struct foo1b_t { char c1; char v[4*2]; } __attribute_packed; struct foo1b_t { char c1; char v[4*2]; } __attribute_packed;
@ -1060,6 +1061,7 @@ void upx_sanity_check(void)
COMPILE_TIME_ASSERT(sizeof(align_assertion_2a_t) == sizeof(align_assertion_2b_t)); COMPILE_TIME_ASSERT(sizeof(align_assertion_2a_t) == sizeof(align_assertion_2b_t));
COMPILE_TIME_ASSERT(sizeof(align_assertion_1a_t) == 3*9); COMPILE_TIME_ASSERT(sizeof(align_assertion_1a_t) == 3*9);
COMPILE_TIME_ASSERT(sizeof(align_assertion_2a_t) == 3*17); COMPILE_TIME_ASSERT(sizeof(align_assertion_2a_t) == 3*17);
#endif
COMPILE_TIME_ASSERT(sizeof(UPX_VERSION_STRING4) == 4 + 1); COMPILE_TIME_ASSERT(sizeof(UPX_VERSION_STRING4) == 4 + 1);
assert(strlen(UPX_VERSION_STRING4) == 4); assert(strlen(UPX_VERSION_STRING4) == 4);

View File

@ -57,7 +57,6 @@ static int mcheck_init()
// //
**************************************************************************/ **************************************************************************/
MemBuffer::MemBuffer() : MemBuffer::MemBuffer() :
b(NULL), b_size(0) b(NULL), b_size(0)
{ {

View File

@ -130,7 +130,7 @@ void printErr(const char *iname, const Throwable *e)
} }
void printErr(const char *iname, const char *format, ...) void __acc_cdecl printErr(const char *iname, const char *format, ...)
{ {
va_list args; va_list args;
char buf[1024]; char buf[1024];
@ -143,7 +143,7 @@ void printErr(const char *iname, const char *format, ...)
} }
void printWarn(const char *iname, const char *format, ...) void __acc_cdecl printWarn(const char *iname, const char *format, ...)
{ {
va_list args; va_list args;
char buf[1024]; char buf[1024];
@ -200,7 +200,7 @@ void infoHeader()
info_header = 0; info_header = 0;
} }
void infoHeader(const char *format, ...) void __acc_cdecl infoHeader(const char *format, ...)
{ {
if (opt->info_mode <= 0) if (opt->info_mode <= 0)
return; return;
@ -214,7 +214,7 @@ void infoHeader(const char *format, ...)
} }
void info(const char *format, ...) void __acc_cdecl info(const char *format, ...)
{ {
if (opt->info_mode <= 0) if (opt->info_mode <= 0)
return; return;
@ -229,7 +229,7 @@ void info(const char *format, ...)
} }
void infoWarning(const char *format, ...) void __acc_cdecl infoWarning(const char *format, ...)
{ {
if (opt->info_mode <= 0) if (opt->info_mode <= 0)
{ {

View File

@ -99,18 +99,18 @@ struct options_t {
// options for various executable formats // options for various executable formats
struct { struct {
bool force_stub; bool split_segments;
bool no_reloc; } atari_tos;
} dos;
struct { struct {
bool coff; bool coff;
} djgpp2; } djgpp2_coff;
struct {
bool force_stub;
bool no_reloc;
} dos_exe;
struct { struct {
bool no_align; bool no_align;
} ps1; } ps1_exe;
struct {
bool split_segments;
} tos;
struct { struct {
unsigned blocksize; unsigned blocksize;
bool force_execve; // force the linux/386 execve format bool force_execve; // force the linux/386 execve format
@ -120,14 +120,14 @@ struct options_t {
} unix; } unix;
struct { struct {
bool le; bool le;
} wcle; } watcom_le;
struct { struct {
int compress_exports; int compress_exports;
int compress_icons; int compress_icons;
int compress_resources; int compress_resources;
signed char compress_rt[25]; // 25 == RT_LAST signed char compress_rt[25]; // 25 == RT_LAST
int strip_relocs; int strip_relocs;
} w32pe; } win32_pe;
}; };
extern struct options_t * volatile opt; extern struct options_t * volatile opt;

View File

@ -109,7 +109,7 @@ int PackDjgpp2::buildLoader(const Filter *ft)
void PackDjgpp2::handleStub(OutputFile *fo) void PackDjgpp2::handleStub(OutputFile *fo)
{ {
if (fo && !opt->djgpp2.coff) if (fo && !opt->djgpp2_coff.coff)
{ {
if (coff_offset > 0) if (coff_offset > 0)
{ {

View File

@ -72,7 +72,7 @@ int PackExe::fillExeHeader(struct exe_header_t *eh) const
#define oh (*eh) #define oh (*eh)
// fill new exe header // fill new exe header
int flag = 0; int flag = 0;
if (!opt->dos.no_reloc) if (!opt->dos_exe.no_reloc)
flag |= USEJUMP; flag |= USEJUMP;
if (ih.relocs == 0) if (ih.relocs == 0)
flag |= NORELOC; flag |= NORELOC;
@ -213,7 +213,7 @@ bool PackExe::canPack()
fi->readx(&offs,sizeof (offs)); fi->readx(&offs,sizeof (offs));
if (ih.relocoffs >= 0x40 && offs) if (ih.relocoffs >= 0x40 && offs)
{ {
if (opt->dos.force_stub) if (opt->dos_exe.force_stub)
opt->overlay = opt->COPY_OVERLAY; opt->overlay = opt->COPY_OVERLAY;
else else
throwCantPack("can't pack new-exe"); throwCantPack("can't pack new-exe");

View File

@ -318,7 +318,7 @@ void PackPs1::pack(OutputFile *fo)
oh.tx_len = ph.c_len + e_len + pad_code; oh.tx_len = ph.c_len + e_len + pad_code;
oh.epc = entry; oh.epc = entry;
if (!opt->ps1.no_align) if (!opt->ps1_exe.no_align)
{ {
pad = oh.tx_len; pad = oh.tx_len;
oh.tx_len = ALIGN_UP(oh.tx_len, CD_SEC); oh.tx_len = ALIGN_UP(oh.tx_len, CD_SEC);

View File

@ -580,7 +580,7 @@ void PackTos::pack(OutputFile *fo)
// set new file_hdr // set new file_hdr
memcpy(&oh, &ih, FH_SIZE); memcpy(&oh, &ih, FH_SIZE);
if (opt->tos.split_segments) if (opt->atari_tos.split_segments)
{ {
oh.fh_text = o_text; oh.fh_text = o_text;
oh.fh_data = o_data; oh.fh_data = o_data;

View File

@ -88,7 +88,7 @@ PackW32Pe::PackW32Pe(InputFile *f) : super(f)
//printf("pe_section_t %d\n", (int) sizeof(pe_section_t)); //printf("pe_section_t %d\n", (int) sizeof(pe_section_t));
COMPILE_TIME_ASSERT(sizeof(pe_header_t) == 248); COMPILE_TIME_ASSERT(sizeof(pe_header_t) == 248);
COMPILE_TIME_ASSERT(sizeof(pe_section_t) == 40); COMPILE_TIME_ASSERT(sizeof(pe_section_t) == 40);
COMPILE_TIME_ASSERT(RT_LAST == TABLESIZE(opt->w32pe.compress_rt)); COMPILE_TIME_ASSERT(RT_LAST == TABLESIZE(opt->win32_pe.compress_rt));
isection = NULL; isection = NULL;
oimport = NULL; oimport = NULL;
@ -391,7 +391,7 @@ void Reloc::finish(upx_byte *&p,unsigned &siz)
void PackW32Pe::processRelocs(Reloc *rel) // pass2 void PackW32Pe::processRelocs(Reloc *rel) // pass2
{ {
rel->finish(oxrelocs,soxrelocs); rel->finish(oxrelocs,soxrelocs);
if (opt->w32pe.strip_relocs && !isdll) if (opt->win32_pe.strip_relocs && !isdll)
soxrelocs = 0; soxrelocs = 0;
} }
@ -403,7 +403,7 @@ void PackW32Pe::processRelocs() // pass1
const unsigned *counts = rel.getcounts(); const unsigned *counts = rel.getcounts();
const unsigned rnum = counts[1] + counts[2] + counts[3]; const unsigned rnum = counts[1] + counts[2] + counts[3];
if ((opt->w32pe.strip_relocs && !isdll) || rnum == 0) if ((opt->win32_pe.strip_relocs && !isdll) || rnum == 0)
{ {
if (IDSIZE(PEDIR_RELOC)) if (IDSIZE(PEDIR_RELOC))
ibuf.fill(IDADDR(PEDIR_RELOC), IDSIZE(PEDIR_RELOC), FILLVAL); ibuf.fill(IDADDR(PEDIR_RELOC), IDSIZE(PEDIR_RELOC), FILLVAL);
@ -489,7 +489,7 @@ void PackW32Pe::processImports(unsigned myimport) // pass 2
unsigned PackW32Pe::processImports() // pass 1 unsigned PackW32Pe::processImports() // pass 1
{ {
static const upx_byte kernel32dll[] = "KERNEL32.DLL"; static const unsigned char kernel32dll[] = "KERNEL32.DLL";
static const char llgpa[] = "\x0\x0""LoadLibraryA\x0\x0""GetProcAddress\x0\x0"; static const char llgpa[] = "\x0\x0""LoadLibraryA\x0\x0""GetProcAddress\x0\x0";
static const char exitp[] = "ExitProcess\x0\x0\x0"; static const char exitp[] = "ExitProcess\x0\x0\x0";
@ -777,7 +777,7 @@ class Export
Interval iv; Interval iv;
public: public:
Export(char *base); Export(char *_base);
~Export(); ~Export();
void convert(unsigned eoffs,unsigned esize); void convert(unsigned eoffs,unsigned esize);
@ -785,6 +785,7 @@ public:
unsigned getsize() const { return size; } unsigned getsize() const { return size; }
private: private:
// disable copy and assignment
Export(const Export&); Export(const Export&);
Export& operator=(const Export&); Export& operator=(const Export&);
}; };
@ -850,7 +851,7 @@ void Export::convert(unsigned eoffs,unsigned esize)
names[ic + edir.names] = strdup(forw); names[ic + edir.names] = strdup(forw);
} }
else else
names[ic + edir.names] = 0; names[ic + edir.names] = NULL;
len = 2 * edir.names; len = 2 * edir.names;
ordinals = new char[len + 1]; ordinals = new char[len + 1];
@ -907,7 +908,7 @@ void PackW32Pe::processExports(Export *xport) // pass1
soexport = ALIGN_UP(IDSIZE(PEDIR_EXPORT),4); soexport = ALIGN_UP(IDSIZE(PEDIR_EXPORT),4);
if (soexport == 0) if (soexport == 0)
return; return;
if (!isdll && opt->w32pe.compress_exports) if (!isdll && opt->win32_pe.compress_exports)
{ {
infoWarning("exports compressed, --compress-exports=0 might be needed"); infoWarning("exports compressed, --compress-exports=0 might be needed");
soexport = 0; soexport = 0;
@ -1098,7 +1099,7 @@ public:
void init(const upx_byte *); void init(const upx_byte *);
unsigned dirsize() const {return ALIGN_UP(dsize + ssize,4);} unsigned dirsize() const {return ALIGN_UP(dsize + ssize,4);}
bool next() {return (current = current ? current->next : head) != 0;} // wow, builtin autorewind... :-) bool next() {return (current = current ? current->next : head) != NULL;} // wow, builtin autorewind... :-)
unsigned itype() const {return current->parent->parent->id;} unsigned itype() const {return current->parent->parent->id;}
const upx_byte *ntype() const {return current->parent->parent->name;} const upx_byte *ntype() const {return current->parent->parent->name;}
@ -1126,10 +1127,10 @@ void Resource::init(const upx_byte *res)
COMPILE_TIME_ASSERT(sizeof(res_data) == 16); COMPILE_TIME_ASSERT(sizeof(res_data) == 16);
start = res; start = res;
root = head = current = 0; root = head = current = NULL;
dsize = ssize = 0; dsize = ssize = 0;
check((const res_dir*) start,0); check((const res_dir*) start,0);
root = convert(start,0,0); root = convert(start,NULL,0);
} }
void Resource::check(const res_dir *node,unsigned level) void Resource::check(const res_dir *node,unsigned level)
@ -1153,7 +1154,7 @@ Resource::upx_rnode *Resource::convert(const void *rnode,upx_rnode *parent,unsig
{ {
const res_data *node = (const res_data *) rnode; const res_data *node = (const res_data *) rnode;
upx_rleaf *leaf = new upx_rleaf; upx_rleaf *leaf = new upx_rleaf;
leaf->name = 0; leaf->name = NULL;
leaf->parent = parent; leaf->parent = parent;
leaf->next = head; leaf->next = head;
leaf->newoffset = 0; leaf->newoffset = 0;
@ -1166,7 +1167,7 @@ Resource::upx_rnode *Resource::convert(const void *rnode,upx_rnode *parent,unsig
const res_dir *node = (const res_dir *) rnode; const res_dir *node = (const res_dir *) rnode;
upx_rbranch *branch = new upx_rbranch; upx_rbranch *branch = new upx_rbranch;
branch->name = 0; branch->name = NULL;
branch->parent = parent; branch->parent = parent;
int ic = branch->nc = node->identr + node->namedentr; int ic = branch->nc = node->identr + node->namedentr;
branch->children = new upx_rnode*[ic]; branch->children = new upx_rnode*[ic];
@ -1317,20 +1318,20 @@ void PackW32Pe::processResources(Resource *res)
return; return;
// setup default options for resource compression // setup default options for resource compression
if (opt->w32pe.compress_resources < 0) if (opt->win32_pe.compress_resources < 0)
opt->w32pe.compress_resources = true; opt->win32_pe.compress_resources = true;
if (!opt->w32pe.compress_resources) if (!opt->win32_pe.compress_resources)
{ {
opt->w32pe.compress_icons = false; opt->win32_pe.compress_icons = false;
for (int i = 0; i < RT_LAST; i++) for (int i = 0; i < RT_LAST; i++)
opt->w32pe.compress_rt[i] = false; opt->win32_pe.compress_rt[i] = false;
} }
if (opt->w32pe.compress_rt[RT_STRING] < 0) if (opt->win32_pe.compress_rt[RT_STRING] < 0)
{ {
// by default, don't compress RT_STRINGs of screensavers (".scr") // by default, don't compress RT_STRINGs of screensavers (".scr")
opt->w32pe.compress_rt[RT_STRING] = true; opt->win32_pe.compress_rt[RT_STRING] = true;
if (fn_has_ext(fi->getName(),"scr")) if (fn_has_ext(fi->getName(),"scr"))
opt->w32pe.compress_rt[RT_STRING] = false; opt->win32_pe.compress_rt[RT_STRING] = false;
} }
res->init(ibuf + vaddr); res->init(ibuf + vaddr);
@ -1341,7 +1342,7 @@ void PackW32Pe::processResources(Resource *res)
upx_byte *ores = oresources + res->dirsize(); upx_byte *ores = oresources + res->dirsize();
unsigned iconsin1stdir = 0; unsigned iconsin1stdir = 0;
if (opt->w32pe.compress_icons == 2) if (opt->win32_pe.compress_icons == 2)
while (res->next()) // there is no rewind() in Resource while (res->next()) // there is no rewind() in Resource
if (res->itype() == RT_GROUP_ICON && iconsin1stdir == 0) if (res->itype() == RT_GROUP_ICON && iconsin1stdir == 0)
iconsin1stdir = get_le16(ibuf + res->offs() + 4); iconsin1stdir = get_le16(ibuf + res->offs() + 4);
@ -1359,16 +1360,16 @@ void PackW32Pe::processResources(Resource *res)
{ {
const unsigned rtype = res->itype(); const unsigned rtype = res->itype();
bool do_compress = true; bool do_compress = true;
if (!opt->w32pe.compress_resources) if (!opt->win32_pe.compress_resources)
do_compress = false; do_compress = false;
else if (rtype == RT_VERSION) // version info else if (rtype == RT_VERSION) // version info
do_compress = false; do_compress = false;
else if (rtype == RT_ICON) // icon else if (rtype == RT_ICON) // icon
do_compress = compress_icon && opt->w32pe.compress_icons; do_compress = compress_icon && opt->win32_pe.compress_icons;
else if (rtype == RT_GROUP_ICON) // icon directory else if (rtype == RT_GROUP_ICON) // icon directory
do_compress = compress_idir && opt->w32pe.compress_icons; do_compress = compress_idir && opt->win32_pe.compress_icons;
else if (rtype > 0 && rtype < RT_LAST) else if (rtype > 0 && rtype < RT_LAST)
do_compress = opt->w32pe.compress_rt[rtype] ? true : false; do_compress = opt->win32_pe.compress_rt[rtype] ? true : false;
else if (res->ntype()) // named resource type else if (res->ntype()) // named resource type
{ {
const upx_byte * const t = res->ntype(); const upx_byte * const t = res->ntype();
@ -1394,10 +1395,10 @@ void PackW32Pe::processResources(Resource *res)
ibuf.fill(res->offs(), res->size(), FILLVAL); ibuf.fill(res->offs(), res->size(), FILLVAL);
res->newoffs() = ptr_diff(ores,oresources); res->newoffs() = ptr_diff(ores,oresources);
if (rtype == RT_ICON) if (rtype == RT_ICON)
compress_icon = (++iconcnt >= iconsin1stdir || opt->w32pe.compress_icons == 1); compress_icon = (++iconcnt >= iconsin1stdir || opt->win32_pe.compress_icons == 1);
else if (rtype == RT_GROUP_ICON) else if (rtype == RT_GROUP_ICON)
{ {
if (opt->w32pe.compress_icons == 1) if (opt->win32_pe.compress_icons == 1)
{ {
icondir_offset = 4 + ptr_diff(ores,oresources); icondir_offset = 4 + ptr_diff(ores,oresources);
icondir_count = get_le16(oresources + icondir_offset); icondir_count = get_le16(oresources + icondir_offset);
@ -1539,7 +1540,7 @@ int PackW32Pe::buildLoader(const Filter *ft)
void PackW32Pe::pack(OutputFile *fo) void PackW32Pe::pack(OutputFile *fo)
{ {
unsigned objs = ih.objects; const unsigned objs = ih.objects;
isection = new pe_section_t[objs]; isection = new pe_section_t[objs];
fi->seek(pe_offset+sizeof(ih),SEEK_SET); fi->seek(pe_offset+sizeof(ih),SEEK_SET);
fi->readx(isection,sizeof(pe_section_t)*objs); fi->readx(isection,sizeof(pe_section_t)*objs);
@ -1569,10 +1570,10 @@ void PackW32Pe::pack(OutputFile *fo)
//if (IDSIZE(PEDIR_DELAYIMP)) //if (IDSIZE(PEDIR_DELAYIMP))
// throwCantPack("delay load imports are not supported"); // throwCantPack("delay load imports are not supported");
if (isdll) if (isdll)
opt->w32pe.strip_relocs = 0; opt->win32_pe.strip_relocs = false;
else if (opt->w32pe.strip_relocs < 0) else if (opt->win32_pe.strip_relocs < 0)
opt->w32pe.strip_relocs = (ih.imagebase >= 0x400000); opt->win32_pe.strip_relocs = (ih.imagebase >= 0x400000);
if (opt->w32pe.strip_relocs) if (opt->win32_pe.strip_relocs)
if (ih.imagebase < 0x400000) if (ih.imagebase < 0x400000)
throwCantPack("--strip-relocs is not allowed when imagebase < 0x400000"); throwCantPack("--strip-relocs is not allowed when imagebase < 0x400000");
else else
@ -1819,7 +1820,7 @@ void PackW32Pe::pack(OutputFile *fo)
const unsigned esi0 = s1addr + ic; const unsigned esi0 = s1addr + ic;
patch_le32(loader,codesize,"EDI0", rvamin - esi0); patch_le32(loader,codesize,"EDI0", rvamin - esi0);
patch_le32(loader,codesize,"ESI0",esi0 + ih.imagebase); patch_le32(loader,codesize,"ESI0", esi0 + ih.imagebase);
ic = getLoaderSection("PEMAIN01") + 2 + upxsection; ic = getLoaderSection("PEMAIN01") + 2 + upxsection;
Reloc rel(1024); // new relocations are put here Reloc rel(1024); // new relocations are put here
@ -1865,7 +1866,7 @@ void PackW32Pe::pack(OutputFile *fo)
processExports(&xport,ic); processExports(&xport,ic);
ODADDR(PEDIR_EXPORT) = soexport ? ic : 0; ODADDR(PEDIR_EXPORT) = soexport ? ic : 0;
ODSIZE(PEDIR_EXPORT) = soexport; ODSIZE(PEDIR_EXPORT) = soexport;
if (!isdll && opt->w32pe.compress_exports) if (!isdll && opt->win32_pe.compress_exports)
{ {
ODADDR(PEDIR_EXPORT) = IDADDR(PEDIR_EXPORT); ODADDR(PEDIR_EXPORT) = IDADDR(PEDIR_EXPORT);
ODSIZE(PEDIR_EXPORT) = IDSIZE(PEDIR_EXPORT); ODSIZE(PEDIR_EXPORT) = IDSIZE(PEDIR_EXPORT);
@ -1927,7 +1928,7 @@ void PackW32Pe::pack(OutputFile *fo)
// oh.headersize = osection[0].rawdataptr; // oh.headersize = osection[0].rawdataptr;
oh.headersize = rvamin; oh.headersize = rvamin;
if (opt->w32pe.strip_relocs && !isdll) if (opt->win32_pe.strip_relocs && !isdll)
oh.flags |= RELOCS_STRIPPED; oh.flags |= RELOCS_STRIPPED;
//for (ic = 0; ic < oh.filealign; ic += 4) //for (ic = 0; ic < oh.filealign; ic += 4)
@ -2026,14 +2027,14 @@ int PackW32Pe::canUnpack()
if (is_packed && ih.entry < isection[2].vaddr) if (is_packed && ih.entry < isection[2].vaddr)
{ {
unsigned char buf[256]; unsigned char buf[256];
memset(buf, 0, sizeof(buf));
bool x = false; bool x = false;
memset(buf, 0, sizeof(buf));
try { try {
fi->seek(ih.entry - isection[1].vaddr + isection[1].rawdataptr, SEEK_SET); fi->seek(ih.entry - isection[1].vaddr + isection[1].rawdataptr, SEEK_SET);
fi->read(buf, sizeof(buf)); fi->read(buf, sizeof(buf));
static const char magic[] = "\x8b\x1e\x83\xee\xfc\x11\xdb"; static const unsigned char magic[] = "\x8b\x1e\x83\xee\xfc\x11\xdb";
// mov ebx, [esi]; sub esi, -4; adc ebx,ebx // mov ebx, [esi]; sub esi, -4; adc ebx,ebx
int offset = find(buf, sizeof(buf), magic, 7); int offset = find(buf, sizeof(buf), magic, 7);
@ -2194,7 +2195,7 @@ void PackW32Pe::rebuildRelocs(upx_byte *& extrainfo)
} }
rel.finish (oxrelocs,soxrelocs); rel.finish (oxrelocs,soxrelocs);
if (opt->w32pe.strip_relocs && !isdll) if (opt->win32_pe.strip_relocs && !isdll)
{ {
obuf.clear(ODADDR(PEDIR_RELOC) - rvamin, ODSIZE(PEDIR_RELOC)); obuf.clear(ODADDR(PEDIR_RELOC) - rvamin, ODSIZE(PEDIR_RELOC));
ODADDR(PEDIR_RELOC) = 0; ODADDR(PEDIR_RELOC) = 0;
@ -2214,7 +2215,7 @@ void PackW32Pe::rebuildExports()
if (ODSIZE(PEDIR_EXPORT) == 0 || ODADDR(PEDIR_EXPORT) == IDADDR(PEDIR_EXPORT)) if (ODSIZE(PEDIR_EXPORT) == 0 || ODADDR(PEDIR_EXPORT) == IDADDR(PEDIR_EXPORT))
return; // nothing to do return; // nothing to do
opt->w32pe.compress_exports = 0; opt->win32_pe.compress_exports = 0;
Export xport((char*)(unsigned char*) ibuf - isection[2].vaddr); Export xport((char*)(unsigned char*) ibuf - isection[2].vaddr);
processExports(&xport); processExports(&xport);
processExports(&xport,ODADDR(PEDIR_EXPORT)); processExports(&xport,ODADDR(PEDIR_EXPORT));
@ -2323,7 +2324,7 @@ void PackW32Pe::unpack(OutputFile *fo)
oh.chksum = 0; oh.chksum = 0;
// FIXME: ih.flags is checked here because of a bug in UPX 0.92 // FIXME: ih.flags is checked here because of a bug in UPX 0.92
if ((opt->w32pe.strip_relocs && !isdll) || (ih.flags & RELOCS_STRIPPED)) if ((opt->win32_pe.strip_relocs && !isdll) || (ih.flags & RELOCS_STRIPPED))
{ {
oh.flags |= RELOCS_STRIPPED; oh.flags |= RELOCS_STRIPPED;
ODADDR(PEDIR_RELOC) = 0; ODADDR(PEDIR_RELOC) = 0;

View File

@ -120,7 +120,7 @@ int PackWcle::buildLoader(const Filter *ft)
void PackWcle::handleStub(OutputFile *fo) void PackWcle::handleStub(OutputFile *fo)
{ {
if (fo && !opt->wcle.le) if (fo && !opt->watcom_le.le)
Packer::handleStub(fi,fo,le_offset); Packer::handleStub(fi,fo,le_offset);
} }
@ -540,7 +540,7 @@ void PackWcle::pack(OutputFile *fo)
patch_le32(oimage,e_len,"EDI0",((ic+d_len+3)&~3)-4); patch_le32(oimage,e_len,"EDI0",((ic+d_len+3)&~3)-4);
patch_le32(oimage,e_len,"ESI0",e_len+jpos*4-4); patch_le32(oimage,e_len,"ESI0",e_len+jpos*4-4);
writeFile(fo, opt->wcle.le); writeFile(fo, opt->watcom_le.le);
// copy the overlay // copy the overlay
const unsigned overlaystart = ih.data_pages_offset + exe_offset const unsigned overlaystart = ih.data_pages_offset + exe_offset
@ -827,7 +827,7 @@ void PackWcle::unpack(OutputFile *fo)
// write decompressed file // write decompressed file
if (fo) if (fo)
writeFile(fo, opt->wcle.le); writeFile(fo, opt->watcom_le.le);
// copy the overlay // copy the overlay
const unsigned overlaystart = ih.data_pages_offset + exe_offset const unsigned overlaystart = ih.data_pages_offset + exe_offset

View File

@ -153,7 +153,7 @@ static Packer* try_packers(InputFile *f, try_function func)
// //
// .exe // .exe
// //
if (!opt->dos.force_stub) if (!opt->dos_exe.force_stub)
{ {
if ((p = func(new PackDjgpp2(f),f)) != NULL) if ((p = func(new PackDjgpp2(f),f)) != NULL)
return p; return p;

View File

@ -795,13 +795,13 @@ static int xdopr(char *buffer, size_t maxlen, const char *format, va_list args)
} }
int __UPX_CDECL upx_vsnprintf(char *str, size_t count, const char *format, va_list ap) int __acc_cdecl upx_vsnprintf(char *str, size_t count, const char *format, va_list ap)
{ {
return xdopr(str, count, format, ap); return xdopr(str, count, format, ap);
} }
int __UPX_CDECL upx_snprintf(char *str, size_t count, const char *format,...) int __acc_cdecl upx_snprintf(char *str, size_t count, const char *format,...)
{ {
va_list ap; va_list ap;
int ret; int ret;
@ -813,7 +813,7 @@ int __UPX_CDECL upx_snprintf(char *str, size_t count, const char *format,...)
} }
int __UPX_CDECL upx_vasprintf(char **ptr, const char *format, va_list ap) int __acc_cdecl upx_vasprintf(char **ptr, const char *format, va_list ap)
{ {
int ret; int ret;
@ -832,7 +832,7 @@ int __UPX_CDECL upx_vasprintf(char **ptr, const char *format, va_list ap)
} }
int __UPX_CDECL upx_asprintf(char **ptr, const char *format, ...) int __acc_cdecl upx_asprintf(char **ptr, const char *format, ...)
{ {
va_list ap; va_list ap;
int ret; int ret;

View File

@ -38,10 +38,10 @@ extern "C" {
// //
**************************************************************************/ **************************************************************************/
int __UPX_CDECL upx_vsnprintf(char *str, size_t count, const char *format, va_list ap); int __acc_cdecl upx_vsnprintf(char *str, size_t count, const char *format, va_list ap);
int __UPX_CDECL upx_snprintf(char *str, size_t count, const char *format,...); int __acc_cdecl upx_snprintf(char *str, size_t count, const char *format,...);
int __UPX_CDECL upx_vasprintf(char **ptr, const char *format, va_list ap); int __acc_cdecl upx_vasprintf(char **ptr, const char *format, va_list ap);
int __UPX_CDECL upx_asprintf(char **ptr, const char *format, ...); int __acc_cdecl upx_asprintf(char **ptr, const char *format, ...);
#if 1 #if 1
# undef sprintf # undef sprintf