MCPcopy Create free account
hub / github.com/lief-project/LIEF / print_header

Function print_header

api/python/examples/elf_reader.py:51–96  ·  view source on GitHub ↗
(binary)

Source from the content-addressed store, hash-verified

49
50@exceptions_handler(Exception)
51def print_header(binary):
52 header = binary.header
53 identity = header.identity
54
55
56 print("== Header ==\n")
57 format_str = "{:<30} {:<30}"
58 format_hex = "{:<30} 0x{:<13x}"
59 format_dec = "{:<30} {:<30d}"
60 format_ide = "{:<30} {:<02x} {:<02x} {:<02x} {:<02x}"
61
62 eflags_str = ""
63 if header.machine_type == lief.ELF.ARCH.ARM:
64 eflags_str = " - ".join([str(s).split(".")[-1] for s in header.arm_flags_list])
65
66 if header.machine_type in [lief.ELF.ARCH.MIPS, lief.ELF.ARCH.MIPS_RS3_LE, lief.ELF.ARCH.MIPS_X]:
67 eflags_str = " - ".join([str(s).split(".")[-1] for s in header.mips_flags_list])
68
69 if header.machine_type == lief.ELF.ARCH.PPC64:
70 eflags_str = " - ".join([str(s).split(".")[-1] for s in header.ppc64_flags_list])
71
72 if header.machine_type == lief.ELF.ARCH.HEXAGON:
73 eflags_str = " - ".join([str(s).split(".")[-1] for s in header.hexagon_flags_list])
74
75 if header.machine_type == lief.ELF.ARCH.LOONGARCH:
76 eflags_str = " - ".join([str(s).split(".")[-1] for s in header.loongarch_flags_list])
77 print(identity)
78 print(format_ide.format("Magic:", identity[0], identity[1], identity[2], identity[3]))
79 print(format_str.format("Class:", str(header.identity_class).split(".")[-1]))
80 print(format_str.format("Endianness:", str(header.identity_data).split(".")[-1]))
81 print(format_str.format("Version:", str(header.identity_version).split(".")[-1]))
82 print(format_str.format("OS/ABI:", str(header.identity_os_abi).split(".")[-1]))
83 print(format_dec.format("ABI Version:", header.identity_abi_version))
84 print(format_str.format("File Type:", str(header.file_type).split(".")[-1]))
85 print(format_str.format("Machine Type:", str(header.machine_type).split(".")[-1]))
86 print(format_str.format("Object File Version:", str(header.object_file_version).split(".")[-1]))
87 print(format_hex.format("Entry Point:", header.entrypoint))
88 print(format_hex.format("Program Header Offset:", header.program_header_offset))
89 print(format_hex.format("Section Header Offset:", header.section_header_offset))
90 print(format_hex.format("Processor flags:", header.processor_flag) + eflags_str)
91 print(format_dec.format("Header Size:", header.header_size))
92 print(format_dec.format("Program Header Size:", header.program_header_size))
93 print(format_dec.format("Section Header Size:", header.section_header_size))
94 print(format_dec.format("Number of segments:", header.numberof_segments))
95 print(format_dec.format("Number of sections:", header.numberof_sections))
96 print("")
97
98
99@exceptions_handler(Exception)

Callers 1

mainFunction · 0.70

Calls 2

printFunction · 0.50
formatMethod · 0.45

Tested by

no test coverage detected