Created
February 13, 2020 00:51
-
-
Save alexander-hanel/7dc4cd009616524d0f348d2ac801612a to your computer and use it in GitHub Desktop.
IDAPython: calculate data size based off of xrefs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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