From 40846fe7c9335f25975f027ee7f0175210986b77 Mon Sep 17 00:00:00 2001 From: "gergely.erdelyi" Date: Mon, 16 Jun 2008 18:47:02 +0000 Subject: [PATCH] idautils.py: Return copies of the xref class instances so they are storable --- python/idautils.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/python/idautils.py b/python/idautils.py index 3c8db32..a0f33dc 100644 --- a/python/idautils.py +++ b/python/idautils.py @@ -133,6 +133,17 @@ def XrefTypeName(typecode): return ref_types[typecode] +def _copy_xref(xref): + """ Make a private copy of the xref class to preserve its contents """ + class _xref: + pass + + xr = _xref() + for attr in [ 'frm', 'to', 'iscode', 'type', 'user' ]: + setattr(xr, attr, getattr(xref, attr)) + return xr + + def XrefsFrom(ea, flags=0): """ Return all references from address 'ea' @@ -144,13 +155,12 @@ def XrefsFrom(ea, flags=0): for xref in XrefsFrom(here(), 0): print xref.type, XrefTypeName(xref.type), \ 'from', hex(xref.frm), 'to', hex(xref.to) - """ xref = idaapi.xrefblk_t() if xref.first_from(ea, flags): - yield xref + yield _copy_xref(xref) while xref.next_from(): - yield xref + yield _copy_xref(xref) def XrefsTo(ea, flags=0): @@ -167,9 +177,9 @@ def XrefsTo(ea, flags=0): """ xref = idaapi.xrefblk_t() if xref.first_to(ea, flags): - yield xref + yield _copy_xref(xref) while xref.next_to(): - yield xref + yield _copy_xref(xref) def Heads(start, end):