mirror of
https://git.checksum.fail/alec/saphir.git
synced 2026-05-01 18:09:42 +03:00
Refactor everything
We now hijack existing system functions to integrate with `WinMgr`, instead of `Spawn`ing our own `SaphirTask`. Also, you can now use `Saphir(Bool)` to toggle enable/disable the features. There is a global var `saphir` which values are set by `Defaults.HC` for colors and other behaviors; these values can be changed at any time.
This commit is contained in:
53
Saphir/Misc.HC
Normal file
53
Saphir/Misc.HC
Normal file
@@ -0,0 +1,53 @@
|
||||
#define FN_MAXNUM 32
|
||||
|
||||
class FunctionIndex {
|
||||
U64 addr;
|
||||
U64 prologue;
|
||||
} fn_index[FN_MAXNUM];
|
||||
MemSet(fn_index, 0, sizeof(FunctionIndex));
|
||||
|
||||
I64 fn_restore(U32 from)
|
||||
{
|
||||
if (!from) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
I64 i;
|
||||
for (i = 0; i < FN_MAXNUM; i++) {
|
||||
if (fn_index[i].addr == from) {
|
||||
MemCpy(fn_index[i].addr, &fn_index[i].prologue, 8);
|
||||
fn_index[i].addr = fn_index[i].prologue = 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
I64 fn_patch(U32 from, U32 to, Bool patch = TRUE)
|
||||
{
|
||||
if (!from || !to) {
|
||||
return -1;
|
||||
}
|
||||
if (!patch) {
|
||||
return fn_restore(from);
|
||||
}
|
||||
|
||||
I64 i = 0;
|
||||
while (i < FN_MAXNUM && fn_index[i].addr) {
|
||||
if (fn_index[i].addr == from) {
|
||||
// Function already patched
|
||||
return -1;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
if (i >= FN_MAXNUM) {
|
||||
// Maximum entires reached
|
||||
return -1;
|
||||
}
|
||||
|
||||
fn_index[i].addr = from;
|
||||
MemCpy(&fn_index[i].prologue, from, 8);
|
||||
*(from(U8*)) = 0xE9;
|
||||
*((from + 1)(I32*)) = to - from - 5;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user