ida_get_current_function_decompiled
Retrieve decompiled pseudocode for the function at your current cursor position in IDA Pro to analyze binary code structure.
Instructions
Get decompiled pseudocode for the function at the current cursor position
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- Core implementation performing Hex-Rays decompilation for a function at the given address using IDA APIs.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)}
- Handler for current function decompilation: retrieves current screen EA and delegates to internal decompilation method.def get_current_function_decompiled(self) -> Dict[str, Any]: """Get decompiled code for the function at the current cursor position""" try: # Get current address curr_addr = idaapi.get_screen_ea() if curr_addr == idaapi.BADADDR: return {"error": "No valid cursor position"} # Use the internal implementation without decorator return self._get_function_decompiled_by_address_internal(curr_addr) except Exception as e: traceback.print_exc() return {"error": str(e)}
- plugin/ida_mcp_server_plugin.py:199-200 (handler)Socket server request handler dispatching 'get_current_function_decompiled' requests to the IDAMCPCore implementation.elif request_type == "get_current_function_decompiled": response.update(self.core.get_current_function_decompiled())
- src/mcp_server_ida/server.py:953-957 (registration)MCP tool registration defining the tool name 'ida_get_current_function_decompiled', description, and input schema.Tool( name=IDATools.GET_CURRENT_FUNCTION_DECOMPILED, description="Get decompiled pseudocode for the function at the current cursor position", inputSchema=GetCurrentFunctionDecompiled.schema(), ),
- src/mcp_server_ida/server.py:39-40 (schema)Pydantic input schema for the tool (empty as no parameters required).class GetCurrentFunctionDecompiled(BaseModel): pass
- src/mcp_server_ida/server.py:1076-1081 (handler)MCP @server.call_tool() handler executing the tool by calling the bridge function and formatting response.case IDATools.GET_CURRENT_FUNCTION_DECOMPILED: decompiled: str = ida_functions.get_current_function_decompiled() return [TextContent( type="text", text=decompiled )]
- src/mcp_server_ida/server.py:474-503 (handler)Bridge handler in MCP server that sends socket request to IDA plugin and processes/formats the response.def get_current_function_decompiled(self) -> str: """Get decompiled code for the function at current cursor position""" try: response: Dict[str, Any] = self.communicator.send_request( "get_current_function_decompiled", {} ) if "error" in response: return f"Error retrieving decompiled code for current function: {response['error']}" decompiled_code: Any = response.get("decompiled_code") function_name: str = response.get("function_name", "Current function") # Detailed type checking and conversion if decompiled_code is None: return f"Error: No decompiled code returned for current function" # 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}':\n{decompiled_code}" except Exception as e: self.logger.error(f"Error getting current function decompiled code: {str(e)}", exc_info=True) return f"Error retrieving decompiled code for current function: {str(e)}"