forked from NytroRST/ShellcodeCompiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebugUtils.cpp
More file actions
71 lines (55 loc) · 1.78 KB
/
DebugUtils.cpp
File metadata and controls
71 lines (55 loc) · 1.78 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
#include "DebugUtils.h"
#include "SEHUtils.h"
// Dump all data - debug purposes
void DebugUtils::DumpAllData()
{
cout << endl;
for (size_t i = 0; i < DeclaredFunctions::AllDeclaredFunctions.size(); i++)
{
cout << "Declared:" << DeclaredFunctions::AllDeclaredFunctions[i].Name << " @ " << DeclaredFunctions::AllDeclaredFunctions[i].DLL << endl;
}
cout << endl;
for (size_t i = 0; i < FunctionCalls::AllFunctionCalls.size(); i++)
{
cout << "Call function: " << FunctionCalls::AllFunctionCalls[i].Name << endl;
for (size_t j = 0; j < FunctionCalls::AllFunctionCalls[i].Parameters.size(); j++)
{
cout << ((FunctionCalls::AllFunctionCalls[i].Parameters[j].Type == FunctionCalls::PARAMETER_TYPE_STRING) ? "String" : "Int") << " parameter: ";
if (FunctionCalls::AllFunctionCalls[i].Parameters[j].Type == FunctionCalls::PARAMETER_TYPE_STRING) cout << FunctionCalls::AllFunctionCalls[i].Parameters[j].StringValue << endl;
else cout << FunctionCalls::AllFunctionCalls[i].Parameters[j].IntValue << endl;
}
}
cout << endl;
}
// Test the generated shellcode
void DebugUtils::TestShellcode(string p_sFilename)
{
unsigned char *p = NULL;
size_t size = 0;
p = Utils::ReadBinaryFile(p_sFilename, &size);
// Check if successful read
if (size == 0 || p == NULL)
{
cout << "Error: Cannot read shellcode file!" << endl;
return;
}
// Get space for shellcode
void *sc = VirtualAlloc(0, size, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if (sc == NULL)
{
cout << "Error: Cannot allocate space for shellcode!" << endl;
return;
}
// Copy shellcode and execute it
try
{
_set_se_translator(CxxTranslateSehException);
memcpy(sc, p, size);
(*(int(*)()) sc)();
}
catch (const seh_exception& e)
{
cout << "Error when executing shellcode: "
<< e.what() << endl;
}
}