ida_get_function_decompiled_by_name
Retrieve decompiled pseudocode for a specific function by its name to analyze program behavior and logic in IDA Pro.
Instructions
Get decompiled pseudocode for a function by name
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| function_name | Yes |
Implementation Reference
- Core implementation of decompilation by function name: resolves name to EA, decompiles using Hex-Rays ida_hexrays.decompile(), returns pseudocode string or error.@idaread def get_function_decompiled_by_name(self, function_name: str) -> Dict[str, Any]: """Get decompiled code for a function by its name""" try: # Get function address from name func_addr = idaapi.get_name_ea(0, function_name) if func_addr == idaapi.BADADDR: return {"error": f"Function '{function_name}' not found"} # Call internal implementation without decorator result = self._get_function_decompiled_by_address_internal(func_addr) # If successful, add function name to result if "error" not in result: result["function_name"] = function_name return result except Exception as e: traceback.print_exc() return {"error": str(e)} @idaread def get_function_decompiled_by_address(self, address: int) -> Dict[str, Any]: """Get decompiled code for a function by its address""" return self._get_function_decompiled_by_address_internal(address) def _get_function_decompiled_by_address_internal(self, address: int) -> Dict[str, Any]: """Internal implementation for get_function_decompiled_by_address without sync wrapper""" try: # Get function from address func = idaapi.get_func(address) if not func: return {"error": f"No function found at address 0x{address:X}"} # Get function name func_name = idaapi.get_func_name(func.start_ea) # Try to import decompiler module try: import ida_hexrays except ImportError: return {"error": "Hex-Rays decompiler is not available"} # Check if decompiler is available if not ida_hexrays.init_hexrays_plugin(): return {"error": "Unable to initialize Hex-Rays decompiler"} # Get decompiled function cfunc = None try: cfunc = ida_hexrays.decompile(func.start_ea) except Exception as e: return {"error": f"Unable to decompile function: {str(e)}"} if not cfunc: return {"error": "Decompilation failed"} # Get pseudocode as string decompiled_code = str(cfunc) return {"decompiled_code": decompiled_code, "function_name": func_name} except Exception as e: traceback.print_exc() return {"error": str(e)}
- src/mcp_server_ida/server.py:24-26 (schema)Pydantic input schema for the tool requiring 'function_name' string parameter.class GetFunctionDecompiledByName(BaseModel): function_name: str
- src/mcp_server_ida/server.py:928-932 (registration)MCP Tool registration in server.list_tools(), specifying name 'ida_get_function_decompiled_by_name', description, and input schema.Tool( name=IDATools.GET_FUNCTION_DECOMPILED_BY_NAME, description="Get decompiled pseudocode for a function by name", inputSchema=GetFunctionDecompiledByName.schema(), ),
- src/mcp_server_ida/server.py:1041-1046 (handler)MCP server call_tool() dispatch for the tool: calls IDAProFunctions wrapper with function_name argument.case IDATools.GET_FUNCTION_DECOMPILED_BY_NAME: decompiled: str = ida_functions.get_function_decompiled_by_name(arguments["function_name"]) return [TextContent( type="text", text=decompiled )]
- plugin/ida_mcp_server_plugin.py:189-191 (handler)Socket request dispatcher in IDA plugin that maps 'get_function_decompiled_by_name' to IDAMCPCore.get_function_decompiled_by_name call.elif request_type == "get_function_decompiled_by_name": response.update(self.core.get_function_decompiled_by_name(request_data.get("function_name", ""))) elif request_type == "get_function_decompiled_by_address":