memory_write
Write hex bytes to a memory address on Android devices for runtime patching in mobile security testing.
Instructions
Write bytes to memory address (for patching)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | Memory address (e.g., '0x12345678') | |
| hex_bytes | Yes | Hex bytes to write (e.g., 'deadbeef') |
Implementation Reference
- src/frida_mcp/memory.py:33-50 (handler)The memory_write handler function that executes the write logic: converts hex string to bytes, uses Frida's Memory.protect() and Memory.writeByteArray() to write to the target address, and returns success/failure via a synchronous Frida script.
def memory_write(address: str, hex_bytes: str) -> dict: """Write bytes to memory address.""" js_code = ''' var addr = ptr(''' + json.dumps(address) + '''); var bytes = ''' + json.dumps(hex_bytes) + '''; var arr = []; for (var i = 0; i < bytes.length; i += 2) { arr.push(parseInt(bytes.substr(i, 2), 16)); } try { Memory.protect(addr, arr.length, 'rwx'); Memory.writeByteArray(addr, arr); send({success: true, address: addr.toString(), bytes_written: arr.length}); } catch(e) { send({success: false, error: e.message}); } ''' return run_script_sync(js_code) - src/frida_mcp/tools.py:341-352 (registration)The tool registration/schema definition for memory_write, declaring name, description ('Write bytes to memory address (for patching)'), and inputSchema with required 'address' (string) and 'hex_bytes' (string) parameters.
Tool( name="memory_write", description="Write bytes to memory address (for patching)", inputSchema={ "type": "object", "properties": { "address": {"type": "string", "description": "Memory address (e.g., '0x12345678')"}, "hex_bytes": {"type": "string", "description": "Hex bytes to write (e.g., 'deadbeef')"}, }, "required": ["address", "hex_bytes"], }, ), - src/frida_mcp/tools.py:341-352 (schema)The input schema for memory_write defining two required parameters: address (hex string like '0x12345678') and hex_bytes (hex bytes like 'deadbeef').
Tool( name="memory_write", description="Write bytes to memory address (for patching)", inputSchema={ "type": "object", "properties": { "address": {"type": "string", "description": "Memory address (e.g., '0x12345678')"}, "hex_bytes": {"type": "string", "description": "Hex bytes to write (e.g., 'deadbeef')"}, }, "required": ["address", "hex_bytes"], }, ), - src/frida_mcp/server.py:70-71 (handler)The dispatcher in call_tool() that routes 'memory_write' requests to memory.memory_write() with address and hex_bytes arguments.
elif name == "memory_write": return memory.memory_write(arguments["address"], arguments["hex_bytes"])