6 #define IMAGE_DOS_MAGIC 0x5a4d
7 #define IMAGE_PE_MAGIC 0x00004550
9 #define IMAGE_SIZEOF_SHORT_NAME 8
11 #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
13 typedef unsigned char BYTE
;
14 typedef unsigned char UCHAR
;
15 typedef unsigned short WORD
;
16 typedef unsigned short USHORT
;
17 #if defined(__x86_64__) && defined(linux)
18 typedef signed int LONG
;
19 typedef unsigned int ULONG
;
20 typedef unsigned int DWORD
;
22 typedef signed long LONG
;
23 typedef unsigned long ULONG
;
24 typedef unsigned long DWORD
;
27 typedef unsigned __int64 ULONG_PTR
;
29 #if defined(__x86_64__) && defined(linux)
30 typedef unsigned int ULONG_PTR
;
32 typedef unsigned long ULONG_PTR
;
37 typedef struct _IMAGE_DOS_HEADER
{
57 } IMAGE_DOS_HEADER
,*PIMAGE_DOS_HEADER
;
60 #define IMAGE_FILE_LINE_NUMS_STRIPPED 4
61 #define IMAGE_FILE_LOCAL_SYMS_STRIPPED 8
62 #define IMAGE_FILE_DEBUG_STRIPPED 512
65 typedef struct _IMAGE_FILE_HEADER
{
67 WORD NumberOfSections
;
69 DWORD PointerToSymbolTable
;
70 DWORD NumberOfSymbols
;
71 WORD SizeOfOptionalHeader
;
73 } IMAGE_FILE_HEADER
, *PIMAGE_FILE_HEADER
;
75 typedef struct _IMAGE_DATA_DIRECTORY
{
78 } IMAGE_DATA_DIRECTORY
,*PIMAGE_DATA_DIRECTORY
;
80 #define IMAGE_DIRECTORY_ENTRY_BASERELOC 5
82 typedef struct _IMAGE_OPTIONAL_HEADER
{
84 BYTE MajorLinkerVersion
;
85 BYTE MinorLinkerVersion
;
87 DWORD SizeOfInitializedData
;
88 DWORD SizeOfUninitializedData
;
89 DWORD AddressOfEntryPoint
;
93 DWORD SectionAlignment
;
95 WORD MajorOperatingSystemVersion
;
96 WORD MinorOperatingSystemVersion
;
97 WORD MajorImageVersion
;
98 WORD MinorImageVersion
;
99 WORD MajorSubsystemVersion
;
100 WORD MinorSubsystemVersion
;
106 WORD DllCharacteristics
;
107 DWORD SizeOfStackReserve
;
108 DWORD SizeOfStackCommit
;
109 DWORD SizeOfHeapReserve
;
110 DWORD SizeOfHeapCommit
;
112 DWORD NumberOfRvaAndSizes
;
113 IMAGE_DATA_DIRECTORY DataDirectory
[IMAGE_NUMBEROF_DIRECTORY_ENTRIES
];
114 } IMAGE_OPTIONAL_HEADER
,*PIMAGE_OPTIONAL_HEADER
;
116 #define IMAGE_SCN_TYPE_NOLOAD 0x00000002
117 #define IMAGE_SCN_LNK_REMOVE 0x00000800
118 #define IMAGE_SCN_MEM_READ 0x40000000
119 #define IMAGE_SCN_MEM_DISCARDABLE 0x02000000
121 typedef struct _IMAGE_SECTION_HEADER
{
122 BYTE Name
[IMAGE_SIZEOF_SHORT_NAME
];
124 DWORD PhysicalAddress
;
127 DWORD VirtualAddress
;
129 DWORD PointerToRawData
;
130 DWORD PointerToRelocations
;
131 DWORD PointerToLinenumbers
;
132 WORD NumberOfRelocations
;
133 WORD NumberOfLinenumbers
;
134 DWORD Characteristics
;
135 } IMAGE_SECTION_HEADER
,*PIMAGE_SECTION_HEADER
;
137 typedef struct _IMAGE_BASE_RELOCATION
{
138 DWORD VirtualAddress
;
140 } IMAGE_BASE_RELOCATION
,*PIMAGE_BASE_RELOCATION
;
144 USHORT f_magic
; /* magic number */
145 USHORT f_nscns
; /* number of sections */
146 ULONG f_timdat
; /* time & date stamp */
147 ULONG f_symptr
; /* file pointer to symtab */
148 ULONG f_nsyms
; /* number of symtab entries */
149 USHORT f_opthdr
; /* sizeof(optional hdr) */
150 USHORT f_flags
; /* flags */
154 char s_name
[8]; /* section name */
155 ULONG s_paddr
; /* physical address, aliased s_nlib */
156 ULONG s_vaddr
; /* virtual address */
157 ULONG s_size
; /* section size */
158 ULONG s_scnptr
; /* file ptr to raw data for section */
159 ULONG s_relptr
; /* file ptr to relocation */
160 ULONG s_lnnoptr
; /* file ptr to line numbers */
161 USHORT s_nreloc
; /* number of relocation entries */
162 USHORT s_nlnno
; /* number of line number entries */
163 ULONG s_flags
; /* flags */
167 typedef struct _SYMBOLFILE_HEADER
{
172 } SYMBOLFILE_HEADER
, *PSYMBOLFILE_HEADER
;
174 typedef struct _STAB_ENTRY
{
175 ULONG n_strx
; /* index into string table of name */
176 UCHAR n_type
; /* type of symbol */
177 UCHAR n_other
; /* misc info (usually empty) */
178 USHORT n_desc
; /* description field */
179 ULONG n_value
; /* value of symbol */
180 } STAB_ENTRY
, *PSTAB_ENTRY
;
186 /* COFF symbol table */
188 #define E_SYMNMLEN 8 /* # characters in a symbol name */
189 #define E_FILNMLEN 14 /* # characters in a file name */
190 #define E_DIMNUM 4 /* # array dimensions in auxiliary entry */
192 #define N_BTMASK (0xf)
193 #define N_TMASK (0x30)
197 /* derived types, in e_type */
198 #define DT_NON (0) /* no derived type */
199 #define DT_PTR (1) /* pointer */
200 #define DT_FCN (2) /* function */
201 #define DT_ARY (3) /* array */
203 #define BTYPE(x) ((x) & N_BTMASK)
205 #define ISPTR(x) (((x) & N_TMASK) == (DT_PTR << N_BTSHFT))
206 #define ISFCN(x) (((x) & N_TMASK) == (DT_FCN << N_BTSHFT))
207 #define ISARY(x) (((x) & N_TMASK) == (DT_ARY << N_BTSHFT))
208 #define ISTAG(x) ((x)==C_STRTAG||(x)==C_UNTAG||(x)==C_ENTAG)
209 #define DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK))
211 #define C_EFCN 0xff /* physical end of function */
213 #define C_AUTO 1 /* automatic variable */
214 #define C_EXT 2 /* external symbol */
215 #define C_STAT 3 /* static */
216 #define C_REG 4 /* register variable */
217 #define C_EXTDEF 5 /* external definition */
218 #define C_LABEL 6 /* label */
219 #define C_ULABEL 7 /* undefined label */
220 #define C_MOS 8 /* member of structure */
221 #define C_ARG 9 /* function argument */
222 #define C_STRTAG 10 /* structure tag */
223 #define C_MOU 11 /* member of union */
224 #define C_UNTAG 12 /* union tag */
225 #define C_TPDEF 13 /* type definition */
226 #define C_USTATIC 14 /* undefined static */
227 #define C_ENTAG 15 /* enumeration tag */
228 #define C_MOE 16 /* member of enumeration */
229 #define C_REGPARM 17 /* register parameter */
230 #define C_FIELD 18 /* bit field */
231 #define C_AUTOARG 19 /* auto argument */
232 #define C_LASTENT 20 /* dummy entry (end of block) */
233 #define C_BLOCK 100 /* ".bb" or ".eb" */
234 #define C_FCN 101 /* ".bf" or ".ef" */
235 #define C_EOS 102 /* end of structure */
236 #define C_FILE 103 /* file name */
237 #define C_LINE 104 /* line # reformatted as symbol table entry */
238 #define C_ALIAS 105 /* duplicate tag */
239 #define C_HIDDEN 106 /* ext symbol in dmert public lib */
242 typedef struct _COFF_SYMENT
246 char e_name
[E_SYMNMLEN
];
260 } COFF_SYMENT
, *PCOFF_SYMENT
;
263 typedef struct _ROSSYM_ENTRY
{
265 ULONG FunctionOffset
;
268 } ROSSYM_ENTRY
, *PROSSYM_ENTRY
;
270 #define ROUND_UP(N, S) (((N) + (S) - 1) & ~((S) - 1))
273 convert_path(const char* origpath
);
276 load_file ( const char* file_name
, size_t* file_size
);