Skip to main content
Glama

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
NameRequiredDescriptionDefault
function_nameYes

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)}
  • Pydantic input schema for the tool requiring 'function_name' string parameter.
    class GetFunctionDecompiledByName(BaseModel):
        function_name: str
  • 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(),
    ),
  • 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
        )]
  • 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":

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/MxIris-Reverse-Engineering/ida-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server