-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManualMapper.hpp
94 lines (73 loc) · 2 KB
/
ManualMapper.hpp
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#pragma once
#include <Windows.h>
#include <TlHelp32.h>
#include <cstdint>
typedef HMODULE(__stdcall* MMAP_LoadLibraryA)(LPCSTR);
typedef FARPROC(__stdcall* MMAP_GetProcAddress)(HMODULE, LPCSTR);
typedef int(__stdcall* MMAP_dllmain)(HMODULE, DWORD, LPVOID);
struct ManualMapperLoadData
{
void* imageBase;
IMAGE_NT_HEADERS* NTHeaders;
IMAGE_BASE_RELOCATION* baseRelocation;
IMAGE_IMPORT_DESCRIPTOR* importDirectory;
MMAP_LoadLibraryA fnLoadLibraryA;
MMAP_GetProcAddress fnGetProcAddress;
};
class ManualMapper
{
private:
HANDLE process = nullptr;
/*
HEADER INFO
*/
DWORD DOSHeaderFileLocation = 0;
size_t nBytesReadDOSHeader = 0;
IMAGE_DOS_HEADER DOSHeader{};
DWORD NTHeadersFileLocation = 0;
size_t nBytesReadNTHeaders = 0;
IMAGE_NT_HEADERS NTHeaders{};
DWORD sectionHeadersFileLocation = 0;
size_t nBytesReadSectionHeaders = 0;
size_t sectionHeadersSize = 0;
IMAGE_SECTION_HEADER* sectionHeaders = nullptr; // its an array, btw ;)
/*
REMOTE COPYING INFORMATION
*/
void* remoteAddressOfImage = 0;
size_t nBytesHeadersWritten = 0;
size_t indexOfSectionToCopy = 0;
size_t nBytesCopiedForSection = 0;
void* remoteAddressOfLoader = 0;
ManualMapperLoadData loaderParameters{};
/*
CLASS INFORMATION
*/
DWORD seekFileLocation = 0;
int errorCode = 0;
int errorContext = 0;
bool executed = false;
/*
UTIL
*/
bool processStillAlive();
public:
ManualMapper(HANDLE process);
~ManualMapper();
// returns the file location that the bytes in next ProcessBytesFromFile call should come from
DWORD GetNextFileSeekLocation();
// returns true if its done mapping the DLL
bool ProcessBytesFromFile(BYTE* bytes, size_t nBytes);
// returns a value from namespace ManualMapperError
int GetErrorCode();
int GetErrorContext();
bool Errored();
// begins the execution of the DLL
// returns true if it was actually ready to execute
bool Execute();
// returns a char* descriptive of the
// next step in the injection processs
const char* GetNextStepDescription();
// debug
void printHeaders();
};