Skip to main content
Glama

ida_get_global_variable_by_address

Retrieve details of a global variable in IDA Pro by specifying its memory address, enabling enhanced reverse engineering and analysis workflows via the IDA-MCP server.

Instructions

Get information about a global variable by address

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYes

Implementation Reference

  • Core implementation of the tool logic: retrieves global variable details (name, address, segment, type, size, value, string content if applicable) using IDA Pro APIs.
    def _get_global_variable_by_address_internal(self, address: int) -> Dict[str, Any]: """Internal implementation for get_global_variable_by_address without sync wrapper""" try: # Verify address is valid if address == idaapi.BADADDR: return {"error": f"Invalid address: {hex(address)}"} # Get variable name if available variable_name = ida_name.get_name(address) if not variable_name: variable_name = f"unnamed_{hex(address)}" # Get variable segment segment: Optional[ida_segment.segment_t] = ida_segment.getseg(address) if not segment: return {"error": f"No segment found for address {hex(address)}"} segment_name: str = ida_segment.get_segm_name(segment) segment_class: str = ida_segment.get_segm_class(segment) # Get variable type tinfo = idaapi.tinfo_t() guess_type: bool = idaapi.guess_tinfo(tinfo, address) type_str: str = tinfo.get_type_name() if guess_type else "unknown" # Try to get variable value size: int = ida_bytes.get_item_size(address) if size <= 0: size = 8 # Default to 8 bytes # Read data based on size value: Optional[int] = None if size == 1: value = ida_bytes.get_byte(address) elif size == 2: value = ida_bytes.get_word(address) elif size == 4: value = ida_bytes.get_dword(address) elif size == 8: value = ida_bytes.get_qword(address) # Build variable info var_info: Dict[str, Any] = { "name": variable_name, "address": hex(address), "segment": segment_name, "segment_class": segment_class, "type": type_str, "size": size, "value": hex(value) if value is not None else "N/A" } # If it's a string, try to read string content if ida_bytes.is_strlit(ida_bytes.get_flags(address)): str_value = idc.get_strlit_contents(address, -1, 0) if str_value: try: var_info["string_value"] = str_value.decode('utf-8', errors='replace') except: var_info["string_value"] = str(str_value) return {"variable_info": json.dumps(var_info, indent=2)} except Exception as e: print(f"Error getting global variable by address: {str(e)}") traceback.print_exc() return {"error": str(e)}
  • Public handler method for the tool, decorated with @idaread for safe execution in IDA's main thread.
    @idaread def get_global_variable_by_address(self, address: int) -> Dict[str, Any]: """Get global variable information by its address""" return self._get_global_variable_by_address_internal(address)
  • Tool registration and dispatching in the MCP server request handler: matches request_type and calls core implementation.
    elif request_type == "get_global_variable_by_address": response.update(self.core.get_global_variable_by_address(request_data.get("address", 0)))
  • @idaread decorator used on the handler: ensures read operations are executed synchronously in IDA's main thread.
    def idaread(func: Callable[..., T]) -> Callable[..., T]: """ Decorator for functions that read from the IDA database Args: func: The function to decorate Returns: Decorated function that executes in IDA's main thread with read access """ @functools.wraps(func) def wrapper(*args: Any, **kwargs: Any) -> T: # Create a partial function with the arguments partial_func = functools.partial(func, *args, **kwargs) # Preserve the original function name partial_func.__name__ = func.__name__ # Execute with sync_wrapper return sync_wrapper(partial_func, idaapi.MFF_READ) return wrapper

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