#!/usr/bin/env python3 """Identify the 7 differing 64KB pages and dump per-page summaries.""" import struct import os here = os.path.dirname(os.path.abspath(__file__)) canary = open(os.path.join(here, "canary-v80.bin"), "rb").read() ours = open(os.path.join(here, "ours-v80.bin"), "rb").read() PG = 65536 PC_LO, PC_HI = 0x82000000, 0x82A00000 V80 = 0x80000000 print("=== differing 64KB pages ===\n") for i in range(0, len(canary), PG): if not any(canary[i:i+PG]) and not any(ours[i:i+PG]): continue if canary[i:i+PG] == ours[i:i+PG]: continue page_addr = V80 + i # count differing dwords diffs = 0 pc_diffs_canary = 0 pc_diffs_ours = 0 for j in range(0, PG, 4): cdw = struct.unpack_from(">I", canary, i+j)[0] odw = struct.unpack_from(">I", ours, i+j)[0] if cdw != odw: diffs += 1 if PC_LO <= cdw < PC_HI: pc_diffs_canary += 1 if PC_LO <= odw < PC_HI: pc_diffs_ours += 1 cnz = sum(1 for b in canary[i:i+PG] if b != 0) onz = sum(1 for b in ours[i:i+PG] if b != 0) print(f"page {page_addr:#010x}: {diffs} diff dwords, canary_nz={cnz}, ours_nz={onz}, " f"PCs_in_diffs(canary={pc_diffs_canary}, ours={pc_diffs_ours})") print("\n=== detailed dump: first 64 differing dwords per page ===") for i in range(0, len(canary), PG): if canary[i:i+PG] == ours[i:i+PG]: continue if not any(canary[i:i+PG]) and not any(ours[i:i+PG]): continue page_addr = V80 + i print(f"\n--- page {page_addr:#010x} ---") shown = 0 for j in range(0, PG, 4): cdw = struct.unpack_from(">I", canary, i+j)[0] odw = struct.unpack_from(">I", ours, i+j)[0] if cdw != odw: addr = V80 + i + j shown += 1 print(f" +{j:#06x}={addr:#010x}: canary={cdw:#010x} ours={odw:#010x}") if shown >= 64: # report total remaining remaining = sum(1 for k in range(j+4, PG, 4) if struct.unpack_from(">I", canary, i+k)[0] != struct.unpack_from(">I", ours, i+k)[0]) print(f" ... and {remaining} more on this page") break