Skip to main content
Glama

ida_rename_local_variable

Rename local variables within functions in IDA databases to improve code clarity and maintainability during reverse engineering analysis.

Instructions

Rename a local variable within a function in the IDA database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
function_nameYes
old_nameYes
new_nameYes

Implementation Reference

  • Core implementation of the rename_local_variable tool. Validates inputs, locates the function and decompiles it using Hex-Rays, finds the local variable by name, renames it using ida_hexrays.rename_lvar, refreshes the view, and returns success/error status.
    def _rename_local_variable_internal(self, function_name: str, old_name: str, new_name: str) -> Dict[str, Any]: """Internal implementation for rename_local_variable without sync wrapper""" try: # Parameter validation if not function_name: return {"success": False, "message": "Function name cannot be empty"} if not old_name: return {"success": False, "message": "Old variable name cannot be empty"} if not new_name: return {"success": False, "message": "New variable name cannot be empty"} # Get function address func_addr: int = ida_name.get_name_ea(0, function_name) if func_addr == idaapi.BADADDR: return {"success": False, "message": f"Function '{function_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"'{function_name}' is not a function"} # Check if decompiler is available if not ida_hexrays.init_hexrays_plugin(): return {"success": False, "message": "Hex-Rays decompiler is not available"} # Get decompilation result cfunc: Optional[ida_hexrays.cfunc_t] = ida_hexrays.decompile(func_addr) if not cfunc: return {"success": False, "message": f"Failed to decompile function '{function_name}'"} ida_hexrays.open_pseudocode(func_addr, 0) # Find local variable to rename found: bool = False renamed: bool = False lvar: Optional[ida_hexrays.lvar_t] = None # Iterate through all local variables lvars = cfunc.get_lvars() for i in range(lvars.size()): v = lvars[i] if v.name == old_name: lvar = v found = True break if not found: return {"success": False, "message": f"Local variable '{old_name}' not found in function '{function_name}'"} # Rename local variable if ida_hexrays.rename_lvar(cfunc.entry_ea, lvar.name, new_name): renamed = True if renamed: # Refresh view self._refresh_view_internal() return {"success": True, "message": f"Local variable renamed from '{old_name}' to '{new_name}' in function '{function_name}'"} else: return {"success": False, "message": f"Failed to rename local variable from '{old_name}' to '{new_name}', possibly due to invalid name format or other IDA restrictions"} except Exception as e: print(f"Error renaming local variable: {str(e)}") traceback.print_exc() return {"success": False, "message": str(e)}
  • Entry point for the rename_local_variable tool handler, decorated with @idawrite for IDA synchronization, delegates to internal implementation.
    def rename_local_variable(self, function_name: str, old_name: str, new_name: str) -> Dict[str, Any]: """Rename a local variable within a function""" return self._rename_local_variable_internal(function_name, old_name, new_name)
  • Tool registration in MCP server request handler: matches request_type 'rename_local_variable', extracts parameters from request_data, calls core.rename_local_variable and updates response.
    elif request_type == "rename_local_variable": response.update(self.core.rename_local_variable( request_data.get("function_name", ""), request_data.get("old_name", ""), request_data.get("new_name", "") ))

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