Skip to main content
Glama

ida_get_function_decompiled_by_address

Retrieve decompiled pseudocode for a specific function using its memory address, enabling efficient analysis of binary code in IDA database environments.

Instructions

Get decompiled pseudocode for a function by address

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYes

Implementation Reference

  • Core handler function that executes the decompilation logic using IDA's Hex-Rays decompiler (ida_hexrays.decompile). Called internally by the decorated get_function_decompiled_by_address method.
    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)}
  • Proxy handler in IDAProFunctions that sends the 'get_function_decompiled_by_address' request to the IDA plugin via socket communicator and formats the response.
    def get_function_decompiled_by_address(self, address: str) -> str: """Get decompiled pseudocode for a function by its address""" try: # Convert string address to int try: addr_int = int(address, 16) if address.startswith("0x") else int(address) except ValueError: return f"Error: Invalid address format '{address}', expected hexadecimal (0x...) or decimal" response: Dict[str, Any] = self.communicator.send_request( "get_function_decompiled_by_address", {"address": addr_int} ) if "error" in response: return f"Error retrieving decompiled code for address '{address}': {response['error']}" decompiled_code: Any = response.get("decompiled_code") function_name: str = response.get("function_name", "Unknown function") # Detailed type checking and conversion if decompiled_code is None: return f"Error: No decompiled code returned for address '{address}'" # Ensure result is string if not isinstance(decompiled_code, str): self.logger.warning(f"Decompiled code type is not string but {type(decompiled_code).__name__}, attempting conversion") try: decompiled_code = str(decompiled_code) except Exception as e: return f"Error: Failed to convert decompiled code: {str(e)}" return f"Decompiled code for function '{function_name}' at address {address}:\n{decompiled_code}" except Exception as e: self.logger.error(f"Error getting function decompiled code by address: {str(e)}", exc_info=True) return f"Error retrieving decompiled code for address '{address}': {str(e)}"
  • Registers the MCP tool 'ida_get_function_decompiled_by_address' in the server.list_tools() with input schema and description.
    Tool( name=IDATools.GET_FUNCTION_DECOMPILED_BY_ADDRESS, description="Get decompiled pseudocode for a function by address", inputSchema=GetFunctionDecompiledByAddress.schema(), ),
  • Pydantic model defining the input schema for the tool: requires 'address' as string (hex address).
    class GetFunctionDecompiledByAddress(BaseModel): address: str # Hexadecimal address as string
  • Primary MCP server @server.call_tool() handler case that invokes the proxy function and returns result as MCP TextContent.
    case IDATools.GET_FUNCTION_DECOMPILED_BY_ADDRESS: decompiled: str = ida_functions.get_function_decompiled_by_address(arguments["address"]) return [TextContent( type="text", text=decompiled )]
  • Enum definition providing the exact tool name constant IDATools.GET_FUNCTION_DECOMPILED_BY_ADDRESS = 'ida_get_function_decompiled_by_address' used in registration and dispatch.
    GET_FUNCTION_DECOMPILED_BY_ADDRESS = "ida_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