# -*- coding: utf-8 -*- """Differential sampler: FP-heavy vs int-heavy compile -> FP-codegen functions. Samples EIP of both compiles (same flags), attributes to c2 functions via call-target boundaries, and reports functions whose sample share is much higher in the FP compile. """ import ctypes as C from ctypes import wintypes as W import collections, importlib.util, struct, sys, bisect import capstone _spec = importlib.util.spec_from_file_location('c2dbg', 'c2dbg.py') d = importlib.util.module_from_spec(_spec); _spec.loader.exec_module(d) k32 = d.k32 CREATE_NO_WINDOW = 0x08000000 TH32CS_SNAPTHREAD = 0x4 C2_LO, C2_HI = 0x10700000, 0x1084a000 ROOT = r'C:\Users\isabe\Documents\Codex\2026-07-13\i-w\work\libcmt-stream' CL = ROOT + r'\xbox\bin\vc7\CL.Exe' FLAGS = ['/nologo', '/c', '/O2', '/Oy-', '/QIfist'] class THREADENTRY32(C.Structure): _fields_ = [("dwSize", W.DWORD), ("cntUsage", W.DWORD), ("th32ThreadID", W.DWORD), ("th32OwnerProcessID", W.DWORD), ("tpBasePri", C.c_long), ("tpDeltaPri", C.c_long), ("dwFlags", W.DWORD)] k32.OpenThread.restype = W.HANDLE k32.OpenThread.argtypes = [W.DWORD, W.BOOL, W.DWORD] k32.CreateToolhelp32Snapshot.restype = W.HANDLE def func_starts(): data = open(CL.replace('CL.Exe', 'C2.Dll'), 'rb').read() text = data[0x1000:0x1000 + 0x14a000] ib = 0x10700000 md = capstone.Cs(capstone.CS_ARCH_X86, capstone.CS_MODE_32) starts = set() # call targets (E8 rel32) for i in range(len(text) - 5): if text[i] == 0xE8: rel = struct.unpack_from(' 1 else 15)