Rizin
unix-like reverse engineering framework and cli tools
coff_specs.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2014 Fedor Sakharov <fedor.sakharov@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 #ifndef COFF_SPECS_H
4 #define COFF_SPECS_H
5 
6 #include <rz_types_base.h>
7 
8 #define COFF_FILE_MACHINE_UNKNOWN 0x0
9 #define COFF_FILE_MACHINE_AM33 0x1d3
10 #define COFF_FILE_MACHINE_AMD64 0x8664
11 #define COFF_FILE_MACHINE_ARM 0x1c0
12 #define COFF_FILE_MACHINE_ARMNT 0x1c4
13 #define COFF_FILE_MACHINE_ARM64 0xaa64
14 #define COFF_FILE_MACHINE_EBC 0xebc
15 #define COFF_FILE_MACHINE_I386 0x14c
16 #define COFF_FILE_MACHINE_IA64 0x200
17 #define COFF_FILE_MACHINE_M32R 0x9041
18 #define COFF_FILE_MACHINE_MIPS16 0x266
19 #define COFF_FILE_MACHINE_MIPSFPU 0x366
20 #define COFF_FILE_MACHINE_MIPSFPU16 0x466
21 #define COFF_FILE_MACHINE_AMD29KBE 0x7a01
22 #define COFF_FILE_MACHINE_AMD29KLE 0x17a
23 #define COFF_FILE_MACHINE_POWERPC 0x1f0
24 #define COFF_FILE_MACHINE_POWERPCFP 0x1f1
25 #define COFF_FILE_MACHINE_R4000 0x166
26 #define COFF_FILE_MACHINE_SH3 0x1a2
27 #define COFF_FILE_MACHINE_SH3DSP 0x1a3
28 #define COFF_FILE_MACHINE_SH4 0x1a6
29 #define COFF_FILE_MACHINE_SH5 0x1a8
30 #define COFF_FILE_MACHINE_THUMB 0x1c2
31 #define COFF_FILE_MACHINE_WCEMIPSV2 0x169
32 #define COFF_FILE_MACHINE_H8300 0x0083
33 
34 #define COFF_FILE_TI_COFF 0xc1
35 #define COFF_FILE_MACHINE_TMS470 0x0097
36 #define COFF_FILE_MACHINE_TMS320C54 0x0098
37 #define COFF_FILE_MACHINE_TMS320C60 0x0099
38 #define COFF_FILE_MACHINE_TMS320C55 0x009C
39 #define COFF_FILE_MACHINE_TMS320C28 0x009D
40 #define COFF_FILE_MACHINE_MSP430 0x00A0
41 #define COFF_FILE_MACHINE_TMS320C55PLUS 0x00A1
42 
43 #define COFF_FLAGS_TI_F_RELFLG 0x0001
44 #define COFF_FLAGS_TI_F_EXEC 0x0002
45 #define COFF_FLAGS_TI_F_LNNO 0x0004
46 #define COFF_FLAGS_TI_F_LSYMS 0x0008
47 #define COFF_FLAGS_TI_F_BIG 0x0200
48 #define COFF_FLAGS_TI_F_LITTLE 0x0100
49 
50 #define COFF_SCN_TYPE_NO_PAD 0x00000008
51 #define COFF_SCN_CNT_CODE 0x00000020
52 #define COFF_SCN_CNT_INIT_DATA 0x00000040
53 #define COFF_SCN_LNK_OTHER 0x00000100
54 #define COFF_SCN_LNK_INFO 0x00000200
55 #define COFF_SCN_LNK_REMOVE 0x00000800
56 #define COFF_SCN_LNK_COMDAT 0x00001000
57 #define COFF_SCN_GPREL 0x00008000
58 #define COFF_SCN_MEM_PURGEABLE 0x00010000
59 #define COFF_SCN_MEM_16BIT 0x00020000
60 #define COFF_SCN_MEM_LOCKED 0x00040000
61 #define COFF_SCN_MEM_PRELOAD 0x00080000
62 #define COFF_SCN_ALIGN_1BYTES 0x00100000
63 #define COFF_SCN_ALIGN_2BYTES 0x00200000
64 #define COFF_SCN_ALIGN_4BYTES 0x00300000
65 #define COFF_SCN_ALIGN_8BYTES 0x00400000
66 #define COFF_SCN_ALIGN_16BYTES 0x00500000
67 #define COFF_SCN_ALIGN_32BYTES 0x00600000
68 #define COFF_SCN_ALIGN_64BYTES 0x00700000
69 #define COFF_SCN_ALIGN_128BYTES 0x00800000
70 #define COFF_SCN_ALIGN_256BYTES 0x00900000
71 #define COFF_SCN_ALIGN_512BYTES 0x00A00000
72 #define COFF_SCN_ALIGN_1024BYTES 0x00B00000
73 #define COFF_SCN_ALIGN_2048BYTES 0x00C00000
74 #define COFF_SCN_ALIGN_4096BYTES 0x00D00000
75 #define COFF_SCN_ALIGN_8192BYTES 0x00E00000
76 #define COFF_SCN_LNK_NRELOC_OVFL 0x01000000
77 #define COFF_SCN_MEM_DISCARDABLE 0x02000000
78 #define COFF_SCN_MEM_NOT_CACHED 0x04000000
79 #define COFF_SCN_MEM_NOT_PAGED 0x08000000
80 #define COFF_SCN_MEM_SHARED 0x10000000
81 #define COFF_SCN_MEM_EXECUTE 0x20000000
82 #define COFF_SCN_MEM_READ 0x40000000
83 #define COFF_SCN_MEM_WRITE 0x80000000
84 
85 #define COFF_SYM_SCNUM_UNDEF 0
86 #define COFF_SYM_SCNUM_ABS 0xffff
87 #define COFF_SYM_SCNUM_DEBUG 0xfffe
88 
89 #define COFF_SYM_TYPE_NULL 0
90 #define COFF_SYM_TYPE_VOID 1
91 #define COFF_SYM_TYPE_CHAR 2
92 #define COFF_SYM_TYPE_SHORT 3
93 #define COFF_SYM_TYPE_INT 4
94 #define COFF_SYM_TYPE_LONG 5
95 #define COFF_SYM_TYPE_FLOAT 6
96 #define COFF_SYM_TYPE_DOUBLE 7
97 #define COFF_SYM_TYPE_STRUCT 8
98 #define COFF_SYM_TYPE_UNION 9
99 #define COFF_SYM_TYPE_ENUM 10
100 #define COFF_SYM_TYPE_MOE 11
101 #define COFF_SYM_TYPE_BYTE 12
102 #define COFF_SYM_TYPE_WORD 13
103 #define COFF_SYM_TYPE_UINT 14
104 #define COFF_SYM_TYPE_DWORD 15
105 
106 #define COFF_SYM_DTYPE_NULL 0
107 #define COFF_SYM_DTYPE_POINTER 1
108 #define COFF_SYM_DTYPE_FUNCTION 2
109 #define COFF_SYM_DTYPE_ARRAY 3
110 
111 #define COFF_SYM_CLASS_END_OF_FUNCTION 0xFF
112 #define COFF_SYM_CLASS_NULL 0
113 #define COFF_SYM_CLASS_AUTOMATIC 1
114 #define COFF_SYM_CLASS_EXTERNAL 2
115 #define COFF_SYM_CLASS_STATIC 3
116 #define COFF_SYM_CLASS_REGISTER 4
117 #define COFF_SYM_CLASS_EXTERNAL_DEF 5
118 #define COFF_SYM_CLASS_LABEL 6
119 #define COFF_SYM_CLASS_UNDEFINED_LABEL 7
120 #define COFF_SYM_CLASS_MEMBER_OF_STRUCT 8
121 #define COFF_SYM_CLASS_ARGUMENT 9
122 #define COFF_SYM_CLASS_STRUCT_TAG 10
123 #define COFF_SYM_CLASS_MEMBER_OF_UNION 11
124 #define COFF_SYM_CLASS_UNION_TAG 12
125 #define COFF_SYM_CLASS_TYPE_DEFINITION 13
126 #define COFF_SYM_CLASS_UNDEFINED_STATIC 14
127 #define COFF_SYM_CLASS_ENUM_TAG 15
128 #define COFF_SYM_CLASS_MEMBER_OF_ENUM 16
129 #define COFF_SYM_CLASS_REGISTER_PARAM 17
130 #define COFF_SYM_CLASS_BIT_FIELD 18
131 #define COFF_SYM_CLASS_BLOCK 100
132 #define COFF_SYM_CLASS_FUNCTION 101
133 #define COFF_SYM_CLASS_END_OF_STRUCT 102
134 #define COFF_SYM_CLASS_FILE 103
135 #define COFF_SYM_CLASS_SECTION 104
136 #define COFF_SYM_CLASS_WEAK_EXTERNAL 105
137 #define COFF_SYM_CLASS_CLR_TOKEN 107
138 
139 #define COFF_REL_I386_ABS 0
140 #define COFF_REL_I386_DIR16 1
141 #define COFF_REL_I386_REL16 2
142 #define COFF_REL_I386_DIR32 6
143 #define COFF_REL_I386_DIR32NB 7
144 #define COFF_REL_I386_REL32 20
145 
146 #define COFF_REL_AMD64_ABS 0
147 #define COFF_REL_AMD64_ADDR64 1
148 #define COFF_REL_AMD64_ADDR32 2
149 #define COFF_REL_AMD64_ADDR32_NB 3
150 #define COFF_REL_AMD64_REL32 4
151 #define COFF_REL_AMD64_REL32_1 5
152 #define COFF_REL_AMD64_REL32_2 6
153 #define COFF_REL_AMD64_REL32_3 7
154 #define COFF_REL_AMD64_REL32_4 8
155 #define COFF_REL_AMD64_REL32_5 9
156 
157 #define COFF_REL_ARM_BRANCH24T 20
158 #define COFF_REL_ARM_BLX23T 21
159 
160 #define COFF_REL_ARM64_ABSOLUTE 0
161 #define COFF_REL_ARM64_ADDR32 1
162 #define COFF_REL_ARM64_ADDR32NB 2
163 #define COFF_REL_ARM64_BRANCH26 3
164 
166  struct coff_hdr {
167  ut16 f_magic; /* Magic number */
168  ut16 f_nscns; /* Number of Sections */
169  ut32 f_timdat; /* Time & date stamp */
170  ut32 f_symptr; /* File pointer to Symbol Table */
171  ut32 f_nsyms; /* Number of Symbols */
172  ut16 f_opthdr; /* sizeof(Optional Header) */
173  ut16 f_flags; /* Flags */
174  }); // __attribute__ ((packed));
175 
177  struct coff_opt_hdr {
178  ut16 magic; /* Magic Number */
179  ut16 vstamp; /* Version stamp */
180  ut32 tsize; /* Text size in bytes */
181  ut32 dsize; /* Initialised data size */
182  ut32 bsize; /* Uninitialised data size */
183  ut32 entry; /* Entry point */
184  ut32 text_start; /* Base of Text used for this file */
185  ut32 data_start; /* Base of Data used for this file */
186  });
187 
189  struct coff_scn_hdr {
190  char s_name[8]; /* Section Name */
191  ut32 s_paddr; /* Physical Address */
192  ut32 s_vaddr; /* Virtual Address */
193  ut32 s_size; /* Section Size in Bytes */
194  ut32 s_scnptr; /* File offset to the Section data */
195  ut32 s_relptr; /* File offset to the Relocation table for this Section */
196  ut32 s_lnnoptr; /* File offset to the Line Number table for this Section */
197  ut16 s_nreloc; /* Number of Relocation table entries */
198  ut16 s_nlnno; /* Number of Line Number table entries */
199  ut32 s_flags; /* Flags for this section */
200  });
201 
203  struct coff_symbol {
204  char n_name[8]; /* Symbol Name */
205  ut32 n_value; /* Value of Symbol */
206  ut16 n_scnum; /* Section Number */
207  ut16 n_type; /* Symbol Type */
208  ut8 n_sclass; /* Storage Class */
209  ut8 n_numaux; /* Auxiliary Count */
210  });
211 
212 struct coff_reloc {
213  ut32 rz_vaddr; /* Reference Address */
214  ut32 rz_symndx; /* Symbol index */
215  ut16 rz_type; /* Type of relocation */
216 };
217 
218 #define COFF_SYM_GET_DTYPE(type) (((type) >> 4) & 3)
219 #endif /* COFF_SPECS_H */
RZ_PACKED(struct coff_hdr { ut16 f_magic;ut16 f_nscns;ut32 f_timdat;ut32 f_symptr;ut32 f_nsyms;ut16 f_opthdr;ut16 f_flags;})
uint16_t ut16
uint32_t ut32
uint8_t ut8
Definition: lh5801.h:11
ut32 rz_vaddr
Definition: coff_specs.h:213
ut32 rz_symndx
Definition: coff_specs.h:214
ut16 rz_type
Definition: coff_specs.h:215
Definition: zipcmp.c:77