Skip to content

Instantly share code, notes, and snippets.

@alexander-hanel
Created February 13, 2020 00:51
Show Gist options
  • Save alexander-hanel/7dc4cd009616524d0f348d2ac801612a to your computer and use it in GitHub Desktop.
Save alexander-hanel/7dc4cd009616524d0f348d2ac801612a to your computer and use it in GitHub Desktop.
IDAPython: calculate data size based off of xrefs
def get_to_xrefs(ea):
xref_set = set([])
for xref in idautils.XrefsTo(ea, 1):
xref_set.add(xref)
return xref_set
def get_from_xrefs(ea):
xref_set = set([])
for xref in idautils.XrefsTo(ea, 1):
xref_set.add(xref)
return xref_set
def get_next_xref(ea):
ss = 0
cur_addr = idc.next_head(ea)
while True:
if get_to_xrefs(cur_addr):
return cur_addr - 1
elif get_from_xrefs(cur_addr):
return cur_addr - 1
cur_addr = idc.next_head(cur_addr)
if cur_addr == idc.BADADDR:
return ea
def calculate_data_size(ea):
return get_next_xref(ea) - ea
print(calculate_buffer_size(here()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment