Loading...
testing/kernel-cache-tests/auxkc-vtable-patching/test.py dyld-1066.8 dyld-852.2
--- dyld/dyld-1066.8/testing/kernel-cache-tests/auxkc-vtable-patching/test.py
+++ dyld/dyld-852.2/testing/kernel-cache-tests/auxkc-vtable-patching/test.py
@@ -1,15 +1,13 @@
-#!/usr/bin/python3
+#!/usr/bin/python2.7
 
 import os
 import KernelCollection
-from FixupHelpers import *
 
 # This verifies that a kext can bind to another kext
 # foo.kext exports foo and bar.kext uses it
 # We put foo.kext in the base KC so that the patch slot in bar.kext has to know to use the correct fixup level in the fixup chain
 
 def check(kernel_cache):
-    enableLogging = False
     kernel_cache.buildKernelCollection("x86_64", "/auxkc-vtable-patching/main.kc", "/auxkc-vtable-patching/main.kernel", "/auxkc-vtable-patching/extensions", ["com.apple.foo"], [])
     kernel_cache.analyze("/auxkc-vtable-patching/main.kc", ["-layout", "-arch", "x86_64"])
 
@@ -22,25 +20,20 @@
     
     # From foo, we want to know where the vtable is, and the foo() and fooUsed0() slots in that vtable
     # Foo::foo()
-    fooClassFooVMAddr = findGlobalSymbolVMAddr(kernel_cache, 1, "__ZN3Foo3fooEv")
-    if enableLogging:
-        print("fooClassFooVMAddr: " + fooClassFooVMAddr)
+    assert kernel_cache.dictionary()["dylibs"][1]["global-symbols"][6]["name"] == "__ZN3Foo3fooEv"
+    assert kernel_cache.dictionary()["dylibs"][1]["global-symbols"][6]["vmAddr"] == "0x16ED0"
     # Foo::fooUsed0()
-    fooClassFooUsed0VMAddr = findGlobalSymbolVMAddr(kernel_cache, 1, "__ZN3Foo8fooUsed0Ev")
-    if enableLogging:
-        print("fooClassFooUsed0VMAddr: " + fooClassFooUsed0VMAddr)
+    assert kernel_cache.dictionary()["dylibs"][1]["global-symbols"][7]["name"] == "__ZN3Foo8fooUsed0Ev"
+    assert kernel_cache.dictionary()["dylibs"][1]["global-symbols"][7]["vmAddr"] == "0x16EF0"
 
 
     # Check the fixups
     kernel_cache.analyze("/auxkc-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
-    kernelFooFixupAddr = findFixupVMAddr(kernel_cache, "kc(0) + " + fooClassFooVMAddr)
-    if enableLogging:
-        print("kernelFooFixupAddr: " + kernelFooFixupAddr)
+    assert kernel_cache.dictionary()["fixups"]["0x1D150"] == "kc(0) + 0x16ED0"
     # Then the following fixup should be to Foo::fooUsed0()
-    kernelFooNextFixupAddr = offsetVMAddr(kernelFooFixupAddr, 8)
-    assert kernel_cache.dictionary()["fixups"][kernelFooNextFixupAddr] == "kc(0) + " + fooClassFooUsed0VMAddr
+    assert kernel_cache.dictionary()["fixups"]["0x1D158"] == "kc(0) + 0x16EF0"
 
 
     # -----------------------------------------------------------
@@ -57,23 +50,17 @@
     
     # From bar, find the vtable and its override of foo()
     # Bar::foo()
-    barFooVMAddr = findGlobalSymbolVMAddr(kernel_cache, 0, "__ZN3Bar3fooEv")
-    if enableLogging:
-        print("barFooVMAddr: " + barFooVMAddr)
+    assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][3]["name"] == "__ZN3Bar3fooEv"
+    assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][3]["vmAddr"] == "0xCF10"
 
 
     # Check the fixups
     kernel_cache.analyze("/auxkc-vtable-patching/aux.kc", ["-fixups", "-arch", "x86_64"])
 
     # Now in bar, again match the entry for its Bar::foo() symbol
-    fixupAddr = findAuxFixupVMAddr(kernel_cache, 0, "kc(3) + " + barFooVMAddr)
-    if enableLogging:
-        print("fixupAddr: " + fixupAddr)
-
+    assert kernel_cache.dictionary()["dylibs"][0]["fixups"]["0x10150"] == "kc(3) + 0xCF10"
     # And if the patching was correct, then following entry should be to Foo::fooUsed0()
-    nextFixupAddr = offsetVMAddr(fixupAddr, 8)
-    offsetOfFooUsed0 = offsetVMAddr(fooClassFooUsed0VMAddr, -16384)
-    assert kernel_cache.dictionary()["dylibs"][0]["fixups"][nextFixupAddr] == "kc(0) + " + offsetOfFooUsed0
+    assert kernel_cache.dictionary()["dylibs"][0]["fixups"]["0x10158"] == "kc(0) + 0x12EF0"
 
 
 # [~]> xcrun -sdk macosx.internal cc -arch x86_64 -Wl,-static -mkernel -nostdlib -Wl,-e,__start -Wl,-pie main.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--