jmpews / Dobby

a lightweight, multi-platform, multi-architecture hook framework.
Apache License 2.0
3.89k stars 796 forks source link

mingw-w64-x86_64 HOOK失败(异常) #163

Open qokelate opened 2 years ago

qokelate commented 2 years ago

版本: commit 223aabced0431525c7d45196f9409fc505d58ac8 症状: CALL无效地址导致异常 x86_64-w64-mingw32-gcc: gcc version 10.1.0 (GCC)

debug037:0000000000350020 pushfq
debug037:0000000000350021 sub     rsp, 8
debug037:0000000000350028 sub     rsp, 80h
debug037:000000000035002F mov     [rsp], rax
debug037:0000000000350033 mov     [rsp+8], rbx
debug037:0000000000350038 mov     [rsp+10h], rcx
debug037:000000000035003D mov     [rsp+18h], rdx
debug037:0000000000350042 mov     [rsp+20h], rbp
debug037:0000000000350047 mov     [rsp+28h], rsp
debug037:000000000035004C mov     [rsp+30h], rdi
debug037:0000000000350051 mov     [rsp+38h], rsi
debug037:0000000000350056 mov     [rsp+40h], r8
debug037:000000000035005B mov     [rsp+48h], r9
debug037:0000000000350060 mov     [rsp+50h], r10
debug037:0000000000350065 mov     [rsp+58h], r11
debug037:000000000035006A mov     [rsp+60h], r12
debug037:000000000035006F mov     [rsp+68h], r13
debug037:0000000000350074 mov     [rsp+70h], r14
debug037:0000000000350079 mov     [rsp+78h], r15
debug037:000000000035007E mov     rax, rsp
debug037:0000000000350081 add     rax, 98h
debug037:0000000000350088 sub     rsp, 10h
debug037:000000000035008F mov     [rsp+8], rax
debug037:0000000000350094 mov     rdi, rsp
debug037:0000000000350097 mov     rsi, [rsp+0A0h]
debug037:000000000035009F mov     rax, rsp
debug037:00000000003500A2 and     rax, 0Fh
debug037:00000000003500A6 cmp     rax, 0
debug037:00000000003500AA jnz     short loc_3500C1
debug037:00000000003500AC nop
debug037:00000000003500AD call    $+5
debug037:00000000003500B2 pop     r11
debug037:00000000003500B4 call    qword ptr [r11+56h]  //此处异常
debug037:00000000003500BB nop
debug037:00000000003500BC jmp     loc_3500D3

源码:

static void dib(RegisterContext *ctx, const HookEntryInfo *info)
{
    MessageBoxW(NULL, L"hook_tramp", L"hook_tramp", 0);
}

int main(int argc, char **argv)
{
    DobbyInstrument((void *)MessageBoxA, dib); //add hook
    MessageBoxW(NULL, L"MessageBoxW", L"MessageBoxW", 0);
    MessageBoxA(NULL, "MessageBoxA", "MessageBoxA", 0); //test hook, not work
    return 0;
}