-
Notifications
You must be signed in to change notification settings - Fork 1
/
synexts.cpp
220 lines (186 loc) · 6.57 KB
/
synexts.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
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
209
210
211
212
213
214
215
216
217
218
219
220
// synexts.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
// ----------------------------------------------------------------------------
namespace
{
// ----------------------------------------------------------------------------
const CHAR g_szArgumentTokens[] = " \t";
// ----------------------------------------------------------------------------
}
// ----------------------------------------------------------------------------
extern "C"
HRESULT
CALLBACK
help(
__in IDebugClient4 *pDebugClient,
__in PCSTR args
)
{
UNREFERENCED_PARAMETER(args);
// query required debug engine interface
ATL::CComQIPtr<IDebugControl> pDebugControl{pDebugClient};
// print help messafe
pDebugControl->Output(DEBUG_OUTPUT_NORMAL, "Synthetic symbols extension\n");
pDebugControl->Output(DEBUG_OUTPUT_NORMAL, "\n");
pDebugControl->Output(DEBUG_OUTPUT_NORMAL, " addsymbol <NAME> <OFFSET> <SIZE>\n");
pDebugControl->Output(DEBUG_OUTPUT_NORMAL, " create artificial symbol in any existing module\n");
pDebugControl->Output(DEBUG_OUTPUT_NORMAL, "\n");
pDebugControl->Output(DEBUG_OUTPUT_NORMAL, " addmodule <NAME> <PATH> <BASE> <SIZE>\n");
pDebugControl->Output(DEBUG_OUTPUT_NORMAL, " create artificial loaded modules in engine's module list\n");
pDebugControl->Output(DEBUG_OUTPUT_NORMAL, "\n");
return S_OK;
}
// ----------------------------------------------------------------------------
extern "C"
HRESULT
CALLBACK
addsymbol(
__in IDebugClient4 *pDebugClient,
__in PCSTR args
)
{
// query required debug engine interfaces
ATL::CComQIPtr<IDebugControl> pDebugControl{pDebugClient};
ATL::CComQIPtr<IDebugSymbols3> pDebugSymbols{pDebugClient};
// parse command arguments
const ATL::CStringA csArguments{args};
int nTokenize{};
const auto csName{csArguments.Tokenize(g_szArgumentTokens, nTokenize)};
if (csName.IsEmpty())
{
pDebugControl->Output(DEBUG_OUTPUT_ERROR, "Missing first parameter (NAME)\n");
return E_INVALIDARG;
}
const auto csOffset{csArguments.Tokenize(g_szArgumentTokens, nTokenize)};
if (csOffset.IsEmpty())
{
pDebugControl->Output(DEBUG_OUTPUT_ERROR, "Missing second parameter (OFFSET)\n");
return E_INVALIDARG;
}
DEBUG_VALUE OffsetValue{};
auto hResult =
pDebugControl->Evaluate(
csOffset,
DEBUG_VALUE_INVALID,
&OffsetValue,
nullptr);
if (S_OK != hResult)
{
pDebugControl->Output(DEBUG_OUTPUT_ERROR, "Second parameter (OFFSET) cannot be converted to number (0x%x)\n", hResult);
return hResult;
}
const auto csSize{csArguments.Tokenize(g_szArgumentTokens, nTokenize)};
if (csSize.IsEmpty())
{
pDebugControl->Output(DEBUG_OUTPUT_ERROR, "Missing third parameter (SIZE)\n");
return E_INVALIDARG;
}
DEBUG_VALUE SizeValue{};
hResult =
pDebugControl->Evaluate(
csSize,
DEBUG_VALUE_INVALID,
&SizeValue,
nullptr);
if (S_OK != hResult)
{
pDebugControl->Output(DEBUG_OUTPUT_ERROR, "Third parameter (SIZE) cannot be converted to number (0x%x)\n", hResult);
return hResult;
}
// try to create artificial symbol
hResult =
pDebugSymbols->AddSyntheticSymbol(
OffsetValue.I64,
SizeValue.I32,
csName,
DEBUG_ADDSYNTHSYM_DEFAULT,
nullptr);
if (S_OK != hResult)
{
pDebugControl->Output(DEBUG_OUTPUT_ERROR, "Cannot add synthetic symbol (0x%x)\n", hResult);
return hResult;
}
pDebugControl->Output(DEBUG_OUTPUT_NORMAL, "Synthetic symbol successfully added\n");
return S_OK;
}
// ----------------------------------------------------------------------------
extern "C"
HRESULT
CALLBACK
addmodule(
__in IDebugClient4 *pDebugClient,
__in PCSTR args
)
{
// query required debug engine interfaces
ATL::CComQIPtr<IDebugControl> pDebugControl{pDebugClient};
ATL::CComQIPtr<IDebugSymbols3> pDebugSymbols{pDebugClient};
// parse command arguments
const ATL::CStringA csArguments{args};
int nTokenize{};
const auto csName{csArguments.Tokenize(g_szArgumentTokens, nTokenize)};
if (csName.IsEmpty())
{
pDebugControl->Output(DEBUG_OUTPUT_ERROR, "Missing 1st parameter (NAME)\n");
return E_INVALIDARG;
}
const auto csPath{csArguments.Tokenize(g_szArgumentTokens, nTokenize)};
if (csPath.IsEmpty())
{
pDebugControl->Output(DEBUG_OUTPUT_ERROR, "Missing 2th parameter (PATH)\n");
return E_INVALIDARG;
}
const auto csBase{csArguments.Tokenize(g_szArgumentTokens, nTokenize)};
if (csBase.IsEmpty())
{
pDebugControl->Output(DEBUG_OUTPUT_ERROR, "Missing 3th parameter (BASE)\n");
return E_INVALIDARG;
}
DEBUG_VALUE BaseValue{};
auto hResult =
pDebugControl->Evaluate(
csBase,
DEBUG_VALUE_INVALID,
&BaseValue,
nullptr);
if (S_OK != hResult)
{
pDebugControl->Output(DEBUG_OUTPUT_ERROR, "BASE (3th parameter) cannot be converted to number (0x%x)\n", hResult);
return hResult;
}
const auto csSize{csArguments.Tokenize(g_szArgumentTokens, nTokenize)};
if (csSize.IsEmpty())
{
pDebugControl->Output(DEBUG_OUTPUT_ERROR, "Missing 4th parameter (SIZE)\n");
return E_INVALIDARG;
}
DEBUG_VALUE SizeValue{};
hResult =
pDebugControl->Evaluate(
csSize,
DEBUG_VALUE_INVALID,
&SizeValue,
nullptr);
if (S_OK != hResult)
{
pDebugControl->Output(DEBUG_OUTPUT_ERROR, "SIZE (4th) cannot be converted to number (0x%x)\n", hResult);
return hResult;
}
// try to create artificial loaded module
hResult =
pDebugSymbols->AddSyntheticModule(
BaseValue.I64,
SizeValue.I32,
csPath,
csName,
DEBUG_ADDSYNTHMOD_DEFAULT);
if (S_OK != hResult)
{
pDebugControl->Output(DEBUG_OUTPUT_ERROR, "Cannot add synthetic module (0x%x)\n", hResult);
return hResult;
}
pDebugControl->Output(DEBUG_OUTPUT_NORMAL, "Synthetic module successfully added\n");
return S_OK;
}
// ----------------------------------------------------------------------------