Skip to main content
Glama

ida_get_function_assembly_by_address

Extract assembly code for a specific function using its memory address to analyze program behavior and structure.

Instructions

Get assembly code for a function by address

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYes

Implementation Reference

  • Core IDA plugin handler that retrieves function assembly by address using IDA APIs: get_func, FuncItems iterator, and GetDisasm. Wrapped with @idaread for main thread execution.
    def get_function_assembly_by_address(self, address: int) -> Dict[str, Any]:
        """Get assembly code for a function by its address"""
        return self._get_function_assembly_by_address_internal(address)
        
    def _get_function_assembly_by_address_internal(self, address: int) -> Dict[str, Any]:
        """Internal implementation for get_function_assembly_by_address without sync wrapper"""
        try:
            # Get function object
            func = ida_funcs.get_func(address)
            
            # Get function name
            func_name = idaapi.get_func_name(func.start_ea)
            
            if not func:
                return {"error": f"Invalid function at {hex(address)}"}
            
            # Collect all assembly instructions
            assembly_lines = []
            for instr_addr in idautils.FuncItems(address):
                disasm = idc.GetDisasm(instr_addr)
                assembly_lines.append(f"{hex(instr_addr)}: {disasm}")
            
            if not assembly_lines:
                return {"error": "No assembly instructions found"}
                
            return {"assembly": "\n".join(assembly_lines), "function_name": func_name}
        except Exception as e:
            print(f"Error getting function assembly: {str(e)}")
            traceback.print_exc()
            return {"error": str(e)}
  • MCP server-side tool handler. Converts address string to int, sends socket request to IDA plugin, receives and formats the assembly response as text.
    def get_function_assembly_by_address(self, address: str) -> str:
        """Get assembly code 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_assembly_by_address", 
                {"address": addr_int}
            )
            
            if "error" in response:
                return f"Error retrieving assembly for address '{address}': {response['error']}"
            
            assembly: Any = response.get("assembly")
            function_name: str = response.get("function_name", "Unknown function")
            
            # Verify assembly is string type
            if assembly is None:
                return f"Error: No assembly data returned for address '{address}'"
            if not isinstance(assembly, str):
                self.logger.warning(f"Assembly data type is not string but {type(assembly).__name__}, attempting conversion")
                assembly = str(assembly)
            
            return f"Assembly code for function '{function_name}' at address {address}:\n{assembly}"
        except Exception as e:
            self.logger.error(f"Error getting function assembly by address: {str(e)}", exc_info=True)
            return f"Error retrieving assembly for address '{address}': {str(e)}"
  • Pydantic input schema model for the tool, defining the 'address' parameter as string.
    class GetFunctionAssemblyByAddress(BaseModel):
        address: str  # Hexadecimal address as string
  • MCP tool registration in server.list_tools(), specifying name, description, and input schema.
        name=IDATools.GET_FUNCTION_ASSEMBLY_BY_ADDRESS,
        description="Get assembly code for a function by address",
        inputSchema=GetFunctionAssemblyByAddress.schema(),
    ),
  • Tool dispatch/execution in server.call_tool(), matching tool name and calling the handler function.
    case IDATools.GET_FUNCTION_ASSEMBLY_BY_ADDRESS:
        assembly: str = ida_functions.get_function_assembly_by_address(arguments["address"])
        return [TextContent(
            type="text",
            text=assembly
        )]

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