forked from nevillegrech/gigahorse-toolchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneratefacts
executable file
·66 lines (52 loc) · 1.97 KB
/
generatefacts
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
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
# Standard lib imports
import argparse
import logging
import sys
from os.path import abspath, dirname, join
# Local project imports
import src.exporter as exporter
import src.blockparse as blockparse
def main(args):
# Parse bytecode
logging.info("Reading from '%s'.", args.infile.name)
if args.generate_interface:
logging.info("Generating decompiler input interface")
exporter.generate_interface()
return
if args.disassembly:
blocks = blockparse.EVMDasmParser(args.infile).parse()
else:
bytecode = args.infile.read().strip()
blocks = blockparse.EVMBytecodeParser(bytecode).parse()
logging.info("Initial parsing completed.")
logging.info("Writing facts to disk.")
exporter.InstructionTsvExporter(blocks).export(output_dir=args.outdir, bytecode_hex=bytecode)
if __name__ == '__main__':
# Configure argparse
parser = argparse.ArgumentParser(
description="Fact generation for EVM bytecode disassembly.")
parser.add_argument("-a",
"--disassembly",
action="store_true",
default=False,
help="decompile dissassembled input.")
parser.add_argument("--generate_interface",
action="store_true",
default=False,
help="generate .dl decompiler input interface.")
parser.add_argument("infile",
nargs="?",
type=argparse.FileType("r"),
default=sys.stdin,
help="file from which decompiler input should be read "
"(stdin by default).")
parser.add_argument("outdir",
nargs="?",
const="",
metavar="DIR",
default="",
help="produce facts for original bytecode input.")
# Parse the arguments.
args = parser.parse_args()
main(args)