summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZephiles <cae222@yahoo.com>2021-09-10 19:33:26 -0500
committerZephiles <cae222@yahoo.com>2021-09-10 19:33:26 -0500
commit6e5b2a626ab58159c7159723ee1c07d5446ca376 (patch)
treebe4e5be278979703e508367cafe017ca10e9f1f4
parentae891d8b1c9866924f779ea51b501b7513c9e4f0 (diff)
Implement more efficient code for unhookFunction
-rw-r--r--include/patch.h22
1 files changed, 8 insertions, 14 deletions
diff --git a/include/patch.h b/include/patch.h
index e9e14f5..c68ecf2 100644
--- a/include/patch.h
+++ b/include/patch.h
@@ -48,24 +48,18 @@ namespace libtp::patch
uint32_t* instructions = reinterpret_cast<uint32_t*>( trampoline );
// Restore the original instruction
- uint32_t instructionAddress = reinterpret_cast<uint32_t>( &instructions[1] );
- uint32_t branchInstruction = instructions[1];
- uint32_t branchLength;
- uint32_t* address;
+ int32_t branchLength = instructions[1] & 0x03FFFFFC;
- if ( branchInstruction >= 0x4A000000 )
- {
- // Branch is negative
- branchLength = 0x4C000000 - branchInstruction;
- address = reinterpret_cast<uint32_t*>( instructionAddress - branchLength - 0x4 );
- }
- else
+ // Check if this is a negative branch
+ if ( branchLength > 0x01FFFFFC )
{
- // Branch is positive
- branchLength = branchInstruction - 0x48000000;
- address = reinterpret_cast<uint32_t*>( instructionAddress + branchLength - 0x4 );
+ const int32_t Width = 26;
+ const int32_t Mask = ( 1 << ( Width - 1 ) );
+ branchLength = ( branchLength ^ Mask ) - Mask - 0x4;
}
+ uint32_t instructionAddress = reinterpret_cast<uint32_t>( &instructions[1] );
+ uint32_t* address = reinterpret_cast<uint32_t*>( instructionAddress + branchLength );
*address = instructions[0];
// Clear the cache for both the address and where the instructions were stored