disassemble_function
Extract and analyze the disassembly of a specific function from a binary file using Binary Ninja, enabling detailed reverse engineering and examination.
Instructions
Disassemble a function from a binary
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| function | Yes | ||
| path | Yes |
Implementation Reference
- binaryninja_mcp_http_server.py:330-349 (handler)Main handler for disassemble_function tool call, validates params, calls client.get_disassembly, returns wrapped text content.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_mcp_http_server.py:57-68 (schema)Input schema definition for disassemble_function tool in MCP_TOOLS list."name": "disassemble_function", "description": "Disassemble function", "streaming": False, "inputSchema": { "type": "object", "properties": { "path": {"type": "string"}, "function": {"type": "string"} }, "required": ["path", "function"] } },
- binaryninja_server.py:330-342 (handler)Handler implementation in stdio MCP server, calls client.get_disassembly.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_server.py:82-98 (schema)Tool schema in list_tools 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_http_client.py:160-208 (helper)Core helper function that implements the disassembly logic by searching functions and fetching HLIL as pseudo-disassembly.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