Ver Fonte

Avoid passing redundant VtableDisamb to vtable helpers

``LinuxBinary.vtable_disambiguator`` is the same thing.
nosoop há 10 meses atrás
pai
commit
982aaf1e5b
2 ficheiros alterados com 9 adições e 12 exclusões
  1. 2 3
      src/smgdc/validate.py
  2. 7 9
      src/smgdc/vtable.py

+ 2 - 3
src/smgdc/validate.py

@@ -188,12 +188,11 @@ class VirtualFunctionEntry(BaseEntry, tag="vfn"):
             bin, LinuxBinary
         ), "Expected Linux binary for virtual function handling"
         self.typename = self.typename or self.typename_from_symbol
-        vtda = bin.vtable_disambiguator
         vtsym = bin.angr.loader.find_symbol(f"_ZTV{self.typename}")
         if not vtsym:
             raise ValueError(f"Could not find vtable symbol _ZTV{self.typename}")
-        orig_vtable, *thunk_vtables = vt_helpers.get_vtables_from_address(bin, vtda, vtsym)
-        win_vtable = vt_helpers.get_windows_vtables_from(bin, vtda, vtsym)
+        orig_vtable, *thunk_vtables = vt_helpers.get_vtables_from_address(bin, vtsym)
+        win_vtable = vt_helpers.get_windows_vtables_from(bin, vtsym)
 
         sym = bin.angr.loader.find_symbol(self.symbol)
         return {

+ 7 - 9
src/smgdc/vtable.py

@@ -12,7 +12,6 @@ import itanium_demangler as demangler
 from cle.backends.symbol import Symbol
 
 from . import demangler_helpers as dh
-from .angr import VtableDisambiguator
 
 if typing.TYPE_CHECKING:
     from .validate import LinuxBinary
@@ -45,9 +44,8 @@ def reorder_vfns_windows_estimate(symbols: list[Symbol], start_pos) -> list[Symb
     return output_symbols
 
 
-def get_windows_vtables_from(
-    bin: "LinuxBinary", vtda: VtableDisambiguator, vt: Symbol
-) -> VTable:
+def get_windows_vtables_from(bin: "LinuxBinary", vt: Symbol) -> VTable:
+    vtda = bin.vtable_disambiguator
     vt_typeinfo = bin.angr.loader.memory.unpack_word(vt.rebased_addr + 0x4)
 
     vt_parent_spans = [1]
@@ -55,10 +53,10 @@ def get_windows_vtables_from(
         vt_parent = bin.angr.loader.find_symbol(f"_ZTV{name}")
         if not vt_parent:
             continue
-        vt_first, *_ = get_vtables_from_address(bin, vtda, vt_parent)
+        vt_first, *_ = get_vtables_from_address(bin, vt_parent)
         vt_parent_spans.append(len(vt_first))
 
-    vt_first, *vt_others = get_vtables_from_address(bin, vtda, vt)
+    vt_first, *vt_others = get_vtables_from_address(bin, vt)
     thunk_fns = set()
     for vt_other in vt_others:
         for sym in vt_other:
@@ -90,9 +88,9 @@ def get_windows_vtables_from(
     return vt_out
 
 
-def get_vtables_from_address(
-    bin: "LinuxBinary", vtda: VtableDisambiguator, vt: Symbol
-) -> list[VTable]:
+def get_vtables_from_address(bin: "LinuxBinary", vt: Symbol) -> list[VTable]:
+    vtda = bin.vtable_disambiguator
+
     # returns a list of vtables for each vtable present on the class
     VTableFunction = collections.namedtuple("VTableFunction", "tblidx sym")