diff --git a/src/MachO/MachOFat.jl b/src/MachO/MachOFat.jl index b636f21..52f83e1 100644 --- a/src/MachO/MachOFat.jl +++ b/src/MachO/MachOFat.jl @@ -11,8 +11,8 @@ abstract type MachOFatArchitecture end end @io struct MachOFatArch64 <: MachOFatArchitecture - cputype::UInt64 - cpusubtype::UInt64 + cputype::UInt32 + cpusubtype::UInt32 offset::UInt64 size::UInt64 align::UInt32 @@ -59,7 +59,7 @@ function readmeta(io::IO,::Type{FatMachOHandle}) # Unpack the header header = unpack(io, header_type, endianness) - return FatMachOHandle(io, start, header, path(io)) + return FatMachOHandle(io, Int64(start), header, path(io)) end # Iteration @@ -67,7 +67,7 @@ keys(h::FatMachOHandle) = 1:length(h) iterate(h::FatMachOHandle, idx=1) = idx > length(h) ? nothing : (h[idx], idx+1) lastindex(h::FatMachOHandle) = lastindex(h.header.archs) length(h::FatMachOHandle) = length(h.header.archs) -eltype(::Type{S}) where {S <: FatMachOHandle} = MachOLoadCmdRef +eltype(::Type{<:FatMachOHandle}) = MachOHandle function getindex(h::FatMachOHandle, idx) seek(h.io, h.start + h.header.archs[idx].offset) only(readmeta(h.io, MachOHandle)) diff --git a/src/MachO/MachOHeader.jl b/src/MachO/MachOHeader.jl index de965e6..9a855e4 100644 --- a/src/MachO/MachOHeader.jl +++ b/src/MachO/MachOHeader.jl @@ -74,9 +74,9 @@ Given the `magic` field from a Mach-O file header, return the endianness of the Mach-O header. """ function macho_endianness(magic::UInt32) - if magic in (MH_CIGAM, MH_CIGAM_64, FAT_CIGAM, FAT_CIGAM_METAL) + if magic in (MH_CIGAM, MH_CIGAM_64, FAT_CIGAM, FAT_CIGAM_64, FAT_CIGAM_METAL) return :BigEndian - elseif magic in (MH_MAGIC, MH_MAGIC_64, FAT_MAGIC, FAT_MAGIC_METAL, METALLIB_MAGIC) + elseif magic in (MH_MAGIC, MH_MAGIC_64, FAT_MAGIC, FAT_MAGIC_64, FAT_MAGIC_METAL, METALLIB_MAGIC) return :LittleEndian else throw(MagicMismatch("Invalid Magic (0x$(string(magic, base=16, pad=8)))!")) diff --git a/test/mac64/libfoo_fat64.dylib b/test/mac64/libfoo_fat64.dylib new file mode 100755 index 0000000..09a0549 Binary files /dev/null and b/test/mac64/libfoo_fat64.dylib differ diff --git a/test/runtests.jl b/test/runtests.jl index c5b1146..860620e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -207,7 +207,7 @@ function test_libfoo_and_fooifier(fooifier_path, libfoo_path) end function test_fat_libfoo(file) - ohs = readmeta(open(file, "r")) + ohs = readmeta(file isa IO ? file : open(file, "r")) @test isa(ohs, FatMachOHandle) @test length(ohs) == 2 ntotal, n64 = 0, 0 @@ -217,6 +217,10 @@ function test_fat_libfoo(file) end @test ntotal == 2 @test n64 == 1 + + handles = collect(ohs) + @test handles isa Vector{<:MachOHandle} + @test length(handles) == 2 end function test_metal(file) @@ -241,6 +245,9 @@ test_libfoo_and_fooifier("./linux64/fooifier", "./linux64/libfoo.so") # Run MachO tests test_libfoo_and_fooifier("./mac64/fooifier", "./mac64/libfoo.dylib") test_fat_libfoo("./mac64/libfoo_fat.dylib") +test_fat_libfoo(IOBuffer(read("./mac64/libfoo_fat.dylib"))) +test_fat_libfoo("./mac64/libfoo_fat64.dylib") +test_fat_libfoo(IOBuffer(read("./mac64/libfoo_fat64.dylib"))) test_metal("./macmetal/dummy") # Run COFF tests