Skip to content

Commit

Permalink
Add liveness diffing utility
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexodia committed Oct 28, 2024
1 parent b5fb883 commit 1a50529
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions obfuscator/diff-liveness.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import json
import argparse

def liveness_eq(title: str, a: dict[str, list[str]], b: dict[str, list[str]]) -> bool:
aflags = set(a["flags"])
bflags = set(b["flags"])
if aflags != bflags:
print(f"{title} flags differ")
print(f" A: {sorted(aflags)}")
print(f" B: {sorted(bflags)}")
aregs = set(a["regs"])
bregs = set(b["regs"])
if aregs != bregs:
print(f"{title} regs differ")
print(f" A: {sorted(aregs)}")
print(f" B: {sorted(bregs)}")
return True

def main():
parser = argparse.ArgumentParser(description="Diff liveness")
parser.add_argument("A", type=str, help="Old liveness")
parser.add_argument("B", type=str, help="New liveness")
args = parser.parse_args()

old = json.load(open(args.A))
new = json.load(open(args.B))

for block_addr in old:
if block_addr not in new:
print(f"Block {block_addr} not found in new")
continue
old_block = old[block_addr]
new_block = new[block_addr]
liveness_eq(f"Block {block_addr} liveness in", old_block["Liveness in"], new_block["Liveness in"])
liveness_eq(f"Block {block_addr} liveness out", old_block["Liveness out"], new_block["Liveness out"])
for instr_addr in old_block["Instr Liveness"]:
if instr_addr not in new_block["Instr Liveness"]:
print(f"Instr {instr_addr} not found in new")
continue
old_instr = old_block["Instr Liveness"][instr_addr]
new_instr = new_block["Instr Liveness"][instr_addr]
liveness_eq(f"Block {block_addr} -> {instr_addr}", old_instr, new_instr)

if __name__ == "__main__":
main()

0 comments on commit 1a50529

Please sign in to comment.