Files
lief-project-LIEF/api/python/examples/pe_json.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

44 lines
842 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 PE binary in the JSON format
#
# python pe_json.py C:\\windows\\explorer.exe
#  
# {
# "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='PE 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())