ida_get_current_function_assembly
Extract assembly code for the function at the current cursor position in IDA, enabling precise analysis and automation of binary data.
Instructions
Get assembly code for the function at the current cursor position
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/mcp_server_ida/server.py:948-952 (registration)MCP tool registration in server.list_tools() defining the tool name, description, and schemaTool( name=IDATools.GET_CURRENT_FUNCTION_ASSEMBLY, description="Get assembly code for the function at the current cursor position", inputSchema=GetCurrentFunctionAssembly.schema(), ),
- src/mcp_server_ida/server.py:36-37 (schema)Pydantic input schema for the tool (no parameters)class GetCurrentFunctionAssembly(BaseModel): pass
- src/mcp_server_ida/server.py:1069-1075 (handler)MCP server tool call handler dispatching to IDAProFunctionscase IDATools.GET_CURRENT_FUNCTION_ASSEMBLY: assembly: str = ida_functions.get_current_function_assembly() return [TextContent( type="text", text=assembly )]
- src/mcp_server_ida/server.py:448-472 (handler)Server-side proxy handler sending socket RPC to IDA plugin and formatting responsedef get_current_function_assembly(self) -> str: """Get assembly code for the function at current cursor position""" try: response: Dict[str, Any] = self.communicator.send_request( "get_current_function_assembly", {} ) if "error" in response: return f"Error retrieving assembly for current function: {response['error']}" assembly: Any = response.get("assembly") function_name: str = response.get("function_name", "Current function") # Verify assembly is string type if assembly is None: return f"Error: No assembly data returned for current function" 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}':\n{assembly}" except Exception as e: self.logger.error(f"Error getting current function assembly: {str(e)}", exc_info=True) return f"Error retrieving assembly for current function: {str(e)}"
- IDA plugin RPC handler getting current screen EA and delegating to internal assembly getterdef get_current_function_assembly(self) -> Dict[str, Any]: """Get assembly 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_assembly_by_address_internal(curr_addr) except Exception as e: traceback.print_exc() return {"error": str(e)}
- Core logic extracting assembly disassembly lines from function using IDA APIs (idautils.FuncItems, idc.GetDisasm)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)}
- src/mcp_server_ida/server.py:94-94 (registration)Enum definition for the tool name constantGET_CURRENT_FUNCTION_ASSEMBLY = "ida_get_current_function_assembly"