import os
import KernelCollection
def check(kernel_cache):
kernel_cache.buildKernelCollection("x86_64", "/kext-bind-to-kext-old-section-type/main.kc", "/kext-bind-to-kext-old-section-type/main.kernel", "/kext-bind-to-kext-old-section-type/extensions", ["com.apple.foo", "com.apple.bar"], [])
kernel_cache.analyze("/kext-bind-to-kext-old-section-type/main.kc", ["-layout", "-arch", "x86_64"])
assert len(kernel_cache.dictionary()["dylibs"]) == 3
assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.foo"
assert kernel_cache.dictionary()["dylibs"][2]["name"] == "com.apple.bar"
assert len(kernel_cache.dictionary()["dylibs"][2]["segments"]) == 3
assert kernel_cache.dictionary()["dylibs"][2]["segments"][1]["name"] == "__DATA"
assert kernel_cache.dictionary()["dylibs"][2]["segments"][1]["vmAddr"] == "0x19000"
kernel_cache.analyze("/kext-bind-to-kext-old-section-type/main.kc", ["-symbols", "-arch", "x86_64"])
assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.foo"
assert kernel_cache.dictionary()["dylibs"][1]["global-symbols"][0]["name"] == "_foo"
assert kernel_cache.dictionary()["dylibs"][1]["global-symbols"][0]["vmAddr"] == "0x14000"
kernel_cache.analyze("/kext-bind-to-kext-old-section-type/main.kc", ["-fixups", "-arch", "x86_64"])
assert len(kernel_cache.dictionary()["fixups"]) == 1
assert kernel_cache.dictionary()["fixups"]["0x15000"] == "kc(0) + 0x14000"
assert len(kernel_cache.dictionary()["dylibs"]) == 3
assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
assert kernel_cache.dictionary()["dylibs"][0]["fixups"] == "none"
assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.foo"
assert kernel_cache.dictionary()["dylibs"][1]["fixups"] == "none"
assert kernel_cache.dictionary()["dylibs"][2]["name"] == "com.apple.bar"
assert kernel_cache.dictionary()["dylibs"][2]["fixups"] == "none"