diff --git a/src/consts.rs b/src/consts.rs index 542cff5..f02099b 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -343,7 +343,9 @@ pub const MH_MAGIC_64: u32 = 0xfeed_facf; pub const MH_CIGAM_64: u32 = 0xcffa_edfe; pub const FAT_MAGIC: u32 = 0xcafe_babe; +pub const FAT_MAGIC64: u32 = 0xcafe_babf; pub const FAT_CIGAM: u32 = 0xbeba_feca; /* NXSwapLong(FAT_MAGIC) */ +pub const FAT_CIGAM64: u32 = 0xbfba_feca; /* NXSwapLong(FAT_MAGIC) */ pub const ARMAG: &[u8] = b"!\n"; diff --git a/src/loader.rs b/src/loader.rs index 265f941..83ffd49 100644 --- a/src/loader.rs +++ b/src/loader.rs @@ -135,9 +135,9 @@ pub struct FatArch { /// machine specifier (int) pub cpusubtype: cpu_subtype_t, /// file offset to this object file - pub offset: u32, + pub offset: u64, /// size of this object file - pub size: u32, + pub size: u64, /// alignment as a power of 2 pub align: u32, } @@ -270,8 +270,7 @@ impl OFile { MH_CIGAM => Self::parse_mach_file::(magic, buf), MH_MAGIC_64 => Self::parse_mach_file::(magic, buf), MH_CIGAM_64 => Self::parse_mach_file::(magic, buf), - FAT_MAGIC => Self::parse_fat_file::(magic, buf), - FAT_CIGAM => Self::parse_fat_file::(magic, buf), + FAT_MAGIC | FAT_MAGIC64 | FAT_CIGAM | FAT_CIGAM64 => Self::parse_fat_file::(magic, buf), _ => { let mut ar_magic = [0; 8]; @@ -327,12 +326,26 @@ impl OFile { let mut archs = Vec::new(); for i in 0..nfat_arch { - let arch = FatArch { - cputype: buf.read_u32::()? as cpu_type_t, - cpusubtype: buf.read_u32::()? as cpu_subtype_t, - offset: buf.read_u32::()?, - size: buf.read_u32::()?, - align: buf.read_u32::()?, + let arch = if matches!(magic, FAT_MAGIC64 | FAT_CIGAM64) { + FatArch { + cputype: buf.read_u32::()? as cpu_type_t, + cpusubtype: buf.read_u32::()? as cpu_subtype_t, + offset: buf.read_u64::()?, + size: buf.read_u64::()?, + align: { + let align = buf.read_u32::()?; + let _reserved = buf.read_u32::()?; + align + }, + } + } else { + FatArch { + cputype: buf.read_u32::()? as cpu_type_t, + cpusubtype: buf.read_u32::()? as cpu_subtype_t, + offset: buf.read_u32::()? as u64, + size: buf.read_u32::()? as u64, + align: buf.read_u32::()?, + } }; debug!("0x{:08}\tfat header arch#{}, arch={:?}", buf.position(), i, arch);