Skip to main content
Glama
0xhackerfren

Frida Game Hacking MCP

by 0xhackerfren

replace_function

Modify game behavior by intercepting function calls to return predetermined values, enabling memory manipulation for reverse engineering and debugging purposes.

Instructions

Replace a function to always return a specific value.

Args:
    address: Address of function to replace
    return_value: Value to return

Returns:
    Replacement status.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYes
return_valueNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Implements the replace_function MCP tool using Frida Interceptor.replace to override a native function to always return a specified value. Stores the hook in session state.
    @mcp.tool()
    def replace_function(address: str, return_value: Union[int, str] = 0) -> Dict[str, Any]:
        """
        Replace a function to always return a specific value.
        
        Args:
            address: Address of function to replace
            return_value: Value to return
        
        Returns:
            Replacement 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 isinstance(address, str) and address.startswith("0x") else int(address)
            ret_val = int(return_value, 16) if isinstance(return_value, str) and return_value.startswith("0x") else int(return_value)
            
            script_code = f"""
            Interceptor.replace(ptr("{hex(addr)}"), new NativeCallback(function() {{
                return {ret_val};
            }}, 'int', []));
            send("Function replaced");
            """
            
            script = _session.session.create_script(script_code)
            script.on('message', lambda m, d: None)
            script.load()
            
            _session.hooks[address] = HookInfo(
                address=address, script=script, hook_type="replace",
                description=f"Returns {ret_val}"
            )
            
            return {"success": True, "address": address, "return_value": ret_val}
        
        except Exception as e:
            return {"error": f"Failed to replace function: {str(e)}"}
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 of behavioral disclosure. It states the tool replaces a function to return a specific value, implying a mutation operation, but fails to describe critical behaviors: whether this requires specific permissions, if it's reversible, potential side effects on the system, or rate limits. This is a significant gap for a tool that modifies function behavior.

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, with the purpose stated first followed by parameter explanations. It avoids unnecessary details, though the 'Returns' section could be more informative. Overall, it's efficient with minimal waste.

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 tool's complexity (function replacement with potential system impact), no annotations, and an output schema that only indicates 'Replacement status', the description is incomplete. It covers the basic purpose and parameters but lacks behavioral context, usage guidelines, and detailed return information. The output schema helps, but more is needed for safe and effective use.

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

Parameters3/5

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

The schema description coverage is 0%, so the description must compensate. It adds meaning by explaining 'address' as the 'Address of function to replace' and 'return_value' as the 'Value to return', which clarifies the parameters beyond their titles. However, it doesn't specify formats (e.g., address syntax) or constraints, leaving some ambiguity. This partial compensation justifies a baseline score.

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: 'Replace a function to always return a specific value.' It specifies the verb ('replace') and resource ('function'), and while it doesn't explicitly differentiate from siblings like 'hook_function' or 'intercept_module_function', the focus on replacement with a fixed return value is specific enough for clarity.

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. It lacks context about prerequisites, such as whether the function must be hooked or attached first, and doesn't mention sibling tools like 'hook_function' or 'unhook_function' that might be related. This omission leaves the agent without clear usage instructions.

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