1- export MachOHandle, FatMachOHandle
1+ export MachOHandle
22
3- struct MachOHandle{T <: IO } <: ObjectHandle
3+ abstract type AbstractMachOHandle{T <: IO } <: ObjectHandle end
4+
5+ struct MachOHandle{T <: IO } <: AbstractMachOHandle{T}
46 # Backing IO and start point within the IOStream of this MachO object
57 io:: T
68 start:: Int64
79
810 # The parsed-out header of the MachO object
911 header:: MachOHeader
10-
12+
1113 # The path of the file this was created with, if it exists
1214 path:: String
1315end
1416
15- function readmeta (io:: IO ,:: Type{MachOHandle } )
17+ function readmeta (io:: IO , :: Type{AbstractMachOHandle } )
1618 start = position (io)
17-
19+
1820 # Peek at the magic
1921 magic = read (io,UInt32)
2022 seek (io, start)
@@ -23,32 +25,35 @@ function readmeta(io::IO,::Type{MachOHandle})
2325 header_type = macho_header_type (magic)
2426 endianness = macho_endianness (magic)
2527
26- # If it's fat, just throw MagicMismatch
27- if header_type <: MachOFatHeader
28- throw (MagicMismatch (" FAT header" ))
29- end
28+ header_type, endianness
29+ end
30+
31+ function readmeta (io:: IO ,:: Type{MachOHandle} )
32+ start = position (io)
33+ header_type, endianness = readmeta (io, AbstractMachOHandle)
34+ ! (header_type <: MachOFatHeader ) || throw (MagicMismatch (" Binary is fat" ))
3035
3136 # Unpack the header
3237 header = unpack (io, header_type, endianness)
33- return MachOHandle (io, Int64 (start), header, path (io))
38+ return [ MachOHandle (io, Int64 (start), header, path (io))]
3439end
3540
3641# # IOStream-like operations:
37- startaddr (oh:: MachOHandle ) = oh. start
38- iostream (oh:: MachOHandle ) = oh. io
42+ startaddr (oh:: AbstractMachOHandle ) = oh. start
43+ iostream (oh:: AbstractMachOHandle ) = oh. io
3944
4045
4146# # Format-specific properties:
42- header (oh:: MachOHandle ) = oh. header
43- endianness (oh:: MachOHandle ) = macho_endianness (header (oh). magic)
47+ header (oh:: AbstractMachOHandle ) = oh. header
48+ endianness (oh:: AbstractMachOHandle ) = macho_endianness (header (oh). magic)
4449is64bit (oh:: MachOHandle ) = macho_is64bit (header (oh). magic)
4550isrelocatable (oh:: MachOHandle ) = header (oh). filetype == MH_OBJECT
4651isexecutable (oh:: MachOHandle ) = header (oh). filetype == MH_EXECUTE
4752islibrary (oh:: MachOHandle ) = header (oh). filetype == MH_DYLIB
4853isdynamic (oh:: MachOHandle ) = ! isempty (findall (MachOLoadCmds (oh), [MachOLoadDylibCmd]))
4954mangle_section_names (oh:: MachOHandle , name) = string (" __" , name)
5055mangle_symbol_name (oh:: MachOHandle , name:: AbstractString ) = string (" _" , name)
51- format_string (:: Type{H} ) where {H <: MachOHandle } = " MachO"
56+ format_string (:: Type{H} ) where {H <: AbstractMachOHandle } = " MachO"
5257
5358# Section information
5459section_header_size (oh:: MachOHandle ) = sizeof (section_header_type (oh))
0 commit comments