-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWindowImplementations.cpp
More file actions
321 lines (281 loc) · 7.12 KB
/
WindowImplementations.cpp
File metadata and controls
321 lines (281 loc) · 7.12 KB
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
#include "stdafx.h"
#include "SerializerInheritors.h"
#include "Main.h"
#include "MiscHelpers.h"
#include "CommonFunctions.h"
#include <cassert>
#include <limits>
#include <memory>
#include <string>
void WindowsCES::AddResultInner(INktHookCallInfoPlugin &hcip)
{
result = hcip.Result()->GetSizeTVal();
abuffer->AddInteger(result);
}
template <bool IsAnsi>
bool CreateWindowExCES<IsAnsi>::IgnoreCall(INktHookCallInfoPlugin &hcip)
{
INktStackTracePtr trace = hcip.StackTrace();
return MH_CheckCallFrom(trace, L"user32.dll!CreateWindowExA") != FALSE;
}
void WindowsCES::AddClassNameFromClassAtom(INktParamPtr ¶m, int cast)
{
if (valid_pointer(param))
{
long class_atom = param->GetIntResourceString();
if (class_atom > 0)
abuffer->AddHexInteger(class_atom);
else if (cast < 0)
abuffer->AddString(param->ReadString());
else if (cast)
abuffer->AddAnsiString(get_pointer_or_null<const char>(param));
else
abuffer->AddString(get_pointer_or_null<const wchar_t>(param));
}
else
abuffer->AddEmptyString();
}
const int CAST_TO_CHAR = 1;
const int CAST_TO_WCHAR = 0;
void WindowsCES::AddParentClassName(INktParamPtr param)
{
HWND parent_handle = (HWND)param->GetSizeTVal();
if (parent_handle == HWND_MESSAGE)
{
abuffer->AddString("HWND_MESSAGE");
return;
}
size_t characters;
auto classname = BetterGetClassNameW(characters, parent_handle);
if (!characters)
abuffer->AddInteger((intptr_t)parent_handle);
else
abuffer->AddString(classname.get(), characters);
}
auto_array_ptr<wchar_t> BetterGetClassNameW(size_t &size, HWND handle)
{
size = 100;
auto_array_ptr<wchar_t> buffer;
int res;
do
{
buffer.reset(new (std::nothrow) wchar_t[size]);
if (!buffer)
THROW_CIPC_OUTOFMEMORY;
res = GetClassNameW(handle, buffer.get(), (int)size);
if (res)
{
size = res;
continue;
}
//Ideally, I'd use err to decide what to do, but I have no idea what it can return
//for GetClassName().
DWORD err = GetLastError();
if (err != ERROR_INSUFFICIENT_BUFFER)
{
size = 0;
return 0;
}
buffer.reset();
size *= 2;
}
while (!res);
return buffer;
}
template <bool IsAnsi>
void CreateWindowExCES<IsAnsi>::AddParamsInner(INktHookCallInfoPlugin &hcip)
{
INktParamsEnumPtr params = hcip.Params();
INktParamPtr param;
if (is_precall)
{
AddClassNameFromClassAtom(params->GetAt(1), IsAnsi ? CAST_TO_CHAR : CAST_TO_WCHAR);
return;
}
param = params->GetAt(2);
if (valid_pointer(param))
{
if (IsAnsi)
abuffer->AddAnsiString(get_pointer_or_null<const char>(param));
else
abuffer->AddString(param->ReadString());
}
else
abuffer->AddEmptyString();
param = params->GetAt(10);
this->AddOptionalModule(hcip, param->GetSizeTVal());
size_t buffer_size = 0;
auto_array_ptr<wchar_t> buffer;
if (Success())
buffer = BetterGetClassNameW(buffer_size, GetHandleValue());
if (buffer_size != 0)
{
abuffer->AddString(buffer.get(), buffer_size);
}
else
{
param = params->GetAt(1);
if (valid_pointer(param))
AddClassNameFromClassAtom(param, IsAnsi ? CAST_TO_CHAR : CAST_TO_WCHAR);
else
abuffer->AddEmptyString();
}
param = params->GetAt(0);
abuffer->AddIntegerForceUnsigned(param->GetULongVal());
param = params->GetAt(3);
abuffer->AddIntegerForceUnsigned(param->GetULongVal());
AddParentClassName(params->GetAt(8));
}
struct DLG_TEMPLATE
{
DWORD style;
DWORD exStyle;
DWORD helpId;
WORD nbItems;
short x;
short y;
short cx;
short cy;
LPCWSTR menuName;
LPCWSTR className;
LPCWSTR caption;
WORD pointSize;
WORD weight;
BOOL italic;
LPCWSTR faceName;
BOOL dialogEx;
};
inline DWORD get_dword(const WORD *&p){
DWORD ret = *(const DWORD *)p;
p += 2;
return ret;
}
static LPCSTR DIALOG_ParseTemplate32(DLG_TEMPLATE *result, void *dlg_template)
{
auto p = (const WORD *)dlg_template;
WORD signature;
WORD dlgver;
dlgver = *p++;
signature = *p++;
if (dlgver == 1 && signature == 0xffff) /* DIALOGEX resource */
{
result->dialogEx = TRUE;
result->helpId = get_dword(p);
result->exStyle = get_dword(p);
result->style = get_dword(p);
}
else
{
p -= 2;
result->style = get_dword(p);
result->dialogEx = FALSE;
result->helpId = 0;
result->exStyle = get_dword(p);
}
result->nbItems = *p++;
result->x = *p++;
result->y = *p++;
result->cx = *p++;
result->cy = *p++;
/* Get the menu name */
switch(*p)
{
case 0x0000:
result->menuName = NULL;
p++;
break;
case 0xffff:
result->menuName = (LPCWSTR)(UINT_PTR)*++p;
p++;
break;
default:
result->menuName = (LPCWSTR)p;
p += wcslen( result->menuName ) + 1;
break;
}
/* Get the class name */
switch(*p)
{
case 0x0000:
result->className = WC_DIALOG;
p++;
break;
case 0xffff:
result->className = (LPCWSTR)(UINT_PTR)*++p;
p++;
break;
default:
result->className = (LPCWSTR)p;
p += wcslen( result->className ) + 1;
break;
}
/* Get the window caption */
result->caption = (LPCWSTR)p;
p += wcslen( result->caption ) + 1;
/* Get the font name */
result->pointSize = 0;
result->faceName = NULL;
result->weight = FW_DONTCARE;
result->italic = FALSE;
if (result->style & DS_SETFONT)
{
result->pointSize = *p;
p++;
/* If pointSize is 0x7fff, it means that we need to use the font
* in NONCLIENTMETRICSW.lfMessageFont, and NOT read the weight,
* italic, and facename from the dialog dlg_template.
*/
if (result->pointSize == 0x7fff)
{
/* We could call SystemParametersInfo here, but then we'd have
* to convert from pixel size to point size (which can be
* imprecise).
*/
}
else
{
if (result->dialogEx)
{
result->weight = *p; p++;
result->italic = LOBYTE(*p); p++;
}
result->faceName = (LPCWSTR)p;
p += wcslen( result->faceName ) + 1;
}
}
/* First control is on dword boundary */
return (LPCSTR)((((UINT_PTR)p) + 3) & ~3);
}
void CreateDialogIndirectCES::AddParamsInner(INktHookCallInfoPlugin &hcip)
{
INktParamsEnumPtr params = hcip.Params();
if (is_precall)
return;
auto hinstance = params->GetAt(0)->GetSizeTVal();
DLG_TEMPLATE t;
if (Success())
{
auto p = (void *)params->GetAt(1)->GetPointerVal();
DIALOG_ParseTemplate32(&t, p);
abuffer->AddString(t.caption);
}
else
abuffer->AddEmptyString();
this->AddOptionalModule(hcip, hinstance);
if (Success())
{
if (t.className == WC_DIALOG)
abuffer->AddString("#32770");
else
abuffer->AddString(t.className);
abuffer->AddIntegerForceUnsigned(t.exStyle);
abuffer->AddIntegerForceUnsigned(t.style);
}
else
abuffer->AddEmptyString(3);
AddParentClassName(params->GetAt(2));
}
void DialogBoxIndirectCES::AddResultInner(INktHookCallInfoPlugin &hcip){
DialogBoxIndirectCES_result = (INT_PTR)hcip.Result()->GetSizeTVal();
abuffer->AddInteger(DialogBoxIndirectCES_result);
}