-
Notifications
You must be signed in to change notification settings - Fork 10
/
symbol_parser.cpp
126 lines (95 loc) · 1.59 KB
/
symbol_parser.cpp
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
#include "includes.hpp"
SymbolParser::~SymbolParser()
{
Cleanup();
}
bool SymbolParser::Cleanup()
{
if (initialized)
{
if (sym_table)
{
SymUnloadModule64(h_proc, sym_table);
sym_table = 0;
}
SymCleanup(h_proc);
initialized = false;
}
if (h_proc)
{
CloseHandle(h_proc);
h_proc = 0;
}
is_ready = false;
return true;
}
bool SymbolParser::Initialize(const SymbolLoader* loader)
{
is_ready = false;
if (!loader)
{
return false;
}
if (!loader->IsReady())
{
return false;
}
if (sym_table)
{
if (!SymUnloadModule64(h_proc, sym_table))
{
return false;
}
sym_table = 0;
}
if (!h_proc)
{
h_proc = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, NULL, GetCurrentProcessId());
if (!h_proc)
{
return false;
}
}
if (!initialized)
{
SymSetOptions(SYMOPT_UNDNAME | SYMOPT_AUTO_PUBLICS | SYMOPT_DEFERRED_LOADS);
if (!SymInitialize(h_proc, NULL, NULL))
{
CloseHandle(h_proc);
return false;
}
initialized = true;
}
sym_table = SymLoadModuleExW(h_proc, NULL, loader->GetPDBPath().c_str(), NULL, 0x10000000, loader->GetPDBSize(), NULL, NULL);
if (!sym_table)
{
SymCleanup(h_proc);
CloseHandle(h_proc);
initialized = false;
return false;
}
is_ready = true;
return true;
}
DWORD SymbolParser::GetSymbolAddress(const wchar_t* sym_name)
{
if (!is_ready)
{
return 0;
}
if (!sym_name)
{
return 0;
}
SYMBOL_INFOW si = { 0 };
si.SizeOfStruct = sizeof(si);
if (!SymFromNameW(h_proc, sym_name, &si))
{
return 0;
}
return (DWORD)(si.Address - si.ModBase);
}
bool SymbolParser::IsReady()
{
return is_ready;
}