-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,056 additions
and
331 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
|
||
// MachoArm64RelocationType | ||
#define ARM64_RELOC_UNSIGNED 0 | ||
#define ARM64_RELOC_BRANCH26 2 | ||
#define ARM64_RELOC_PAGE21 3 | ||
#define ARM64_RELOC_PAGEOFF12 4 | ||
#define ARM64_RELOC_GOT_LOAD_PAGE21 5 | ||
#define ARM64_RELOC_GOT_LOAD_PAGEOFF12 6 | ||
#define ARM64_RELOC_ADDEND 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#pragma once | ||
|
||
#include <stdint.h> | ||
|
||
struct mach_header_64 { | ||
uint32_t magic; | ||
int32_t cputype; | ||
int32_t cpusubtype; | ||
uint32_t filetype; | ||
uint32_t ncmds; | ||
uint32_t sizeofcmds; | ||
uint32_t flags; | ||
uint32_t reserved; | ||
}; | ||
|
||
#define MH_MAGIC_64 0xfeedfacf | ||
|
||
#define MH_OBJECT 0x1 | ||
#define MH_EXECUTE 0x2 | ||
|
||
#define MH_SUBSECTIONS_VIA_SYMBOLS 0x2000 | ||
|
||
struct load_command { | ||
uint32_t cmd; | ||
uint32_t cmdsize; | ||
}; | ||
|
||
#define LC_SYMTAB 0x2 | ||
#define LC_SEGMENT_64 0x19 | ||
#define LC_BUILD_VERSION 0x32 | ||
|
||
struct symtab_command { | ||
uint32_t cmd; | ||
uint32_t cmdsize; | ||
uint32_t symoff; | ||
uint32_t nsyms; | ||
uint32_t stroff; | ||
uint32_t strsize; | ||
}; | ||
|
||
struct segment_command_64 { /* for 64-bit architectures */ | ||
uint32_t cmd; | ||
uint32_t cmdsize; | ||
char segname[16]; | ||
uint64_t vmaddr; | ||
uint64_t vmsize; | ||
uint64_t fileoff; | ||
uint64_t filesize; | ||
int32_t maxprot; | ||
int32_t initprot; | ||
uint32_t nsects; | ||
uint32_t flags; | ||
}; | ||
|
||
struct build_version_command { | ||
uint32_t cmd; | ||
uint32_t cmdsize; | ||
uint32_t platform; | ||
uint32_t minos; | ||
uint32_t sdk; | ||
uint32_t ntools; | ||
}; | ||
|
||
#define PLATFORM_MACOS 1 | ||
|
||
struct section_64 { /* for 64-bit architectures */ | ||
char sectname[16]; | ||
char segname[16]; | ||
uint64_t addr; | ||
uint64_t size; | ||
uint32_t offset; | ||
uint32_t align; | ||
uint32_t reloff; | ||
uint32_t nreloc; | ||
uint32_t flags; | ||
uint32_t reserved1; | ||
uint32_t reserved2; | ||
uint32_t reserved3; | ||
}; | ||
|
||
#define S_ATTR_PURE_INSTRUCTIONS 0x80000000 | ||
#define S_ATTR_SOME_INSTRUCTIONS 0x00000400 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#include <stdint.h> | ||
|
||
#define N_STAB 0xe0 | ||
#define N_PEXT 0x10 | ||
#define N_TYPE 0x0e | ||
#define N_EXT 0x01 | ||
|
||
#define N_UNDF 0x0 | ||
#define N_ABS 0x2 | ||
#define N_SECT 0xe | ||
#define N_PBUD 0xc | ||
#define N_INDR 0xa | ||
|
||
struct nlist_64 { | ||
union { | ||
uint32_t n_strx; | ||
} n_un; | ||
uint8_t n_type; | ||
uint8_t n_sect; | ||
uint16_t n_desc; | ||
uint64_t n_value; | ||
}; | ||
|
||
#define GET_COMM_ALIGN(n_desc) (((n_desc) >> 8) & 0x0f) | ||
#define SET_COMM_ALIGN(n_desc, align) (n_desc) = (((n_desc) & 0xf0ff) | (((align) & 0x0f) << 8)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
#include <stdint.h> | ||
|
||
struct relocation_info { | ||
int32_t r_address; | ||
uint32_t | ||
r_symbolnum : 24, | ||
r_pcrel : 1, | ||
r_length : 2, | ||
r_extern : 1, | ||
r_type : 4; | ||
}; | ||
#define R_ABS 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
enum reloc_type_x86_64 { | ||
X86_64_RELOC_UNSIGNED, | ||
X86_64_RELOC_SIGNED, | ||
X86_64_RELOC_BRANCH, | ||
X86_64_RELOC_GOT_LOAD, | ||
X86_64_RELOC_GOT, | ||
X86_64_RELOC_SUBTRACTOR, | ||
X86_64_RELOC_SIGNED_1, | ||
X86_64_RELOC_SIGNED_2, | ||
X86_64_RELOC_SIGNED_4, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
|
||
#define CPU_TYPE_ARM ((cpu_type_t)12) | ||
#define CPU_TYPE_X86 ((cpu_type_t)7) | ||
|
||
#define CPU_ARCH_MASK 0xff000000 | ||
#define CPU_ARCH_ABI64 0x01000000 | ||
|
||
#define CPU_TYPE_X86_64 (CPU_TYPE_X86 | CPU_ARCH_ABI64) | ||
|
||
#define CPU_SUBTYPE_X86_ALL ((cpu_subtype_t)3) | ||
|
||
#define CPU_TYPE_ARM64 (CPU_TYPE_ARM | CPU_ARCH_ABI64) | ||
|
||
#define CPU_SUBTYPE_ARM_ALL ((cpu_subtype_t)0) | ||
|
||
typedef int integer_t; | ||
typedef integer_t cpu_type_t; | ||
typedef integer_t cpu_subtype_t; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.