ida_rename_function
Renames a function in an IDA database by specifying the old and new function names. Facilitates easy updates and organization within reverse engineering workflows.
Instructions
Rename a function in the IDA database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| new_name | Yes | ||
| old_name | Yes |
Implementation Reference
- src/mcp_server_ida/server.py:51-53 (schema)Pydantic input schema model for the 'ida_rename_function' tool, defining old_name and new_name parameters.class RenameFunction(BaseModel): old_name: str new_name: str
- 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:1104-1113 (handler)MCP server tool call handler for 'ida_rename_function' that calls IDAProFunctions.rename_function() and returns the result as text content.case IDATools.RENAME_FUNCTION: result: str = ida_functions.rename_function( arguments["old_name"], arguments["new_name"] ) return [TextContent( type="text", text=result )]
- src/mcp_server_ida/server.py:549-569 (handler)Proxy handler in IDAProFunctions class that sends 'rename_function' request to IDA Pro plugin via communicator and formats the response.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)}"
- Core implementation of function renaming in IDA Pro plugin: resolves function by name, renames using ida_name.set_name(), refreshes views. This is the exact logic that performs the rename.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)}