ida_rename_multi_global_variables
Rename multiple global variables simultaneously in IDA databases to improve code readability and maintain consistency during reverse engineering analysis.
Instructions
Rename multiple global variables at once in the IDA database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| rename_pairs_old2new | Yes |
Implementation Reference
- Core handler implementing the multi-rename logic by iterating over pairs and delegating to single rename. Performs the actual IDA API calls via the single rename helper.def rename_multi_global_variables(self, rename_pairs_old2new: List[Dict[str, str]]) -> Dict[str, Any]: """Rename multiple global variables at once""" try: success_count: int = 0 failed_pairs: List[Dict[str, str]] = [] for pair in rename_pairs_old2new: old_name = next(iter(pair.keys())) new_name = pair[old_name] # Call existing rename_global_variable_internal for each pair result = self._rename_global_variable_internal(old_name, new_name) if result.get("success", False): success_count += 1 else: failed_pairs.append({ "old_name": old_name, "new_name": new_name, "error": result.get("message", "Unknown error") }) return { "success": True, "message": f"Renamed {success_count} out of {len(rename_pairs_old2new)} global variables", "success_count": success_count, "failed_pairs": failed_pairs } except Exception as e: print(f"Error in rename_multi_global_variables: {str(e)}") traceback.print_exc() return { "success": False, "message": str(e), "success_count": 0, "failed_pairs": rename_pairs_old2new }
- Helper function performing the single global variable rename using IDA's ida_name.set_name API.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)}
- src/mcp_server_ida/server.py:59-60 (schema)Pydantic model defining the input schema: list of dicts with old_name to new_name pairs.class RenameMultiGlobalVariables(BaseModel): rename_pairs_old2new: List[Dict[str, str]]
- src/mcp_server_ida/server.py:978-982 (registration)MCP tool registration in list_tools() with name, description, and input schema.Tool( name=IDATools.RENAME_MULTI_GLOBAL_VARIABLES, description="Rename multiple global variables at once in the IDA database", inputSchema=RenameMultiGlobalVariables.schema(), ),
- src/mcp_server_ida/server.py:602-628 (handler)MCP server-side handler proxy that sends the request to IDA plugin via socket and formats response.def rename_multi_global_variables(self, rename_pairs_old2new: List[Dict[str, str]]) -> str: """Rename multiple global variables at once""" try: response: Dict[str, Any] = self.communicator.send_request( "rename_multi_global_variables", {"rename_pairs_old2new": rename_pairs_old2new} ) if "error" in response: return f"Error renaming multiple global variables: {response['error']}" success_count: int = response.get("success_count", 0) failed_pairs: List[Dict[str, str]] = response.get("failed_pairs", []) result_parts: List[str] = [ f"Successfully renamed {success_count} global variables" ] if failed_pairs: result_parts.append("\nFailed renamings:") for pair in failed_pairs: result_parts.append(f"- {pair['old_name']} → {pair['new_name']}: {pair.get('error', 'Unknown error')}") return "\n".join(result_parts) except Exception as e: self.logger.error(f"Error renaming multiple global variables: {str(e)}", exc_info=True) return f"Error renaming multiple global variables: {str(e)}"