blob: cc615723aa9a597e0a2c5fb76462bf237d37be59 (
plain)
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
|
#pragma once
#include <string>
#include <Windows.h>
typedef void(*LibEntry_FN)(void);
static inline bool LoadAndTestLibraryEntry(const char * const fullDllPath)
{
HMODULE TestDLLModule = LoadLibraryA(fullDllPath);
LibEntry_FN LibEntryProc = (LibEntry_FN)GetProcAddress(TestDLLModule, "LibEntry");
if (LibEntryProc) {
LibEntryProc();
return true;
}
else {
return false;
}
}
class DLLHelper
{
public:
DLLHelper();
~DLLHelper();
bool Init(HANDLE targetPID, const char * fullDllPath);
bool VerifyHeader();
bool InitTargetMemory();
bool HasImports() {
return m_NTHeader &&
m_NTHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].Size;
}
bool FixImports();
bool HasRelocs() {
return m_NTHeader &&
m_NTHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size;
}
bool FixRelocs();
bool CopyHeaderAndSections();
private:
HANDLE m_TargetPID = 0;
std::string m_DLLPath;
DWORD m_DLLSize = 0;
UINT8 *m_DLLPtr = nullptr;
IMAGE_DOS_HEADER *m_DOSHeader = nullptr;
IMAGE_NT_HEADERS *m_NTHeader = nullptr;
PVOID m_TargetBaseAddress = nullptr;
};
|