-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmemutil.h
118 lines (94 loc) · 3 KB
/
memutil.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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#ifndef MEMUTIL_H
#define MEMUTIL_H
#pragma once
#include <windows.h>
#include <vector>
#include <map>
typedef struct ImageSectionInfo
{
char Name[8];//the macro is defined WinNT.h
void* Address;
int Size;
};
typedef struct PatchInformation {
void* Address;
byte* Memory;
int Size;
};
typedef struct DetourDef {
void* targetf;
void* detourf;
void* trampolinef;
int bytecount;
byte* oldbytes;
};
typedef enum CODEINJ_t {
JUMPHOOK,
CALLHOOK,
};
typedef enum SSResult {
SSRESULT_UNINITIATED,
SSRESULT_FAILURE,
SSRESULT_SUCCESS,
};
typedef void(*SSCallback)(void*);
typedef struct SSEntry {
int* out;
const char* aob;
const char* mask;
signed int offset;
SSCallback callback;
SSResult state;
};
typedef std::map<const char*, SSEntry> map_queue;
#define reg_offset(o) (memutil->register_offset(&o))
class MemoryUtility {
private:
std::vector<PatchInformation>* patch_list;
std::vector<DetourDef>* detour_list;
HMODULE base_module;
void destroy_detour(DetourDef* def);
/* base function used for all writing in the class */
virtual int write_memory(int dAddress, const void* patch, int dSize);
public:
HMODULE GetBase() { return base_module; }
int WriteNOPs(int dAddress, byte dSize);
/* type:
0 = jmp
1 = call
*/
int CodeInjection(int destAddress, byte nopCount, void(*func)(void), int funcLength, byte saveInjection, CODEINJ_t type, PatchInformation** pPatchInfo = 0);
void* CreateDetour(void* targetf, void* detourf, int nopCount = 0);
void DestroyDetour(void* targetf);
/* writes patch information to patch_info if doDiscard is true */
int WriteMemory(int dAddress, const void* patch, int dSize, byte nopCount, byte doDiscard, PatchInformation** pPatchInfo = 0);
int GetSegmentInformation(HMODULE hModule, const char* s_name, ImageSectionInfo* pSectionInfo);
void* CopySegment(ImageSectionInfo& seg_info, int page_protection);
MemoryUtility();
~MemoryUtility();
int offset(int off) { return (int)base_module + off; }
void register_offset(void* val) { *(int*)val += (int)base_module; }
};
namespace sigscan {
int compare(const char* location, const char* aob, const char* mask);
int scan(const char* aob, const char* mask);
int scan(const char* aob, const char* mask, int start, int end);
int scan(const char* module, const char* aob, const char* mask);
int scan_writable(const char* aob, const char* mask);
int scan_writable(const char* aob, const char* mask, int start);
};
class SignatureScanner {
private:
map_queue queue;
int error_count;
public:
SignatureScanner();
void Queue(const char* tag, int* out, const char* aob, const char* mask, signed int offset, SSCallback callback);
void Queue(const char* tag, int* out, const char* aob, const char* mask, signed int offset);
void Run();
int ErrorCount();
map_queue GetResults();
void Reset();
};
extern MemoryUtility* memutil;
#endif