8#include <mach-o/loader.h>
19#if defined(Q_PROCESSOR_X86_64)
21static const cpu_type_t my_cputype = CPU_TYPE_X86_64;
22#elif defined(Q_PROCESSOR_X86_32)
23static const cpu_type_t my_cputype = CPU_TYPE_X86;
24#elif defined(Q_PROCESSOR_POWER_64)
26static const cpu_type_t my_cputype = CPU_TYPE_POWERPC64;
27#elif defined(Q_PROCESSOR_POWER_32)
28static const cpu_type_t my_cputype = CPU_TYPE_POWERPC;
29#elif defined(Q_PROCESSOR_ARM_64)
31static const cpu_type_t my_cputype = CPU_TYPE_ARM64;
32#elif defined(Q_PROCESSOR_ARM)
33static const cpu_type_t my_cputype = CPU_TYPE_ARM;
35# error "Unknown CPU type"
43static const uint32_t
my_magic = MH_MAGIC_64;
54 *errorString = QLibrary::tr(
"'%1' is not a valid Mach-O binary (%2)")
55 .
arg(*errorString, reason.
isEmpty() ? QLibrary::tr(
"file is corrupt") : reason);
62 for (uint32_t
i = 0;
i <
header->ncmds; ++
i) {
63 load_command *loadCommand =
reinterpret_cast<load_command *
>(commandCursor);
64 if (loadCommand->cmd == LC_ENCRYPTION_INFO || loadCommand->cmd == LC_ENCRYPTION_INFO_64) {
67 auto encryptionInfoCommand =
reinterpret_cast<encryption_info_command*
>(loadCommand);
68 return encryptionInfoCommand->cryptid != 0;
70 commandCursor += loadCommand->cmdsize;
84 static const size_t MinFatHeaderSize =
sizeof(fat_header) + 2 *
sizeof(fat_arch);
91 const fat_header *fat =
reinterpret_cast<const fat_header *
>(m_s);
94 const fat_arch *arch =
reinterpret_cast<const fat_arch *
>(fat + 1);
96 return notfound(QLibrary::tr(
"file too small"), errorString);
118 return notfound(QLibrary::tr(
"no suitable architecture in fat binary"), errorString);
138 if (
header->cputype != my_cputype) {
141 return notfound(QLibrary::tr(
"wrong architecture"), errorString);
146 return notfound(QLibrary::tr(
"not a dynamic library"), errorString);
150 ulong minsize =
sizeof(*header);
153 seg =
reinterpret_cast<const my_segment_command *
>(
reinterpret_cast<const char *
>(seg) + seg->cmdsize)) {
156 if (
Q_UNLIKELY(fdlen < minsize +
sizeof(load_command)))
162 minsize += seg->cmdsize;
166 const uint32_t MyLoadCommand =
sizeof(
void *) > 4 ? LC_SEGMENT_64 : LC_SEGMENT;
167 if (seg->cmd != MyLoadCommand)
171 if (strcmp(seg->segname,
"__TEXT") == 0) {
173 for (
uint j = 0;
j < seg->nsects; ++
j) {
175 if (strcmp(sect[
j].sectname,
"qtmetadata") != 0)
194 if (expectedMagic != actualMagic)
195 return notfound(QLibrary::tr(
".qtmetadata section has incorrect magic"), errorString);
204 seg =
reinterpret_cast<const my_segment_command *
>(
reinterpret_cast<const char *
>(seg) + seg->cmdsize);
208 *
errorString = QLibrary::tr(
"'%1' is not a Qt plugin").
arg(*errorString);
constexpr qsizetype size() const noexcept
static constexpr QByteArrayView fromArray(const Byte(&data)[Size]) noexcept
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString arg(qlonglong a, int fieldwidth=0, int base=10, QChar fillChar=u' ') const
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Combined button and popup list for selecting options.
#define Q_DECL_COLD_FUNCTION
static QString header(const QString &name)
constexpr T qToBigEndian(T source)
constexpr T qFromBigEndian(T source)
static Q_DECL_COLD_FUNCTION QLibraryScanResult notfound(const QString &reason, QString *errorString)
mach_header my_mach_header
static bool isEncrypted(const my_mach_header *header)
static const uint32_t my_magic
segment_command my_segment_command
static constexpr bool IncludeValidityChecks
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLenum GLsizei count
GLenum GLuint GLintptr offset