-
Notifications
You must be signed in to change notification settings - Fork 8
/
Decryptor.h
304 lines (229 loc) · 6.07 KB
/
Decryptor.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
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
294
295
296
297
298
299
300
301
302
303
304
#pragma once
#include "Alignments.h"
#include "FNamePool.h"
#include "decryption.h"
#include <Windows.h>
#include <string>
uint64 BaseAddress = (uint64)GetModuleHandleA(0);
class FNamePool* NamePoolData = nullptr;
#define DecryptWideOffset 0x32D05D0
#define DecryptNonWideOffset 0x32D0560
#define NamePoolDataOffset 0x9095380
static constexpr uint32 FNameMaxBlockBits = 13;
static constexpr uint32 FNameBlockOffsetBits = 16;
static constexpr uint32 FNameMaxBlocks = 1 << FNameMaxBlockBits;
static constexpr uint32 FNameBlockOffsets = 1 << FNameBlockOffsetBits;
struct FNameEntryId
{
FNameEntryId() : Value(0) {}
FNameEntryId(uint32 Id) : Value(Id) {}
explicit operator bool() const { return Value != 0; }
FORCEINLINE bool operator==(FNameEntryId Other) const
{
return Value == Other.Value;
}
FORCEINLINE static FNameEntryId FromUnstableInt(uint32 UnstableInt)
{
FNameEntryId Id;
Id.Value = UnstableInt;
return Id;
}
FORCEINLINE uint32 ToUnstableInt() const {
return Value;
}
uint32 Value;
};
struct FNameEntryHandle
{
uint32 Block = 0;
uint32 Offset = 0;
FNameEntryHandle(uint32 InBlock, uint32 InOffset)
: Block(InBlock)
, Offset(InOffset)
{}
FNameEntryHandle(FNameEntryId Id)
: Block(Id.ToUnstableInt() >> FNameBlockOffsetBits)
, Offset(Id.ToUnstableInt()& (FNameBlockOffsets - 1))
{}
operator FNameEntryId() const
{
return FNameEntryId::FromUnstableInt(Block << FNameBlockOffsetBits | Offset);
}
explicit operator bool() const { return Block | Offset; }
};
struct FNameEntryHeader
{
uint16 bIsWide : 1;
uint16 Len : 15;
};
struct FNameEntry {
enum { NAME_SIZE = 1024 };
public:
FORCEINLINE bool IsWide() const
{
return Header.bIsWide;
}
FORCEINLINE int32 GetNameLength() const
{
return Header.Len;
}
FORCEINLINE FNameEntryHeader GetEntryHeader() const
{
return Header;
}
static int32 GetSize(int32 Length, bool bIsPureAnsi);
char* DecryptNonWide();
wchar_t* DecryptWide();
FORCEINLINE void CopyUnterminatedName(ANSICHAR* Out)
{
memcpy(Out, DecryptNonWide(), sizeof(ANSICHAR) * Header.Len);
}
FORCEINLINE void CopyUnterminatedName(WIDECHAR* Out)
{
memcpy(Out, DecryptWide(), sizeof(WIDECHAR) * Header.Len);
}
FORCEINLINE static int32 GetDataOffset()
{
return offsetof(FNameEntry, AnsiName);
}
void GetAnsiName(ANSICHAR(&Out)[NAME_SIZE]);
void GetWideName(WIDECHAR(&Out)[NAME_SIZE]);
WCHAR* Wchar();
std::string String();
FNameEntryId ComparisonId;
FNameEntryHeader Header;
union
{
ANSICHAR AnsiName[NAME_SIZE];
WIDECHAR WideName[NAME_SIZE];
};
};
void FNameEntry::GetAnsiName(ANSICHAR(&Out)[NAME_SIZE])
{
if (!IsWide())
{
CopyUnterminatedName(Out);
Out[Header.Len] = '\0';
}
}
void FNameEntry::GetWideName(WIDECHAR(&Out)[NAME_SIZE])
{
if (IsWide())
{
CopyUnterminatedName(Out);
Out[Header.Len] = '\0';
}
}
class FNameEntryAllocator
{
public:
enum { Stride = alignof(FNameEntry) };
enum { BlockSizeBytes = Stride * FNameBlockOffsets };
void* FRWLock;
uint32 CurrentBlock = 0;
uint32 CurrentByteCursor = 0;
uint8* Blocks[FNameMaxBlocks] = {};
FORCEINLINE uint32 NumBlocks() const
{
return CurrentBlock + 1;
}
FORCEINLINE FNameEntry& Resolve(FNameEntryHandle Handle) const
{
if (Handle.Offset < 0 && Handle.Block > NumBlocks() && Handle.Offset * Stride < FNameBlockOffsets)
return *reinterpret_cast<FNameEntry*>(Blocks[0] + Stride * 0);
return *reinterpret_cast<FNameEntry*>(Blocks[Handle.Block] + Stride * Handle.Offset);
}
};
wchar_t* FNameEntry::DecryptWide()
{
auto _DecryptWideEntry = (__int64(__fastcall*)(FNameEntry * Entry, wchar_t* Buffer))(BaseAddress + DecryptWideOffset);
wchar_t Buffer[1024];
__int64 Result = _DecryptWideEntry(this, Buffer);
return Buffer;
}
char* FNameEntry::DecryptNonWide()
{
auto _DecryptNonWideEntry = (__int64(__fastcall*)(FNameEntry * Entry, char* Buffer))(BaseAddress + DecryptNonWideOffset);
char Buffer[1024];
__int64 Result = _DecryptNonWideEntry(this, Buffer);
return Buffer;
}
std::string FNameEntry::String()
{
if (IsWide()) {
WCHAR* DecryptedName = DecryptWide();
std::wstring Wide(DecryptedName, Header.Len);
return std::string(Wide.begin(), Wide.end());
}
char* DecryptedName = DecryptNonWide();
return std::string(DecryptedName, Header.Len);
}
WCHAR* FNameEntry::Wchar()
{
if (IsWide())
return DecryptWide();
else
return 0;
}
int32 FNameEntry::GetSize(int32 Length, bool bIsPureAnsi)
{
int32 Bytes = GetDataOffset() + Length * (bIsPureAnsi ? sizeof(ANSICHAR) : sizeof(WIDECHAR));
return Align(Bytes, alignof(FNameEntry));
}
class FNamePool
{
public:
enum { MaxENames = 512 };
FNameEntryAllocator Entries;
/*
* Not interested in other members.
*/
};
struct FName {
FNameEntryId ComparisonIndex;
FNameEntryId DisplayIndex;
uint32 Number;
FORCEINLINE FNameEntryId GetComparisonIndex() const
{
return ComparisonIndex;
}
FORCEINLINE FNameEntryId GetDisplayIndex() const
{
return DisplayIndex;
}
FORCEINLINE bool operator==(FName Other) const
{
return (ComparisonIndex == Other.ComparisonIndex) && (GetNumber() == Other.GetNumber());
}
FORCEINLINE bool operator!=(FName Other) const
{
return !(*this == Other);
}
FORCEINLINE int32 GetNumber() const
{
return Number;
}
FName() :
ComparisonIndex(FNameEntryId()),
Number(0)
{ }
FName(int32 i, int32 n = 0) :
ComparisonIndex(FNameEntryId(i)),
Number(n)
{ }
const FNameEntry* GetDisplayNameEntry() const;
std::string GetName();
};
const FNameEntry* FName::GetDisplayNameEntry() const
{
return &NamePoolData->Entries.Resolve(GetDisplayIndex());
}
std::string FName::GetName()
{
FNameEntry Entry = NamePoolData->Entries.Resolve(GetDisplayIndex());
std::string Name = Entry.String();
if (Number > 0) Name += '_' + std::to_string(Number);
std::size_t Pos = Name.rfind('/');
if (Pos != std::string::npos) Name = Name.substr(Pos + 1);
return Name;
}