File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -53,4 +53,39 @@ Func hookFunction(Func function, Dest destination)
53
53
return reinterpret_cast <Func>(trampoline);
54
54
}
55
55
56
+ template <typename Func>
57
+ Func unhookFunction (Func trampoline)
58
+ {
59
+ uint32_t *instructions = reinterpret_cast <uint32_t *>(trampoline);
60
+
61
+ // Restore the original instruction
62
+ uint32_t instructionAddress = reinterpret_cast <uint32_t >(&instructions[1 ]);
63
+ uint32_t branchInstruction = instructions[1 ];
64
+ uint32_t branchLength;
65
+ uint32_t *address;
66
+
67
+ if (branchInstruction >= 0x4A000000 )
68
+ {
69
+ // Branch is negative
70
+ branchLength = 0x4C000000 - branchInstruction;
71
+ address = reinterpret_cast <uint32_t *>(instructionAddress - branchLength - 0x4 );
72
+ }
73
+ else
74
+ {
75
+ // Branch is positive
76
+ branchLength = branchInstruction - 0x48000000 ;
77
+ address = reinterpret_cast <uint32_t *>(instructionAddress + branchLength - 0x4 );
78
+ }
79
+
80
+ *address = instructions[0 ];
81
+
82
+ // Clear the cache for both the address and where the instructions were stored
83
+ clear_DC_IC_Cache (address, sizeof (uint32_t ));
84
+ clear_DC_IC_Cache (instructions, sizeof (uint32_t ));
85
+
86
+ // Free the memory used by the trampoline
87
+ delete[] (instructions);
88
+ return nullptr ;
89
+ }
90
+
56
91
}
You can’t perform that action at this time.
0 commit comments