Skip to content

Instantly share code, notes, and snippets.

@newlc
Forked from syndrowm/get_stack_arg.py
Created November 11, 2017 22:06
Show Gist options
  • Select an option

  • Save newlc/4910e032a7db7e5d0d9fe244b543a1f5 to your computer and use it in GitHub Desktop.

Select an option

Save newlc/4910e032a7db7e5d0d9fe244b543a1f5 to your computer and use it in GitHub Desktop.

Revisions

  1. @syndrowm syndrowm revised this gist Jun 21, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion get_stack_arg.py
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ def get_stack_arg(arg, base='ebp'):
    names.append(n)

    # The stack offsets can be negative
    # GetFrame and GetStrucSize do not
    # GetFrame and GetStrucSize are not
    #-0000000A var_A dw ?
    #+00000000 s db 4 dup(?) ; s is always at 0x0
    #+00000004 r db 4 dup(?)
  2. @syndrowm syndrowm revised this gist Jun 21, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions get_stack_arg.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    from idaapi import *
    from idc import *

    def get_stack_arg(arg, base='ebp'):
    # find the stack frame
  3. @syndrowm syndrowm created this gist Jun 21, 2012.
    32 changes: 32 additions & 0 deletions get_stack_arg.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    from idaapi import *

    def get_stack_arg(arg, base='ebp'):
    # find the stack frame
    stack = GetFrame(here())
    size = GetStrucSize(stack)

    # figure out all of the variable names
    names = []
    for i in xrange(size):
    n = GetMemberName(stack, i)
    if n and not n in names:
    names.append(n)

    # The stack offsets can be negative
    # GetFrame and GetStrucSize do not
    #-0000000A var_A dw ?
    #+00000000 s db 4 dup(?) ; s is always at 0x0
    #+00000004 r db 4 dup(?)
    #+00000008 arg_0 dd ?
    #+0000000C arg_4 dd
    # there has got too be a better way (hax)
    if ' s' in names and arg in names:
    adjusted = size - (size - GetMemberOffset(stack, ' s'))

    offset = GetMemberOffset(stack, arg) - adjusted
    if base:
    return GetRegValue(base) + offset
    else:
    return offset

    return -1