Files
lief-project-LIEF/api/python/examples/elf_json.py
T
2023-06-24 07:36:55 +02:00

44 lines
827 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
# -----------
# Print information about a ELF binary in the JSON format
#
# python elf_json.py /bin/ls
#
# {
# "dynamic_entries": [
# {
# "library": "libcap.so.2",
# "tag": "NEEDED",
# "value": 1
# },
# {
# "library": "libc.so.6",
# "tag": "NEEDED",
# "value": 74
# },
# ...
import argparse
import sys
import lief
import json
def main():
parser = argparse.ArgumentParser()
parser.add_argument('binary', help='ELF binary')
args = parser.parse_args()
binary = lief.parse(args.binary)
json_data = json.loads(lief.to_json(binary))
print(json.dumps(json_data, sort_keys = True, indent = 4))
if __name__ == "__main__":
sys.exit(main())