disassemble_function
Analyze binary files by extracting and displaying the assembly code of specific functions to understand program behavior.
Instructions
Disassemble a function from a binary
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | ||
| function | Yes |
Implementation Reference
- binaryninja_server.py:82-97 (schema)Input schema definition for the disassemble_function tool in the list_tools MCP method response."name": "disassemble_function", "description": "Disassemble a function in a binary file", "inputSchema": { "type": "object", "properties": { "path": { "type": "string", "description": "Path to the binary file" }, "function": { "type": "string", "description": "Name of the function to disassemble" } }, "required": ["path", "function"] }
- binaryninja_server.py:272-276 (registration)Registration and dispatching of call_tool 'disassemble_function' to the internal method handler.elif tool_name == "disassemble_function": return handle_request({ "method": "disassemble_function", "params": tool_args }, client)
- binaryninja_server.py:330-341 (handler)Core handler for the disassemble_function MCP method: validates params, calls BinaryNinjaHTTPClient.get_disassembly, returns disassembly lines.elif method == "disassemble_function": path = params.get("path") func_name = params.get("function") if not path or not func_name: return {"error": "Path and function parameters are required"} # We assume the binary is already loaded # Just log the path for debugging logger.info(f"Using binary: {path}") disasm = client.get_disassembly(path, function_name=func_name) return {"result": disasm}
- binaryninja_mcp_http_server.py:330-348 (handler)HTTP MCP server handler for disassemble_function with JSON-RPC error handling and response wrapping.elif method == "disassemble_function": path = params.get("path") func = params.get("function") if not path: logger.error("Missing 'path' parameter") return self._error_response(request_id, -32602, "Missing 'path' parameter") if not func: logger.error("Missing 'function' parameter") return self._error_response(request_id, -32602, "Missing 'function' parameter") if not isinstance(path, str): logger.error(f"Invalid path type: {type(path)}") return self._error_response(request_id, -32602, "Parameter 'path' must be a string") if not isinstance(func, str): logger.error(f"Invalid function type: {type(func)}") return self._error_response(request_id, -32602, "Parameter 'function' must be a string") logger.debug(f"Disassembling function {func} in file: {path}") code = self.client.get_disassembly(path, function_name=func) return self._wrap_result(request_id, "\n".join(code))
- binaryninja_http_client.py:160-207 (helper)Helper method implementing the disassembly logic by searching functions and providing function info + decompiled HLIL as pseudo-disassembly via Binary Ninja HTTP API.def get_disassembly(self, file_path=None, function_name=None, function_address=None): """Get the disassembly of a specific function.""" try: # Get function info first to get the address identifier = function_name if function_name else function_address if identifier is None: return ["No function identifier provided"] # Convert to string if it's not already if not isinstance(identifier, str): identifier = str(identifier) # Use the function info endpoint to get the function details # Since there's no direct disassembly endpoint, we'll use the function info # and format it as disassembly lines try: # First try to get function info response = self._request('GET', 'searchFunctions', params={"query": identifier}) matches = response.get("matches", []) if not matches: return [f"Function '{identifier}' not found"] # Get the first match func = matches[0] # Format the function info as disassembly lines disasm = [] disasm.append(f"Function: {func.get('name', 'unknown')}") disasm.append(f"Address: {func.get('address', '0x0')}") # Try to get the decompiled code to show as pseudo-disassembly try: decompiled = self.get_hlil(file_path, function_name=func.get('name')) if decompiled and decompiled != "No decompilation available": disasm.append("Decompiled code:") for line in decompiled.split("\n"): disasm.append(f" {line}") except Exception: pass return disasm except Exception as e: logger.warning(f"Failed to get function info: {e}") return [f"Error getting disassembly: {e}"] except Exception as e: logger.error(f"Failed to get disassembly: {e}") raise