Skip to content

Commit

Permalink
Fixes to generate arm64 native version
Browse files Browse the repository at this point in the history
Fix the LC_UNIXTHREAD processing
Add the thread_status includes because they depend on the target build arch and we need them all
Remove mach-o includes from Prefix.pch and move them to each source file that requires them
  • Loading branch information
gdbinit committed May 11, 2023
1 parent 6d3b897 commit 50911df
Show file tree
Hide file tree
Showing 15 changed files with 474 additions and 231 deletions.
2 changes: 2 additions & 0 deletions AppController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#import "Document.h"
#import "PreferenceController.h"
#import "Attach.h"
#import <mach-o/fat.h>
#import <mach-o/loader.h>

// counters for statistics
int64_t nrow_total; // number of rows (loaded and empty)
Expand Down
1 change: 1 addition & 0 deletions ArchiveLayout.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#import "DataController.h"
#import "MachOLayout.h"
#import "ReadWrite.h"
#import <mach-o/ranlib.h>

//============================================================================
@implementation MVObjectInfo
Expand Down
1 change: 1 addition & 0 deletions CRTFootPrints.mm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#import "CRTFootPrints.h"
#import "DataController.h"
#import <mach-o/loader.h>

#define MATCHASM(_pattern) \
(offset + sizeof(_pattern) < dataLength && \
Expand Down
3 changes: 3 additions & 0 deletions DataController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#import "MachOLayout.h"
#import "FatLayout.h"
#import "ArchiveLayout.h"
#import <mach-o/loader.h>
#import <mach-o/fat.h>
#import <mach-o/swap.h>

enum {
MVUnderlineAttributeOrdinal = 1,
Expand Down
1 change: 1 addition & 0 deletions DyldInfo.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#import "DyldInfo.h"
#import "ReadWrite.h"
#import "DataController.h"
#import <mach-o/loader.h>

using namespace std;

Expand Down
1 change: 1 addition & 0 deletions Exceptions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#import "Exceptions.h"
#import "ReadWrite.h"
#import "DataController.h"
#import <mach-o/compact_unwind_encoding.h>

using namespace std;

Expand Down
2 changes: 2 additions & 0 deletions FatLayout.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#import "DataController.h"
#import "MachOLayout.h"
#import "ReadWrite.h"
#import <mach-o/fat.h>
#import <mach-o/swap.h>

using namespace std;

Expand Down
6 changes: 6 additions & 0 deletions LinkEdit.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
#import "LinkEdit.h"
#import "ReadWrite.h"
#import "DataController.h"
#import <mach-o/loader.h>
#import <mach-o/reloc.h>
#import <mach-o/arm/reloc.h>
#import <mach-o/arm64/reloc.h>
#import <mach-o/x86_64/reloc.h>
#import <mach-o/nlist.h>

using namespace std;

Expand Down
402 changes: 190 additions & 212 deletions LoadCommands.mm

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions MachOLayout.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#import "SectionContents.h"
#import "ObjC.h"
#import "CRTFootPrints.h"
#import <mach-o/loader.h>
#import <mach-o/nlist.h>
#import <mach-o/reloc.h>

using namespace std;

Expand Down
13 changes: 0 additions & 13 deletions Prefix.pch
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,4 @@
#import <Cocoa/Cocoa.h>
#endif


#include <mach-o/arch.h>
#include <mach-o/loader.h>
#include <mach-o/fat.h>
#include <mach-o/nlist.h>
#include <mach-o/reloc.h>
#include <mach-o/x86_64/reloc.h>
#include <mach-o/arm/reloc.h>
#include <mach-o/arm64/reloc.h>
#include <mach-o/ranlib.h>
#include <mach-o/compact_unwind_encoding.h>
#include <mach-o/swap.h>

#include <libkern/OSAtomic.h>
1 change: 1 addition & 0 deletions SectionContents.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#import "ReadWrite.h"
#import "DataController.h"
#import "capstone.h"
#import <mach-o/loader.h>

#define TAB_WIDTH 10

Expand Down
142 changes: 142 additions & 0 deletions mach-o/thread_status.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
//
// thread_status.h
// MachOView
//
// Created by reverser on 10/05/2023.
//

/*
* Copyright (c) 1999-2010 Apple Inc. All Rights Reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/

#ifndef thread_status_h
#define thread_status_h

#include <stdint.h>

#define __STRUCT_X86_THREAD_STATE32 struct ___darwin_i386_thread_state
__STRUCT_X86_THREAD_STATE32
{
unsigned int eax;
unsigned int ebx;
unsigned int ecx;
unsigned int edx;
unsigned int edi;
unsigned int esi;
unsigned int ebp;
unsigned int esp;
unsigned int ss;
unsigned int eflags;
unsigned int eip;
unsigned int cs;
unsigned int ds;
unsigned int es;
unsigned int fs;
unsigned int gs;
};

#define __STRUCT_X86_THREAD_STATE64 struct ___darwin_x86_thread_state64
__STRUCT_X86_THREAD_STATE64
{
uint64_t rax;
uint64_t rbx;
uint64_t rcx;
uint64_t rdx;
uint64_t rdi;
uint64_t rsi;
uint64_t rbp;
uint64_t rsp;
uint64_t r8;
uint64_t r9;
uint64_t r10;
uint64_t r11;
uint64_t r12;
uint64_t r13;
uint64_t r14;
uint64_t r15;
uint64_t rip;
uint64_t rflags;
uint64_t cs;
uint64_t fs;
uint64_t gs;
};

/*
* THREAD_STATE_FLAVOR_LIST 0
* these are the supported flavors
*/
#define _x86_THREAD_STATE32 1
#define _x86_FLOAT_STATE32 2
#define _x86_EXCEPTION_STATE32 3
#define _x86_THREAD_STATE64 4
#define _x86_FLOAT_STATE64 5
#define _x86_EXCEPTION_STATE64 6
#define _x86_THREAD_STATE 7
#define _x86_FLOAT_STATE 8
#define _x86_EXCEPTION_STATE 9
#define _x86_DEBUG_STATE32 10
#define _x86_DEBUG_STATE64 11
#define _x86_DEBUG_STATE 12
#define _x86_THREAD_STATE_NONE 13
/* 14 and 15 are used for the internal x86_SAVED_STATE flavours */
/* Arrange for flavors to take sequential values, 32-bit, 64-bit, non-specific */
#define _x86_AVX_STATE32 16
#define _x86_AVX_STATE64 (_x86_AVX_STATE32 + 1)
#define _x86_AVX_STATE (_x86_AVX_STATE32 + 2)
#define _x86_AVX512_STATE32 19
#define _x86_AVX512_STATE64 (_x86_AVX512_STATE32 + 1)
#define _x86_AVX512_STATE (_x86_AVX512_STATE32 + 2)
#define _x86_PAGEIN_STATE 22
#define _x86_THREAD_FULL_STATE64 23
#define _x86_INSTRUCTION_STATE 24
#define _x86_LAST_BRANCH_STATE 25

struct _x86_state_hdr {
uint32_t flavor;
uint32_t count;
};
typedef struct _x86_state_hdr _x86_state_hdr_t;

typedef __STRUCT_X86_THREAD_STATE32 _x86_thread_state32_t;
#define x86_THREAD_STATE32_COUNT ((mach_msg_type_number_t) \
( sizeof (x86_thread_state32_t) / sizeof (int) ))

typedef __STRUCT_X86_THREAD_STATE64 _x86_thread_state64_t;
#define x86_THREAD_STATE64_COUNT ((mach_msg_type_number_t) \
( sizeof (x86_thread_state64_t) / sizeof (int) ))

/*
* Combined thread, float and exception states
*/
struct _x86_thread_state {
_x86_state_hdr_t tsh;
union {
_x86_thread_state32_t ts32;
_x86_thread_state64_t ts64;
} uts;
};

typedef struct _x86_thread_state _x86_thread_state_t;
#define _x86_THREAD_STATE_COUNT ((mach_msg_type_number_t) \
( sizeof (x86_thread_state_t) / sizeof (int) ))

#endif /* thread_status_h */
111 changes: 111 additions & 0 deletions mach-o/thread_status_arm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
//
// thread_status_arm.h
// MachOView
//
// Created by reverser on 10/05/2023.
//

/*
* Copyright (c) 1999-2010 Apple Inc. All Rights Reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/

#ifndef thread_status_arm_h
#define thread_status_arm_h

#include <stdint.h>

#define __STRUCT_ARM_THREAD_STATE struct ___darwin_arm_thread_state
__STRUCT_ARM_THREAD_STATE
{
uint32_t r[13]; /* General purpose register r0-r12 */
uint32_t sp; /* Stack pointer r13 */
uint32_t lr; /* Link register r14 */
uint32_t pc; /* Program counter r15 */
uint32_t cpsr; /* Current program status register */
};

#define __STRUCT_ARM_THREAD_STATE64 struct ___darwin_arm_thread_state64
__STRUCT_ARM_THREAD_STATE64
{
uint64_t x[29]; /* General purpose registers x0-x28 */
uint64_t fp; /* Frame pointer x29 */
uint64_t lr; /* Link register x30 */
uint64_t sp; /* Stack pointer x31 */
uint64_t pc; /* Program counter */
uint32_t cpsr; /* Current program status register */
uint32_t pad; /* Same size for 32-bit or 64-bit clients */
};

/*
* Flavors
*/

#define _ARM_THREAD_STATE 1
#define _ARM_UNIFIED_THREAD_STATE ARM_THREAD_STATE
#define _ARM_VFP_STATE 2
#define _ARM_EXCEPTION_STATE 3
#define _ARM_DEBUG_STATE 4 /* pre-armv8 */
#define _ARM_THREAD_STATE_NONE 5
#define _ARM_THREAD_STATE64 6
#define _ARM_EXCEPTION_STATE64 7
// ARM_THREAD_STATE_LAST 8 /* legacy */
#define _ARM_THREAD_STATE32 9
#define _ARM_DEBUG_STATE32 14
#define _ARM_DEBUG_STATE64 15
#define _ARM_NEON_STATE 16
#define _ARM_NEON_STATE64 17
#define _ARM_CPMU_STATE64 18
#define _ARM_PAGEIN_STATE 27

#ifndef ARM_STATE_FLAVOR_IS_OTHER_VALID
#define ARM_STATE_FLAVOR_IS_OTHER_VALID(_flavor_) 0
#endif

struct _arm_state_hdr {
uint32_t flavor;
uint32_t count;
};
typedef struct _arm_state_hdr _arm_state_hdr_t;

typedef __STRUCT_ARM_THREAD_STATE _arm_thread_state_t;
typedef __STRUCT_ARM_THREAD_STATE _arm_thread_state32_t;
typedef __STRUCT_ARM_THREAD_STATE64 _arm_thread_state64_t;

struct _arm_unified_thread_state {
_arm_state_hdr_t ash;
union {
_arm_thread_state32_t ts32;
_arm_thread_state64_t ts64;
} uts;
};
typedef struct _arm_unified_thread_state _arm_unified_thread_state_t;

#define ARM_THREAD_STATE_COUNT ((mach_msg_type_number_t) \
(sizeof (arm_thread_state_t)/sizeof(uint32_t)))
#define ARM_THREAD_STATE32_COUNT ((mach_msg_type_number_t) \
(sizeof (arm_thread_state32_t)/sizeof(uint32_t)))
#define ARM_THREAD_STATE64_COUNT ((mach_msg_type_number_t) \
(sizeof (arm_thread_state64_t)/sizeof(uint32_t)))
#define ARM_UNIFIED_THREAD_STATE_COUNT ((mach_msg_type_number_t) \
(sizeof (arm_unified_thread_state_t)/sizeof(uint32_t)))

#endif /* thread_status_arm_h */
Loading

0 comments on commit 50911df

Please sign in to comment.