Skip to content

Commit 2c46358

Browse files
committed
clean code
1 parent 41672a4 commit 2c46358

File tree

6 files changed

+49
-90
lines changed

6 files changed

+49
-90
lines changed

debugger/attach/windows/src/Arch.vcxproj

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@
7272
<PropertyGroup Label="UserMacros" />
7373
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
7474
<LinkIncremental>true</LinkIncremental>
75-
<IncludePath>$(IncludePath)</IncludePath>
75+
<IncludePath>Shared;$(IncludePath)</IncludePath>
7676
<OutDir>$(SolutionDir)Build\$(Configuration)\x86\</OutDir>
7777
<IntDir>$(SolutionDir)Build\$(Configuration)\x86\Temp\$(ProjectName)</IntDir>
7878
</PropertyGroup>
7979
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
8080
<LinkIncremental>true</LinkIncremental>
81-
<IncludePath>$(IncludePath)</IncludePath>
81+
<IncludePath>Shared;$(IncludePath)</IncludePath>
8282
<OutDir>$(SolutionDir)Build\$(Configuration)\x64</OutDir>
8383
<IntDir>$(SolutionDir)Build\$(Configuration)\x64\Temp\$(ProjectName)</IntDir>
8484
</PropertyGroup>
@@ -168,9 +168,6 @@
168168
<ProjectReference Include="Shared.vcxproj">
169169
<Project>{2cd198e9-319c-48fb-85dc-ae3427a05bd2}</Project>
170170
</ProjectReference>
171-
<ProjectReference Include="tinyxml\tinyxmlSTL.vcxproj">
172-
<Project>{a3a84737-5017-4577-b8a2-79429a25b8b6}</Project>
173-
</ProjectReference>
174171
</ItemGroup>
175172
<ItemGroup>
176173
<ClCompile Include="arch\main.cpp" />

debugger/attach/windows/src/Debugger/DebugFrontend.cpp

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ along with Decoda. If not, see <http://www.gnu.org/licenses/>.
2424
#include "DebugEvent.h"
2525
#include "CriticalSectionLock.h"
2626
#include "StlUtility.h"
27+
#include "Utility.h"
2728

2829
#include <assert.h>
2930
#include <imagehlp.h>
@@ -984,41 +985,6 @@ unsigned int DebugFrontend::GetNumLines(const std::string& source) const
984985

985986
}
986987

987-
bool DebugFrontend::GetExeInfo(LPCSTR fileName, ExeInfo& info) const
988-
{
989-
990-
LOADED_IMAGE loadedImage;
991-
if (!MapAndLoad(const_cast<PSTR>(fileName), nullptr, &loadedImage, FALSE, TRUE))
992-
{
993-
return false;
994-
}
995-
996-
// Check if this is a managed application.
997-
// http://www.codeguru.com/cpp/w-p/system/misc/print.php/c14001
998-
999-
info.managed = false;
1000-
if (loadedImage.FileHeader->Signature == IMAGE_NT_SIGNATURE)
1001-
{
1002-
1003-
DWORD netHeaderAddress =
1004-
loadedImage.FileHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress;
1005-
1006-
if (netHeaderAddress)
1007-
{
1008-
info.managed = true;
1009-
}
1010-
1011-
}
1012-
1013-
info.entryPoint = loadedImage.FileHeader->OptionalHeader.AddressOfEntryPoint;
1014-
info.i386 = loadedImage.FileHeader->FileHeader.Machine == IMAGE_FILE_MACHINE_I386;
1015-
1016-
UnMapAndLoad(&loadedImage);
1017-
1018-
return true;
1019-
1020-
}
1021-
1022988
void DebugFrontend::SetBreakpoint(HANDLE hProcess, LPVOID entryPoint, bool set, BYTE* data) const
1023989
{
1024990

debugger/attach/windows/src/Debugger/DebugFrontend.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,6 @@ class DebugFrontend
200200

201201
private:
202202

203-
struct ExeInfo
204-
{
205-
size_t entryPoint;
206-
bool managed;
207-
bool i386;
208-
};
209-
210203
/**
211204
* Constructor.
212205
*/
@@ -293,12 +286,6 @@ class DebugFrontend
293286
*/
294287
bool GetIsBeingDebugged(DWORD processId) const;
295288

296-
/**
297-
* Gets the entry point for the specified executable file from the PE data. If the PE
298-
* is a .NET/managed application the managed parameter will be set to true.
299-
*/
300-
bool GetExeInfo(LPCSTR fileName, ExeInfo& info) const;
301-
302289
/**
303290
* Writes or clears a breakpoint (interrupt 3) at the address in the specified
304291
* process. When writing a breakpoint, the overwritten byte is store in data. The

debugger/attach/windows/src/Shared/Utility.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "Utility.h"
2+
#include <imagehlp.h>
23

34
HWND g_wnd;
45

@@ -26,3 +27,32 @@ HWND GetCurrentWnd()
2627
EnumWindows(EnumWindowsProcGetWndTitle, 0);
2728
return g_wnd;
2829
}
30+
31+
bool GetExeInfo(LPCSTR fileName, ExeInfo&info)
32+
{
33+
LOADED_IMAGE loadedImage;
34+
if (!MapAndLoad(const_cast<PSTR>(fileName), NULL, &loadedImage, FALSE, TRUE))
35+
{
36+
return false;
37+
}
38+
39+
info.managed = false;
40+
if (loadedImage.FileHeader->Signature == IMAGE_NT_SIGNATURE)
41+
{
42+
43+
DWORD netHeaderAddress =
44+
loadedImage.FileHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress;
45+
46+
if (netHeaderAddress)
47+
{
48+
info.managed = true;
49+
}
50+
}
51+
52+
info.entryPoint = loadedImage.FileHeader->OptionalHeader.AddressOfEntryPoint;
53+
info.i386 = loadedImage.FileHeader->FileHeader.Machine == IMAGE_FILE_MACHINE_I386;
54+
55+
UnMapAndLoad(&loadedImage);
56+
57+
return true;
58+
}

debugger/attach/windows/src/Shared/Utility.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22
#define UTILITY_H
33
#include <windows.h>
44

5+
struct ExeInfo
6+
{
7+
size_t entryPoint;
8+
bool managed;
9+
bool i386;
10+
};
11+
12+
/**
13+
* Gets the entry point for the specified executable file from the PE data. If the PE
14+
* is a .NET/managed application the managed parameter will be set to true.
15+
*/
16+
bool GetExeInfo(LPCSTR fileName, ExeInfo&info);
17+
18+
// »ñÈ¡µ±Ç°Ö÷´°¿Ú
519
HWND GetCurrentWnd();
620

721
#endif

debugger/attach/windows/src/arch/main.cpp

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,8 @@
11
#include <wtypes.h>
22
#include <stdio.h>
3-
#include <imagehlp.h>
43
#include <string>
54
#include <psapi.h>
6-
7-
struct ExeInfo
8-
{
9-
size_t entryPoint;
10-
bool managed;
11-
bool i386;
12-
};
13-
14-
bool GetExeInfo(LPCSTR fileName, ExeInfo&info)
15-
{
16-
LOADED_IMAGE loadedImage;
17-
if (!MapAndLoad(const_cast<PSTR>(fileName), NULL, &loadedImage, FALSE, TRUE))
18-
{
19-
return false;
20-
}
21-
22-
info.managed = false;
23-
if (loadedImage.FileHeader->Signature == IMAGE_NT_SIGNATURE)
24-
{
25-
26-
DWORD netHeaderAddress =
27-
loadedImage.FileHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress;
28-
29-
if (netHeaderAddress)
30-
{
31-
info.managed = true;
32-
}
33-
}
34-
35-
info.entryPoint = loadedImage.FileHeader->OptionalHeader.AddressOfEntryPoint;
36-
info.i386 = loadedImage.FileHeader->FileHeader.Machine == IMAGE_FILE_MACHINE_I386;
37-
38-
UnMapAndLoad(&loadedImage);
39-
40-
return true;
41-
}
5+
#include "Utility.h"
426

437
int main(int argc, char** argv)
448
{
@@ -52,6 +16,7 @@ int main(int argc, char** argv)
5216
printf("%d", info.i386);
5317
return info.i386;
5418
}
19+
return -1;//file not exist
5520
}
5621
else if(cmd == "-pid") {
5722
const char* pid_str = argv[2];

0 commit comments

Comments
 (0)