Skip to content

Commit

Permalink
cleanup timeouts, drop handle, configless patcher
Browse files Browse the repository at this point in the history
  • Loading branch information
moonshadow565 committed Jul 21, 2023
1 parent dbf3eb9 commit 7052de3
Show file tree
Hide file tree
Showing 12 changed files with 691 additions and 290 deletions.
2 changes: 2 additions & 0 deletions cslol-tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ add_library(cslol-lib STATIC
lib/lol/patcher/patcher_dummy.cpp
lib/lol/patcher/patcher_macos.cpp
lib/lol/patcher/patcher_win32.cpp
lib/lol/patcher/utility/delay.hpp
lib/lol/patcher/utility/lineconfig.hpp
lib/lol/patcher/utility/macho.hpp
lib/lol/patcher/utility/peex.hpp
lib/lol/patcher/utility/ppp.hpp
lib/lol/patcher/utility/process.hpp
lib/lol/patcher/utility/process_macos.cpp
Expand Down
50 changes: 38 additions & 12 deletions cslol-tools/lib/lol/patcher/asm/win32_hook_CreateFileA.asm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,32 @@ mov arg_dwShareMode[rbp], r8
mov arg_dwDesiredAccess[rbp], rdx
mov arg_lpFileName[rbp], rcx

; GENERIC_READ
cmp dword arg_dwDesiredAccess[rbp], 0x80000000
jne original

; FILE_SHARE_READ
cmp dword arg_dwShareMode[rbp], 1
jne original

; OPEN_EXISTING
cmp dword arg_dwCreationDisposition[rbp], 0x3
jne original

; FILE_ATTRIBUTE_NORMAL
cmp dword arg_dwFlagsAndAttributes[rbp], 0x80
jne original

; only DATA
cmp byte [rcx], 'D'
jne original
cmp byte [rcx+1], 'A'
jne original
cmp byte [rcx+2], 'T'
jne original
cmp byte [rcx+3], 'A'
jne original

; prepare buffer for writing
lea rdi, QWORD local_buffer[rbp]

Expand All @@ -51,7 +77,6 @@ write_path_skip:
test al, al
jne write_path


; call wide with modified buffer
mov rax, arg_hTemplateFile[rbp]
mov [rsp+48], rax
Expand All @@ -71,17 +96,18 @@ cmp rax, -1
jne done

; just call original
mov rax, arg_hTemplateFile[rbp]
mov [rsp+48], rax
mov rax, arg_dwFlagsAndAttributes[rbp]
mov [rsp+40], rax
mov rax, arg_dwCreationDisposition[rbp]
mov [rsp+32], rax
mov r9, arg_lpSecurityAttributes[rbp]
mov r8, arg_dwShareMode[rbp]
mov rdx, arg_dwDesiredAccess[rbp]
mov rcx, arg_lpFileName[rbp]
call QWORD [rel ptr_CreateFileA]
original:
mov rax, arg_hTemplateFile[rbp]
mov [rsp+48], rax
mov rax, arg_dwFlagsAndAttributes[rbp]
mov [rsp+40], rax
mov rax, arg_dwCreationDisposition[rbp]
mov [rsp+32], rax
mov r9, arg_lpSecurityAttributes[rbp]
mov r8, arg_dwShareMode[rbp]
mov rdx, arg_dwDesiredAccess[rbp]
mov rcx, arg_lpFileName[rbp]
call QWORD [rel ptr_CreateFileA]

; epilogue
done: add rsp, 72
Expand Down
10 changes: 9 additions & 1 deletion cslol-tools/lib/lol/patcher/patcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,16 @@ namespace lol::patcher {
"League exited",
};

extern auto run(std::function<bool(Message, char const*)> update,
extern auto run(std::function<void(Message, char const*)> update,
fs::path const& profile_path,
fs::path const& config_path,
fs::path const& game_path) -> void;

struct PatcherTimeout : std::runtime_error {
using std::runtime_error::runtime_error;
};

struct PatcherAborted : std::runtime_error {
PatcherAborted() : std::runtime_error("Aborted as expected") {}
};
}
4 changes: 2 additions & 2 deletions cslol-tools/lib/lol/patcher/patcher_dummy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ using namespace lol;
using namespace lol::patcher;
using namespace std::chrono_literals;

auto patcher::run(std::function<bool(Message, char const*)> update,
auto patcher::run(std::function<void(Message, char const*)> update,
fs::path const& profile_path,
fs::path const& config_path,
fs::path const& game_path) -> void {
(void)profile_path;
(void)config_path;
(void)game_path;
for (;;) {
if (!update(M_WAIT_START, "")) return;
update(M_WAIT_START, "");
std::this_thread::sleep_for(250ms);
}
}
Expand Down
39 changes: 20 additions & 19 deletions cslol-tools/lib/lol/patcher/patcher_macos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# include <cstring>
# include <thread>

# include "utility/lineconfig.hpp"
# include "utility/delay.hpp"
# include "utility/macho.hpp"
# include "utility/process.hpp"

Expand Down Expand Up @@ -90,7 +90,7 @@ struct Context {
}
};

auto patcher::run(std::function<bool(Message, char const*)> update,
auto patcher::run(std::function<void(Message, char const*)> update,
fs::path const& profile_path,
fs::path const& config_path,
fs::path const& game_path) -> void {
Expand All @@ -99,29 +99,30 @@ auto patcher::run(std::function<bool(Message, char const*)> update,
(void)config_path;
(void)game_path;
for (;;) {
auto process = Process::Find("/LeagueofLegends");
if (!process) {
if (!update(M_WAIT_START, "")) return;
std::this_thread::sleep_for(250ms);
auto pid = Process::FindPid("/LeagueofLegends");
if (!pid) {
update(M_WAIT_START, "");
std::this_thread::sleep_for(10ms);
continue;
}

if (!update(M_FOUND, "")) return;
update(M_FOUND, "");
auto process = Process::Open(pid);

if (!update(M_SCAN, "")) return;
ctx.scan(*process);
update(M_SCAN, "");
ctx.scan(process);

if (!update(M_PATCH, "")) return;
ctx.patch(*process);
update(M_PATCH, "");
ctx.patch(process);

for (std::uint32_t timeout = 3 * 60 * 60 * 1000; timeout; timeout -= 250) {
if (!update(M_WAIT_EXIT, "")) return;
if (process->WaitExit(0)) {
break;
}
std::this_thread::sleep_for(250ms);
}
if (!update(M_DONE, "")) return;
update(M_WAIT_EXIT, "");
run_until_or(
3h,
Intervals{5s, 10s, 15s},
[&] { return process.IsExited(); },
[]() -> bool { throw PatcherTimeout(std::string("Timed out exit")); });

update(M_DONE, "");
}
}

Expand Down

1 comment on commit 7052de3

@ICHIGOATYAGAMI
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EY

Please sign in to comment.