more definitions for macho

Signed-off-by: SergeySlice <sergey.slice@gmail.com>
This commit is contained in:
SergeySlice 2020-07-17 14:36:51 +03:00
parent d320eb9693
commit 16ef973a71
4 changed files with 126 additions and 56 deletions

View File

@ -1,44 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AvoidRuntimeDefrag</key>
<true/>
<key>DevirtualiseMmio</key>
<false/>
<key>DisableSingleUser</key>
<false/>
<key>DisableVariableWrite</key>
<false/>
<key>DiscardHibernateMap</key>
<false/>
<key>EnableSafeModeSlide</key>
<true/>
<key>EnableWriteUnprotector</key>
<true/>
<key>ForceExitBootServices</key>
<false/>
<key>MmioWhitelist</key>
<array/>
<key>ProtectMemoryRegions</key>
<false/>
<key>ProtectSecureBoot</key>
<false/>
<key>ProtectUefiServices</key>
<false/>
<key>ProvideConsoleGopEnable</key>
<true/>
<key>ProvideCustomSlide</key>
<true/>
<key>ProvideMaxSlide</key>
<integer>0</integer>
<key>RebuildAppleMemoryMap</key>
<false/>
<key>SetupVirtualMap</key>
<true/>
<key>SignalAppleOS</key>
<false/>
<key>SyncRuntimePermissions</key>
<true/>
</dict>
</plist>

View File

@ -299,6 +299,16 @@ like environment variable */
#define LC_DATA_IN_CODE 0x29 /* table of non-instructions in __text */
#define LC_SOURCE_VERSION 0x2A /* source version used to build binary */
#define LC_DYLIB_CODE_SIGN_DRS 0x2B /* Code signing DRs copied from linked dylibs */
#define LC_ENCRYPTION_INFO_64 0x2C /* 64-bit encrypted segment information */
#define LC_LINKER_OPTION 0x2D /* linker options in MH_OBJECT files */
#define LC_LINKER_OPTIMIZATION_HINT 0x2E /* optimization hints in MH_OBJECT files */
#define LC_VERSION_MIN_TVOS 0x2F /* build for AppleTV min OS version */
#define LC_VERSION_MIN_WATCHOS 0x30 /* build for Watch min OS version */
#define LC_NOTE 0x31 /* arbitrary data included within a Mach-O file */
#define LC_BUILD_VERSION 0x32 /* build for platform min OS version */
#define LC_DYLD_EXPORTS_TRIE (0x33 | LC_REQ_DYLD) /* used with linkedit_data_command, payload is trie */
#define LC_DYLD_CHAINED_FIXUPS (0x34 | LC_REQ_DYLD) /* used with linkedit_data_command */
#define LC_KEXT (0x35 | LC_REQ_DYLD)
/*
@ -354,12 +364,13 @@ struct segment_command_64 { /* for 64-bit architectures */
char segname[16]; /* segment name */
uint64_t vmaddr; /* memory address of this segment */
uint64_t vmsize; /* memory size of this segment */
uint64_t fileoff; /* file offset of this segment */
uint64_t filesize; /* amount to map from the file */
vm_prot_t maxprot; /* maximum VM protection */
vm_prot_t initprot; /* initial VM protection */
uint32_t nsects; /* number of sections in segment */
uint32_t flags; /* flags */
uint64_t fileoff; /* file offset of this segment */ //0x28
uint64_t filesize; /* amount to map from the file */ //0x30
vm_prot_t maxprot; /* maximum VM protection */ //38
vm_prot_t initprot; /* initial VM protection */ //3c
uint32_t nsects; /* number of sections in segment */ //40
uint32_t flags; /* flags */ //44
//struct section_64 sect[nsects]; //0x48 if nsect > 0
};
/* Constants for the flags field of the segment_command */
@ -377,6 +388,8 @@ segment starts at file offset 0, the
first page of the segment is not
protected. All other pages of the
segment are protected. */
#define SG_READ_ONLY 0x10 /* This segment is made read-only after fixups */
/*
* A segment is made up of zero or more sections. Non-MH_OBJECT files have
@ -502,6 +515,9 @@ descriptors */
#define S_THREAD_LOCAL_INIT_FUNCTION_POINTERS 0x15 /* functions to call
to initialize TLV
values */
#define S_INIT_FUNC_OFFSETS 0x16 /* 32-bit offsets to
initializers */
/*
* Constants for the section attributes part of the flags field of a section
@ -834,7 +850,7 @@ struct routines_command_64 { /* for 64-bit architectures */
* <nlist.h> and <stab.h>.
*/
struct symtab_command {
uint32_t cmd; /* LC_SYMTAB */
uint32_t cmd; /* LC_SYMTAB == 2 */
uint32_t cmdsize; /* sizeof(struct symtab_command) */
uint32_t symoff; /* symbol table offset */
uint32_t nsyms; /* number of symbol table entries */
@ -883,7 +899,7 @@ struct symtab_command {
* off the section structures.
*/
struct dysymtab_command {
uint32_t cmd; /* LC_DYSYMTAB */
uint32_t cmd; /* LC_DYSYMTAB == 0x0b */
uint32_t cmdsize; /* sizeof(struct dysymtab_command) */
/*
@ -1160,7 +1176,10 @@ struct rpath_command {
struct linkedit_data_command {
uint32_t cmd; /* LC_CODE_SIGNATURE, LC_SEGMENT_SPLIT_INFO,
LC_FUNCTION_STARTS, LC_DATA_IN_CODE,
or LC_DYLIB_CODE_SIGN_DRS */
LC_DYLIB_CODE_SIGN_DRS,
LC_LINKER_OPTIMIZATION_HINT,
LC_DYLD_EXPORTS_TRIE, or
LC_DYLD_CHAINED_FIXUPS. */
uint32_t cmdsize; /* sizeof(struct linkedit_data_command) */
uint32_t dataoff; /* file offset of data in __LINKEDIT segment */
uint32_t datasize; /* file size of data in __LINKEDIT segment */
@ -1179,6 +1198,21 @@ struct encryption_info_command {
0 means not-encrypted yet */
};
/*
* The encryption_info_command_64 contains the file offset and size of an
* of an encrypted segment (for use in x86_64 targets).
*/
struct encryption_info_command_64 {
uint32_t cmd; /* LC_ENCRYPTION_INFO_64 */
uint32_t cmdsize; /* sizeof(struct encryption_info_command_64) */
uint32_t cryptoff; /* file offset of encrypted range */
uint32_t cryptsize; /* file size of encrypted range */
uint32_t cryptid; /* which enryption system,
0 means not-encrypted yet */
uint32_t pad; /* padding to make this struct's size a multiple
of 8 bytes */
};
/*
* The version_min_command contains the min OS version on which this
* binary was built to run.
@ -1191,6 +1225,44 @@ struct version_min_command {
uint32_t sdk; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */
};
/*
* The build_version_command contains the min OS version on which this
* binary was built to run for its platform. The list of known platforms and
* tool values following it.
*/
struct build_version_command {
uint32_t cmd; /* LC_BUILD_VERSION */
uint32_t cmdsize; /* sizeof(struct build_version_command) plus */
/* ntools * sizeof(struct build_tool_version) */
uint32_t platform; /* platform */
uint32_t minos; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */
uint32_t sdk; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */
uint32_t ntools; /* number of tool entries following this */
};
struct build_tool_version {
uint32_t tool; /* enum for the tool */
uint32_t version; /* version number of the tool */
};
/* Known values for the platform field above. */
#define PLATFORM_MACOS 1
#define PLATFORM_IOS 2
#define PLATFORM_TVOS 3
#define PLATFORM_WATCHOS 4
#define PLATFORM_BRIDGEOS 5
#define PLATFORM_IOSMAC 6
#define PLATFORM_IOSSIMULATOR 7
#define PLATFORM_TVOSSIMULATOR 8
#define PLATFORM_WATCHOSSIMULATOR 9
#define PLATFORM_DRIVERKIT 10
/* Known values for the tool field above. */
#define TOOL_CLANG 1
#define TOOL_SWIFT 2
#define TOOL_LD 3
/*
* The dyld_info_command contains the file offsets and sizes of
* the new compressed form of the information dyld needs to
@ -1351,6 +1423,9 @@ struct dyld_info_command {
#define BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB 0xA0
#define BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED 0xB0
#define BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB 0xC0
#define BIND_OPCODE_THREADED 0xD0
#define BIND_SUBOPCODE_THREADED_SET_BIND_ORDINAL_TABLE_SIZE_ULEB 0x00
#define BIND_SUBOPCODE_THREADED_APPLY 0x01
/*
@ -1364,6 +1439,18 @@ struct dyld_info_command {
#define EXPORT_SYMBOL_FLAGS_REEXPORT 0x08
#define EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER 0x10
/*
* The linker_option_command contains linker options embedded in object files.
*/
struct linker_option_command {
uint32_t cmd; /* LC_LINKER_OPTION only used in MH_OBJECT filetypes */
uint32_t cmdsize;
uint32_t count; /* number of strings */
/* concatenation of zero terminated UTF8 strings.
Zero filled at end to align */
};
/*
* The symseg_command contains the offset and size of the GNU style
* symbol table information as described in the header file <symseg.h>.
@ -1460,4 +1547,29 @@ struct tlv_descriptor
unsigned long offset;
};
/*
* LC_NOTE commands describe a region of arbitrary data included in a Mach-O
* file. Its initial use is to record extra data in MH_CORE files.
*/
struct note_command {
uint32_t cmd; /* LC_NOTE */
uint32_t cmdsize; /* sizeof(struct note_command) */
char data_owner[16]; /* owner name for this LC_NOTE */
uint64_t offset; /* file offset of this data */
uint64_t size; /* length of data region */
};
//kexts cache
struct command_35 {
uint32_t cmd; //0x35 - LC_KEXT
uint32_t cmdsize; //0x38 - short name, 0x48 - long name
uint64_t offset; /* file offset of this data */
uint64_t size; /* length of data region */
uint32_t res1;
uint32_t res2;
char name[16]; //kext name [16] or [32]
// align to 8 byte boundary
};
#endif /* _MACHO_LOADER_H_ */

View File

@ -3,7 +3,7 @@
*
* Copyright (c) 2011-2012 Frank Peng. All rights reserved.
*
* Correction and improvements by Clover team
* 2012 - 2020 Correction and improvements by Clover team
*/
#include "Platform.h"
@ -18,7 +18,7 @@
//#include "sse3_5_patcher.h"
#ifndef DEBUG_ALL
#define KERNEL_DEBUG 0
#define KERNEL_DEBUG 1
#else
#define KERNEL_DEBUG DEBUG_ALL
#endif

View File

@ -110,10 +110,12 @@ typedef struct SEGMENT {
UINT32 initprot; //0x34 01
UINT32 NumSects; //0x38 00
UINT32 Flags; //0x3C 00
UINT32 Cmd[2]; //0x40 02, 18
UINT32 Cmd; //0x40 02 //LC_SYMTAB link-edit stab symbol table info
UINT32 Cmdsize //0x44 18
UINT32 AddrVtable; //0x48
UINT32 SizeVtable; //0x4C
UINT32 AddrNames; //0x50
UINT32 SizeNamesTable;
} SEGMENT;