-
Notifications
You must be signed in to change notification settings - Fork 0
/
printing_functions.go
69 lines (57 loc) · 2.2 KB
/
printing_functions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"fmt" // imports as package "cli"
"os"
"text/tabwriter"
)
func PrintElfHeaderData(elf_header Elf32_Ehdr) {
_, class, endian, version, osabi, abi_version := ParseIdent(elf_header.E_ident[:])
object_type, machine := ParseElfHeader(elf_header)
fmt.Printf(ELF_HEADER_FILE_INFO_PRINTLINE, class, endian, version, osabi, abi_version, object_type, machine)
fmt.Printf(ELF_HEADER_OFFSETS_INFO_PRINTLINE,
elf_header.E_version,
elf_header.E_entry,
elf_header.E_phoff,
elf_header.E_shoff,
elf_header.E_flags,
elf_header.E_ehsize,
elf_header.E_phentsize,
elf_header.E_phnum,
elf_header.E_shentsize,
elf_header.E_shnum,
elf_header.E_shstrndx)
}
func PrintProgramHeaderData(elf_header Elf32_Ehdr, ph_entries []ReadableProgramHeaderTableEntry) {
/*
This is the print function for Program Header extraction.
It prints Program header tables as well as more basic info about the ELF
*/
w := tabwriter.NewWriter(os.Stdout, 0, 0, PADDING, TABLE_SEPERATOR, tabwriter.TabIndent|tabwriter.Debug)
object_type, _ := ParseElfHeader(elf_header)
fmt.Printf(PROGRAM_HEADER_GENERAL_INFO,
object_type,
elf_header.E_entry,
elf_header.E_phnum,
elf_header.E_phoff,
)
fmt.Fprint(w, PROGRAM_HEADER_TABLE_COLUMNS)
// Iterate over entries slice
for _, entry := range ph_entries[1:] {
fmt.Fprintf(w, PROGRAM_HEADER_TABLE_ROW, entry.Type, entry.Offset, entry.VirtAddr, entry.PhysAddr, entry.FileSiz, entry.MemSiz, entry.Align, entry.Flags)
}
w.Flush()
}
func PrintSectionHeaderData(elf_header Elf32_Ehdr, sh_entries []ReadableSectionHeaderTableEntry) {
/*
This is the print function for Section Header extraction.
It prints Section header tables as well as more basic info about the ELF
*/
w := tabwriter.NewWriter(os.Stdout, 0, 0, PADDING, TABLE_SEPERATOR, tabwriter.TabIndent|tabwriter.Debug)
sh_offset := fmt.Sprintf("%x", elf_header.E_shoff)
fmt.Printf(SECTION_HEADER_GENERAL_INFO, elf_header.E_shnum, sh_offset)
fmt.Fprint(w, SECTION_HEADER_TABLE_COLUMNS)
for _, entry := range sh_entries[1:] {
fmt.Fprintf(w, SECTION_HEADER_TABLE_ROW, entry.Name, entry.Type, entry.Address, entry.Offset, entry.Size, entry.Link, entry.Info, entry.AddrAlign, entry.EntSize, entry.Flags)
}
w.Flush()
}