Loading...
testing/kernel-cache-tests/kernel-vtable-patching/test.py dyld-852.2 dyld-1042.1
--- dyld/dyld-852.2/testing/kernel-cache-tests/kernel-vtable-patching/test.py
+++ dyld/dyld-1042.1/testing/kernel-cache-tests/kernel-vtable-patching/test.py
@@ -1,7 +1,8 @@
-#!/usr/bin/python2.7
+#!/usr/bin/python3
 
 import os
 import KernelCollection
+from FixupHelpers import *
 
 # This tests verifies that the vtable in bar.kext is patched
 # But also that this can be done against a subclass in the kernel, not just 
@@ -19,30 +20,29 @@
     
     # From foo, we want to know where the vtable is, and the foo() and fooUsed0() slots in that vtable
     # Foo::foo()
-    assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][27]["name"] == "__ZN3Foo3fooEv"
-    assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][27]["vmAddr"] == "0x15EC0"
+    fooFooVMAddr = findGlobalSymbolVMAddr(kernel_cache, 0, "__ZN3Foo3fooEv")
     # Foo::fooUsed0()
-    assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][28]["name"] == "__ZN3Foo8fooUsed0Ev"
-    assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][28]["vmAddr"] == "0x15EE0"
+    fooFooUsed0VMAddr = findGlobalSymbolVMAddr(kernel_cache, 0, "__ZN3Foo8fooUsed0Ev")
     
     # From bar, find the vtable and its override of foo()
     # Bar::foo()
-    assert kernel_cache.dictionary()["dylibs"][1]["global-symbols"][3]["name"] == "__ZN3Bar3fooEv"
-    assert kernel_cache.dictionary()["dylibs"][1]["global-symbols"][3]["vmAddr"] == "0x16F10"
+    barFooVMAddr = findGlobalSymbolVMAddr(kernel_cache, 1, "__ZN3Bar3fooEv")
 
 
     # Check the fixups
     kernel_cache.analyze("/kernel-vtable-patching/main.kc", ["-fixups", "-arch", "x86_64"])
     
     # In vtable for Foo, we match the entry for Foo::foo() by looking for its value on the RHS of the fixup
-    assert kernel_cache.dictionary()["fixups"]["0x14500"] == "kc(0) + 0x15EC0 : pointer64"
+    fooFooFixupAddr = findFixupVMAddr(kernel_cache, "kc(0) + " + fooFooVMAddr + " : pointer64")
     # Then the following fixup should be to Foo::fooUsed0()
-    assert kernel_cache.dictionary()["fixups"]["0x14508"] == "kc(0) + 0x15EE0 : pointer64"
+    nextFixupAddr = offsetVMAddr(fooFooFixupAddr, 8)
+    assert kernel_cache.dictionary()["fixups"][nextFixupAddr] == "kc(0) + " + fooFooUsed0VMAddr + " : pointer64"
 
     # Now in bar, again match the entry for its Bar::foo() symbol
-    assert kernel_cache.dictionary()["fixups"]["0x1D150"] == "kc(0) + 0x16F10"
+    barFooFixupAddr = findFixupVMAddr(kernel_cache, "kc(0) + " + barFooVMAddr)
     # And if the patching was correct, then following entry should be to Foo::fooUsed0()
-    assert kernel_cache.dictionary()["fixups"]["0x1D158"] == "kc(0) + 0x15EE0"
+    nextFixupAddr = offsetVMAddr(barFooFixupAddr, 8)
+    assert kernel_cache.dictionary()["fixups"][nextFixupAddr] == "kc(0) + " + fooFooUsed0VMAddr
 
 
 # [~]> xcrun -sdk macosx.internal cc -arch x86_64 -Wl,-static -mkernel -nostdlib -Wl,-e,__start -Wl,-pie main.cpp foo.cpp -Wl,-pagezero_size,0x0 -o main.kernel -Wl,-image_base,0x10000 -Wl,-segaddr,__HIB,0x4000 -Wl,-add_split_seg_info -Wl,-install_name,/usr/lib/swift/split.seg.v2.hack -iwithsysroot /System/Library/Frameworks/Kernel.framework/Headers -Wl,-sectcreate,__LINKINFO,__symbolsets,SymbolSets.plist -Wl,-segprot,__LINKINFO,r--,r--  -DFOO_USED=1