forked from Messi-Q/RNVulDet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
69 lines (54 loc) · 1.46 KB
/
main.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import argparse
import logging
import json
import sys
import engine
def main() -> None:
logging.disable()
args = parse_args()
bytecode = read_bytecode(args.file)
engine_ = engine.Engine(bytecode)
report = engine_.run()
output(args, engine_, report)
def output(args, engine_: engine.Engine, report: bool) -> None:
attr_names = (
"conditions",
"call_values",
"to_addresses",
"todo_keys",
)
res = {
"is_reported": report,
"steps": engine_.step,
}
for attr_name in attr_names:
attr = getattr(engine_, attr_name)
res[attr_name] = len(attr)
if args.output is not None:
with open(args.output, "w") as f:
json.dump(res, f, indent=4)
else:
json.dump(res, sys.stdout, indent=4)
def parse_args():
parser = argparse.ArgumentParser(description="None")
parser.add_argument(
"file",
help="file containing hex-encoded bytecode string",
metavar="BYTECODE_FILE",
)
parser.add_argument(
"-o",
"--output",
help="output information in json format",
metavar="OUTPUT_FILE",
)
args = parser.parse_args()
return args
def read_bytecode(filename: str) -> bytes:
with open(filename) as f:
hex_code = f.read().strip().replace("0x", "").replace("0X", "")
assert hex_code
bytecode = bytes.fromhex(hex_code)
return bytecode
if __name__ == "__main__":
main()