1
- export MachOHandle, FatMachOHandle
1
+ export MachOHandle
2
2
3
- struct MachOHandle{T <: IO } <: ObjectHandle
3
+ abstract type AbstractMachOHandle{T <: IO } <: ObjectHandle end
4
+
5
+ struct MachOHandle{T <: IO } <: AbstractMachOHandle{T}
4
6
# Backing IO and start point within the IOStream of this MachO object
5
7
io:: T
6
8
start:: Int64
7
9
8
10
# The parsed-out header of the MachO object
9
11
header:: MachOHeader
10
-
12
+
11
13
# The path of the file this was created with, if it exists
12
14
path:: String
13
15
end
14
16
15
- function readmeta (io:: IO ,:: Type{MachOHandle } )
17
+ function readmeta (io:: IO , :: Type{AbstractMachOHandle } )
16
18
start = position (io)
17
-
19
+
18
20
# Peek at the magic
19
21
magic = read (io,UInt32)
20
22
seek (io, start)
@@ -23,32 +25,35 @@ function readmeta(io::IO,::Type{MachOHandle})
23
25
header_type = macho_header_type (magic)
24
26
endianness = macho_endianness (magic)
25
27
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" ))
30
35
31
36
# Unpack the header
32
37
header = unpack (io, header_type, endianness)
33
- return MachOHandle (io, Int64 (start), header, path (io))
38
+ return [ MachOHandle (io, Int64 (start), header, path (io))]
34
39
end
35
40
36
41
# # 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
39
44
40
45
41
46
# # 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)
44
49
is64bit (oh:: MachOHandle ) = macho_is64bit (header (oh). magic)
45
50
isrelocatable (oh:: MachOHandle ) = header (oh). filetype == MH_OBJECT
46
51
isexecutable (oh:: MachOHandle ) = header (oh). filetype == MH_EXECUTE
47
52
islibrary (oh:: MachOHandle ) = header (oh). filetype == MH_DYLIB
48
53
isdynamic (oh:: MachOHandle ) = ! isempty (findall (MachOLoadCmds (oh), [MachOLoadDylibCmd]))
49
54
mangle_section_names (oh:: MachOHandle , name) = string (" __" , name)
50
55
mangle_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"
52
57
53
58
# Section information
54
59
section_header_size (oh:: MachOHandle ) = sizeof (section_header_type (oh))
0 commit comments