Files
txspector-new/reconstruct.py
T
2024-06-15 11:27:29 +08:00

48 lines
1.4 KiB
Python

import sys
import json
if __name__ == '__main__':
if len(sys.argv) < 2:
print("Usage: python3 reconstruct.py <path_to_log_file>")
sys.exit(1)
log_file = sys.argv[1]
codes = {
}
vars = {
}
with open(log_file, 'r') as f:
lines = f.readlines()
idx = 0
for line in lines:
if line.startswith('INFO:root:OP:'):
line = line.replace("INFO:root:OP:", "").strip()
stacks, op = line.split("->")
stacks = [item.strip() for item in stacks.replace("[", "").replace("]", "").split(",")]
op = op.strip()
ops = op.split(" ")
pc, opcode, args = ops[0], ops[1], ops[2:]
codes[idx] = {
"pc": pc,
"opcode": opcode,
"args": args,
"stacks": stacks
}
idx += 1
elif line.startswith("WARNING:root:"):
line = line.replace("WARNING:root:", "").strip()
name, value = line.split("=")
name = name.strip()
value = value.strip()
vars[name] = value
# Apply vars
for pc, code in codes.items():
for i, arg in enumerate(code["stacks"]):
if arg in vars:
code["stacks"][i] = vars[arg]
import json
# print(vars)
print(json.dumps(codes, indent=4))