ida_rename_global_variable
Rename global variables in IDA databases to improve code readability and maintain consistent naming conventions during reverse engineering analysis.
Instructions
Rename a global variable in the IDA database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| old_name | Yes | ||
| new_name | Yes |
Implementation Reference
- src/mcp_server_ida/server.py:47-49 (schema)Pydantic input schema for the ida_rename_global_variable tool, defining old_name and new_name as strings.class RenameGlobalVariable(BaseModel): old_name: str new_name: str
- src/mcp_server_ida/server.py:963-967 (registration)MCP tool registration in list_tools(), specifying name, description, and input schema.Tool( name=IDATools.RENAME_GLOBAL_VARIABLE, description="Rename a global variable in the IDA database", inputSchema=RenameGlobalVariable.schema(), ),
- src/mcp_server_ida/server.py:527-547 (handler)MCP server-side handler in IDAProFunctions class that proxies the rename request to the IDA plugin via socket communication.def rename_global_variable(self, old_name: str, new_name: str) -> str: """Rename a global variable""" try: response: Dict[str, Any] = self.communicator.send_request( "rename_global_variable", {"old_name": old_name, "new_name": new_name} ) if "error" in response: return f"Error renaming global variable 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 global variable from '{old_name}' to '{new_name}': {message}" else: return f"Failed to rename global variable from '{old_name}' to '{new_name}': {message}" except Exception as e: self.logger.error(f"Error renaming global variable: {str(e)}", exc_info=True) return f"Error renaming global variable from '{old_name}' to '{new_name}': {str(e)}"
- plugin/ida_mcp_server_plugin.py:201-205 (handler)Socket server dispatch in IDA plugin that routes 'rename_global_variable' requests to the core handler.elif request_type == "rename_global_variable": response.update(self.core.rename_global_variable( request_data.get("old_name", ""), request_data.get("new_name", "") ))
- Core IDA plugin handler (@idawrite decorated) that implements the rename logic using IDA APIs: get_name_ea to find address and set_name to rename the global variable.def rename_global_variable(self, old_name: str, new_name: str) -> Dict[str, Any]: """Rename a global variable""" return self._rename_global_variable_internal(old_name, new_name) def _rename_global_variable_internal(self, old_name: str, new_name: str) -> Dict[str, Any]: """Internal implementation for rename_global_variable without sync wrapper""" try: # Get variable address var_addr: int = ida_name.get_name_ea(0, old_name) if var_addr == idaapi.BADADDR: return {"success": False, "message": f"Variable '{old_name}' not found"} # 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(var_addr, new_name): return {"success": False, "message": f"Failed to rename variable, possibly due to invalid name format or other IDA restrictions"} # Refresh view self._refresh_view_internal() return {"success": True, "message": f"Variable renamed from '{old_name}' to '{new_name}' at address {hex(var_addr)}"} except Exception as e: print(f"Error renaming variable: {str(e)}") traceback.print_exc() return {"success": False, "message": str(e)}