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
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#include "ildasmpch.h"
#ifndef FEATURE_CORECLR
#include "resource.h"
#include "formattype.h"
WCHAR* RstrW(unsigned id);
extern HINSTANCE g_hInstance;
extern HINSTANCE g_hResources;
extern DWORD g_NumClasses;
extern char g_szInputFile[]; // in UTF-8
extern char g_szOutputFile[]; // in UTF-8
#define IDC_CANCEL 101
HWND g_hwndProgress = NULL;
HWND g_hwndProgBox = NULL;
HWND g_hwndFromFile = NULL;
HWND g_hwndToFile = NULL;
HWND g_hwndTally = NULL;
HWND g_hwndCancel = NULL;
HANDLE g_hThreadReady = NULL; // event
BOOL g_fInitCommonControls = TRUE;
BOOL g_fRegisterClass = TRUE;
ULONG g_ulCount, g_ulRange;
RECT rcClient; // client area of parent window
WCHAR* UtfToUnicode(__in __nullterminated const char* sz); // defined in dis.cpp
LRESULT CALLBACK ProgBoxWndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch (uMsg)
{
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_CANCEL:
g_hwndProgress = NULL;
g_hwndProgBox = NULL;
g_hwndFromFile = NULL;
g_hwndToFile = NULL;
g_hwndTally = NULL;
g_hwndCancel = NULL;
DestroyWindow (hwnd);
break;
}
break;
case WM_CLOSE:
g_hwndProgress = NULL;
g_hwndProgBox = NULL;
g_hwndFromFile = NULL;
g_hwndToFile = NULL;
g_hwndTally = NULL;
g_hwndCancel = NULL;
//break;
default:
return WszDefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
DWORD WINAPI ProgressMainLoop(LPVOID pv)
{
MSG msg;
DWORD cyVScroll;
HFONT hFont = (HFONT) GetStockObject(DEFAULT_GUI_FONT); //(ANSI_FIXED_FONT);
WCHAR wzStr[1024];
if(g_fInitCommonControls)
{
InitCommonControls();
g_fInitCommonControls = FALSE;
}
g_ulCount = 0;
if(g_fRegisterClass)
{
_ASSERTE(g_hResources != NULL);
WNDCLASSW wndClass;
wndClass.style = CS_HREDRAW|CS_VREDRAW|CS_NOCLOSE;
wndClass.lpfnWndProc = ProgBoxWndProc;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hInstance = g_hInstance;
wndClass.hIcon = WszLoadIcon(g_hResources,MAKEINTRESOURCE(IDI_ICON2));
wndClass.hCursor = NULL;
wndClass.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
wndClass.lpszMenuName = NULL;
wndClass.lpszClassName = L"ProgressBox";
if (WszRegisterClass(&wndClass) == 0) return 0;
g_fRegisterClass = FALSE;
}
cyVScroll = GetSystemMetrics(SM_CYVSCROLL);
if(g_hwndProgBox = WszCreateWindowEx (0,
RstrW(IDS_PROGRESSBOX), //"ProgressBox",
RstrW(IDS_DISASSEMBLING), //"Disassembling",
WS_VISIBLE | WS_CAPTION | WS_POPUP | WS_SYSMENU | WS_CLIPCHILDREN,
400, 200, 400, 8*cyVScroll,
HWND_DESKTOP,
(HMENU)0,
g_hInstance,
NULL))
{
GetClientRect(g_hwndProgBox, &rcClient);
if(g_hwndFromFile = WszCreateWindowEx (0,
L"STATIC",
L"",
WS_CHILD|WS_VISIBLE|SS_CENTER,
rcClient.left, rcClient.bottom-6*cyVScroll,rcClient.right, cyVScroll,
g_hwndProgBox,
(HMENU)0,
g_hInstance,
NULL))
{
SendMessageA(g_hwndFromFile,WM_SETFONT,(LPARAM)hFont,FALSE);
WCHAR* wzFileName = UtfToUnicode(g_szInputFile);
if(wcslen(wzFileName) <= 60) swprintf_s(wzStr,1024,RstrW(IDS_PB_FILE) /*"File %s"*/,wzFileName);
else
{
WCHAR * p=wzFileName;
while(p = wcschr(p,L'\\'))
{
if(wcslen(p) <= 60) break;
p++;
}
if(p == NULL) p = &wzFileName[wcslen(wzFileName)-50];
swprintf_s(wzStr,1024,RstrW(IDS_PB_FILE1) /*"File ...%s"*/,p);
}
WszSendMessage(g_hwndFromFile, WM_SETTEXT,0,(LPARAM)wzStr);
}
if(g_hwndToFile = WszCreateWindowEx (0,
L"STATIC",
L"",
WS_CHILD|WS_VISIBLE|SS_CENTER,
rcClient.left, rcClient.bottom-5*cyVScroll,rcClient.right, cyVScroll,
g_hwndProgBox,
(HMENU)0,
g_hInstance,
NULL))
{
SendMessageA(g_hwndToFile,WM_SETFONT,(LPARAM)hFont,FALSE);
WCHAR* wzFileName = UtfToUnicode(g_szOutputFile);
if(wcslen(wzFileName) <= 60) swprintf_s(wzStr,1024,RstrW(IDS_PB_TOFILE) /*"To file %s"*/,wzFileName);
else
{
WCHAR * p=wzFileName;
while(p = wcschr(p,L'\\'))
{
if(wcslen(p) <= 60) break;
p++;
}
if(p == NULL) p = &wzFileName[wcslen(wzFileName)-50];
swprintf_s(wzStr,1024,RstrW(IDS_PB_TOFILE1) /*"To file ...%s"*/,p);
}
WszSendMessage(g_hwndToFile, WM_SETTEXT,0,(LPARAM)wzStr);
}
if(g_hwndTally = WszCreateWindowEx (0,
L"STATIC",
L"",
WS_CHILD|WS_VISIBLE|SS_CENTER,
rcClient.left, rcClient.bottom-4*cyVScroll,rcClient.right, cyVScroll,
g_hwndProgBox,
(HMENU)0,
g_hInstance,
NULL))
{
SendMessageA(g_hwndTally,WM_SETFONT,(LPARAM)hFont,FALSE);
if(g_ulCount <= g_NumClasses) swprintf_s(wzStr,1024,RstrW(IDS_PB_CLASSESDONE) /*"%d classes, %d done"*/,g_NumClasses,g_ulCount);
else swprintf_s(wzStr,1024,RstrW(IDS_PB_GLOBALSDONE) /*"%d global methods, %d done"*/,g_ulRange-g_NumClasses,g_ulCount-g_NumClasses);
WszSendMessage(g_hwndTally, WM_SETTEXT,0,(LPARAM)wzStr);
}
if(g_hwndProgress = WszCreateWindowEx (0,
PROGRESS_CLASS,
L"",
WS_CHILD|WS_VISIBLE|SS_CENTER, // SS_CENTER gives smooth progress and solid bar
rcClient.left, rcClient.bottom-3*cyVScroll,rcClient.right, cyVScroll,
g_hwndProgBox,
(HMENU)0,
g_hInstance,
NULL))
{
// Set the range for the progress bar.
SendMessageA (g_hwndProgress, PBM_SETRANGE, 0L, MAKELPARAM(0, g_ulRange));
// Set the step.
SendMessageA (g_hwndProgress, PBM_SETSTEP, (WPARAM)1, 0L);
}
if(g_hwndCancel = WszCreateWindowEx (0,
L"BUTTON",
RstrW(IDS_PB_CANCEL), //"Cancel",
WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON|BS_TEXT,
rcClient.left+150, rcClient.bottom-3*cyVScroll/2,rcClient.right-300, 4*cyVScroll/3,
g_hwndProgBox,
(HMENU)IDC_CANCEL,
g_hInstance,
NULL))
{
SendMessageA(g_hwndCancel,WM_SETFONT,(LPARAM)hFont,FALSE);
}
}
SetEvent(g_hThreadReady);
while (WszGetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
WszDispatchMessage(&msg);
}
return 0;
}
void CreateProgressBar(LONG lRange)
{
DWORD dwThreadID;
g_ulCount = 0;
if((g_ulRange = (ULONG)lRange)==0) return;
g_hThreadReady = WszCreateEvent(NULL,FALSE,FALSE,NULL);
if (g_hThreadReady != NULL)
{
// Thread is never aborted, it always exits by itself
HANDLE hThread = CreateThread(NULL,0,ProgressMainLoop,NULL,0,&dwThreadID);
if (hThread != NULL)
{
CloseHandle(hThread);
WaitForSingleObject(g_hThreadReady,INFINITE);
}
CloseHandle(g_hThreadReady);
}
}
BOOL ProgressStep()
{
if(g_hwndProgBox)
{
WCHAR wzStr[1024];
if(g_hwndTally)
{
if(g_ulCount <= g_NumClasses)
swprintf_s(wzStr,1024,RstrW(IDS_PB_CLASSESDONE) /*"%d classes, %d done"*/,g_NumClasses,g_ulCount);
else if(g_ulCount <= g_ulRange)
swprintf_s(wzStr,1024,RstrW(IDS_PB_GLOBALSDONE) /*"%d global methods, %d done"*/,g_ulRange-g_NumClasses,g_ulCount-g_NumClasses);
else
wcscpy_s(wzStr,1024,RstrW(IDS_PB_WRITINGDATA)); //"Writing global data");
wzStr[1023]=0;
WszSendMessage(g_hwndTally, WM_SETTEXT,0,(LPARAM)wzStr);
}
if(g_hwndProgress && g_ulCount && (g_ulCount <= g_ulRange))
WszSendMessage (g_hwndProgress, PBM_STEPIT, 0L, 0L);
g_ulCount++;
}
else if(g_ulCount) return FALSE; // disassembly started and was aborted
return TRUE;
}
void DestroyProgressBar()
{
if(g_hwndProgBox) WszSendMessage (g_hwndProgBox,WM_COMMAND,IDC_CANCEL,0);
g_hwndProgress = NULL;
g_hwndProgBox = NULL;
g_hwndFromFile = NULL;
g_hwndToFile = NULL;
g_hwndTally = NULL;
g_hwndCancel = NULL;
g_ulCount = 0;
}
#endif
|