Skip to main content
Glama

hook_native_function

Hook native functions in game processes to intercept, analyze, or modify their behavior during execution. Specify calling conventions, argument types, and custom JavaScript handlers for onEnter and onLeave events.

Instructions

Hook a native function with explicit calling convention. Args: address: Address of function calling_convention: "default", "stdcall", "fastcall", "thiscall" arg_types: List of argument types return_type: Return type on_enter: JavaScript for onEnter on_leave: JavaScript for onLeave Returns: Hook status.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYes
calling_conventionNodefault
arg_typesNo
return_typeNoint
on_enterNo
on_leaveNo

Implementation Reference

  • The handler function implementing the 'hook_native_function' MCP tool. It delegates the hooking logic to the supporting 'hook_function' tool with a customized description.
    @mcp.tool() def hook_native_function(address: str, calling_convention: str = "default", arg_types: List[str] = None, return_type: str = "int", on_enter: str = "", on_leave: str = "") -> Dict[str, Any]: """ Hook a native function with explicit calling convention. Args: address: Address of function calling_convention: "default", "stdcall", "fastcall", "thiscall" arg_types: List of argument types return_type: Return type on_enter: JavaScript for onEnter on_leave: JavaScript for onLeave Returns: Hook status. """ return hook_function(address, on_enter, on_leave, f"Native hook ({calling_convention})")
  • The core hook_function utility that performs the actual Frida Interceptor.attach to hook native functions. Called by hook_native_function.
    @mcp.tool() def hook_function(address: str, on_enter: str = "", on_leave: str = "", description: str = "") -> Dict[str, Any]: """ Hook a function at the specified address. Args: address: Address to hook (hex string) on_enter: JavaScript code for onEnter (has access to 'args' array) on_leave: JavaScript code for onLeave (has access to 'retval') description: Optional description Returns: Hook status. """ global _session if not _session.is_attached(): return {"error": "Not attached. Use attach() first."} if address in _session.hooks: return {"error": f"Hook exists at {address}. Use unhook_function() first."} try: addr = int(address, 16) if address.startswith("0x") else int(address) # Use empty statement if no code provided (comment would break JS syntax) on_enter_code = on_enter.strip() if on_enter else "" on_leave_code = on_leave.strip() if on_leave else "" script_code = f""" Interceptor.attach(ptr("{hex(addr)}"), {{ onEnter: function(args) {{ {on_enter_code} }}, onLeave: function(retval) {{ {on_leave_code} }} }}); send("Hook installed"); """ def on_message(message, data): if message['type'] == 'error': logger.error(f"Hook error: {message}") script = _session.session.create_script(script_code) script.on('message', on_message) script.load() _session.hooks[address] = HookInfo( address=address, script=script, hook_type="intercept", description=description or f"Hook at {address}" ) return {"success": True, "address": address, "message": f"Hook installed at {address}"} except Exception as e: return {"error": f"Failed to install hook: {str(e)}"}
  • Registration of the hook_native_function tool via FastMCP decorator.
    @mcp.tool() def hook_native_function(address: str, calling_convention: str = "default", arg_types: List[str] = None, return_type: str = "int", on_enter: str = "", on_leave: str = "") -> Dict[str, Any]: """ Hook a native function with explicit calling convention. Args: address: Address of function calling_convention: "default", "stdcall", "fastcall", "thiscall" arg_types: List of argument types return_type: Return type on_enter: JavaScript for onEnter on_leave: JavaScript for onLeave Returns: Hook status. """ return hook_function(address, on_enter, on_leave, f"Native hook ({calling_convention})")

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/0xhackerfren/frida-game-hacking-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server