-
Notifications
You must be signed in to change notification settings - Fork 0
/
coffsyms.h
151 lines (120 loc) · 4.04 KB
/
coffsyms.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
#pragma once
#include <vector>
#include <string>
typedef std::vector<IMAGE_RELOCATION> SECTION_RELOCS;
typedef std::vector<SECTION_RELOCS> COFF_RELOCS;
typedef std::vector<IMAGE_SYMBOL> SYMBOL_VECTOR;
typedef std::vector<std::string> STRING_VECTOR;
typedef std::vector<size_t> OFFSET_VECTOR;
typedef struct COFF_STRING_TABLE
{
DWORD cbST;
#pragma warning(disable:4200)
char szST[0];
#pragma warning(default:4200)
} COFF_STRING_TABLE, *PCOFF_STRING_TABLE;
#define EMPTY_STRING_TABLE ((PCOFF_STRING_TABLE)1)
PCOFF_STRING_TABLE STCreate (size_t cbST);
PCOFF_STRING_TABLE STDuplicate (PCOFF_STRING_TABLE pOldST);
PSZ STGetStr (PCOFF_STRING_TABLE pST, DWORD Offs);
void STDestroy (PCOFF_STRING_TABLE pST);
char* STGetFirstString (PCOFF_STRING_TABLE pST);
char* STAddString (PCOFF_STRING_TABLE pST, char* pCurST, const char* szSymName, PDWORD pdwOffset);
size_t STGetStringsLength (PCOFF_STRING_TABLE pST);
size_t STGetFullLength (PCOFF_STRING_TABLE pST);
DWORD STGetOffset (PCOFF_STRING_TABLE pST, char* szStr);
void STStore (PCOFF_STRING_TABLE pST, void* pBuffer);
PCOFF_STRING_TABLE STFromStringVector (STRING_VECTOR &strs, OUT OFFSET_VECTOR &offsets);
bool CoffIsSymNameLong (PIMAGE_SYMBOL Sym);
PSZ CoffSTGetSymbolName (PCOFF_STRING_TABLE pST, PIMAGE_SYMBOL Sym);
PIMAGE_SYMBOL CoffLookupSymbol (
SYMBOL_VECTOR &OldSymbolTable,
PCOFF_STRING_TABLE OldStringTable,
PSZ SymName
);
DWORD
CoffLookupSymbolIndex (
PIMAGE_SYMBOL SymbolTable,
SIZE_T NumberOfSymbols,
PCOFF_STRING_TABLE pST,
PSZ SymName
);
PCOFF_STRING_TABLE STCreatePartialStringTable(
SYMBOL_VECTOR &PartialSymbolTable,
PCOFF_STRING_TABLE pOriginalST
);
///////////////////////////////////////////////////////////////////////////////
bool CoffBuildSymbolsFromStringMapAndOffsetMap (
SYMBOL_VECTOR &syms,
STRING_VECTOR &strs,
OFFSET_VECTOR &offsets
);
enum SymSearchCritType {
SSCT_UNKNOWN,
SSCT_TYPE,
SSCT_STORAGE_CLASS,
SSCT_SECTION_NUMBER,
SSCT_VALUE
};
typedef struct SYMBOL_SEARCH_CRITERIA {
DWORD CritType;
union {
DWORD Value;
SHORT SectionNumber;
WORD Type;
BYTE StorageClass;
};
} SYMBOL_SEARCH_CRITERIA, *PSYMBOL_SEARCH_CRITERIA;
PIMAGE_SYMBOL CoffFindSpecialSymbol (
PIMAGE_SYMBOL SymbolTable, // pointer to symbol table
size_t cSyms, // number of symbols
std::vector<SYMBOL_SEARCH_CRITERIA> &crit, // vector of search criterias
bool bAndOperation = true, // = true if AND, = false for OR
PIMAGE_SYMBOL SymStartAt = NULL // symrec to start search at
);
PIMAGE_SYMBOL CoffFirstSymbolForSection (
PIMAGE_SYMBOL SymbolTable,
size_t cSyms,
SHORT SectionNumber
);
PIMAGE_SYMBOL CoffNextSymbolForSection(
PIMAGE_SYMBOL SymbolTable,
size_t cSyms,
SHORT SectionNumber,
PIMAGE_SYMBOL Sym
);
PIMAGE_SYMBOL CoffFindComdatSymrecForSection (
PIMAGE_SYMBOL SymbolTable,
size_t cSyms,
SHORT SectionNumber,
OUT PIMAGE_SYMBOL *ppSectSym OPTIONAL // optionally return section symrec too
);
PIMAGE_AUX_SYMBOL CoffGetAuxSymbols (PIMAGE_SYMBOL Sym);
bool CoffGetPointers (
IN PIMAGE_FILE_HEADER FileHdr,
OUT PIMAGE_SYMBOL *ppSymTbl,
OUT size_t *pcSyms OPTIONAL,
OUT PCOFF_STRING_TABLE *ppST OPTIONAL
);
void CoffDumpAuxSymbols (PIMAGE_FILE_HEADER FileHdr, PIMAGE_SYMBOL Sym);
void CoffGetSzSectionNumber (SHORT SectionNumber, OUT char* pBuf);
void CoffDumpSymbolType (PIMAGE_SYMBOL Sym);
#include <common/tcharex.h>
PCSZ CoffGetSymStorageClass (PIMAGE_SYMBOL Sym);
void CoffDumpSymbol (
PIMAGE_FILE_HEADER FileHdr,
PIMAGE_SYMBOL Sym,
unsigned iSym,
PCOFF_STRING_TABLE pST
);
void CoffDumpSymbolTable (
PIMAGE_FILE_HEADER FileHdr
);
void CoffDumpSectionFlags (
PIMAGE_FILE_HEADER FileHdr,
unsigned iSect,
PIMAGE_SECTION_HEADER Sect
);
void CoffDumpSections (PIMAGE_FILE_HEADER FileHdr);
void CoffDumpSymsVector (SYMBOL_VECTOR &syms, PCOFF_STRING_TABLE pST);
PIMAGE_SYMBOL CoffBuildSymbolTable (SYMBOL_VECTOR &syms);