-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathReaderUtils.h
177 lines (133 loc) · 3.53 KB
/
ReaderUtils.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include "ProcessUtils.h"
#pragma once
class ReaderUtils {
public:
static uint16_t ReadUInt16(ifstream& in) {
uint16_t value = 0;
in.read(reinterpret_cast<char*>(&value), sizeof(uint16_t));
return value;
}
static uint32_t ReadUInt32(ifstream& in) {
uint32_t value = 0;
in.read(reinterpret_cast<char*>(&value), sizeof(uint32_t));
return value;
}
static uint8_t ReadByte(ifstream& in) {
uint8_t value = 0;
in.read(reinterpret_cast<char*>(&value), sizeof(uint8_t));
return value;
}
static uint32_t ReadBytes_3(ifstream& in) {
uint16_t value_short = 0;
in.read(reinterpret_cast<char*>(&value_short), sizeof(uint16_t));
uint8_t value_byte = 0;
in.read(reinterpret_cast<char*>(&value_byte), sizeof(uint8_t));
return value_short+value_byte;
}
static DWORD SearchFileForSigFunc(const char* filePath) {
std::ifstream file(filePath, std::ios::binary);
if (!file.is_open()) {
return 0;
}
std::streampos fileSize;
DWORD offset = 0x0;
file.seekg(0, std::ios::end);
fileSize = file.tellg();
file.seekg(offset, std::ios::beg);
while (offset <= fileSize) {
if (ReadByte(file) == 0xA6) {
if (ReadUInt32(file) == 0x4D000000) {
if (ReadUInt16(file) == 0xC78B) {
file.close();
return offset;
}
offset+=2;
}
offset+=4;
}
offset++;
}
file.close();
return 0;
}
static DWORD SearchFileForPackFunc(const char* filePath) {
std::ifstream file(filePath, std::ios::binary);
if (!file.is_open()) {
return 0;
}
std::streampos fileSize;
DWORD offset = 0x0;
file.seekg(0, std::ios::end);
fileSize = file.tellg();
file.seekg(offset, std::ios::beg);
while (offset <= fileSize) {
if (ReadByte(file) == 0x88) {
if (ReadUInt16(file) == 0x3046) {
if (ReadByte(file) == 0x4C) {
file.close();
return offset;
}
offset++;
}
offset+=2;
}
offset++;
}
file.close();
return 0;
}
static DWORD SearchFileForIntegFunc(const char* filePath) {
std::ifstream file(filePath, std::ios::binary);
if (!file.is_open()) {
return 0;
}
std::streampos fileSize;
DWORD offset = 0x0;
file.seekg(0, std::ios::end);
fileSize = file.tellg();
file.seekg(offset, std::ios::beg);
while (offset <= fileSize) {
// Find Byte
if (ReadByte(file) == 0x84) {
// Find Short
if (ReadUInt16(file) == 0x75C0) {
// Skips two, compares next two bytes
file.seekg(offset + 1, std::ios::beg);
if (ReadUInt16(file) == 0x01B1) {
file.close();
return offset - 1;
}
offset += 3;
}
offset += 2;
}
offset++;
}
file.close();
return 0;
}
static DWORD GetPackOffset(char moduleName[]) {
DWORD offset = ReaderUtils::SearchFileForPackFunc(moduleName);
std::cout << "\n\nAddress: " << std::hex << offset;
if (offset == 0) {
std::cout << "No Addresses found.";
}
return offset;
}
static DWORD GetInterfaceOffset(char moduleName[]) {
DWORD offset = ReaderUtils::SearchFileForIntegFunc(moduleName);
std::cout << "\n\nAddress: " << std::hex << offset;
if (offset == 0) {
std::cout << "No Addresses found.";
}
return offset;
}
static DWORD GetSigOffset(char moduleName[]) {
DWORD offset = ReaderUtils::SearchFileForSigFunc(moduleName);
std::cout << "\n\nAddress: " << std::hex << offset - 2;
if (offset == 0) {
std::cout << "No Addresses found.";
}
return offset - 2;
}
};