Skip to content

Commit

Permalink
mach-o: Fix cputype type (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
littledivy authored Jul 24, 2024
1 parent 35ce0e0 commit f046f8c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ pub(crate) struct SegmentCommand64 {
#[repr(C)]
pub(crate) struct Header64 {
magic: u32,
cputype: u32,
cputype: i32,
cpusubtype: u32,
filetype: u32,
ncmds: u32,
Expand Down Expand Up @@ -255,7 +255,7 @@ const LC_LINKER_OPTIMIZATION_HINT: u32 = 0x2d;
const LC_DYLD_EXPORTS_TRIE: u32 = 0x8000001e;
const LC_DYLD_CHAINED_FIXUPS: u32 = 0x80000034;

const CPU_TYPE_ARM: u32 = 12;
const CPU_TYPE_ARM_64: i32 = 0x0100000c;

fn align(size: u64, base: u64) -> u64 {
let over = size % base;
Expand Down Expand Up @@ -341,7 +341,7 @@ impl Macho {
}

pub fn write_section(mut self, name: &str, sectdata: Vec<u8>) -> Result<Self, Error> {
let page_size = if self.header.cputype & CPU_TYPE_ARM != 0 {
let page_size = if self.header.cputype == CPU_TYPE_ARM_64 {
0x10000
} else {
0x1000
Expand Down Expand Up @@ -540,7 +540,7 @@ impl Macho {
}

pub fn build_and_sign<W: Write>(self, mut writer: W) -> Result<(), Error> {
if self.header.cputype & CPU_TYPE_ARM != 0 {
if self.header.cputype == CPU_TYPE_ARM_64 {
let mut data = Vec::new();
self.build(&mut data)?;
let codesign = apple_codesign::MachoSigner::new(data)?;
Expand Down

0 comments on commit f046f8c

Please # to comment.