X-Git-Url: https://git.saurik.com/apple/ld64.git/blobdiff_plain/d425e3882ca60fabae080ddb890789ef2e73a66b..9543cb2f21e50a417dc8cf37eb7173f353536979:/src/other/machochecker.cpp?ds=sidebyside diff --git a/src/other/machochecker.cpp b/src/other/machochecker.cpp index bd585d1..aec6ebe 100644 --- a/src/other/machochecker.cpp +++ b/src/other/machochecker.cpp @@ -264,11 +264,34 @@ bool MachOChecker::validFile(const uint8_t* fileContent) return false; } +#if SUPPORT_ARCH_arm64 +template <> +bool MachOChecker::validFile(const uint8_t* fileContent) +{ + const macho_header

* header = (const macho_header

*)fileContent; + if ( header->magic() != MH_MAGIC_64 ) + return false; + if ( header->cputype() != CPU_TYPE_ARM64 ) + return false; + switch (header->filetype()) { + case MH_EXECUTE: + case MH_DYLIB: + case MH_BUNDLE: + case MH_DYLINKER: + return true; + } + return false; +} +#endif + template <> uint8_t MachOChecker::loadCommandSizeMask() { return 0x03; } template <> uint8_t MachOChecker::loadCommandSizeMask() { return 0x07; } template <> uint8_t MachOChecker::loadCommandSizeMask() { return 0x03; } template <> uint8_t MachOChecker::loadCommandSizeMask() { return 0x07; } template <> uint8_t MachOChecker::loadCommandSizeMask() { return 0x03; } +#if SUPPORT_ARCH_arm64 +template <> uint8_t MachOChecker::loadCommandSizeMask() { return 0x07; } +#endif template <> @@ -301,9 +324,13 @@ arm::P::uint_t MachOChecker::getInitialStackPointer(const macho_thread_comm return threadInfo->thread_register(13); } - - - +#if SUPPORT_ARCH_arm64 +template <> +arm64::P::uint_t MachOChecker::getInitialStackPointer(const macho_thread_command* threadInfo) +{ + throw "LC_UNIXTHREAD not supported for arm64"; +} +#endif template <> ppc::P::uint_t MachOChecker::getEntryPoint(const macho_thread_command* threadInfo) @@ -335,6 +362,13 @@ arm::P::uint_t MachOChecker::getEntryPoint(const macho_thread_commandthread_register(15); } +#if SUPPORT_ARCH_arm64 +template <> +arm64::P::uint_t MachOChecker::getEntryPoint(const macho_thread_command* threadInfo) +{ + throw "LC_UNIXTHREAD not supported for arm64"; +} +#endif template MachOChecker::MachOChecker(const uint8_t* fileContent, uint32_t fileLength, const char* path) @@ -447,6 +481,7 @@ void MachOChecker::checkLoadCommands() fDyldInfo = (macho_dyld_info_command

*)cmd; break; case LC_ENCRYPTION_INFO: + case LC_ENCRYPTION_INFO_64: encryption_info = (macho_encryption_info_command

*)cmd; break; case LC_SUB_UMBRELLA: @@ -993,6 +1028,15 @@ arm::P::uint_t MachOChecker::relocBase() return fFirstSegment->vmaddr(); } +#if SUPPORT_ARCH_arm64 +template <> +arm64::P::uint_t MachOChecker::relocBase() +{ + return fFirstWritableSegment->vmaddr(); +} +#endif + + template bool MachOChecker::addressInWritableSegment(pint_t address) @@ -1107,6 +1151,14 @@ void MachOChecker::checkExternalReloation(const macho_relocation_info

* r } #endif +#if SUPPORT_ARCH_arm64 +template <> +void MachOChecker::checkExternalReloation(const macho_relocation_info

* reloc) +{ + throw "external relocations not used for arm64"; +} +#endif + template <> void MachOChecker::checkLocalReloation(const macho_relocation_info

* reloc) @@ -1184,6 +1236,15 @@ void MachOChecker::checkLocalReloation(const macho_relocation_info

* relo } #endif +#if SUPPORT_ARCH_arm64 +template <> +void MachOChecker::checkLocalReloation(const macho_relocation_info

* reloc) +{ + throw "local relocations not used for arm64"; +} +#endif + + template void MachOChecker::checkRelocations() { @@ -1602,6 +1663,11 @@ static void check(const char* path) else if ( MachOChecker::validFile(p) ) { MachOChecker::make(p, length, path); } +#endif +#if SUPPORT_ARCH_arm64 + else if ( MachOChecker::validFile(p) ) { + MachOChecker::make(p, length, path); + } #endif else { throw "not a known file type";