Upx_Doxygen
https://github.com/upx/upx
All Classes
lefile.h
1 /* lefile.h --
2 
3  This file is part of the UPX executable compressor.
4 
5  Copyright (C) 1996-2016 Markus Franz Xaver Johannes Oberhumer
6  Copyright (C) 1996-2016 Laszlo Molnar
7  All Rights Reserved.
8 
9  UPX and the UCL library are free software; you can redistribute them
10  and/or modify them under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of
12  the License, or (at your option) any later version.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; see the file COPYING.
21  If not, write to the Free Software Foundation, Inc.,
22  59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 
24  Markus F.X.J. Oberhumer Laszlo Molnar
25  <markus@oberhumer.com> <ezerotven+github@gmail.com>
26  */
27 
28 
29 #ifndef __UPX_LEFILE_H
30 #define __UPX_LEFILE_H 1
31 
32 class InputFile;
33 class OutputFile;
34 
35 
36 /*************************************************************************
37 //
38 **************************************************************************/
39 
40 class LeFile
41 {
42 public:
43  LeFile(InputFile *);
44  virtual ~LeFile();
45 
46  virtual bool readFileHeader();
47  virtual void writeFile(OutputFile *, bool);
48 
49 protected:
50  enum { FIXUP_EXTRA = 3 };
51 
52  __packed_struct(le_header_t)
53  // 0x00
54  char _[2]; // signature: 'LE' || 'LX'
55  char byte_order; // 0 little endian
56  char word_order; // 0 little endian
57  LE32 exe_format_level; // 0
58  LE16 cpu_type; // 1->286..4->586
59  LE16 target_os; // 1->OS2
60  char _0[4]; // module_version = 0
61  // 0x10
62  LE32 module_type; // 0x200->compatible with PM windowing
63  LE32 memory_pages;
64  LE32 init_cs_object;
65  LE32 init_eip_offset;
66  // 0x20
67  LE32 init_ss_object;
68  LE32 init_esp_offset;
69  LE32 memory_page_size;
70  LE32 bytes_on_last_page;
71  // 0x30
72  LE32 fixup_size;
73  char _1[4]; // fixup_checksum = 0
74  LE32 loader_size;
75  char _2[4]; // loader_checksum = 0
76  // 0x40
77  LE32 object_table_offset;
78  LE32 object_table_entries;
79  LE32 object_pagemap_offset;
80  LE32 object_iterate_data_map_offset;
81  // 0x50
82  char _3[4]; // resource_offset
83  LE32 resource_entries;
84  LE32 resident_names_offset;
85  LE32 entry_table_offset;
86  // 0x60
87  char _4[4]; // module_directives_table_offset = 0
88  LE32 module_directives_entries;
89  LE32 fixup_page_table_offset;
90  LE32 fixup_record_table_offset;
91  // 0x70
92  LE32 imported_modules_name_table_offset;
93  LE32 imported_modules_count;
94  LE32 imported_procedures_name_table_offset;
95  char _5[4]; // per_page_checksum_table_offset = 0
96  // 0x80
97  LE32 data_pages_offset;
98  char _6[4]; // preload_page_count = 0
99  LE32 non_resident_name_table_offset;
100  LE32 non_resident_name_table_length;
101  // 0x90
102  char _7[4]; //non_resident_names_checksum
103  LE32 automatic_data_object;
104 #if 1
105  char _8[44];
106 #else
107  LE32 debug_info_offset;
108  LE32 debug_info_length;
109  // 0xA0
110  LE32 preload_instance_pages;
111  LE32 demand_instance_pages;
112  LE32 extra_heap_alloc;
113  char reserved[12];
114  LE32 versioninfo;
115  LE32 unkown;
116  // 0xC0
117  LE16 device_id;
118  LE16 ddk_version;
119 #endif
120  __packed_struct_end()
121 
122  __packed_struct(le_object_table_entry_t)
123  LE32 virtual_size;
124  LE32 base_address;
125  LE32 flags;
126  LE32 pagemap_index;
127  LE32 npages;
128  LE32 reserved;
129  __packed_struct_end()
130 
131  __packed_struct(le_pagemap_entry_t)
132  unsigned char h;
133  unsigned char m;
134  unsigned char l;
135  unsigned char type; // 0x00-legal;0x40-iterated;0x80-invalid;0xC0-zeroed
136  __packed_struct_end()
137 
138  virtual void readObjectTable();
139  virtual void writeObjectTable();
140  //virtual void encodeObjectTable(){oobject_table = iobject_table; iobject_table = NULL;}
141  //virtual void decodeObjectTable(){encodeObjectTable();}
142 
143  virtual void readFixupPageTable();
144  virtual void writeFixupPageTable();
145  //virtual void encodeFixupPageTable(){ofpage_table = ifpage_table; ifpage_table = NULL;}
146  //virtual void decodeFixupPageTable(){encodeFixupPageTable();}
147 
148  virtual void readPageMap();
149  virtual void writePageMap();
150  virtual void encodePageMap(){opm_entries = ipm_entries; ipm_entries = NULL;}
151  virtual void decodePageMap(){encodePageMap();}
152 
153  virtual void readResidentNames();
154  virtual void writeResidentNames();
155  virtual void encodeResidentNames(){ores_names = ires_names; ires_names = NULL;}
156  virtual void decodeResidentNames(){encodeResidentNames();}
157 
158  virtual void readNonResidentNames();
159  virtual void writeNonResidentNames();
160  virtual void encodeNonResidentNames(){ononres_names = inonres_names; inonres_names = NULL;}
161  virtual void decodeNonResidentNames(){encodeNonResidentNames();}
162 
163  virtual void readEntryTable();
164  virtual void writeEntryTable();
165  //virtual void encodeEntryTable(){oentries = ientries; ientries = NULL;}
166  //virtual void decodeEntryTable(){encodeEntryTable();}
167 
168  virtual void readFixups();
169  virtual void writeFixups();
170  //virtual void encodeFixups(){ofixups = ifixups; ifixups = NULL;}
171  //virtual void decodeFixups(){encodeFixups();}
172 
173  virtual void readImage();
174  virtual void writeImage();
175  //virtual void encodeImage(){oimage = iimage; iimage = NULL;}
176  //virtual void decodeImage(){encodeImage();}
177 
178  void countFixups(unsigned *) const;
179  unsigned getImageSize() const;
180 
181  InputFile *fif;
182  OutputFile *fof;
183  unsigned le_offset;
184  unsigned exe_offset;
185 
186  le_header_t ih;
187  le_header_t oh;
188 
189  le_object_table_entry_t *iobject_table;
190  le_object_table_entry_t *oobject_table;
191  unsigned *ifpage_table;
192  unsigned *ofpage_table;
193  le_pagemap_entry_t *ipm_entries;
194  le_pagemap_entry_t *opm_entries;
195  upx_byte *ires_names;
196  upx_byte *ores_names;
197  upx_byte *ifixups;
198  upx_byte *ofixups;
199  upx_byte *inonres_names;
200  upx_byte *ononres_names;
201  MemBuffer iimage;
202  MemBuffer oimage;
203  upx_byte *ientries;
204  upx_byte *oentries;
205 
206  unsigned soobject_table;
207  unsigned sofpage_table;
208  unsigned sopm_entries;
209  unsigned sores_names;
210  unsigned sofixups;
211  unsigned sononres_names;
212  unsigned soimage;
213  unsigned soentries;
214 
215 private:
216  // disable copy and assignment
217  LeFile(const LeFile &); // {}
218  LeFile& operator= (const LeFile &); // { return *this; }
219 };
220 
221 
222 #endif /* already included */
223 
224 /* vim:set ts=4 sw=4 et: */
Definition: mem.h:37
Definition: file.h:89
Definition: lefile.h:40
Definition: file.h:121