ida_rename_function
Rename functions in IDA Pro databases to improve code readability and maintain reverse engineering workflows. Specify old and new function names to update the database.
Instructions
Rename a function in the IDA database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| old_name | Yes | ||
| new_name | Yes |
Implementation Reference
- Core implementation of function renaming using IDA Pro API (ida_name.set_name). This is the actual logic executed in IDA Pro.def rename_function(self, old_name: str, new_name: str) -> Dict[str, Any]: """Rename a function""" return self._rename_function_internal(old_name, new_name) def _rename_function_internal(self, old_name: str, new_name: str) -> Dict[str, Any]: """Internal implementation for rename_function without sync wrapper""" try: # Get function address func_addr: int = ida_name.get_name_ea(0, old_name) if func_addr == idaapi.BADADDR: return {"success": False, "message": f"Function '{old_name}' not found"} # Check if it's a function func: Optional[ida_funcs.func_t] = ida_funcs.get_func(func_addr) if not func: return {"success": False, "message": f"'{old_name}' is not a function"} # Check if new name is already in use if ida_name.get_name_ea(0, new_name) != idaapi.BADADDR: return {"success": False, "message": f"Name '{new_name}' is already in use"} # Try to rename if not ida_name.set_name(func_addr, new_name): return {"success": False, "message": f"Failed to rename function, possibly due to invalid name format or other IDA restrictions"} # Refresh view self._refresh_view_internal() return {"success": True, "message": f"Function renamed from '{old_name}' to '{new_name}' at address {hex(func_addr)}"} except Exception as e: print(f"Error renaming function: {str(e)}") traceback.print_exc() return {"success": False, "message": str(e)}
- src/mcp_server_ida/server.py:549-569 (handler)MCP server-side handler that proxies the rename request to the IDA Pro plugin via socket communication.def rename_function(self, old_name: str, new_name: str) -> str: """Rename a function""" try: response: Dict[str, Any] = self.communicator.send_request( "rename_function", {"old_name": old_name, "new_name": new_name} ) if "error" in response: return f"Error renaming function from '{old_name}' to '{new_name}': {response['error']}" success: bool = response.get("success", False) message: str = response.get("message", "") if success: return f"Successfully renamed function from '{old_name}' to '{new_name}': {message}" else: return f"Failed to rename function from '{old_name}' to '{new_name}': {message}" except Exception as e: self.logger.error(f"Error renaming function: {str(e)}", exc_info=True) return f"Error renaming function from '{old_name}' to '{new_name}': {str(e)}"
- src/mcp_server_ida/server.py:968-972 (registration)Registration of the 'ida_rename_function' tool in the MCP server's list_tools() function.Tool( name=IDATools.RENAME_FUNCTION, description="Rename a function in the IDA database", inputSchema=RenameFunction.schema(), ),
- src/mcp_server_ida/server.py:51-53 (schema)Pydantic input schema for the 'ida_rename_function' tool defining old_name and new_name parameters.class RenameFunction(BaseModel): old_name: str new_name: str
- Request dispatcher in IDA plugin that routes 'rename_function' requests to the core implementation.elif request_type == "rename_function": response.update(self.core.rename_function( request_data.get("old_name", ""), request_data.get("new_name", "") ))