Skip to content

Commit f159431

Browse files
committed
Improve printing and remove unnecessary unpack() export
1 parent 24a24a4 commit f159431

File tree

8 files changed

+43
-24
lines changed

8 files changed

+43
-24
lines changed

src/Abstract/ObjectHandle.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
export ObjectHandle,
33
readmeta,
44
seek, seekstart, skip, start, iostream, position, read, readuntil, eof,
5-
unpack,
65
endianness, is64bit, isrelocatable, isexecutable, islibrary,
76
mangle_section_name, mangle_symbol_name, handle, header, format_string,
87
section_header_offset, section_header_size, section_header_type,

src/COFF/COFFHandle.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
export COFFHandle
22

3-
import Base: show
4-
53
"""
64
COFFHandle
75

src/COFF/COFFHeader.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export COFFHeader
22

3+
import Base: show
4+
35
@io struct COFFHeader
46
Machine::UInt16
57
NumberOfSections::UInt16
@@ -31,3 +33,11 @@ isrelocatable(h::COFFHeader) = !isexecutable(h) && !islibrary(h)
3133

3234
num_sections(h::COFFHeader) = h.NumberOfSections
3335
num_symbols(h::COFFHeader) = h.NumberOfSymbols
36+
37+
function show(io::IO, header::COFFHeader)
38+
println(io, "COFF Header")
39+
println(io, " Machine ", header.Machine)
40+
println(io, " Number of Sections ", header.NumberOfSections)
41+
println(io, " Time Date Stamp ", header.TimeDateStamp)
42+
println(io, " Number of Symbols ", header.NumberOfSymbols)
43+
end

src/ELF/ELFHandle.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
# Export Datatypes
22
export ELFHandle
33

4-
# Import FileIO methods
5-
#import FileIO: load, save, File
6-
74
# Import Base methods
8-
import Base: start, show, getindex
5+
import Base: start, getindex
96

107

118
"""

src/ELF/ELFHeader.jl

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,6 @@ end
4141
e_shstrndx::UInt16
4242
end
4343

44-
function show(io::IO, header::ELFHeader)
45-
printentry(io,"Type",filetype(header.e_type))
46-
printentry(io,"Machine",machinetype(header.e_machine))
47-
# Skip e_version (not particularly useful)
48-
printentry(io,"Entrypoint","0x",hex(header.e_entry))
49-
printentry(io,"PH Offset","0x",hex(header.e_phoff))
50-
printentry(io,"SH Offset","0x",hex(header.e_shoff))
51-
# Skip flags
52-
printentry(io,"Header Size","0x",hex(header.e_ehsize))
53-
printentry(io,"PH Entry Size","0x",hex(header.e_phentsize))
54-
printentry(io,"PH Entry Count",dec(header.e_phnum))
55-
printentry(io,"SH Entry Size","0x",hex(header.e_shentsize))
56-
printentry(io,"SH Entry Count",dec(header.e_shnum))
57-
printentry(io,"Strtab Index",dec(header.e_shstrndx))
58-
end
59-
6044
function filetype(e_type)
6145
if haskey(ET_TYPES, e_type)
6246
return ET_TYPES[e_type]
@@ -71,3 +55,21 @@ function machinetype(e_machine)
7155
end
7256
return string("Unknown (0x",hex(e_machine),")")
7357
end
58+
59+
60+
function show(io::IO, header::ELFHeader)
61+
println(io, "ELF Header")
62+
println(io, " Type ", filetype(header.e_type))
63+
println(io, " Machine ", machinetype(header.e_machine))
64+
# Skip e_version (not particularly useful)
65+
println(io, " Entrypoint ", "0x", hex(header.e_entry))
66+
println(io, " PH Offset ", "0x", hex(header.e_phoff))
67+
println(io, " SH Offset ", "0x", hex(header.e_shoff))
68+
# Skip flags
69+
println(io, " Header Size ", "0x", hex(header.e_ehsize))
70+
println(io, " PH Entry Size ", "0x", hex(header.e_phentsize))
71+
println(io, " PH Entry Count ", dec(header.e_phnum))
72+
println(io, " SH Entry Size ", "0x", hex(header.e_shentsize))
73+
println(io, " SH Entry Count ", dec(header.e_shnum))
74+
println(io, " Strtab Index ", dec(header.e_shstrndx))
75+
end

src/MachO/MachOHandle.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export MachOHandle, FatMachOHandle
2-
import Base: show
32

43
struct MachOHandle{T <: IO} <: ObjectHandle
54
# Backing IO and start point within the IOStream of this MachO object

src/MachO/MachOHeader.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export MachHeader, MachHeader32, MachHeader64, MachFatArch, MachFatHeader
22

3+
import Base: show
4+
35
"""
46
MachHeader
57
@@ -77,4 +79,13 @@ function macho_endianness(magic::UInt32)
7779
else
7880
throw(MagicMismatch("Invalid Magic ($(hex(magic)))!"))
7981
end
82+
end
83+
84+
function show(io::IO, header::MachOHeader)
85+
println(io, "MachO Header")
86+
println(io, " CPU Type ", header.cputype)
87+
println(io, " CPU Subtype ", header.cpusubtype)
88+
println(io, " File Type ", header.filetype)
89+
println(io, " Number of load commands ", header.ncmds)
90+
println(io, " Flags ", header.flags)
8091
end

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ function test_libfoo_and_fooifier(fooifier_path, libfoo_path)
114114
# Show printing of a Handle
115115
tshow(oh_lib)
116116

117+
# Test showing of the header
118+
tshow(header(oh_lib))
119+
117120
# Test showing of Sections
118121
sects = Sections(oh_exe)
119122
tshow(sects)

0 commit comments

Comments
 (0)