Files
Matt Graham ac10ac0e5f tools: tools.diff compares oracle and recomp checkpoint traces
Reports the first register or memory divergence for a bounded guest case.
The Unicorn oracle is an optional, lazily imported dependency.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 22:47:38 +00:00

29 lines
1.0 KiB
Python

from dataclasses import dataclass
import json
from pathlib import Path
REGS = ("eax", "ebx", "ecx", "edx", "esi", "edi", "ebp", "esp", "eflags")
@dataclass
class Case:
data: dict
@classmethod
def load(cls, path):
return cls(json.loads(Path(path).read_text(encoding="utf-8")))
def save(self, path):
Path(path).write_text(json.dumps(self.data, indent=2, sort_keys=True) + "\n", encoding="utf-8")
def validate(self):
required = ("name", "code", "entry_eip", "stop", "state", "memory")
missing = [key for key in required if key not in self.data]
if missing:
raise ValueError("missing case fields: " + ", ".join(missing))
missing = [key for key in REGS if key not in self.data["state"]]
if missing:
raise ValueError("missing registers: " + ", ".join(missing))
if not isinstance(self.data["code"], str) or len(self.data["code"]) % 2:
raise ValueError("code must be an even-length hex string")
return self