get_stack_frame_variables
Retrieve stack frame variables for a specified function in IDA Pro, enabling detailed reverse engineering analysis by identifying local variables and their addresses.
Instructions
Retrieve the stack frame variables for a given function
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| function_address | Yes | Address of the disassembled function to retrieve the stack frame variables |
Implementation Reference
- Core helper function that implements the logic to extract stack frame variables from IDA's function frame type information.def get_stack_frame_variables_internal( fn_addr: int, raise_error: bool ) -> list[StackFrameVariable]: from .sync import ida_major if ida_major < 9: return [] func = idaapi.get_func(fn_addr) if not func: if raise_error: raise IDAError(f"No function found at address {fn_addr}") return [] tif = ida_typeinf.tinfo_t() if not tif.get_type_by_tid(func.frame) or not tif.is_udt(): return [] members: list[StackFrameVariable] = [] udt = ida_typeinf.udt_type_data_t() tif.get_udt_details(udt) for udm in udt: if not udm.is_gap(): name = udm.name offset = udm.offset // 8 size = udm.size // 8 type = str(udm.type) members.append( StackFrameVariable( name=name, offset=hex(offset), size=hex(size), type=type ) ) return members
- MCP tool handler 'stack_frame' that provides stack frame variables for given addresses by calling the internal helper.@tool @idaread def stack_frame(addrs: Annotated[list[str] | str, "Address(es)"]) -> list[dict]: """Get stack vars""" addrs = normalize_list_input(addrs) results = [] for addr in addrs: try: ea = parse_address(addr) vars = get_stack_frame_variables_internal(ea, True) results.append({"addr": addr, "vars": vars}) except Exception as e: results.append({"addr": addr, "vars": None, "error": str(e)}) return results
- Type definition (TypedDict) for stack frame variable objects returned by the implementation.class StackFrameVariable(TypedDict): name: str offset: str size: str type: str
- MCP resource handler that exposes stack frame variables via URI 'ida://stack/{func_addr}'.@resource("ida://stack/{func_addr}") @idaread def stack_func_resource(func_addr: Annotated[str, "Function address"]) -> dict: """Get stack frame variables for a function""" from .utils import get_stack_frame_variables_internal ea = parse_address(func_addr) variables = get_stack_frame_variables_internal(ea, raise_error=True) return {"addr": hex(ea), "variables": variables}