-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.py
More file actions
41 lines (34 loc) · 1.27 KB
/
Copy pathmain.py
File metadata and controls
41 lines (34 loc) · 1.27 KB
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
import re
from insn import Instruction
from path_group import PathGroup
from state import State
IGNORE = r"{|}|B\d\d:|B\d:"
OP = r"\d+: ([a-zA-Z0-9]+)((\(|\[).*)*"
FIRST_BRACKET = r".*\[(\d+)\]"
FIRST_PAREN = r".*\((\d+)\)"
TWO_PARAMTERS = r"VecPack\([\d]+, (\d+)\)"
def parse_line(line) -> Instruction:
op_match = re.search(OP, line)
op_literal = op_match[1]
arg_match = re.search(FIRST_BRACKET, line) or re.search(FIRST_PAREN, line) or re.search(TWO_PARAMTERS, line)
arg = int(arg_match.group(1)) if arg_match else None
return Instruction(op_literal, arg)
def parse_file(file_name="disasm.txt") -> list[Instruction]:
insns = []
with open(file_name, "r") as f:
insns.extend(parse_line(line) for line in f if not re.search(IGNORE, line))
return insns
def main():
insns = parse_file()
# input_ = [ord(x) for x in "pbctf{enjoy haccing blockchains? work for Zellic:pepega:!}"]
# entry_state = State.create_entry_state(insns, input_)
entry_state = State.create_entry_state(insns)
path_group = PathGroup(entry_state)
path_group.explore(
find=lambda state: state.ip == 539,
avoid=lambda state: state.ip in [],
)
print(path_group)
print(path_group.found[0].concretize())
if __name__ == "__main__":
main()