标签: hotpatching

模块可以热补丁吗?

我希望能够在程序运行时为我正在进行的项目编写热点模块.我试过这个,但它不起作用:

qx[rm -r .precomp/*];
try require PSBot;
try PSBot.test;
Run Code Online (Sandbox Code Playgroud)

有可能吗?如果是这样,我该怎么办?

perl6 hotpatching raku

6
推荐指数
1
解决办法
109
查看次数

是否保证 x86 取指令是原子的,以便用短跳转重写指令对于并发线程执行是安全的?

我认为热补丁假设用 2 字节跳转覆盖任何 2 或更多字节长的指令对于并发执行相同的代码是安全的。

因此取指令被假定为原子的。

考虑到使用前缀可以有超过 8 字节的指令,并且它可以跨越任何对齐的边界,它确实是原子的吗?(或者热补丁是否依赖于函数开始的 16 字节对齐?如果是这样,那么大小超过 8 字节又是什么?)


上下文:LLVM 在https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/interception/interception_win.cpp中拦截了 API 函数。这至少用于 Address Sanitizer,也许也用于其他用途。它将 HotPatch 实现为第三种方法(第 61 行):

// 3) HotPatch
//
//    The HotPatch hooking is assuming the presence of an header with padding
//    and a first instruction with at least 2-bytes.
//
//    The reason to enforce the 2-bytes limitation is to provide the minimal
//    space to encode a short jump. HotPatch technique is only rewriting one …
Run Code Online (Sandbox Code Playgroud)

x86 atomic self-modifying hotpatching

5
推荐指数
1
解决办法
524
查看次数

挂钩 - 打屁股

我正在尝试挂钩Windows API函数FindWindowA().我成功地使用下面的代码完成了它而没有"hotpatching"它:我已经覆盖了函数开头的字节.调用myHook()并在调用FindWindowA()时显示一个消息框.

user32.dll启用了hotpatching,我想在实际函数之前覆盖NOP,而不是覆盖函数本身.但是,当我将hotpatching设置为TRUE时,下面的代码将不起作用.FindWindowA()执行时它什么都不做.

#include <stdio.h>
#include <windows.h>

void myHook()
{
    MessageBoxA(NULL, "Hooked", "Hook", MB_ICONINFORMATION);
}

int main(int argc, char *argv[])
{
    BOOLEAN hotpatching = FALSE;

    LPVOID fwAddress = GetProcAddress(GetModuleHandleA("user32.dll"), "FindWindowA");
    LPVOID fwHotpatchingAddress = (LPVOID)((DWORD)fwAddress - 5);
    LPVOID myHookAddress = &myHook;

    DWORD jmpOffset = (DWORD)&myHook - (DWORD)(!hotpatching ? fwAddress : fwHotpatchingAddress) - 5; // -5 because "JMP offset" = 5 bytes (1 + 4)

    printf("fwAddress: %X\n", fwAddress);
    printf("fwHotpatchingAddress: %X\n", fwHotpatchingAddress);
    printf("myHookAddress: %X\n", myHookAddress);
    printf("jmpOffset: %X\n", jmpOffset);
    printf("Ready?\n\n");
    getchar();


    char JMP[1] = …
Run Code Online (Sandbox Code Playgroud)

c windows assembly hook hotpatching

4
推荐指数
1
解决办法
1589
查看次数

标签 统计

hotpatching ×3

assembly ×1

atomic ×1

c ×1

hook ×1

perl6 ×1

raku ×1

self-modifying ×1

windows ×1

x86 ×1