-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathIATModifier.h
50 lines (41 loc) · 1.4 KB
/
IATModifier.h
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
#ifndef IATMODIFIER_H
#define IATMODIFIER_H
#include <iostream>
#include <vector>
#include "Process.h"
class IATModifier
{
public:
IATModifier(const Process& process);
~IATModifier();
std::vector<IMAGE_IMPORT_DESCRIPTOR> readImportTable();
void setImageBase(uintptr_t address);
void writeIAT(const std::vector<std::string>& dlls);
void writeIAT(const std::string& dll);
IMAGE_NT_HEADERS readNTHeaders() const;
private:
DWORD pad(DWORD val, DWORD amount) { return (val+amount) & ~amount; };
DWORD padToDword(DWORD val) { return pad(val, 3); };
void* allocateMemAboveBase(void* baseAddress, size_t size);
DWORD determineIIDSize(PIMAGE_IMPORT_DESCRIPTOR importDescriptorTableAddress);
Process process_;
PIMAGE_IMPORT_DESCRIPTOR importDescrTblAddr_;
uintptr_t ntHeadersAddr_;
unsigned int importDescrTblSize_;
};
// general exception for this class
class IATModifierException : public std::runtime_error
{
public:
IATModifierException(const std::string& msg) : std::runtime_error(msg) {};
};
// exception while writing image import descriptors
class WriteIIDException : public std::runtime_error
{
public:
WriteIIDException(const std::string& msg, const MemoryAccessException& e) : std::runtime_error(msg), innerException_(e) {};
MemoryAccessException innerException() const { return innerException_; };
private:
MemoryAccessException innerException_;
};
#endif