forked from RbxStu/RbxStu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Security.cpp
102 lines (91 loc) · 3.39 KB
/
Security.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
//
// Created by Dottik on 3/4/2024.
//
#include "Security.hpp"
#include <StudioOffsets.h>
#include <Utilities.hpp>
#include <cstdint>
#include <cstdio>
#include <lstate.h>
int64_t RBX::Security::deobfuscate_identity(RBX::Identity identity) {
// Some identities are merged, which means that the output doesn't matter truly. We just need to support the highest
// one.
switch (identity) {
case RBX::Identity::One_Four:
return 4;
case RBX::Identity::Two:
return 2;
case Three_Six:
return 6;
case RBX::Identity::Five:
return 5;
case RBX::Identity::Eight_Seven:
return 8;
case RBX::Identity::Nine:
return 9;
}
return 0;
}
int64_t RBX::Security::to_obfuscated_identity(int64_t identity) {
switch (identity) {
case 1:
case 4:
return RBX::Identity::One_Four;
case 2:
return RBX::Identity::Two;
case 3:
case 6:
return RBX::Identity::Three_Six;
case 5:
return RBX::Identity::Five;
case 7:
case 8:
return RBX::Identity::Eight_Seven;
case 9:
return RBX::Identity::Nine;
}
return 0;
}
RBX::Lua::ExtraSpace *RBX::Security::Bypasses::reallocate_extraspace(lua_State *L) {
const auto ud = static_cast<RBX::Lua::ExtraSpace *>(malloc(sizeof(RBX::Lua::ExtraSpace)));
if (Module::Utilities::is_pointer_valid(static_cast<RBX::Lua::OriginalExtraSpace *>(L->userdata))) {
// If userdata is valid, we must copy it to our new buffer.
// We must only copy the SIZE of Robloxs' ExtraSpace, not ours.
memcpy(ud, L->userdata, 0x98);
}
L->userdata = ud;
return ud;
}
void RBX::Security::Bypasses::set_thread_security(lua_State *L, const RBX::Identity identity) {
// Assume unallocated, what else would be 0 goddam.
if (!Module::Utilities::is_pointer_valid(static_cast<RBX::Lua::ExtraSpace *>(L->userdata)))
L->userdata = malloc(sizeof(RBX::Lua::ExtraSpace));
auto *plStateUd = static_cast<RBX::Lua::ExtraSpace *>(L->userdata);
plStateUd->identity = RBX::Security::deobfuscate_identity(identity);
plStateUd->capabilities =
0x3FFFF00 | RBX::Security::to_obfuscated_identity(RBX::Security::deobfuscate_identity(identity));
// Magical constant | Custom_Identity (Or Capabilities in some cases)
}
static void set_proto(Proto *proto, uintptr_t *proto_identity) {
proto->userdata = static_cast<void *>(proto_identity);
for (auto i = 0; i < proto->sizep; i++)
set_proto(proto->p[i], proto_identity);
}
bool RBX::Security::Bypasses::set_luaclosure_security(Closure *cl, const RBX::Identity identity) {
if (cl->isC)
return false;
const auto pProto = cl->l.p;
auto *pMem = pProto->userdata != nullptr ? static_cast<std::uintptr_t *>(pProto->userdata)
: static_cast<std::uintptr_t *>(malloc(sizeof(std::uintptr_t)));
*pMem = 0x3FFFF00 | (RBX::Security::to_obfuscated_identity(
RBX::Security::deobfuscate_identity(identity))); // Magical constant | Identity 8.
set_proto(pProto, pMem);
return true;
}
void RBX::Security::Bypasses::wipe_proto(Closure *lClosure) {
if (lClosure->isC)
return;
auto proto = lClosure->l.p;
proto->debugname = nullptr;
proto->linedefined = -1;
}