File: nm.py

package info (click to toggle)
lief 0.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 16,036 kB
  • sloc: cpp: 76,013; python: 6,167; ansic: 3,355; pascal: 404; sh: 98; makefile: 32
file content (39 lines) | stat: -rw-r--r-- 848 bytes parent folder | download
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
#!/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])