rdbo / libmem

Advanced Game Hacking Library for C, Modern C++, Rust and Python (Windows/Linux/FreeBSD) (Process/Memory Hacking) (Hooking/Detouring) (Cross Platform) (x86/x64/ARM/ARM64) (DLL/SO Injection) (Internal/External) (Assembler/Disassembler)
GNU Affero General Public License v3.0
784 stars 91 forks source link

Add VMT hooking API #79

Closed rdbo closed 1 year ago

rdbo commented 1 year ago

VMT hooking is a very importart part of game hacking. It allows you to hook the vtable of an object of a class, getting access to all of its virtual functions and the ability to call/overwrite them. This is necessary, although I need to think of a lean way of implementing this.

rdbo commented 1 year ago

Initial look:

typedef struct {
    lm_address_t *vtable;
    struct vmt_func {
        lm_void_t *func;
        lm_size_t index;
        struct vmt_func *next;
    } orig_funcs;
} lm_vmt_t;

lm_bool_t
LM_VmtNew(lm_address_t *vtable, lm_vmt_t *vmtbuf);

lm_bool_t
LM_VmtHook(lm_vmt_t *pvmt, lm_size_t index, lm_void_t *dest);

lm_bool_t
LM_VmtUnhook(lm_vmt_t *pvmt, lm_size_t index);

lm_bool_t
LM_VmtRestore(lm_vmt_t *pvmt);

lm_void_t
LM_VmtFree(lm_vmt_t *pvmt);
rdbo commented 1 year ago

Done: 984d9dcce1240fdc684f7cb3aa3c043cf0187c08 11a963cce910c1282d6745074f3b733fe235215c 5080dfe548769f729f84d0d90a5dfa6c44764544 2fbc33b0f0e999522c41eda66372fc2935aa8228