mirror of
https://git.checksum.fail/alec/saphir.git
synced 2026-05-01 09:59:43 +03:00
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.
53 lines
1.0 KiB
HolyC
53 lines
1.0 KiB
HolyC
#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;
|
|
} |