benilla-re systems structs docs

source

benilla-re

The reverse engineering of the World of Warcraft 1.12.1 client (WoW.exe, build 5875), read at its bytes and cited by address. It is the reference behind benilla, a from-scratch 1.12.1 client in Rust, and it is written for anyone else who needs to know what the client does: another client, a server, a client mod, a format reader.

Browse it at samwhosung.github.io/benilla-re: a page per function, global and struct, per system, per Lua function, event, CVar and opcode, with search, and ?0x5e6853 to jump to whatever holds an address.

Bring your own client. Nothing here comes from a WoW install. The symbol table, the docs, the tables, the site and the exports are plain files that need no exe; only the tests, the table generators and the listing read WoW/WoW.exe from your own copy of 1.12.1.5875, and they refuse any other build.

The Mac client's key input, which only the Mac client has, is read from the i386 slice of the 1.12.1 World of Warcraft.app and cited as mac:5bf320 (systems/core/mackeys.md); its tests and cargo xtask check --exe read the slice from WoW/WoW-mac-i386, which lipo -thin i386 writes from the application, and skip it when absent (symbols/README.md, The Mac client).

Start here

Slash commands and most of what the interface does (/who, the chat frame, the spellbook) are written in the interface code, FrameXML and GlueXML in the player's own install, which calls the Lua API the exe serves. A question about /who starts in that code and comes here for the engine side: the Lua function in bindings, the opcode it sends, the event it fires.

What is here

The address site

cargo xtask site <out dir> writes a static website from symbols/, systems/, the spec docs and tables/; it needs no exe, empties the folder first (and refuses one that does not hold a previous site), and the same input writes the same bytes. .github/workflows/pages.yml builds it on every push to main and deploys it to GitHub Pages. It is plain HTML with one stylesheet and one script, and it reads on a phone and in a dark theme.

Addresses are written 0x and lowercase hex, and every page URL is built from the address alone:

An address page has the row's name, signature or type, meaning, confidence and proof, the claim of the finding it links to, its callers and callees, and its test. A name page has the table's row, and the doc entries that cite its address. A system page has its docs' overviews, the coverage counts (named, verified, proof two, tested), its closure and its rows. The search box finds names and addresses from index.json, loaded in the browser.

Callers and callees come from tables/calls.tsv, which cargo xtask check --exe rebuilds and compares with the committed file: the direct calls and jumps by a bare address. A function reached through a register, a slot or a stored address shows none for that path. The table also leaves out a function's calls to itself, calls and jumps to code that has no row, and jumps into the middle of another row.

Start from the names

cargo xtask export <out dir> writes the symbol table as files to start a session from, so that a function is CDataStore::PutInt8 and not FUN_00514ae0. It needs no exe, and the same tree writes the same bytes.

Other builds

Every row is keyed to 1.12.1.5875, but a function's bytes are mostly the same in a modified 1.12 client, in 1.12.2 and 1.12.3, and in 1.6 to 1.11. tables/signatures.tsv gives each function row a pattern: the body's bytes, hex and spaced, with ?? for each byte that depends on where the code sits. Wildcards cover the rel32 of a call, jmp or conditional jump that leaves the function (a rel8 that leaves it too, with or without a prefix), and every four-byte operand that holds an address in the image (a global, a string, a vtable, a jump table and its entries, of any length). The 5875 image has no .reloc section, so the decoded instructions in the listing supply them (dumps/disasm.txt, which your clone lacks until tools/disasm.sh writes it from your exe). A pattern is cut to the shortest prefix, at least 16 bytes, that occurs once in the executable sections; a body that is shorter, or whose whole body occurs more than once, keeps all of it. unique says which. A pattern has at least one fixed byte. The table also holds each row's size, its calls, and a body: the masked bytes through the last call site, when the pattern stops before it.

cargo xtask match <exe> <out>

reads any PE, searches its executable sections for every pattern, and writes <out>/match.tsv (address in 5875, name, found: the address in that build, missing, ambiguous or conflict; and via: pattern, call or order), <out>/conflicts.tsv (why each conflict is one) and <out>/symbols/, the tables with each found function at its new address and the others left out. Structs and fields are copied; globals have no pattern, so that table is empty. cargo xtask export <dir> --symbols <out>/symbols writes the header, the scripts' inputs and the database from it. It needs no 5875 exe, only the checkout.

A pattern alone leaves most rows ambiguous, so the matcher builds on what it has found, in steps:

  1. Pattern: the row's pattern occurs once, and the row is unique. A row that is not unique in 5875 is never found by pattern, however few places it matches in the build: its twin may be what is left.
  2. Calls: a found function whose whole body matches where it was found has, at the offsets its 5875 body has them, a call or jmp whose 5875 target is row X. X is at the address that instruction goes to, when X's pattern matches there and has at least 6 fixed bytes. Repeated until nothing new is found.
  3. Order: the found rows whose addresses rise with 5875's bound the rows between them (a found row off that rising run moved, and bounds nothing). A row with at least 6 fixed bytes and exactly one address its pattern matches between its bounds, outside the extent (5875's size) of every found row, is found there, and so are several rows between two bounds that have exactly one way to take rising addresses. Rows in one gap with equal patterns are never placed by order. Alternates with step 2 until nothing new is found.

match.tsv's via says how much a placement is worth:

A row with several candidates left stays ambiguous. Two rows claiming one address, a row claimed at two addresses, a claimed address that its pattern refutes, and two rows in one gap that fall out of order are conflict: reported and left out, with what was found from them, not resolved.

On 5875 itself 14,383 of the 37,967 rows have a unique pattern and the matcher finds all 14,383 at their own address. The other 23,584 are indistinguishable by their bytes (the jmp thunks, the static initializers, the one-line accessors). After each step:

stepfoundof which newambiguousconflictat a wrong address
pattern14,38314,38323,58400
calls17,2542,87120,71300
order21,2433,989 (3,986 by order, 3 by calls)16,72400

Nine synthetic builds of 5875 test it (xtask/src/builds.py, run by the matcher's tests; the fast test makes three, cargo test -p xtask -- --ignored all nine): the same bytes shifted by an odd amount, with odd padding, with 60 neighbour pairs swapped, with 12 functions duplicated, with 200 calls sent into the middle of a function, with 200 thunk calls sent to another thunk, with 300 functions deleted, with 100 callees given a new prologue, and unchanged. Each is checked against where every function is in it:

buildrightwrongconflictambiguous
unchanged21,2430016,724
shifted21,2430016,724
padded21,2430016,724
60 pairs swapped21,2380216,727
12 duplicated21,2420016,725
200 calls into a function21,114012616,727
200 thunk calls swapped21,2430016,724
300 deleted21,12803316,806
100 new prologues21,21402816,725

These builds change what a compiler would not, and no real second build has been run through the matcher yet. A found row is a match of bytes and position, not a proof that the function is the same: a changed body can still match, a call can move with a changed caller, and a row's size is 5875's. Take call and order rows as leads to check, and pattern rows as likely.

How to trust it

METHOD.md says what counts as evidence: the binary decides, every claim states its confidence and proof, and a contradiction is settled at the bytes. cargo xtask check holds the repo to it: the formats, every address a doc cites having a row, every row's finding naming its address, and every row of a written system having a class; with --exe, every function's size against its body in the listing, every table against its generator, and every test a row or an entry names against the exe. Each row says how far it goes: inferred is a lead, verified with proof one is one reading of the bytes, proof two is two independent readings reconciled, and a test runs the client's own code against the reimplementation. The site's front page counts each.

Contributing

Names, findings, corrections and checks are welcome: CONTRIBUTING.md covers the setup and how a change is judged, and AGENTS.md is the short version for a coding agent working here. A gap or a wrong finding is an issue, and needs no exe (CONTRIBUTING.md, "Report a gap or a wrong finding").

License

MIT OR Apache-2.0, at your option, for everything here: the code, the symbol table, the docs and the tables. The tests link the Unicorn emulator (unicorn-engine, GPL-2.0) as a test-only dependency, through crates/difftest. Names from the community database vmangos/idb carry idb in their row's name_from. To cite the repo, see CITATION.cff.