Files
lief-project-LIEF/api/python/examples/nm.py
T
Romain Thomas 9da2466609 Improve the LIEF Python build system by using pyproject.toml
- It also provides typing info (close #650)
- Enhance the test suite
- Remove deprecated PE functions
2023-02-19 20:19:03 +01:00

40 lines
848 B
Python
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Description
# -----------
#
# This tool is a cross format Linux nm like. It prints all symbols
# present in the binary. For `PE` it will print symbols in the *symbol section*
# and for `ELF` it will print *static* symbols **AND** *dynamic* symbols.
#
# Example:
#
# >>> nm("/usr/bin/ls")
# >>> nm("C:\\Windows\\explorer.exe")
import sys
from lief import parse
def nm(filename):
""" Return symbols from *filename* binary """
binary = parse(filename) # Build an abstract binary
symbols = binary.symbols
if len(symbols) > 0:
for symbol in symbols:
print(symbol)
else:
print("No symbols found")
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: " + sys.argv[0] + " <binary>")
sys.exit(-1)
nm(sys.argv[1])