Overview
Virtual Method Table (VMT) hooking is a technique used to intercept C++ virtual function calls by replacing function pointers in an object’s virtual table. This is useful for hooking class methods in games and applications. The VMT hooking API in libmem provides a complete set of functions to create, manage, and clean up VMT hooks.lm_vmt_t Structure
Thelm_vmt_t structure is used to manage VMT hooks:
Pointer to the virtual method table being managed.
Linked list of hooked entries, storing original function pointers and their indices.
LM_VmtNew
Creates a new VMT manager from the VMT atvtable.
Signature
Parameters
The virtual method table to manage.
A pointer to the VMT manager that will be populated by this function.
Returns
LM_TRUE on success, LM_FALSE on failure.
LM_VmtHook
Hooks the VMT function at indexfrom_fn_index in the VMT managed by vmt, changing it to to.
Signature
Parameters
The VMT manager.
The index of the VMT function to hook.
The function that will replace the original VMT function.
Returns
LM_TRUE on success, LM_FALSE on failure.
LM_VmtUnhook
Unhooks the VMT function at indexfn_index in the VMT managed by vmt, restoring the original function.
Signature
Parameters
The VMT manager.
The index of the VMT function to unhook.
Returns
LM_TRUE on success, LM_FALSE on failure.
LM_VmtGetOriginal
Returns the original VMT function at indexfn_index in the VMT managed by vmt. If the function has not been hooked before, it returns the function pointer at that index in the VMT array.
Signature
Parameters
The VMT manager.
The index of the VMT function to query.
Returns
The original VMT function at indexfn_index in the VMT managed by vmt.
LM_VmtReset
Resets all the VMT functions back to their original addresses.Signature
Parameters
The VMT manager.
LM_VmtFree
Frees the VMT manager, restoring everything.Signature
Parameters
The VMT manager.