#define S_16BYTE_LITERALS 0xE
#endif
+#ifndef CPU_SUBTYPE_ARM_V5TEJ
+ #define CPU_SUBTYPE_ARM_V5TEJ ((cpu_subtype_t) 7)
+#endif
+#ifndef CPU_SUBTYPE_ARM_XSCALE
+ #define CPU_SUBTYPE_ARM_XSCALE ((cpu_subtype_t) 8)
+#endif
+#ifndef CPU_SUBTYPE_ARM_V7
+ #define CPU_SUBTYPE_ARM_V7 ((cpu_subtype_t) 9)
+#endif
+#ifndef CPU_SUBTYPE_ARM_V7F
+ #define CPU_SUBTYPE_ARM_V7F ((cpu_subtype_t) 10)
+#endif
+#ifndef CPU_SUBTYPE_ARM_V7K
+ #define CPU_SUBTYPE_ARM_V7K ((cpu_subtype_t) 12)
+#endif
+#ifndef CPU_SUBTYPE_ARM_V7S
+ #define CPU_SUBTYPE_ARM_V7S ((cpu_subtype_t) 11)
+#endif
+#ifndef CPU_SUBTYPE_ARM64_ALL
+ #define CPU_SUBTYPE_ARM64_ALL ((cpu_subtype_t) 0)
+#endif
+#ifndef CPU_TYPE_ARM64
+ #define CPU_TYPE_ARM64 ((cpu_type_t) (CPU_TYPE_ARM | CPU_ARCH_ABI64))
+#endif
+
+#define ARM64_RELOC_UNSIGNED 0 // for pointers
+
+
+#ifndef LC_LOAD_UPWARD_DYLIB
+ #define LC_LOAD_UPWARD_DYLIB (0x23|LC_REQ_DYLD) /* load of dylib whose initializers run later */
+#endif
+
+#ifndef EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER
+ #define EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER 0x10
+#endif
+#ifndef EXPORT_SYMBOL_FLAGS_REEXPORT
+ #define EXPORT_SYMBOL_FLAGS_REEXPORT 0x08
+#endif
+
+#ifndef LC_FUNCTION_STARTS
+ #define LC_FUNCTION_STARTS 0x26
+#endif
+
+#ifndef LC_DATA_IN_CODE
+ #define LC_DATA_IN_CODE 0x29
+#endif
+
+#ifndef LC_DYLIB_CODE_SIGN_DRS
+ #define LC_DYLIB_CODE_SIGN_DRS 0x2B
+#endif
+
+#ifndef CPU_SUBTYPE_X86_64_H
+ #define CPU_SUBTYPE_X86_64_H ((cpu_subtype_t) 8)
+#endif
+
+
+#define DYLD_CACHE_ADJ_V2_FORMAT 0x7F
+
+#define DYLD_CACHE_ADJ_V2_POINTER_32 0x01
+#define DYLD_CACHE_ADJ_V2_POINTER_64 0x02
+#define DYLD_CACHE_ADJ_V2_DELTA_32 0x03
+#define DYLD_CACHE_ADJ_V2_DELTA_64 0x04
+#define DYLD_CACHE_ADJ_V2_ARM64_ADRP 0x05
+#define DYLD_CACHE_ADJ_V2_ARM64_OFF12 0x06
+#define DYLD_CACHE_ADJ_V2_ARM64_BR26 0x07
+#define DYLD_CACHE_ADJ_V2_ARM_MOVW_MOVT 0x08
+#define DYLD_CACHE_ADJ_V2_ARM_BR24 0x09
+#define DYLD_CACHE_ADJ_V2_THUMB_MOVW_MOVT 0x0A
+#define DYLD_CACHE_ADJ_V2_THUMB_BR22 0x0B
+#define DYLD_CACHE_ADJ_V2_IMAGE_OFF_32 0x0C
+
+#define MH_HAS_OBJC 0x40000000
+
+#ifndef CPU_SUBTYPE_ARM64_E
+ #define CPU_SUBTYPE_ARM64_E 2
+#endif
#include "FileAbstraction.hpp"
#include "Architectures.hpp"
return (this->arch < other.arch);
return (this->subtype < other.subtype);
}
+
+ bool operator==(const ArchPair& other) const {
+ return this->arch == other.arch && this->subtype == other.subtype;
+ }
};
const macho_segment_command<P>* getSegment(const char *segname) const
{
- const macho_load_command<P>* const cmds = (macho_load_command<P>*)((uint8_t*)this + sizeof(macho_header<P>));
- const uint32_t cmd_count = this->ncmds();
+ const macho_load_command<P>* cmds = (macho_load_command<P>*)((uint8_t*)this + sizeof(macho_header<P>));
+ uint32_t cmd_count = this->ncmds();
const macho_load_command<P>* cmd = cmds;
for (uint32_t i = 0; i < cmd_count; ++i) {
if ( cmd->cmd() == macho_segment_command<P>::CMD ) {
- const macho_segment_command<P>* segcmd =
- (macho_segment_command<P>*)cmd;
+ const macho_segment_command<P>* segcmd = (macho_segment_command<P>*)cmd;
if (0 == strncmp(segname, segcmd->segname(), 16)) {
return segcmd;
- }
+ }
}
- cmd = (const macho_load_command<P>*)(((uint8_t*)cmd)+cmd->cmdsize());
+ cmd = (macho_load_command<P>*)(((uint8_t*)cmd)+cmd->cmdsize());
}
return NULL;
}
const macho_section<P>* getSection(const char *segname, const char *sectname) const
{
- const macho_segment_command<P>* const segcmd = getSegment(segname);
+ const macho_segment_command<P>* segcmd = getSegment(segname);
if (!segcmd) return NULL;
const macho_section<P>* sectcmd = (macho_section<P>*)(segcmd+1);
- const uint32_t section_count = segcmd->nsects();
+ uint32_t section_count = segcmd->nsects();
for (uint32_t j = 0; j < section_count; ++j) {
if (0 == ::strncmp(sectcmd[j].sectname(), sectname, 16)) {
return sectcmd+j;
}
}
+ if (strcmp(segname, "__DATA") == 0)
+ return getSection("__DATA_CONST", sectname);
+ return NULL;
+ }
+
+ const macho_load_command<P>* getLoadCommand(int query) const
+ {
+ const macho_load_command<P>* cmds = (macho_load_command<P>*)((uint8_t*)this + sizeof(macho_header<P>));
+ uint32_t cmd_count = this->ncmds();
+ const macho_load_command<P>* cmd = cmds;
+ for (uint32_t i = 0; i < cmd_count; ++i) {
+ if ( cmd->cmd() == query ) {
+ return cmd;
+ }
+ cmd = (macho_load_command<P>*)(((uint8_t*)cmd)+cmd->cmdsize());
+ }
return NULL;
}
}
-static int64_t read_sleb128(const uint8_t*& p, const uint8_t* end)
+inline int64_t read_sleb128(const uint8_t*& p, const uint8_t* end)
{
int64_t result = 0;
int bit = 0;
if (p == end)
throw "malformed sleb128";
byte = *p++;
- result |= ((byte & 0x7f) << bit);
+ result |= (((int64_t)(byte & 0x7f)) << bit);
bit += 7;
} while (byte & 0x80);
// sign extend negative numbers