Skip to main content
Glama
0xhackerfren

Frida Game Hacking MCP

by 0xhackerfren

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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

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})")
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions 'Hook status' as a return, but doesn't disclose critical behavioral traits: whether this is a destructive operation (e.g., modifies memory), requires specific permissions or states (like an attached process), has side effects (e.g., interrupts execution), or includes rate limits. The description is minimal and lacks necessary context for safe and effective use.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded: the first sentence states the purpose, followed by a structured list of args and returns. Every sentence earns its place, with no redundant information. However, the lack of usage context or behavioral details means it could be more comprehensive without sacrificing conciseness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (6 parameters, no annotations, output schema exists), the description is partially complete. It covers parameters and return value at a high level, but lacks behavioral context, usage guidelines, and detailed semantics. The output schema likely defines 'Hook status', so the description doesn't need to explain returns, but overall, it's inadequate for a tool with this level of technical detail and potential impact.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It lists all 6 parameters with brief explanations (e.g., 'Address of function', 'List of argument types'), adding meaning beyond the schema's titles. However, it doesn't provide examples, format details (e.g., address format, type syntax), or constraints, leaving some ambiguity for implementation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Hook a native function with explicit calling convention.' It specifies the verb ('hook') and resource ('native function'), and distinguishes it from sibling 'hook_function' by emphasizing 'explicit calling convention.' However, it doesn't fully differentiate from 'intercept_module_function' or 'replace_function' in terms of scope or method.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'hook_function', 'intercept_module_function', or 'replace_function'. It lacks context about prerequisites, such as needing an attached process or specific permissions, and doesn't mention when not to use it, such as for non-native functions or without proper setup.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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