Skip to main content
Glama

read_memory

Extract data from game memory addresses to analyze values, strings, or structures for reverse engineering and debugging purposes.

Instructions

Read memory at specified address. Args: address: Memory address (hex string like "0x401234") size: Number of bytes to read format: Output format ("hex", "bytes", "int32", "float", "string") Returns: Memory contents in requested format.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYes
sizeNo
formatNohex

Implementation Reference

  • The handler function decorated with @mcp.tool() that implements the read_memory tool. It attaches to a Frida session, injects JavaScript to read memory bytes using Memory.readByteArray, formats the output based on the specified format (hex, bytes, int32, float, string), and returns the result.
    @mcp.tool() def read_memory(address: str, size: int = 16, format: str = "hex") -> Dict[str, Any]: """ Read memory at specified address. Args: address: Memory address (hex string like "0x401234") size: Number of bytes to read format: Output format ("hex", "bytes", "int32", "float", "string") Returns: Memory contents in requested format. """ global _session if not _session.is_attached(): return {"error": "Not attached. Use attach() first."} try: addr = int(address, 16) if address.startswith("0x") else int(address) script_code = f""" var addr = ptr("{hex(addr)}"); try {{ var data = Memory.readByteArray(addr, {size}); var hex = ''; var bytes = new Uint8Array(data); for (var i = 0; i < bytes.length; i++) {{ hex += ('0' + bytes[i].toString(16)).slice(-2); }} send({{type: 'data', hex: hex}}); }} catch (e) {{ send({{type: 'error', msg: e.toString()}}); }} """ result_data = [] def on_message(message, data): if message['type'] == 'send': result_data.append(message['payload']) script = _session.session.create_script(script_code) script.on('message', on_message) script.load() script.unload() if not result_data: return {"error": "No response from Frida"} response = result_data[0] if response.get('type') == 'error': return {"error": f"Memory read failed: {response.get('msg')}"} raw_bytes = bytes.fromhex(response['hex']) output = {"address": hex(addr), "size": size} if format == "hex": output["hex"] = raw_bytes.hex() output["hex_spaced"] = " ".join(f"{b:02x}" for b in raw_bytes) elif format == "bytes": output["bytes"] = list(raw_bytes) elif format == "int32" and size >= 4: output["value"] = struct.unpack("<i", raw_bytes[:4])[0] elif format == "float" and size >= 4: output["value"] = struct.unpack("<f", raw_bytes[:4])[0] elif format == "string": output["string"] = raw_bytes.split(b'\x00')[0].decode('utf-8', errors='replace') else: output["hex"] = raw_bytes.hex() output["hex_spaced"] = " ".join(f"{b:02x}" for b in raw_bytes) return output except Exception as e: return {"error": f"Failed to read memory: {str(e)}"}
  • The read_memory tool is listed in the capabilities under memory_operations category, advertised by the list_capabilities tool.
    "read_memory", "write_memory", "scan_value", "scan_next", "scan_changed", "scan_unchanged", "scan_pattern", "get_scan_results", "clear_scan", "list_memory_regions" ], "module_information": [ "list_modules", "get_module_info", "get_module_exports", "get_module_imports", "resolve_symbol" ], "function_hooking": [ "hook_function", "unhook_function", "replace_function", "hook_native_function", "list_hooks", "intercept_module_function" ], "debugging": [ "set_breakpoint", "remove_breakpoint", "list_breakpoints", "read_registers" ], "script_management": [ "load_script", "unload_script", "call_rpc" ], "window_interaction": [ "list_windows", "screenshot_window", "screenshot_screen", "send_key_to_window", "focus_window" ], "standard": [ "list_capabilities", "get_documentation", "check_installation" ] }, "total_tools": 42 }

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