Skip to main content
Glama
0xhackerfren

Frida Game Hacking MCP

by 0xhackerfren

hook_function

Intercept and modify game functions by attaching JavaScript handlers to specific memory addresses for debugging or behavior alteration.

Instructions

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.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYes
on_enterNo
on_leaveNo
descriptionNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Core implementation of the hook_function MCP tool. Attaches a Frida Interceptor to the target address, injecting custom JavaScript for onEnter/onLeave callbacks. Manages hook state in the global FridaSession.
    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)}"}
  • MCP tool registration via FastMCP decorator @mcp.tool(), which auto-generates schema from signature/docstring and registers the handler.
    @mcp.tool()
  • Dataclass used to store information about active hooks, referenced in the hook_function handler.
    class HookInfo:
        """Information about an active hook."""
        address: str
        script: Any
        hook_type: str
        description: str = ""
  • Global session manager that stores hooks dictionary used by hook_function.
    class FridaSession:
        """Manages Frida session state."""
        
        def __init__(self):
            self.device: Optional[Any] = None
            self.session: Optional[Any] = None
            self.pid: Optional[int] = None
            self.process_name: Optional[str] = None
            self.spawned: bool = False
            self.scan_state: ScanState = ScanState()
            self.hooks: Dict[str, HookInfo] = {}
            self.breakpoints: Dict[str, Any] = {}
            self.custom_scripts: Dict[str, Any] = {}
        
        def is_attached(self) -> bool:
            return self.session is not None and not self.session.is_detached
        
        def reset(self):
            self.session = None
            self.pid = None
            self.process_name = None
            self.spawned = False
            self.scan_state = ScanState()
            self.hooks.clear()
            self.breakpoints.clear()
            self.custom_scripts.clear()
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While it mentions the tool hooks functions and returns 'Hook status', it doesn't explain critical behaviors: what happens when a function is hooked (does execution pause? are there side effects?), what permissions or conditions are needed, whether hooks persist across sessions, or potential risks like crashes from invalid JavaScript code.

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

Conciseness5/5

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

The description is efficiently structured with a clear purpose statement followed by parameter explanations in a bullet-like format. Every sentence adds value: the first states the action, and the parameter explanations provide necessary context without redundancy.

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?

For a complex function-hooking tool with no annotations, the description covers parameters well but lacks critical behavioral context about how hooking works, security implications, or error conditions. The existence of an output schema means return values don't need explanation, but the description should do more to explain the tool's operational behavior given its potential destructiveness.

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

Parameters5/5

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

With 0% schema description coverage, the description fully compensates by explaining all 4 parameters: 'address' (hex string location), 'on_enter' (JavaScript code with 'args' access), 'on_leave' (JavaScript code with 'retval' access), and 'description' (optional). This provides essential semantic context that the bare schema titles lack.

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 action ('Hook a function') and the target ('at the specified address'), making the purpose understandable. However, it doesn't differentiate from sibling tools like 'hook_native_function' or 'intercept_module_function', which appear to serve similar purposes in this debugging/instrumentation context.

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?

No guidance is provided about when to use this tool versus alternatives like 'hook_native_function' or 'intercept_module_function'. The description only states what the tool does, not when it's appropriate or what prerequisites might be needed for hooking functions.

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