benilla-re systems structs docs

source

Method

How a finding in this repo is made trustworthy. Everything here serves one test: someone who has never seen the exe can implement the mechanism from the finding alone and match the client bit for bit.

The binary decides

The authority on what the client does is WoW.exe 1.12.1.5875 itself. A derivation is a path from the bytes to the claim: addresses, opcodes and constants read from the disassembly or the raw image, or the exe's own code executed in the emulator. Everything else is a lead or corroboration, never a derivation: decompiler output, a name (ours, the community's or a string's), a wiki, a server emulator, another client. A capture of the running client is an observation: it can refute a reading or choose between two, but the bytes still supply the mechanism.

For behaviour only the Mac client has, the authority is the Mac client's own code: the i386 slice of the 1.12.1 (5875) World of Warcraft.app, 7,242,424 bytes, SHA-256 b7ec91bccd382293af6014525f2b6e0fda12d5ec13e9c3ab90395da89f6e543a, whose build string is WoW [Release Assertions Enabled] Build 5875 (Sep 19 2006) (mac:4ca6c8). Its addresses are written mac: and six hex digits (symbols/README.md, The Mac client). For everything else WoW.exe decides, and the slice is a lead about it, never a derivation.

Some instructions have no single exact answer: rsqrtss and rcpss approximate, and the x87 transcendentals (fsin, fcos, fsincos, fptan, f2xm1) differ by CPU. For these a finding gives the full-precision value the instruction approximates, and a test compares them with the host's math library structurally rather than bit for bit. Everything else is deterministic, and the standard for it is exact.

Some code picks its implementation at run time: D3DX's math routines jump through slots filled by CPU feature (x87, 3DNow or SSE versions), and the client itself chooses SSE paths by CPUID. A finding over such code names the selector and each version, says which one a current SSE CPU runs, and derives that one; a version it did not read is inferred.

Confidence and proof

Every claim, in a row or an entry, carries a confidence and a proof, and names its tests.

Proof says how strongly a verified claim is held:

A test is recorded on its own line, never as a proof: a row's test column and an entry's Test line name the bit-exact tests that run the exe's own code beside a reimplementation and pass, and the entry says whether a test runs the whole function or a slice of it. A test proves the transcription, not the prose: a direction, a unit, an order or a meaning the code cannot express still rests on reading, so a test raises neither the confidence nor the proof.

Two readings are independent only when neither reader saw the other's work, its conclusions or any note derived from it, and each re-derives every load-bearing step from the bytes. The second reader gets the addresses and the question, never the answer, and ideally enters from the other end: from a caller where the first started at the callee. A reviewer who checks a derivation after reading it corroborates it; that is valuable, but it is not a second reading.

A contradiction is settled at the bytes

When two readings, or a reading and a published finding, disagree, the question is settled by finding the error: the instruction the losing side misread, quoted beside the correct reading. It is never settled by counting readers or by deferring to the older note. If the error cannot be located, a third reading is made. An observation that contradicts a complete reading is recorded as unexplained, not fitted with a fudge factor. The winning entry is rewritten in place; the commit message says what was wrong and where.

Completeness

A system is understood when its closure is (systems/README.md): every function its roots reach has a row with a class, every struct field its functions touch has a row, every branch is accounted for, and every primitive has a bit-exact test. No system meets this yet: tests cover a few primitives, and the rest are open work (#87).

The closure is only as good as its roots, and a walk of direct calls misses code. Look for:

A census starts from true function starts. A function starts at a call target, a stored address, or the first instruction after padding, unless the code above reaches it another way: an address that the instruction before it falls through to, or that a conditional jump or a jump-table entry of the function above lands on, is that function's code and never a start. Executed nops fall through, a case label is a stored address, and an exit block can sit after ret and padding. An unconditional jmp to the first instruction after padding is a tail call to a new function, as in the static-initializer thunks. Read the function above before deciding where the next one starts.

The reliable census for a function is two scans with a control: every e8/e9 whose target is the function, and every little-endian occurrence of its address anywhere in the image. A function with neither is unreached; say so in the doc rather than leaving it to look owned. Code that is part of the function above is reached whenever that function is.

Checklist: reading the bytes

Checklist: proof by absence

A claim that something never happens is a census, and a census earns its zero.

Checklist: writing a finding

Checklist: observations

Checklist: operands, tables and calls

The harness

A bit-exact test runs the exe's own code in the Unicorn emulator beside the reimplementation. The harness is crates/difftest, and each system's crate under crates/ holds a reimplementation and its tests (CONTRIBUTING.md, Adding a test). The x87 setting below holds for every finding, the emulator's limits after it bound what a test can show, and the rules after them are the ones each test follows.

The client runs the x87 at 53-bit precision, rounding to nearest, every exception masked: the control word 0x023F. WinMain (0x404100) starts by calling __clearfp (0x409bf2) and then __control87(0x9001F, 0xFFFFFFFF) (0x409c06, at 0x40410c): 0x409d0e turns the five exception bits into the mask bits 0x3D (0x409d1b to 0x409d38), adds 0x2 for the denormal bit (0x409d42) and 0x200 for 53-bit precision (0x409d4d, 0x409d83), leaves rounding at nearest, and 0x409c33 loads the result with fldcw. 0x5995c0 creates the Direct3D 9 device with the flags 0x22 or 0x52 (0x599614 to 0x59961c), both of which include D3DCREATE_FPU_PRESERVE, so the device never lowers the precision. Every finding and test assumes this control word unless it says otherwise.

The emulator is the QEMU x86 core of unicorn-engine 2.1.5, and its x87 is not the client's at every instruction. f2xm1, fyl2x, fyl2xp1, fsin, fcos, fsincos, fptan, fpatan, fprem and fprem1 convert their operands to the host's double, call its C library and convert back, so a result carries 53 significant bits where the x87 rounds at 64, and the two remainders are computed in double, not exactly. Their edges differ too: fsin, fcos, fsincos and fptan reduce an operand that rounds to ±2^63 as a double, which the x87 reports out of range, and give ±∞ back unchanged with C2 set where the x87 returns the indefinite. fyl2x of 0 or less and fyl2xp1 of −1 or less, or of a NaN, set C2 and pop nothing, and fyl2xp1 outside |x| < 1 − √2/2, where the x87's result is undefined, gives the host's logarithm. fprem and fprem1 return the host's positive NaN for an infinite or NaN operand, a zero divisor, or exponents so far apart that their scale 2^(gap − N) overflows a double, as fmod(5, 5e-320) does, and with exponents 53 or more apart their partial remainder is not the x87's. Beyond these, a signalling NaN loaded from memory or stored to it stays signalling where the x87 quiets it, and a read of an empty register returns what the register last held: there is no stack fault and no indefinite. A test whose compared values pass through one of these shows the code around the instruction, not the client's result there, and keeps its inputs off the other differences. BENILLA_RE_X87_CENSUS names a file to which every test appends a line for each address of the ten that it runs: its name as a row's test column gives it, the address and the mnemonic, and edge on a second line once it runs one on an operand where the answers differ beyond rounding. A test that runs one names it by address in its file's header and says what its comparison rests on; a test with an edge line compares no value that passes through it there.