-
Notifications
You must be signed in to change notification settings - Fork 0
/
fasmsymfmt.h
208 lines (175 loc) · 6.48 KB
/
fasmsymfmt.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#pragma once
#define FASMSYM_INCLUDED 1
/**
* FASM Symbol File format descibed in this header.
*
* FASM Symbol File can be generated by a fasm call like: fasm -s test.sym test.asm test.exe
*
FASM Symbol File Format
=======================
[FASM Symbol File Header]
[String Table]
[Symbol Table]
[Preprocessed Source]
[Assembly Dump]
[Section Names] (only in object file)
*/
//
// FASM Symbols File Header Format
//
// Object header within fasm symbols file header.
// Defines offset of the object and its length.
struct FASM_SYMHDR_OBJECT
{
DWORD Offset;
DWORD Length;
};
// Fasm Symbols Header Signature
#define FASM_SYM_SIGNATURE 0x1a736166 // 'fas\x1a'
// Fasm Symbols Header
typedef struct FASM_SYMHDR
{
/* +0x00 */ DWORD dwSignature; // 0x1a736166 ('fas' + 0x1a)
/* +0x04 */ BYTE bVerMajor;
/* +0x05 */ BYTE bVerMinor;
/* +0x06 */ WORD wHeaderLen; // sizeof(FASM_SYMHDR)
/* +0x08 */ DWORD dwInputFileNameOffset;
/* +0x0c */ DWORD dwOutputFileNameOffset;
/* +0x10 */ FASM_SYMHDR_OBJECT StringTable;
/* +0x18 */ FASM_SYMHDR_OBJECT SymbolTable;
/* +0x20 */ FASM_SYMHDR_OBJECT PreprocessedSource;
/* +0x28 */ FASM_SYMHDR_OBJECT AssemblyDump;
/* +0x30 */ FASM_SYMHDR_OBJECT SectionNames;
/* Length = 0x38 bytes */
} FASM_SYMHDR, *PFASM_SYMHDR;
// Symbol name in preprocessed source?
#define IS_FASM_SYMBOL_NAME_IN_PREPROCESSED_SOURCE(SYM) (((SYM)->SymbolNameOffset & 0x80000000) == 0)
// Offset of symbol name in preprocessed source
#define PREPROCESSED_SOURCE_SYMBOL_NAME_OFFSET(SYM) ((SYM)->SymbolNameOffset & 0x3fffffff)
// Is symbol anonymous?
#define IS_FASM_SYMBOL_ANONYMOUS(SYM) ((SYM)->SymbolNameOffset == 0)
// Is symbol name in string table?
#define IS_FASM_SYMBOL_NAME_IN_STRING_TABLE(SYM) (((SYM)->SymbolNameOffset & 0x80000000) == 0x80000000)
// String table offset of the symbol name
#define STRING_TABLE_SYMBOL_NAME_OFFSET(SYM) ((SYM)->SymbolNameOffset & 0x3fffffff)
//
// Pascal String
//
#pragma pack(push, 1)
typedef struct PASCAL_STRING
{
BYTE Length;
BYTE String[1];
} PASCAL_STRING, *PPASCAL_STRING;
#pragma pack(pop)
//
// Fasm Symbol Flags
//
#define FASM_SYMBOL_DEFINED 0x0001
#define FASM_SYMBOL_ASSEMBLY_TIME_VAR 0x0002
#define FASM_SYMBOL_NOT_FORWARD_REFERENCED 0x0004
#define FASM_SYMBOL_USED 0x0008
#define FASM_SYMBOL_PREDICTED_USE 0x0010
#define FASM_SYMBOL_PREDICTED_USE_RES 0x0020
#define FASM_SYMBOL_PREDICTED_DEFINITION 0x0040
#define FASM_SYMBOL_PREDICTED_DEFINITION_RES 0x0080
#define FASM_SYMBOL_OPTIMIZATION_ADJ_APPLIED 0x0100
#define FASM_SYMBOL_RESERVED_BITS 0xfe00
#define FASM_SYMBOL_FLAGS_VALID(SYM) (((SYM)->Flags & FASM_SYMBOL_RESERVED_BITS) == 0)
//
// Fasm Symbol Types
//
#define FASM_SYMBOL_TYPE_ABSOLUTE 0 // Absolute Value
#define FASM_SYMBOL_TYPE_RELOC_SEG_ADDR 1 // Relocatable segment adddress (MZ)
#define FASM_SYMBOL_TYPE_RELOC32 2 // Relocatable 32-bit address
#define FASM_SYMBOL_TYPE_RELOC_REL32 3 // Relocatable relative 32-bit address (internal)
#define FASM_SYMBOL_TYPE_RELOC64 4 // Relocatable 64-bit address
#define FASM_SYMBOL_TYPE_ELF_GREL32 5 // (ELF only) GOT-relative 32-bit address
#define FASM_SYMBOL_TYPE_ELF_ADDR32_OF_PLT 6 // (ELF only) 32-bit address of PLT entry
#define FASM_SYMBOL_TYPE_ELF_RELADDR32_OF_PLT 7 // (ELF only) Relative 32-bit address of PLT entry (internal)
#define FASM_SYMBOL_TYPE_MAX 7
#define FASM_SYMBOL_TYPE_VALID(t) ((t) <= FASM_SYMBOL_TYPE_MAX)
// Address of first symbol
#define FASM_FIRST_SYMBOL(HDR) ((PFASM_SYMBOL)((PCHAR)(HDR) + (HDR)->SymbolTable.Offset))
#define FASM_SYMBOL_TABLE(HDR) FASM_FIRST_SYMBOL(HDR)
// Address of first string table
#define FASM_STRING_TABLE(HDR) ((PSZ)(HDR) + (HDR)->StringTable.Offset)
// Address of first preprocessed source element
#define FASM_PREPROCESSED_SOURCE(HDR) ((PSZ)(HDR) + (HDR)->PreprocessedSource.Offset)
#define FASM_FIRST_PSLINE(HDR) ((PFASM_SYM_LINE)FASM_PREPROCESSED_SOURCE(HDR))
// First row of assembly dump
#define FASM_FIRST_ASMDUMP_ROW(HDR) ((PFASM_ASMDUMP_ROW)((PSZ)(HDR) + (HDR)->AssemblyDump.Offset))
// Address of DWORD[] array with offsets (in ST) of sections
#define FASM_SECTION_NAMES(HDR) ((PDWORD)((PSZ)(HDR) + (HDR)->SectionNames.Offset))
//
// Fasm Symbol
//
union FASM_SECTION_OR_EXTERNAL_SYMBOL_REF
{
DWORD RawValue;
struct {
DWORD SectionIndex : 30;
DWORD ReservedBit1 : 1;
DWORD RelativeToExternal : 1; // =0 - relative to section
};
struct {
DWORD ExternalSymNameOffset : 30; // in string table
DWORD ReservedBit2 : 1;
DWORD RelativeToExternal : 1; // =1 - relative to external symbol
};
};
typedef struct FASM_SYMBOL
{
/* +0x00 */ ULONGLONG Value;
/* +0x08 */ WORD Flags;
/* +0x0a */ BYTE SizeOfData;
/* +0x0b */ BYTE Type;
/* +0x0c */ DWORD ExtendedSIB;
/* +0x10 */ WORD LastPassDefined;
/* +0x12 */ WORD LastPassUsed;
/* +0x14 */ FASM_SECTION_OR_EXTERNAL_SYMBOL_REF Ref;
/* +0x18 */ DWORD SymbolNameOffset;
/* +0x1c */ DWORD LineOffset; // in preprocessed source
/* Length = 0x20 = 32 bytes */
} FASM_SYMBOL, *PFASM_SYMBOL;
//
// Preprocessed Source Line Format
//
typedef struct FASM_SYM_LINE
{
union {
/* +0x00 */ DWORD FileNameOffset; // ASCIIZ string or 0
/* +0x00 */ DWORD MacroNameOffset; // Within the PS, pascal string.
};
/* +0x04 */ DWORD LineNumber : 30;
/* +0x04 */ DWORD ReservedBit : 1;
/* +0x04 */ DWORD MacroGenerated : 1;
union {
/* +0x08 */ DWORD SourceFilePosition;
/* +0x08 */ DWORD MacroInvokedLineOffset;
};
/* +0x0c */ DWORD InMacroLineOffset; // only if MacroGenerated=1
#pragma warning(disable:4200)
/* +0x10 (?) The tokenized contents of the line */ BYTE Contents[0];
#pragma warning(default:4200)
/* Length = 0x10 + (?) bytes */
} FASM_SYM_LINE, *PFASM_SYM_LINE;
//
// FASM Row of the Assembly Dump Format
//
#pragma pack (push, 4)
typedef struct FASM_ASMDUMP_ROW
{
/* +0x00 */ DWORD InOutputFileOffset;
/* +0x04 */ DWORD LineOffset;
/* +0x08 */ ULONGLONG AddressValue;
/* +0x10 */ DWORD ExtendedSIB;
/* +0x14 */ FASM_SECTION_OR_EXTERNAL_SYMBOL_REF Ref;
/* +0x18 */ BYTE AddressType; // see Symbol Types
/* +0x19 */ BYTE CodeType; // 16, 32 or 64
/* +0x1a */ WORD InVirtualBlock : 1;
/* +0x00 */ WORD NotIncludedInOutput : 1;
/* +0x00 */ WORD ReservedBits : 14;
/* Length = 0x1c = 28 bytes*/
} FASM_ASMDUMP_ROW, *PFASM_ASMDUMP_ROW;
#pragma pack (pop)