Skip to main content
Glama

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
NameRequiredDescriptionDefault
old_nameYes
new_nameYes

Implementation Reference

  • 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
  • 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(),
    ),
  • 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)}"
  • 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)}

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/MxIris-Reverse-Engineering/ida-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server