-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsonify.py
52 lines (48 loc) · 1.35 KB
/
jsonify.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
import argparse
from pathlib import Path
import subprocess
import os
from config import IMZOUNA_DIR
def main():
global imhex_path
parser = argparse.ArgumentParser()
parser.add_argument(
"--binary", help="Name of file to JSONify", type=str, required=True
)
parser.add_argument(
"--json", help="Name of output JSON file", type=str, required=True
)
parser.add_argument(
"--imhex", help="Path to ImHex executable", type=str, default="imhex"
)
args = parser.parse_args()
imhex_path = args.imhex
binary_path = Path(args.binary)
json_path = Path(args.json)
process = subprocess.Popen(
[
imhex_path,
"--pl",
"format",
"-v",
"-I",
IMZOUNA_DIR / "includes",
"-i",
binary_path.absolute(),
"-o",
json_path.absolute(),
"-p",
IMZOUNA_DIR / f"patterns/fuel/{os.path.splitext(binary_path)[1][1:]}.hexpat",
],
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
)
stdout, stderr = process.communicate()
exit_code = process.wait()
if exit_code != 0:
print(binary_path.absolute(), stdout, stderr, exit_code)
if __name__ == "__main__":
try:
main()
except (KeyboardInterrupt, SystemExit):
os._exit(0)