-
Notifications
You must be signed in to change notification settings - Fork 62
/
SrcDumper.cpp
293 lines (220 loc) · 6.62 KB
/
SrcDumper.cpp
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#include "stdafx.h"
#include "SrcDumper.h"
SrcDumper::SrcDumper() {}
SrcDumper::SrcDumper(jsonxx::Object* json)
{
jsonConfig = json;
std::string procName = jsonConfig->get<std::string>("executable");
//Find proc & open handle
proc = ProcEx((char*)procName.c_str());
}
intptr_t SrcDumper::GetdwGetAllClassesAddr()
{
for (auto s : signatures)
{
if (s.name == "dwGetAllClasses")
{
return s.result;
}
}
return 0;
}
HMODULE SrcDumper::LoadClientDLL(ProcEx proc)
{
ModEx mod(_T("client.dll"), proc);
std::filesystem::path p(mod.modEntry.szExePath);
p = p.parent_path().parent_path().parent_path() / "bin";
AddDllDirectory(p.wstring().c_str());
return LoadLibraryEx(mod.modEntry.szExePath, NULL, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
}
intptr_t GetOffset(RecvTable* table, const char* tableName, const char* netvarName)
{
for (int i = 0; i < table->m_nProps; i++)
{
RecvProp prop = table->m_pProps[i];
if (!_stricmp(prop.m_pVarName, netvarName))
{
return prop.m_Offset;
}
if (prop.m_pDataTable)
{
intptr_t offset = GetOffset(prop.m_pDataTable, tableName, netvarName);
if (offset)
{
return offset + prop.m_Offset;
}
}
}
return 0;
}
intptr_t SrcDumper::GetNetVarOffset(const char* tableName, const char* netvarName, ClientClass* clientClass)
{
ClientClass* currNode = clientClass;
for (auto currNode = clientClass; currNode; currNode = currNode->m_pNext)
{
if (!_stricmp(tableName, currNode->m_pRecvTable->m_pNetTableName))
{
return GetOffset(currNode->m_pRecvTable, tableName, netvarName);
}
}
return 0;
}
void SrcDumper::ProcessNetvars()
{
jsonxx::Array netvars = jsonConfig->get<jsonxx::Array>("netvars");
//Loop through JSON netvar array
for (size_t i = 0; i < netvars.size(); i++)
{
jsonxx::Object curr = netvars.get<jsonxx::Object>(i);
NetvarData currData;
currData.name = curr.get<jsonxx::String>("name");
currData.prop = curr.get<jsonxx::String>("prop");
currData.table = curr.get<jsonxx::String>("table");
//dump offsets from json into vector
if (curr.has<jsonxx::Number>("offset"))
{
jsonxx::Number offset = curr.get<jsonxx::Number>("offset");
currData.offset = (int)offset;
}
Netvars.push_back(currData);
}
//^ we parsed the json into Netvars
//now we can locally load client_panorama.dll and get the netvar offsets internally
HMODULE hMod = LoadClientDLL(proc);
//Get First ClientClass in the linked list
ClientClass* dwGetallClassesAddr = (ClientClass*)((intptr_t)hMod + GetdwGetAllClassesAddr());
//for each netvar in netvars, get the offset
for (NetvarData& n : Netvars)
{
n.result = GetNetVarOffset(n.table.c_str(), n.prop.c_str(), dwGetallClassesAddr);
if (n.offset)
{
n.result += n.offset;
}
}
}
void SrcDumper::GenerateHeaderOuput()
{
//TODO: convert to string output
std::ofstream file;
file.open(jsonConfig->get<std::string>("filename") + ".h");
file << "#pragma once\n#include <cstdint>\n";
//timestamp
file << "//GuidedHacking.com r0x0rs ur b0x0rs\n";
file << "namespace offsets\n{\n";
file << "//signatures\n";
for (auto s : signatures)
{
file << "constexpr ptrdiff_t " << s.name << " = 0x" << std::uppercase << std::hex << s.result << ";\n";
}
file << "\n//netvars\n";
for (auto n : Netvars)
{
file << "constexpr ptrdiff_t " << n.name << " = 0x" << std::uppercase << std::hex << n.result << ";\n";
}
file << "}";
file.close();
}
void SrcDumper::GenerateCheatEngineOutput()
{
std::string output;
//header
output += "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
output += "<CheatTable CheatEngineTableVersion=\"31\">\n";
//todo: add all vars to the cheat table in module.dll + symbol form
//most are offset from client base address, some from clientstate I believe
//most are prefixed with f, i, etc... to define the variable type, we can use substring search to pull this info maybe
//Work In Progress: We are only adding symbol names and adding each sig/netvar as a relative offset
//not currently displaying correct data type and the full address, just a basic CE Table
int count = 0;
output += "<CheatEntries>\n";
for (auto n : Netvars)
{
std::string netvarOutput;
netvarOutput += "<CheatEntry>\n<ID>";
netvarOutput += std::to_string(count); //decimal
netvarOutput += "</ID>\n<Description>";
netvarOutput += n.name;
netvarOutput += "</Description>\n";
netvarOutput += n.GetCEVariableTypeString();
//netvarOutput += "<LastState/>\n<Address>client_panorama.dll + ";
//netvarOutput += AddrToHexString(n.result); //hex uppercase
//temporary output for basic CE table
netvarOutput += "<LastState/>\n<Address>" + n.name;
//end temp output
netvarOutput += "</Address>\n</CheatEntry>\n";;
output += netvarOutput;
count++;
}
for (auto s : signatures)
{
std::string sigOutput;
sigOutput += "<CheatEntry>\n";
sigOutput += "<ID>" + std::to_string(count);
sigOutput += "</ID>\n";
sigOutput += "<Description>" + s.name + "</Description>\n";
//sigOutput += "<LastState/>\n";
//sigOutput += "<Address>client_panorama.dll + ";
//sigOutput += AddrToHexString(s.result);
//temporary output for basic CE table
sigOutput += "<LastState/>\n<Address>" + s.name;
//end temp output
sigOutput += "</Address>\n</CheatEntry>\n";
output += sigOutput;
count++;
}
output += "</CheatEntries>";
//end cheat entries output
//Add all offsets as User Defined Symbols, these are aliases for addresses you can use throughout your table
output += "<UserdefinedSymbols>";
for (auto n : Netvars)
{
output += "<SymbolEntry>\n";
output += "<Name>" + n.name + "</Name>\n";
output += "<Address>";
output += AddrToHexString(n.result);
output += "</Address>\n";
output += "</SymbolEntry>\n";
}
for (auto s : signatures)
{
output += "<SymbolEntry>\n";
output += "<Name>" + s.name + "</Name>\n";
output += "<Address>";
output += AddrToHexString(s.result);
output += "</Address>\n";
output += "</SymbolEntry>\n";
}
output += "</UserdefinedSymbols>\n";
//end symbol output
//footer
output += "</CheatTable>";
std::ofstream file;
file.open(jsonConfig->get<std::string>("filename") + ".CT");
file << output;
file.close();
}
void SrcDumper::Dump()
{
ProcessSignatures();
ProcessNetvars();
//Generate header output
GenerateHeaderOuput();
//Generate Cheat Engine output
GenerateCheatEngineOutput();
//Generate ReClass.NET output
}
std::string SrcDumper::GetSigBase(SigData sigdata)
{
std::string sigBase;
if (sigdata.name.find("clientstate_") != std::string::npos)
{
sigBase = "[" + sigdata.module + "dwClientState]";
}
else
{
sigBase = sigdata.module;
}
return sigBase;
//does sig.module define the base module of the offset as well as signature? think so
}