29 #ifndef __UPX_PEFILE_H 30 #define __UPX_PEFILE_H 1 50 virtual int getVersion()
const {
return 13; }
52 void readSectionHeaders(
unsigned objs,
unsigned sizeof_ih);
53 unsigned readSections(
unsigned objs,
unsigned usize,
54 unsigned ih_filealign,
unsigned ih_datasize);
55 void checkHeaderValues(
unsigned subsystem,
unsigned mask,
56 unsigned ih_entry,
unsigned ih_filealign);
57 unsigned handleStripRelocs(upx_uint64_t ih_imagebase,
58 upx_uint64_t default_imagebase,
61 virtual bool handleForceOption() = 0;
62 virtual void callCompressWithFilters(
Filter &,
int filter_strategy,
63 unsigned ih_codebase);
64 virtual void defineSymbols(
unsigned ncsection,
unsigned upxsection,
65 unsigned sizeof_oh,
unsigned isize_isplit,
66 Reloc &rel,
unsigned s1addr) = 0;
67 virtual void addNewRelocations(
Reloc &,
unsigned) {}
68 void callProcessRelocs(
Reloc &rel,
unsigned &ic);
69 void callProcessResources(
Resource &res,
unsigned &ic);
70 virtual unsigned getProcessImportParam(
unsigned) {
return 0; }
71 virtual void setOhDataBase(
const pe_section_t *osection) = 0;
72 virtual void setOhHeaderSize(
const pe_section_t *osection) = 0;
74 template <
typename LEXX,
typename ht>
76 unsigned subsystem_mask, upx_uint64_t default_imagebase,
77 bool last_section_rsrc_only);
79 template <
typename ht,
typename LEXX,
typename ord_mask_t>
80 void unpack0(
OutputFile *fo,
const ht &ih, ht &oh,
81 ord_mask_t ord_mask,
bool set_oft);
84 virtual bool canUnpackVersion(
int version)
const 85 {
return (version >= 12 && version <= 13); }
87 int canUnpack0(
unsigned max_sections, LE16 &ih_objects,
88 LE32 &ih_entry,
unsigned ihsize);
91 virtual int readFileHeader();
92 virtual bool testUnpackVersion(
int version)
const;
93 virtual void readPeHeader() = 0;
97 template <
typename LEXX,
typename ord_mask_t>
98 unsigned processImports0(ord_mask_t ord_mask);
100 template <
typename LEXX,
typename ord_mask_t>
101 void rebuildImports(upx_byte *& extrainfo,
102 ord_mask_t ord_mask,
bool set_oft);
103 virtual unsigned processImports() = 0;
104 virtual void processImports2(
unsigned,
unsigned);
109 ImportLinker *ilinker;
110 virtual const char *kernelDll()
const {
return "KERNEL32.DLL"; }
111 void addKernelImport(
const char *);
112 virtual void addStubImports();
113 upx_uint64_t ilinkerGetAddress(
const char *,
const char *)
const;
115 virtual void processRelocs() = 0;
116 void processRelocs(
Reloc *);
117 void rebuildRelocs(upx_byte *&,
unsigned bits,
118 unsigned flags, upx_uint64_t imagebase);
124 void processExports(
Export *);
125 void processExports(
Export *,
unsigned);
126 void rebuildExports();
131 void processResources(
Resource *,
unsigned);
132 void rebuildResources(upx_byte *&,
unsigned);
133 upx_byte *oresources;
134 unsigned soresources;
138 template <
typename LEXX>
142 template <
typename LEXX>
143 void processTls2(
Reloc *rel,
const Interval *iv,
unsigned newaddr,
145 virtual void processTls(
Interval *iv) = 0;
146 virtual void processTls(
Reloc *r,
const Interval *iv,
unsigned a) = 0;
153 unsigned tls_handler_offset;
154 bool use_tls_callbacks;
161 unsigned stripDebug(
unsigned);
163 unsigned icondir_offset;
166 bool importbyordinal;
167 bool kernel32ordinal;
173 __packed_struct(ddirs_t)
176 __packed_struct_end()
180 LE32 &IDSIZE(
unsigned x) {
return iddirs[x].size; }
181 LE32 &IDADDR(
unsigned x) {
return iddirs[x].vaddr; }
182 LE32 &ODSIZE(
unsigned x) {
return oddirs[x].size; }
183 LE32 &ODADDR(
unsigned x) {
return oddirs[x].vaddr; }
185 __packed_struct(pe_section_t)
193 __packed_struct_end()
195 pe_section_t *isection;
199 bool use_clear_dirty_stack;
202 static
unsigned virta2objnum (
unsigned, pe_section_t *,
unsigned);
203 unsigned tryremove (
unsigned,
unsigned);
228 PEFL_EXTRELS = 0x01000000,
229 PEFL_DISCARD = 0x02000000,
230 PEFL_NOCACHE = 0x04000000,
231 PEFL_NOPAGE = 0x08000000,
232 PEFL_SHARED = 0x10000000,
233 PEFL_EXEC = 0x20000000,
234 PEFL_READ = 0x40000000,
235 PEFL_WRITE = 0x80000000
239 RELOCS_STRIPPED = 0x0001,
241 LNUM_STRIPPED = 0x0004,
242 LSYMS_STRIPPED = 0x0008,
243 AGGRESSIVE_TRIM = 0x0010,
244 TWO_GIGS_AWARE = 0x0020,
245 FLITTLE_ENDIAN = 0x0080,
246 BITS_32_MACHINE = 0x0100,
247 DEBUG_STRIPPED = 0x0200,
248 REMOVABLE_SWAP = 0x0400,
249 SYSTEM_PROGRAM = 0x1000,
256 IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE = 0x0040,
257 IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY = 0x0080,
258 IMAGE_DLL_CHARACTERISTICS_NX_COMPAT = 0x0100,
259 IMAGE_DLLCHARACTERISTICS_NO_ISOLATION = 0x0200,
260 IMAGE_DLLCHARACTERISTICS_NO_SEH = 0x0400,
261 IMAGE_DLLCHARACTERISTICS_NO_BIND = 0x0800,
262 IMAGE_DLLCHARACTERISTICS_WDM_DRIVER = 0x2000,
263 IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE = 0x8000
268 RT_CURSOR = 1, RT_BITMAP, RT_ICON, RT_MENU, RT_DIALOG, RT_STRING,
269 RT_FONTDIR, RT_FONT, RT_ACCELERATOR, RT_RCDATA, RT_MESSAGETABLE,
270 RT_GROUP_CURSOR, RT_GROUP_ICON = 14, RT_VERSION = 16, RT_DLGINCLUDE,
271 RT_PLUGPLAY = 19, RT_VXD, RT_ANICURSOR, RT_ANIICON, RT_HTML,
290 void add(
unsigned start,
unsigned len);
291 void add(
const void *start,
unsigned len);
292 void add(
const void *start,
const void *end);
300 static int __acc_cdecl_qsort compare(
const void *p1,
const void *p2);
308 void newRelocPos(
void *p);
316 Reloc(upx_byte *,
unsigned);
317 Reloc(
unsigned rnum);
319 bool next(
unsigned &pos,
unsigned &type);
320 const unsigned *getcounts()
const {
return counts; }
322 void add(
unsigned pos,
unsigned type);
323 void finish(upx_byte *&p,
unsigned &size);
328 struct res_dir_entry;
335 const upx_byte *start;
343 const upx_byte *ibufstart;
344 const upx_byte *ibufend;
346 void check(
const res_dir*,
unsigned);
347 upx_rnode *convert(
const void *,upx_rnode *,
unsigned);
348 void build(
const upx_rnode *,
unsigned &,
unsigned &,
unsigned);
349 void clear(upx_byte *,
unsigned,
Interval *);
350 void dump(
const upx_rnode *,
unsigned)
const;
351 void destroy(upx_rnode *urd,
unsigned level);
353 void ibufcheck(
const void *m,
unsigned size);
356 Resource(
const upx_byte *ibufstart,
const upx_byte *ibufen);
357 Resource(
const upx_byte *p,
const upx_byte *ibufstart,
358 const upx_byte *ibufend);
360 void init(
const upx_byte *);
362 unsigned dirsize()
const;
365 unsigned itype()
const;
366 const upx_byte *ntype()
const;
367 unsigned size()
const;
368 unsigned offs()
const;
375 unsigned iname()
const;
376 const upx_byte *nname()
const;
385 __packed_struct(export_dir_t)
394 __packed_struct_end()
410 void convert(
unsigned eoffs,
unsigned esize);
411 void build(
char *base,
unsigned newoffs);
412 unsigned getsize()
const {
return size; }
423 void pack0(
OutputFile *fo,
unsigned subsystem_mask,
424 upx_uint64_t default_imagebase,
bool last_section_rsrc_only);
426 virtual int canUnpack();
428 virtual void readPeHeader();
430 virtual unsigned processImports();
431 virtual void processRelocs();
432 virtual void processTls(
Interval *);
435 __packed_struct(pe_header_t)
472 __packed_struct_end()
484 void pack0(
OutputFile *fo,
unsigned subsystem_mask,
485 upx_uint64_t default_imagebase);
488 virtual int canUnpack();
490 virtual void readPeHeader();
492 virtual unsigned processImports();
493 virtual void processRelocs();
494 virtual void processTls(
Interval *);
497 __packed_struct(pe_header_t)
534 __packed_struct_end()
Definition: pefile.cpp:1462
Definition: pefile.cpp:1455