From c8d2e6ed99e77c4ba6f911e6dbeeffb8cefe2e95 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 28 Jun 2021 10:31:54 -0400 Subject: [PATCH 1/2] fix warnings and fix return values for nop/blr. Add post-build event --- libpsutil/encryption/rc4.cpp | 10 ++++++++-- libpsutil/libpsutil.vcxproj | 12 +++++++++++- libpsutil/system/memory.cpp | 4 ++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/libpsutil/encryption/rc4.cpp b/libpsutil/encryption/rc4.cpp index 9d97dab..36a5421 100644 --- a/libpsutil/encryption/rc4.cpp +++ b/libpsutil/encryption/rc4.cpp @@ -26,11 +26,14 @@ namespace libpsutil for (int i = 0; i < N; i++) S[i] = i; - for (int i = 0; i < N; i++) { + for (int i = 0; i < N; i++) + { j = (j + S[i] + key[i % len]) % N; swap(&S[i], &S[j]); } + + return 0; } int PRGA(unsigned char* S, char* plaintext, unsigned char* ciphertext) @@ -48,8 +51,9 @@ namespace libpsutil int rnd = S[(S[i] + S[j]) % N]; ciphertext[n] = rnd ^ plaintext[n]; - } + + return 0; } } @@ -59,6 +63,8 @@ namespace libpsutil KSA(key, S); PRGA(S, plaintext, ciphertext); + + return 0; } } } \ No newline at end of file diff --git a/libpsutil/libpsutil.vcxproj b/libpsutil/libpsutil.vcxproj index 5914bbf..f26b8a4 100644 --- a/libpsutil/libpsutil.vcxproj +++ b/libpsutil/libpsutil.vcxproj @@ -34,7 +34,7 @@ - + NDEBUG;%(PreprocessorDefinitions); @@ -42,6 +42,16 @@ NotUsing Cpp11 + + + + + + copy /y "$(TargetPath)" "$(SCE_PS3_ROOT)/target/ppu/lib/" + + + Copy Lib to SCE Lib Directory + diff --git a/libpsutil/system/memory.cpp b/libpsutil/system/memory.cpp index b0f9ca6..6c96b12 100644 --- a/libpsutil/system/memory.cpp +++ b/libpsutil/system/memory.cpp @@ -31,12 +31,12 @@ namespace libpsutil bool nop(uint32_t address) { - return set(address, 0x60000000) == SUCCEEDED; + return memory::set(address, 0x60000000); } bool blr(uint32_t address) { - return set(address, 0x4E800020) == SUCCEEDED; + return memory::set(address, 0x4E800020); } void jump(uint32_t address, uint32_t destination, bool linked) From 7b0a608ffdce69befcaecfb9ea8ed49c5171dbfe Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 30 Jun 2021 19:22:13 -0400 Subject: [PATCH 2/2] add a safe jump to detours to fix hooks using r0 --- libpsutil/system/memory.cpp | 20 ++++++++++++++++++-- libpsutil/system/memory.hpp | 1 + 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/libpsutil/system/memory.cpp b/libpsutil/system/memory.cpp index 6c96b12..b7fb16a 100644 --- a/libpsutil/system/memory.cpp +++ b/libpsutil/system/memory.cpp @@ -51,6 +51,22 @@ namespace libpsutil memory::set(address, instructions, sizeof(uint32_t) * 4); } + void jump_safe(uint32_t address, uint32_t destination, bool linked) + { + uint32_t instructions[8] = { 0 }; + + instructions[0] = 0xF821FFF9; + instructions[1] = 0xF8010000; + instructions[2] = 0x3C000000 + ((destination >> 16) & 0xFFFF); + instructions[3] = 0x60000000 + (destination & 0xFFFF); + instructions[4] = 0x7C0903A6; + instructions[5] = 0xE8010000; + instructions[6] = 0x38210008; + instructions[7] = 0x4E800420 + (linked ? 1 : 0); + + memory::set(address, instructions, sizeof(uint32_t) * 8); + } + uint32_t get_game_toc() { uint32_t* entry_point = *reinterpret_cast(0x1001C); //ElfHeader->e_entry @@ -65,7 +81,7 @@ namespace libpsutil stub_section = reinterpret_cast(detour::force_stub_addr); } - auto stub_address = reinterpret_cast(&stub_section[this->hook_count * 0x80]); + auto stub_address = reinterpret_cast(&stub_section[this->hook_count * 0x90]); this->hook_count++; return stub_address; @@ -111,7 +127,7 @@ namespace libpsutil } } - memory::jump(reinterpret_cast(&stub_address[instruction_count]), address + 0x10, false); + memory::jump_safe(reinterpret_cast(&stub_address[instruction_count]), address + 0x10, false); memory::jump(address, *reinterpret_cast(destination), false); this->stub_opd[0] = reinterpret_cast(stub_address); diff --git a/libpsutil/system/memory.hpp b/libpsutil/system/memory.hpp index c7556d4..b6c8f2f 100644 --- a/libpsutil/system/memory.hpp +++ b/libpsutil/system/memory.hpp @@ -17,6 +17,7 @@ namespace libpsutil bool blr(uint32_t address); void jump(uint32_t address, uint32_t destination, bool linked = false); + void jump_safe(uint32_t address, uint32_t destination, bool linked = false); uint32_t get_game_toc();