Skip to main content
Glama

ida_get_function_decompiled_by_address

Retrieve decompiled pseudocode for a specific function using its memory address in IDA Pro. This tool helps analyze binary code by converting machine instructions into readable pseudocode.

Instructions

Get decompiled pseudocode for a function by address

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYes

Implementation Reference

  • Core IDA plugin implementation: performs Hex-Rays decompilation of the function at the given address and returns pseudocode as string.
    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)}
  • MCP server-side handler: proxies the tool call by sending socket request to IDA plugin 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)}"
  • MCP tool registration in server.list_tools(): defines tool name, description, and input schema.
    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: expects 'address' as string.
    class GetFunctionDecompiledByAddress(BaseModel): address: str # Hexadecimal address as string
  • Enum constant defining the exact tool name string used for registration and dispatching.
    GET_FUNCTION_DECOMPILED_BY_ADDRESS = "ida_get_function_decompiled_by_address"
  • IDA plugin socket request handler: dispatches 'get_function_decompiled_by_address' request to IDAMCPCore.
    elif request_type == "get_function_decompiled_by_address": response.update(self.core.get_function_decompiled_by_address(request_data.get("address", 0)))

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