-
Notifications
You must be signed in to change notification settings - Fork 12
/
dllmain.cpp
76 lines (65 loc) · 2.22 KB
/
dllmain.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
#include "dllmain.h"
Console g_console = Console(CONSOLE_TITLE);
BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
CreateThread(nullptr, NULL, &DllThread, hModule, NULL, nullptr);
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
DWORD WINAPI DllThread(void* lpParam)
{
HMODULE hModule = reinterpret_cast<HMODULE>(lpParam);
g_console.Write(HeadingArt);
const auto start = chrono::high_resolution_clock::now();
auto moduleList = GetModuleList(hModule); // Skip our module, we dont need that one
if (moduleList.empty())
{
g_console.WriteBold("GetModuleList Failed!\n");
Sleep(5000);
FreeLibraryAndExitThread(hModule, -1);
}
g_console.FWrite("[i] %s has %zu non-system modules\n", moduleList[0]->szModule, moduleList.size());
string moduleName = moduleList[0]->szModule;
moduleName = moduleName.substr(0, moduleName.length() - 4); // remove the .exe from the name
InitializeLogs(moduleName); // Create the log directories and file streams
for (auto *targetModule : moduleList)
{
g_console.FWrite("[i] scanning %s\n", targetModule->szModule);
// Read PE file and get section headers
SectionInfo* sectInfo = GetSectionInformation(targetModule);
if (!sectInfo)
{
g_console.WriteBold("[!] Error: NULL Section Information!\n");
continue;
}
LogModuleStart(targetModule->szModule);
auto vtableList = FindAllVTables(sectInfo); // Scan for vtables
g_console.FWrite("[i] Found %d virtual function tables!\n\n", vtableList.size());
// Sort vtables alphabetically by class name then address
SortSymbols(vtableList);
//Dump all the metadata for this module
for (auto vtable : vtableList)
{
DumpVTableInfo(vtable, sectInfo);
DumpInheritanceInfo(vtable);
}
LogModuleEnd(targetModule->szModule);
}
const auto end = chrono::high_resolution_clock::now();
g_console.FWrite("[+] Took %d milliseconds\n", chrono::duration_cast<chrono::milliseconds>(end - start).count());
g_console.Write("[i] Output will be in Desktop\\Class_Dumper\\...");
CloseLogs();
g_console.WaitInput();
FreeLibraryAndExitThread(hModule, 0);
}