-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexportTablePrint.cpp
More file actions
55 lines (42 loc) · 1.46 KB
/
exportTablePrint.cpp
File metadata and controls
55 lines (42 loc) · 1.46 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
#include <windows.h>
#include <iostream>
/*
Use: .\exportTablePrint.exe [DLL]
*/
int main(int argc, char ** argv) {
char* dllPath = argv[1];
// Load DLL into memory
HMODULE hModule = LoadLibraryA(dllPath);
if (!hModule) {
std::cerr << "Failed to load DLL\n";
return 1;
}
// Get DOS Header
PIMAGE_DOS_HEADER dosHeader = (PIMAGE_DOS_HEADER)hModule;
if (dosHeader->e_magic != IMAGE_DOS_SIGNATURE) {
std::cerr << "Not a valid PE file\n";
return 1;
}
// Get NT Headers
PIMAGE_NT_HEADERS ntHeaders = (PIMAGE_NT_HEADERS)((BYTE*)hModule + dosHeader->e_lfanew);
if (ntHeaders->Signature != IMAGE_NT_SIGNATURE) {
std::cerr << "Invalid NT headers\n";
return 1;
}
// Get Export Directory
DWORD exportRVA = ntHeaders->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
if (!exportRVA) {
std::cerr << "No export table found\n";
return 1;
}
PIMAGE_EXPORT_DIRECTORY exportDir = (PIMAGE_EXPORT_DIRECTORY)((BYTE*)hModule + exportRVA);
DWORD* nameRVAs = (DWORD*)((BYTE*)hModule + exportDir->AddressOfNames);
WORD* nameOrdinals = (WORD*)((BYTE*)hModule + exportDir->AddressOfNameOrdinals);
std::cout << "Exported functions:\n";
for (DWORD i = 0; i < exportDir->NumberOfNames; ++i) {
char* funcName = (char*)hModule + nameRVAs[i];
std::cout << funcName << "\n";
}
FreeLibrary(hModule);
return 0;
}