Browse Source

Hoist Windows vtable filtering logic

nosoop 10 months ago
parent
commit
2b479e2d21
1 changed files with 22 additions and 15 deletions
  1. 22 15
      src/smgdc/angr/vtable_disamb.py

+ 22 - 15
src/smgdc/angr/vtable_disamb.py

@@ -53,6 +53,26 @@ def _reorder_vfns_windows_estimate(symbols: list[Symbol]) -> list[Symbol]:
     return list(itertools.chain.from_iterable(reversed(syms) for syms in name_buckets.values()))
 
 
+def _allow_symbol_for_windows_vtable(
+    sym: Symbol, thunk_fns: set[tuple[demangler.Node, ...]]
+) -> bool:
+    dmsym = demangler.parse(sym.name)
+    if dmsym:
+        # MSVC only provides one dtor, so here we'll use the deleting one (D0)
+        if dh.is_dtor(dmsym) and dh.get_dtor_type(dmsym) != "deleting":
+            return False
+        elif (
+            not demangler.is_ctor_or_dtor(dmsym)
+            and dh.extract_method_signature(dmsym) in thunk_fns
+        ):
+            # filter MI thunks
+            return False
+    else:
+        # __cxa_pure_virtual returns None here; we still add it to the vtable slice
+        pass
+    return True
+
+
 VTable = list[Symbol]
 
 
@@ -291,21 +311,8 @@ class VtableDisambiguator(angr.Analysis):
             class_vfns = []
 
             for sym in vt_first[vt_low:vt_high]:
-                # filter MI thunks
-                dmsym = demangler.parse(sym.name)
-                if dmsym:
-                    # MSVC only provides one dtor, so here we'll use the deleting one (D0)
-                    if dh.is_dtor(dmsym) and dh.get_dtor_type(dmsym) != "deleting":
-                        continue
-                    elif (
-                        not demangler.is_ctor_or_dtor(dmsym)
-                        and dh.extract_method_signature(dmsym) in thunk_fns
-                    ):
-                        continue
-                else:
-                    # __cxa_pure_virtual returns None here; we still add it to the vtable slice
-                    pass
-                class_vfns.append(sym)
+                if _allow_symbol_for_windows_vtable(sym, thunk_fns):
+                    class_vfns.append(sym)
             vt_out.extend(_reorder_vfns_windows_estimate(class_vfns))
 
         return vt_out