2025-02-22 18:53:39 +00:00
|
|
|
import pelfy
|
2025-02-27 15:54:20 +00:00
|
|
|
import glob
|
2025-02-22 18:53:39 +00:00
|
|
|
|
2025-02-27 15:54:20 +00:00
|
|
|
def known_name(text: str):
|
|
|
|
return not text.isnumeric() and not text.startswith('0x')
|
2025-02-24 22:28:02 +00:00
|
|
|
|
2025-02-23 22:13:21 +00:00
|
|
|
def test_simple_c():
|
2025-02-27 15:54:20 +00:00
|
|
|
for path in glob.glob('tests/obj/*.o'):
|
|
|
|
print(f'Open {path}...')
|
|
|
|
elf = pelfy.open_elf_file(path)
|
2025-02-23 22:13:21 +00:00
|
|
|
|
2025-02-27 15:54:20 +00:00
|
|
|
print(elf)
|
|
|
|
print(elf.sections)
|
|
|
|
print(elf.symbols)
|
|
|
|
print(elf.code_relocations)
|
|
|
|
print('\n')
|
2025-02-23 22:13:21 +00:00
|
|
|
|
2025-02-27 15:54:20 +00:00
|
|
|
for section in elf.sections:
|
|
|
|
assert known_name(section.description), f"Section type {section.type} for {elf.architecture} in {path} is unknown."
|
|
|
|
|
|
|
|
for sym in elf.symbols:
|
|
|
|
assert known_name(sym.info), f"Symbol info {sym.info} for {elf.architecture} in {path} is unknown."
|
|
|
|
|
|
|
|
for reloc in elf.get_relocations():
|
|
|
|
assert known_name(reloc.type), f"Relocation type {reloc.type} for {elf.architecture} in {path} is unknown."
|
2025-02-24 22:28:02 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
test_simple_c()
|