-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCryPEWindow.cpp
233 lines (195 loc) · 7.58 KB
/
CryPEWindow.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
221
222
223
224
225
226
227
228
229
230
231
232
233
#include "CryPEWindow.h"
#include "ImlProvider.h"
#include "FrontendGlobalDef.h"
#include "BackendGlobalDef.h"
String GetPEFieldKey(const int index)
{
return LoadedProcessPEInformation.PEFields.GetKey(index);
}
String GetPEFieldValue(const int index)
{
return LoadedProcessPEInformation.PEFields.Get(LoadedProcessPEInformation.PEFields.GetKey(index)).ToString();
}
String GetSectionName(const int index)
{
return LoadedProcessPEInformation.ImageSections[index].SectionName;
}
String GetSectionBaseAddress(const int index)
{
#ifdef _WIN64
return FormatInt64HexUpper((__int64)LoadedProcessPEInformation.ImageSections[index].BaseAddress);
#else
return FormatHexadecimalIntSpecial((int)LoadedProcessPEInformation.ImageSections[index].BaseAddress);
#endif
}
String GetSectionVirtualSize(const int index)
{
#ifdef _WIN64
return FormatInt64HexUpper((__int64)LoadedProcessPEInformation.ImageSections[index].SectionSize);
#else
return FormatHexadecimalIntSpecial((int)LoadedProcessPEInformation.ImageSections[index].SectionSize);
#endif
}
String GetDotNetSectionName(const int index)
{
return LoadedProcessPEInformation.DotNetInformation.DotNetSections[index].SectionName;
}
String GetDotNetSectionOffset(const int index)
{
return Format("%lX", LoadedProcessPEInformation.DotNetInformation.DotNetSections[index].Offset);
}
String GetDotNetSectionSize(const int index)
{
return Format("%lX", LoadedProcessPEInformation.DotNetInformation.DotNetSections[index].Size);
}
CryPEWindow::CryPEWindow()
{
this->AddFrame(this->mToolStrip);
this->mPeInformationCtrl.CryAddRowNumColumn("Field").SetConvert(Single<IndexBasedValueConvert<GetPEFieldKey>>());
this->mPeInformationCtrl.CryAddRowNumColumn("Value").SetConvert(Single<IndexBasedValueConvert<GetPEFieldValue>>());
this->mSections.CryAddRowNumColumn("Name").SetConvert(Single<IndexBasedValueConvert<GetSectionName>>());
this->mSections.CryAddRowNumColumn("Virtual Address").SetConvert(Single<IndexBasedValueConvert<GetSectionBaseAddress>>());
this->mSections.CryAddRowNumColumn("Virtual Size").SetConvert(Single<IndexBasedValueConvert<GetSectionVirtualSize>>());
this->mSections.WhenBar = THISBACK(SectionsListRightClick);
this->mSections.WhenSel = THISBACK(SectionsListSelectionChanged);
this->mDotNetInformation.CryAddRowNumColumn("Name").SetConvert(Single<IndexBasedValueConvert<GetDotNetSectionName>>());
this->mDotNetInformation.CryAddRowNumColumn("Offset").SetConvert(Single<IndexBasedValueConvert<GetDotNetSectionOffset>>());
this->mDotNetInformation.CryAddRowNumColumn("Size").SetConvert(Single<IndexBasedValueConvert<GetDotNetSectionSize>>());
this->mDotNetInformation.WhenBar = THISBACK(DotNetSectionsListRightClick);
this->mSplitter.SetMinPixels(0, 200);
this->mSplitter.SetMinPixels(1, 200);
this->mRightPaneSplitter.SetMinPixels(0, 100);
this->mRightPaneSplitter.SetMinPixels(1, 100);
}
CryPEWindow::~CryPEWindow()
{
}
void CryPEWindow::ToolBar(Bar& pBar)
{
pBar.Add("Refresh", CrySearchIml::RefreshButtonSmall(), THISBACK(RefreshPEWindow));
pBar.ToolGapRight();
pBar.Add(this->mSections.IsCursor(), "Dump Section", CrySearchIml::DumpModuleSmall(), THISBACK(DumpSection));
// If a suspended process was created, a button to resume the process should be visible to the user
// straight away. Using the Threads window is not straight forward.
if (mMemoryScanner && mMemoryScanner->IsProcessSuspended())
{
pBar.Add("Resume Process", CrySearchIml::ResumeAllThreadsSmall(), THISBACK(ResumeSuspendedProcess));
}
}
void CryPEWindow::SectionsListRightClick(Bar& pBar)
{
if (this->mSections.GetCursor() >= 0 && LoadedProcessPEInformation.PEFields.GetCount() > 0)
{
pBar.Add("Dump Section", CrySearchIml::DumpModuleSmall(), THISBACK(DumpSection));
}
}
void CryPEWindow::DotNetSectionsListRightClick(Bar& pBar)
{
if (this->mSections.GetCursor() >= 0 && LoadedProcessPEInformation.PEFields.GetCount() > 0)
{
pBar.Add("Dump Section", CrySearchIml::DumpModuleSmall(), THISBACK(DumpDotNetSection));
}
}
void CryPEWindow::SectionsListSelectionChanged()
{
this->mToolStrip.Set(THISBACK(ToolBar));
}
void CryPEWindow::RefreshPEWindow()
{
this->Initialize();
}
void CryPEWindow::ResumeSuspendedProcess()
{
// Resume suspended process by iterating all suspended threads and resuming them.
const int tCount = mThreadsList.GetCount();
for (int i = 0; i < tCount; ++i)
{
CryResumeThread(mThreadsList[i].ThreadIdentifier);
}
// Sleep for a short unnoticable time to let the process build up.
Sleep(100);
// Reload the toolbar to remove the gap and button.
mMemoryScanner->ResetSuspendedState();
this->mToolStrip.Set(THISBACK(ToolBar));
// Reload tab window contents.
mCrySearchWindowManager->ClearWindows();
mCrySearchWindowManager->GetModuleWindow()->Initialize();
mCrySearchWindowManager->GetThreadWindow()->Initialize();
mCrySearchWindowManager->GetImportsWindow()->Initialize();
mCrySearchWindowManager->GetDisasmWindow()->Initialize();
mCrySearchWindowManager->GetPEWindow()->Initialize();
}
void CryPEWindow::Initialize()
{
// On window initialization, reset toolbar.
this->mToolStrip.Set(THISBACK(ToolBar));
// Get executable file PE information.
if (mModuleManager->GetModuleCount() > 0)
{
mPeInstance->GetExecutablePeInformation();
}
this->mPeInformationCtrl.SetVirtualCount(LoadedProcessPEInformation.PEFields.GetCount());
this->mSections.SetVirtualCount(LoadedProcessPEInformation.ImageSections.GetCount());
this->mDotNetInformation.SetVirtualCount(LoadedProcessPEInformation.DotNetInformation.DotNetSections.GetCount());
// Depending on the type of file, the lower right pane may or may not be visible.
*this
<< this->mSplitter.Horz(this->mPeInformationCtrl.SizePos(), LoadedProcessPEInformation.DotNetInformation.DotNetSections.GetCount() > 0 ?
this->mRightPaneSplitter.Vert(this->mSections.SizePos(), this->mDotNetInformation.SizePos()) : this->mSections.SizePos())
;
}
void CryPEWindow::ClearList()
{
LoadedProcessPEInformation.Reset();
this->mPeInformationCtrl.SetVirtualCount(0);
this->mSections.SetVirtualCount(0);
this->mDotNetInformation.SetVirtualCount(0);
}
void CryPEWindow::DumpSection()
{
const int row = this->mSections.GetCursor();
if (row >= 0 && LoadedProcessPEInformation.ImageSections.GetCount() > 0)
{
FileSel* fs = new FileSel();
fs->Types("Memory Dump files\t*.dmp");
if (fs->ExecuteSaveAs("Select dump directory"))
{
const Win32PESectionInformation& sect = LoadedProcessPEInformation.ImageSections[row];
if (mPeInstance->DumpProcessSection(fs->Get(), mPeInstance->GetBaseAddress() + sect.BaseAddress, sect.RawSectionSize ? sect.RawSectionSize : sect.SectionSize))
{
PromptOK("Dump succeeded!");
}
else
{
Prompt("Fatal error", CtrlImg::error(), "Failed to dump the section!", "OK");
}
}
delete fs;
}
}
void CryPEWindow::DumpDotNetSection()
{
const int row = this->mDotNetInformation.GetCursor();
if (row >= 0 && LoadedProcessPEInformation.DotNetInformation.DotNetSections.GetCount() > 0)
{
FileSel* fs = new FileSel();
fs->Types("Memory Dump files\t*.dmp");
if (fs->ExecuteSaveAs("Select dump directory"))
{
const Win32DotNetSectionInformation& sect = LoadedProcessPEInformation.DotNetInformation.DotNetSections[row];
if (mPeInstance->DumpProcessSection(fs->Get(), mPeInstance->GetBaseAddress() + LoadedProcessPEInformation.DotNetInformation.MetadataHeaderOffset + sect.Offset, sect.Size))
{
PromptOK("Dump succeeded!");
}
else
{
Prompt("Fatal error", CtrlImg::error(), "Failed to dump the section!", "OK");
}
}
delete fs;
}
}
// Updates the toolbar inside this lower pane window instance.
void CryPEWindow::UpdateToolbar()
{
this->mToolStrip.Set(THISBACK(ToolBar));
}