Skip to content

Commit edbd86b

Browse files
committed
fix(RCE): typos
1 parent 557a25e commit edbd86b

1 file changed

Lines changed: 58 additions & 7 deletions

File tree

src/component/engine/patches/patches.cpp

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "loader/component_loader.hpp"
33

44
#include "component/engine/console/console.hpp"
5+
#include "component/engine/console/command.hpp"
56
#include "component/utils/scheduler.hpp"
67

78
#include "game/game.hpp"
@@ -111,11 +112,11 @@ namespace patches
111112
return 1;
112113
}
113114

114-
using cl_parse_server_message_huffman_t = unsigned int(__cdecl*)(int, _DWORD*);
115+
using cl_parse_server_message_huffman_t = unsigned int(__cdecl*)(int, std::uint32_t*);
115116
utils::hook::detour cl_parse_server_message_huffman_hook;
116-
unsigned int __cdecl CL_ParseServerMessage_huffman_guard(int a1, _DWORD* a2)
117+
unsigned int __cdecl CL_ParseServerMessage_huffman_guard(int a1, std::uint32_t* a2)
117118
{
118-
const auto* const original = reinterpret_cast<cl_parse_server_message_huffman_t>(cl_parse_server_message_huffman_hook.get_original());
119+
const cl_parse_server_message_huffman_t original = reinterpret_cast<cl_parse_server_message_huffman_t>(cl_parse_server_message_huffman_hook.get_original());
119120

120121
if (!a2)
121122
{
@@ -152,7 +153,7 @@ namespace patches
152153
utils::hook::detour ui_replace_directive_hook;
153154
char* __fastcall UI_ReplaceDirective_guard(int ArgList, char* a2, int a3, unsigned __int8 a4)
154155
{
155-
const auto* const original = reinterpret_cast<ui_replace_directive_t>(ui_replace_directive_hook.get_original());
156+
const ui_replace_directive_t original = reinterpret_cast<ui_replace_directive_t>(ui_replace_directive_hook.get_original());
156157
const auto* const arg_list = reinterpret_cast<const char*>(ArgList);
157158
if (bounded_length(arg_list, k_ui_replace_directive_max_len + 1) > k_ui_replace_directive_max_len
158159
|| bounded_length(a2, k_ui_replace_directive_max_len + 1) > k_ui_replace_directive_max_len)
@@ -164,11 +165,11 @@ namespace patches
164165
return original(ArgList, a2, a3, a4);
165166
}
166167

167-
using party_atomic_host_handle_member_join_t = int(__cdecl*)(char, _DWORD*, int, __int64, int, _DWORD*);
168+
using party_atomic_host_handle_member_join_t = int(__cdecl*)(char, std::uint32_t*, int, __int64, int, std::uint32_t*);
168169
utils::hook::detour party_atomic_host_handle_member_join_hook;
169-
int __cdecl PartyAtomicHost_HandleMemberJoin_guard(char a1, _DWORD* a2, int a3, __int64 a4, int a5, _DWORD* a6)
170+
int __cdecl PartyAtomicHost_HandleMemberJoin_guard(char a1, std::uint32_t* a2, int a3, __int64 a4, int a5, std::uint32_t* a6)
170171
{
171-
const auto* const original = reinterpret_cast<party_atomic_host_handle_member_join_t>(party_atomic_host_handle_member_join_hook.get_original());
172+
const party_atomic_host_handle_member_join_t original = reinterpret_cast<party_atomic_host_handle_member_join_t>(party_atomic_host_handle_member_join_hook.get_original());
172173
if (!a2 || !a6)
173174
{
174175
return original(a1, a2, a3, a4, a5, a6);
@@ -190,6 +191,55 @@ namespace patches
190191
return original(a1, a2, a3, a4, a5, a6);
191192
}
192193

194+
bool PartyAtomicHost_HandleMemberJoin_self_test()
195+
{
196+
std::uint32_t packet_cursor[8]{};
197+
std::uint32_t join_state[8]{};
198+
199+
packet_cursor[5] = 0;
200+
packet_cursor[7] = 1;
201+
202+
const auto result = PartyAtomicHost_HandleMemberJoin_guard(0, &join_state[0], 0, 0, 0, &packet_cursor[0]);
203+
if (result != 0)
204+
{
205+
game::Com_Printf(0, "PartyAtomicHost_HandleMemberJoin self-test failed\n");
206+
return false;
207+
}
208+
209+
game::Com_Printf(0, "PartyAtomicHost_HandleMemberJoin self-test passed\n");
210+
return true;
211+
}
212+
213+
bool UI_ReplaceDirective_self_test()
214+
{
215+
char oversized[0x110]{};
216+
char output[0x110]{};
217+
std::memset(oversized, 'A', sizeof(oversized) - 1);
218+
oversized[sizeof(oversized) - 1] = '\0';
219+
220+
const auto result = UI_ReplaceDirective_guard(reinterpret_cast<int>(oversized), output, 0, 0);
221+
if (result != output)
222+
{
223+
game::Com_Printf(0, "UI_ReplaceDirective self-test failed\n");
224+
return false;
225+
}
226+
227+
game::Com_Printf(0, "UI_ReplaceDirective self-test passed\n");
228+
return true;
229+
}
230+
231+
void register_security_guard_self_test()
232+
{
233+
command::add("securityGuardSelfTest", [](const command::params&)
234+
{
235+
const auto party_ok = PartyAtomicHost_HandleMemberJoin_self_test();
236+
const auto ui_ok = UI_ReplaceDirective_self_test();
237+
game::Com_Printf(0, "securityGuardSelfTest: party=%s ui=%s\n",
238+
party_ok ? "pass" : "fail",
239+
ui_ok ? "pass" : "fail");
240+
});
241+
}
242+
193243
bool dvar_enabled(const char* name)
194244
{
195245
const auto* const dvar = game::Dvar_FindVar(name);
@@ -600,6 +650,7 @@ namespace patches
600650
cl_parse_server_message_huffman_hook.create(game::game_offset(0x1030D960), CL_ParseServerMessage_huffman_guard);
601651
ui_replace_directive_hook.create(game::game_offset(0x102BB870), UI_ReplaceDirective_guard);
602652
party_atomic_host_handle_member_join_hook.create(game::game_offset(0x103087B0), PartyAtomicHost_HandleMemberJoin_guard);
653+
register_security_guard_self_test();
603654

604655
scheduler::loop([]
605656
{

0 commit comments

Comments
 (0)