Skip to content

Latest commit

 

History

History
313 lines (231 loc) · 49.3 KB

FORMAT.md

File metadata and controls

313 lines (231 loc) · 49.3 KB

CDAL file formats

Source database (db/)

Human-edited JSON. It is the source of truth, and reviewed through pull requests.

  • db/symbols/<area>.json: {"symbols": [ {id, name, kind, found_by?, description, seen_in, retired?, prototype?, game_code?, rechecked_builds?, contract?, signatures: [{pattern, ops, index?, source}]} ]} (rechecked_builds and contract: see "Symbol fields for checks" below). game_code is {signature, how, checked_builds, agreed_runs, tools?}: the index of CDAL's signature that re-finds the ID from the game's own code, what in the code proves it, the builds it was checked on, how many independent runs agreed and the research tools they used. It is required on every ID from GAME_CODE_REQUIRED_FROM on, and from TOOLS_REQUIRED_FROM (5712) on its tools must be a non-empty list of the tools used, and cdal gen copies it into docs/reference/ids.json; see Proving an ID from game code. found_by is "cdal" when CDAL found the address from the game's own code alone; leave it out otherwise. validate rejects any other value, and "cdal" on an ID whose signature sources or description name a mod, in a credit form or in any words, or that succeeds a mod-credited ID ("Successor of Name (id)"). cdal gen writes each ID's credit into docs/reference/ids.json (found_by cdal or mod, and for mod the mods it was checked with under patterns, hooks and mod_scan, or unnamed; opted-out authors, successors and unattributed records have no credit and are listed under Unlisted in credits.md) and lists every mod and project alongside CDAL's independent game_code proof totals in docs/reference/credits.md; see Recording who found an ID for the forms the names are read from. validate also rejects a source that names a GitHub project with a licence but no commit (owner/repo (MIT)): write owner/repo@commit. The tests (python/tests/test_found_by.py) refuse a function ID whose address on a build is also another active function or code ID's, unless each description names the other as Same function as <name> (<id>) (PF-044). Function prototype metadata is described below. A vtable symbol can also have an RTTI signature, {"pattern": "rtti .?AVName@ns@@", "source"}, with no ops and no index; another symbol's RTTI signature has ops that start with ptr, for a function in one of the class's vtable slots (see "RTTI signatures" below). Any symbol can have a string signature, {"pattern": "str <text>", "ops", "index"?} or wstr for UTF-16, which starts from the code that loads that string (see "String signatures" below).
  • db/builds/<build>.json: {"build", "pe_timestamp", "size_of_image", "game_version"?, "game_version_from"?, "exe_sha256"?, "exe_size"?, "steam_build_id"?, "resolved_at"?, "source"?, "checked_ids"?, "bsx_held"?, "bsx_checked"?, "unavailable"?, "quarantined"?, "values": {"<id>": {"value": "0x...", "status": "resolved|verified"}}}. Values are RVAs for address kinds and plain numbers for offset.
  • db/ids.lock.json: every id ever assigned, with its name and kind at assignment.
  • db/candidates/*.json: unverified harvested material. Not compiled.
  • db/compat-site-reviews.json: reviewed hook records from the Nexus lab, {"reviews": [{"nexus_id", "mod"?, "site", "builds": ["<build>", ...], "ids": ["Class::member", ...] | "not_a_game_place": "<one sentence why>"}]}. site is compat.site_key(<nexus id>, <address>), 16 hex digits of a SHA-256, so the file holds no address read from a mod (python -c "from cdal_tools.compat import site_key; print(site_key(1234, 0x1A2B3C))" from the python folder). When a mod's hook at that address on one of those builds really means the named CDAL IDs, ids makes it count as having them. When it is no place in the game (a fixed offset from another build, a code cave in padding), not_a_game_place leaves it out of the mod's addresses count. The Nexus export applies it, and validate refuses an entry without exactly one of the two, with a site that isn't 16 hex digits, with an ID that isn't active, or with an empty reason (PF-046).
  • db/compat-code-reviews.json: what reading the code of a mod with no game address found showed, {"reviews": [{"nexus_id", "mod", "file_uploaded", "uses_game_code": true | false, "how", "checked": "YYYY-MM-DD", "evidence"}]}, one entry per mod. file_uploaded is the mod record's newest_code_upload when its code was read (a UTC time such as YYYY-MM-DDTHH:MM:SSZ); the entry applies only while that is still the newest code file. how is one of fixed (fixed game addresses for one game version; the export then matches them to CDAL IDs, pinned in the mod's record, docs/maintainers/NEXUS.md), patterns (byte patterns in a form the scan can't read), class_tables (finds code through the game's class tables), byte_patch (patches code at places it finds while running), runtime (builds its patterns while running) or other_code when uses_game_code is true, and system_only (hooks only Windows, DirectX or input), memory_data (reads or changes game values in memory; shown as Uses game data, with Works on unknown, as those values can move in a game update), loader_only (only loads other files or mods) or other_none when it is false. evidence is one sentence for maintainers on what in the code shows it, never an address or byte pattern read from the mod. An entry may also hold places, what two independent readings of the mod's code agreed on about the game places it uses: {"builds": {"<build>": {"found": 4, "missing": 0}}, "only": true | false}, only when uses_game_code is true. builds lists, for each game build the code was followed on, how many of the places it uses are there and how many it looks for and doesn't find; only is true when the mod's own code compares the game's version, hash, size or timestamp and does nothing on a build that isn't listed. Counts only: the addresses stay in the private library, in reviews/places/<nexus id>.json (docs/maintainers/NEXUS.md). The mod watch writes entries itself when its AI review is on and two agents agree (docs/maintainers/NEXUS.md). The status page and the per-mod pages show it instead of Not checked yet (STATUS_SITE.md), and validate checks every field (PF-053).
  • db/mods/<key>.json: one enrolled mod (ENROLL.md): {"name", "author", "nexus"?, "discord"?, "site_pack"?, "features": [{"name", "core"?, "ids": ["Class::member", ...]}]}. Not compiled. cdal gen turns them into docs/reference/mods.md and docs/reference/mods.json, which has each mod's builds: {"<build>": {"status": "ok|partly|broken", "off": [{"feature", "missing": [names]}]}}.

A build is identified by the executable's PE header TimeDateStamp and SizeOfImage. The build name is for people and is at most 23 bytes. Builds are named after the executable's file version, for example 1.0.0.3576; the optional game_version says which game versions ship it, for example "2.03.01 and 2.03.02" for 1.0.0.2976. game_version_from says where it came from: "game files" (<game>\meta\0.paver, recorded by cdal resolve --exe) or "patch notes date" (matched by date with the game's patch notes on Steam). exe_sha256 and exe_size are the exe's SHA-256 and size in bytes, recorded by cdal resolve from the exe on disk; only these numbers are kept, never the exe. The status page's Game builds tab shows them (STATUS_SITE.md).

Build files may append "checked_ids": [34, 35, ...]: sorted, unique active ID numbers with stored values. This is the per-build offline contract approval used by typed BSX after/combat adapters, separate from the historical prototype.checked_builds documentation. An absent or empty list approves none. resolve and report import clear it; audit --write-bsx-checks writes it after comparing fingerprint-matched images. It carries forward only previously checked prototype IDs with no findings, changed bodies or security changes. A missing previous image approves none. See patch-day gates.

Build files may also append "bsx_held": [248, 775, ...]: sorted, unique active ID numbers that BSX requires and that have no stored value on this build, held off on purpose by the maintainer so the build's data can ship while BSX is still off on it. That build's .cdal file carries these IDs without signatures, so cdal.dll reports them missing at once instead of scanning for them on that build; cdal-signatures.cdal keeps their signatures for builds nobody has resolved yet (see "Withheld IDs" below). The latest build may be missing only these BSX-required IDs or IDs quarantined by patch day (test_build_gates.py). resolve leaves held IDs without a value even when their signatures match, unless --release-held <IDs|all> names them. It then stores them and drops them from the list. Report import also drops an ID from the list once it has a value. The key goes once the list is empty. See BSX on a new build.

Build files may also have "bsx_checked": "<text>", after "source": a non-empty sentence saying which game session or comparison checked BSX on this build. validate refuses an empty or non-string value. It is compiled as flags bit 3 of that build's .cdal file, and BSX turns its game events on only on a build with that bit (or with [BSX] UncheckedBuild=1). See BSX on a new build.

Build files may also append "unavailable": {"2404": "changed-meaning", ...}: why an ID has no value on this build, keyed by ID number in numeric order. The reasons are changed-meaning (the game still has the code but it now does something else, so mods need a new ID) and removed (the game removed it). Each key must be an active ID with no stored value on this build and not in bsx_held. An ID in bsx_held counts as held, one in quarantined as quarantined, and any other ID without a value counts as not found, so none of them needs an entry. That build's .cdal file carries these IDs without signatures (see "Withheld IDs" below). The generated catalogs show it: ids.md writes none: changed meaning, ids.json adds why_none per ID, and mods.json splits each build's lost count into lost_why (held, quarantined, changed_meaning, removed, not_found). resolve and report import drop an ID from the map once it has a value again. When resolve, report import or patch-analyze writes a build, they also copy in the entries of the build before it (the highest older PE timestamp): its unavailable map, and its quarantined entries labelled changed meaning or removed, for IDs with no value, no bsx_held entry and no quarantined or unavailable entry of their own on the new build. See When an ID changed meaning.

Build files may also append "quarantined": {"5168": "vtable grew; slot not corroborated", ...}: IDs a patch day is still checking on this build, keyed by ID number in numeric order, each with a non-empty reason in words. Each key must be an active ID with no stored value on this build, and not in bsx_held or unavailable. It differs from both: unavailable says the game changed or removed the thing for good, bsx_held keeps BSX off, and quarantined only says the value isn't trusted yet. A reason that starts with held is a maintainer's hold, which the next build written by resolve, report import or patch-analyze keeps word for word while the ID has no value there (MAINTAINING.md). The catalogs and pages show it as quarantined (under review), except that a reason starting with changed meaning or removed counts as that, and one saying it is held (held ..., BSX hardcodes ..., ; held for ...) counts as held (sourcedb.quarantine_reason). The next resolve that stores a value for the ID takes it off the map, and the key goes once the map is empty.

Withheld IDs

A build's own .cdal file (cdal-<build>.cdal) carries the IDs that build lists in unavailable, bsx_held or quarantined with no value and no signatures. On that exact build, cdal.dll then answers them at once with "no value for this game build and no signature", even when scanning is allowed: a scan there could only find the wrong place, or the place a patch day is still checking. cdal-signatures.cdal keeps every ID's signatures, so a build nobody has resolved yet still scans for all of them. No ABI changes: an entry without signatures was always valid.

Symbol fields for checks

A symbol may also have two fields the audit reads instead of, or as well as, its description:

  • "rechecked_builds": ["<build1>", "<build2>"]: the builds on which someone re-read the ID and found it right, unique and sorted by build number. The audit's sign-off: an ID that lists the new build counts as re-checked there, as a description or signature source that names the build does.
  • "contract": {"offsets": ["0x28", "0x30"], "arg_regs": ["rcx", "rdx"], "ret_reg": "al"}, every part optional: offsets are struct offsets the ID's users read (hex strings, in numeric order), which the audit's layout check compares with the code as it does offsets written in the description; arg_regs (from rcx, rdx, r8, r9, xmm0 to xmm3) and ret_reg (rax, eax, ax, al, xmm0 or none) are for function IDs only. When a function with arg_regs changed on a new build, the audit flags an argument register its entry block writes before it reads it (PF-037).

Function prototypes

An active function symbol may have a prototype object. Omit it (or use null) when the complete calling shape is unknown. Never turn an unknown result into void or leave out an unclassified argument. For example, the five arguments of ClientEquipment::Equip are represented as:

"prototype": {
  "calling_convention": "win64",
  "return_type": "ptr",
  "arguments": [
    {"name": "equipment_component", "type": "ptr"},
    {"name": "result", "type": "out-pointer"},
    {"name": "bucket", "type": "u16"},
    {"name": "inventory_index", "type": "u16"},
    {"name": "slot_tag", "type": "u16"}
  ],
  "stack_argument_count": 1,
  "return_register": "RAX",
  "checked_builds": ["<build1>", "<build2>"]
}

All six fields are required; other fields are rejected. This is a scalar, fixed-argument Win64 description, not a C++ type declaration. It does not represent variadic functions, vectorcall, vectors passed by value or nonstandard register assignments. Leave those functions without a prototype until a format that describes them is defined.

Field Meaning and validation
calling_convention Exactly win64. Argument positions 1-4 use RCX/RDX/R8/R9 for integers and pointers, or XMM0/XMM1/XMM2/XMM3 for f32/f64, according to the position, not a separate floating-point counter.
return_type void, ptr, u8, u16, u32, u64, i8, i16, i32, i64, f32, f64 or bool. void means no usable return value was established by the checked body and callers, not an unknown return.
arguments Ordered objects containing exactly name and type. Names are unique identifiers. Include this, explicit output buffers and any hidden result pointer in their actual positions. Types are the scalar types above except void, plus out-pointer.
stack_argument_count Integer equal to max(0, len(arguments) - 4). Does not count the return address or the four shadow-space slots. Argument 5 is at entry RSP+0x28, argument 6 at +0x30, then 8 bytes per argument.
return_register none for void; AL for bool/u8/i8; EAX for 16/32-bit integers; RAX for ptr/64-bit integers; XMM0 for f32/f64. Only the type's low bits are meaningful (for example, low 16 of EAX for u16); upper bits need not be extended.
checked_builds Nonempty, nonrepeating list of known builds with a stored value for this ID, on which the calling shape was checked by disassembly. This is independent of the address's resolved/verified status. A new build is not covered automatically.

ptr is an address to an object, buffer or opaque context; it does not promise constness. out-pointer is an address to writable output or in/out storage, passed in the same register/stack slot as ptr. It does not specify allocation, size, alignment, nullability, ownership or lifetime. Keep these requirements, argument meanings, thread/lock requirements and checked versus inferred semantics in the symbol's description and research contract. bool promises a logical result/argument; use u8 for a byte whose values or meaning are not established. Signed integer types require evidence of signed use; an opaque 64-bit value can be described as u64 without claiming a semantic type.

cdal gen copies the object into docs/reference/ids.json, renders it in docs/reference/ids.md and adds a comment beside the ID in include/cdal/ids.hpp. It adds no function typedef, changes no constant or C ABI, and does not store prototypes in the binary .cdal format. Consumers must reject absent prototypes and builds outside checked_builds; this metadata alone does not enable native calls or Lua hooks, or establish that a function is safe to call from a script.

Runtime database (CDAL/*.cdal)

compile writes one file per known build (cdal-<build>.cdal, values included) plus cdal-signatures.cdal, which has signatures and no values. compile --latest N writes only the N newest builds' files (by PE timestamp), and compile --shipped the ones the player packages carry: the newest build and the two before it. At startup the runtime reads the 64-byte header of every *.cdal in the folder and loads the one whose fingerprint matches the running executable and that has the has_values flag. If none matches, it loads the newest file (highest timestamp) and scans signatures.

All integers are little-endian. Offsets are from the start of the file.

Header (64 bytes)
  0  char[4]  magic "CDAL"
  4  u16      format = 1
  6  u16      flags: bit 0 has_values, bit 1 runtime-generated, bit 2 checked_ids, bit 3 bsx_checked (the build file has `bsx_checked`; read with `cdal_build_flags`, C API 7; BSX turns game events on only with it)
  8  u32      pe_timestamp
 12  u32      size_of_image
 16  u32      entry_count
 20  u32      entries_offset
 24  u32      signature_count
 28  u32      signatures_offset
 32  u32      strings_offset
 36  u32      strings_size
 40  char[24] build name, NUL-padded

Entry (24 bytes), sorted by id, ids strictly increasing
  0  u32  id
  4  u8   kind: 1 function, 2 data, 3 vtable, 4 offset, 5 code
  5  u8   status: 0 missing, 1 resolved, 2 verified, 3 scanned
  6  u16  signature count
  8  u32  name (string offset)
 12  u32  first signature index
 16  u64  value (RVA or plain value; meaningful when status != missing)

Signature (16 bytes); an entry's signatures are contiguous
  0  u32  pattern (string offset), e.g. "48 8B 05 ?? ?? ?? ??", or "rtti .?AVName@ns@@"
  4  u32  recipe (string offset), ops joined by "; ", e.g. "add 0x4; rip 3 7"
  8  i32  match index, -1 = the pattern must match exactly once
 12  u32  reserved, 0

Strings: NUL-terminated UTF-8

Optional trailer at strings_offset + strings_size, when flags bit 2 is set
  0  char[4] magic "CHKD"
  4  u32     trailer_version = 1
  8  u32     checked_count
 12  u32[]   checked IDs, sorted and strictly increasing

The checked-ID extension is append-only: format stays 1 and all previous header, entry and signature fields retain their meaning. Old readers ignore the trailer; old files provide no checked contracts to new readers. New readers require has_values, an exact trailer length, version 1, no duplicates and an existing resolved/verified entry for every checked ID. Scanned entries cannot grant approval. cdal_build_supports(id, require_checked) additionally requires an exact executable/database match and never scans. Zero-valued offsets remain available. BSX using this API needs the updated runtime (C API 5); no existing C function or BSX structure changes.

The terminal recipe read xor32 N extracts a value from precisely B9 imm32 33 0D disp32 at cursor + N: mov ecx, imm32; xor ecx, dword [rip+disp32]. It validates both opcodes and both operand ranges and returns the unsigned XOR. It cannot be followed by another operation. This decodes XOR-obfuscated immediates without storing a guessed constant. Other instruction shapes fail closed. Python and C++ implement the same operation; older scanners reject this new recipe rather than misinterpret it.

The terminal recipe read sub32 N is its counterpart for subtract-obfuscated immediate loads: precisely 8B 0D disp32 81 E9 imm32 at cursor + N, that is mov ecx, dword [rip+disp32]; sub ecx, imm32. The RIP target is relative to the end of the mov (cursor + N + 6). It validates both opcodes and the operand range and returns (dword - imm32) mod 2^32. It cannot be followed by another operation, and other instruction shapes fail closed. A cdal.dll built before this op rejects the recipe, so that signature gives nothing there and the ID's other signatures still work.

The C++ runtime reader rejects files with a wrong magic or format, out-of-range offsets, unterminated strings, or non-increasing IDs. The Python inspection reader checks the magic and format and that each entry's signatures lie inside the signature table, but does not fully validate the other tables or ID ordering. A new format version gets a new format number. At database selection, runtimes skip files whose headers they cannot read.

Scanning rules (identical in C++ and Python)

  • Patterns are scanned in the sections marked executable (IMAGE_SCN_MEM_EXECUTE, 0x20000000) only. When no section has that flag, the sections marked as holding code (IMAGE_SCN_CNT_CODE, 0x20) are scanned, and when none has either, every section. A section that only says it holds code is not scanned while an executable one exists: the game protector can mark non-executable read-only sections that way, and the CPU never runs code there.

  • Overlapping matches count. With index unset, more than one match is a failure, not "take the first".

  • The result must lie inside the image.

  • The result must fit its kind: a function or code result in an executable section, a data or vtable result outside every function the exception directory (.pdata) lists. cdal.dll and cdal.hpp refuse a scanned value that doesn't, with "lands outside the code sections (...)" or "a data ID that lands in code, inside the function at 0x...", and try the ID's next signature. Stored values are not checked at run time; patch day's audit checks them before they ship.

  • Hooked starts. With index unset and no match at all, the scan looks once more, allowing for another mod's inline hook over the first bytes of the pattern. A match then needs:

    • one of these jumps at the pattern's start: E9 rel32, FF 25 00 00 00 00 plus an 8-byte target, FF 25 disp32, 48 B8 imm64 FF E0, or MinHook's hot patch (EB F9 with E9 rel32 in the 5 bytes before);
    • in the 14 bytes after the jump, only the pattern's own bytes, 90 (NOP) or CC (INT3), since the hook took whole instructions and padded or kept the rest;
    • every fixed byte after that window, and at least 10 of them, so short patterns never match this way;
    • exactly one such place in the image.

    The recipe may not read (rip, read) bytes the hook could have overwritten, may not use find_in_func (it reads the whole function, the hooked bytes too) and may not read anything after a func_start (the cursor may be the hooked start again). Such a match sets hooked on the resolution and in the report, and resolve prints "behind another mod's hook".

RTTI signatures

A signature whose pattern is rtti followed by an MSVC decorated type name, such as rtti .?AVClientUserActor@pa@@, finds that class's primary vtable through the game's run-time type information instead of code bytes. A class keeps its name across patches, so this survives changes to the constructors and destructors that store the vtable. It is allowed on vtable symbols with no ops and no index, and on other symbols with ops that start with ptr N (no index): the ops then run from the vtable, so rtti .?AVName@ns@@ with ptr 0x10 is the function in slot 2. The name is .?AV (class) or .?AU (struct), then the name and its namespaces, then @@.

The data sections are searched: the readable sections that patterns are not scanned in (see Scanning rules), or every section when patterns are scanned in all of them. Each step must find what it looks for:

  1. Type descriptor. The name followed by a NUL, at an 8-aligned position. The descriptor starts 16 bytes before the name.
  2. Complete object locator. A 4-aligned 24-byte record with signature 1, offset 0, the descriptor's RVA at +12 and its own RVA at +20. Locators with another offset belong to secondary vtables and are ignored.
  3. Vtable. An 8-aligned pointer to the locator. The vtable starts right after it. The pointer is the locator's RVA plus the address the module was loaded at, so either the module's address in memory or the header's ImageBase is accepted. That covers the running game, a cdal-dump (the dumper writes the load address into ImageBase) and an executable read from disk.

Exactly one vtable must be found. The errors are "RTTI type name not found", "RTTI complete object locator not found", "RTTI vtable not found" and "RTTI vtable is not unique". One RTTI signature reads the data sections three times, which takes a few tenths of a second on the game; Library::prefetch() and cdal-resolve do the three passes once for all of a database's RTTI signatures. Runtimes older than this rule can't parse the pattern and move on to the symbol's next signature, so keep a code signature after the RTTI one where a unique one exists.

String signatures

A signature whose pattern is str followed by a string, such as str ItemInfo의 _itemType를 읽어들이는데 실패했다., finds the place in the game's code that loads that string, instead of matching code bytes. wstr does the same for a UTF-16LE string. Messages like this belong to one piece of code and keep their text across patches, so the signature finds the same place after the code around it is rewritten, and it can't land on a neighbouring copy of the same instructions. Use it for any ID whose code loads a string of its own: the field a reader reads just before its failure message, the call that logs a message, a function that names itself.

  1. The string. Everything after str (or wstr ), exactly, encoded as UTF-8 (or UTF-16LE) and followed by a NUL (two for wstr, at an even address), inside one section. It must be the whole string: the byte (or two) before it is a NUL, or it starts its section, so the tail of a longer string doesn't count. It must be in the image exactly once. At most 1024 bytes; no spaces at either end, and no NUL inside.
  2. The lea. Every lea r64, [rip+disp32] in the sections patterns are scanned in that loads the string's address (REX.W 48 or 4C, 8D, a ModRM with mod 00 and r/m 101). Without index exactly one must load it; with index N the N-th in address order (from 0) is used.
  3. The ops run from the start of that lea, as they do from a pattern's match. For example add -0x19; expect 48 8D 56; read u8 3 reads the 8-bit field offset of the lea rdx, [rsi+imm8] 0x19 bytes before the string's lea. Keep an expect on the instruction the ops read, so a change in the code between them fails instead of reading the wrong bytes, and wildcard (??) or omit the displacement bytes extracted by read so shifted fields still resolve (PF-092).

The errors are "string not found", "string is not unique", "no lea loads the string", "the string is loaded by more than one lea" and "the string is loaded by fewer than index+1 leas", then those of the ops. String signatures work in db/symbols, not in site packs. Runtimes older than this rule can't parse the pattern and move on to the symbol's next signature, as they do for RTTI signatures.

Function ops (func_start, find_in_func)

Two recipe ops find a place through the function around the cursor, as the exception directory (.pdata) lists it, instead of a byte distance inside that function. A distance breaks whenever the compiler changes the code before the place; the function's start and a unique instruction in it usually stay.

  • func_start (no operand) moves the cursor to the start of the function that holds it. It takes the .pdata entry (RUNTIME_FUNCTION) whose range holds the cursor and, while that entry's unwind information has UNW_FLAG_CHAININFO (the range is a part the compiler split off, such as cold code), follows the RUNTIME_FUNCTION stored after its unwind codes, at most 8 times. The cursor becomes the start of the last one, the primary function. A str signature with func_start is a function ID found through its one string use: {"pattern": "str ItemInfo의 _itemType를 읽어들이는데 실패했다.", "ops": ["func_start"]}.
  • find_in_func P moves the cursor to the one match of byte pattern P (1 to 255 tokens, ?? for any byte, at least one fixed byte, as expect) inside the function that holds the cursor: the primary function's own .pdata range, then every range chained to it, in .pdata order. A match must lie inside one range. Together they may span at most 512 KB. An rtti slot signature with find_in_func reaches an instruction inside the slot's function wherever it moved: ["ptr 0x188", "find_in_func 66 89 7B 58 48 8B 5C 24 ?? 48 8B 03"].

Both fail closed. The errors are "no function in the exception directory holds the cursor" (no .pdata, or the cursor between functions), "the function's unwind information is unreadable" (outside the image, or a chain longer than 8 links), and for find_in_func also "the function's start is not in the exception directory", "the function lies outside the image", "the function is larger than 512 KB", "the pattern is not in the function" and "the pattern is not unique in the function", each after func_start: or find_in_func: . cdal.hpp reads the function's bytes with CDAL's own hooks and patches put back (as it does for expect), so a CDAL hook inside the function never hides a match; another mod's hook over the bytes can, and then the op fails instead of finding them elsewhere. C++ and Python implement both the same way.

A cdal.dll before 0.8 rejects a recipe with either op, so that signature gives nothing there and the ID's other signatures still work. validate therefore refuses an ID in db/symbols whose every signature uses one of them; keep a byte signature without them as the fallback. Site packs may use them; such a pack needs CDAL 0.8 (MOD_AUTHORS.md).

Classes (cdal_tools rtti, find_vtable, class_name)

The game is built with MSVC and keeps run-time type information for most classes. Three tools read it:

  • python -m cdal_tools rtti <exe or dump> lists every class that has a vtable. It reads the image once: every decorated type name, every complete object locator that points to one of them, every vtable that points to a locator, and each class's hierarchy descriptor. Locators and vtables are searched for in the non-executable sections, and a vtable's slot count is the number of entries, from slot 0, that point into an executable section.
  • Library::find_vtable(name) and cdal_vtable_by_type resolve one class the way an RTTI signature does (above). A plain name ns::Class is tried as a class (.?AVClass@ns@@) and then as a struct (.?AUClass@ns@@).
  • Library::class_name(object) and cdal_class_name go the other way: the object's first 8 bytes point to a vtable, slot -1 points to its locator, and the locator points to the type descriptor. The vtable, the locator and the name must all lie in the game's image, the locator must have signature 1 and its own RVA at +20, and each read is checked with VirtualQuery first. A secondary vtable's locator names the complete object's class, so a pointer to a base subobject gives the most-derived class too.

The layout, with RVAs relative to the module:

Record Fields
Type descriptor +0 pointer to type_info's vtable, +8 reserved, +16 the decorated name, NUL-terminated
Complete object locator u32 signature (1), u32 offset of this vtable's subobject, u32 constructor displacement offset, u32 type descriptor, u32 class hierarchy descriptor, u32 its own RVA
vtable slot -1 the locator's address, then the virtual functions
Class hierarchy descriptor u32 signature, u32 attributes (1 multiple, 2 virtual inheritance), u32 number of bases, u32 base class array
Base class array u32 per base class descriptor: the class itself first, then its bases depth first
Base class descriptor u32 type descriptor, u32 number of bases it contains, i32 mdisp, i32 pdisp (-1 unless the base is virtual), i32 vdisp, u32 attributes, u32 class hierarchy descriptor

A base is direct when it is not contained in an earlier base of the array. Function-local classes have names that end in @Z@ or XZ@ instead of @@, and template names can be several hundred characters long. demangle_rtti and the dumper's name field read namespaces, templates and template arguments (types, pointers, references and integers), so .?AV?$vector@HV?$allocator@H@std@@@std@@ becomes std::vector<int,std::allocator<int>>. Function-local types and function-pointer arguments keep the decorated form.

--json writes:

{
  "cdal_rtti": 1,
  "pe_timestamp": "0x6AB28F00",
  "size_of_image": "0x173AB000",
  "classes": [
    {
      "name": "pa::ClientUserActor",
      "type": ".?AVClientUserActor@pa@@",
      "kind": "class",
      "type_descriptor": "0x...",
      "vtables": [{"rva": "0x55B59F0", "offset": 0, "slots": 59}],
      "bases": [{"name": "pa::CommonUserActor", "type": ".?AVCommonUserActor@pa@@", "offset": 0, "direct": true, "virtual": false}]
    }
  ]
}

Classes are sorted by name, a class's vtables by offset, and its bases in the order of the base class array.

Site packs

A mod's own list of addresses (PACKS.md). The author writes pack.json: {"pack": 1, "name", "reference": {"build", "pe_timestamp", "size_of_image"}, "sites": [{name, rva, kind, verify?, ref?, base?, vtable?, slot?, offset?, rtti?, todo?, literal?}]}. A site with "literal": true is a constant kept in the list, not an address: it gets no id and no signature. cdal pack keeps a source database of the same shape as db/ in the pack's db/ folder, with ids of its own (ids.lock.json: an id stays with its site name for good), plus fingerprints.json:

{"reference": "<build>", "sites": {"<id>": {"function_offset": N, "size": N, "masked_sha256": "<hex>",
                                            "parts": N, "part": N, "part_offset": N, "check": "slot"}}}

for each site with "verify": "body", and with "check": "slot" for each other site whose signature reads a pointer from a table (ptr, optionally followed by add) to code. parts is how many .pdata ranges of the function are hashed: its own and the ranges chained to it (UNW_FLAG_CHAININFO), in that order, the chained ones by address. For a site in a chained range, part (from 0) and part_offset say which range and where in it; resolve counts the site as changed when that range isn't at the same distance from the function's start any more. An entry without parts (written before CDAL 0.6.0) hashes the first range only. A slot entry whose function is the same is verified; when it isn't, the slots up to 4 either side are compared, and the site is not found if the reference function is in one of them (the table moved its slots), else it is published as resolved and listed in the report for the author to check. The fingerprint is SHA-256 over the instructions of the site's function, from its start to the end of its entry in the exception directory (.pdata), each instruction hashed as its length, its bytes with rel32 branch targets, RIP-relative displacements and 64-bit immediates set to FF, and a mask byte per byte that says which were set. Code that only moved hashes the same; changed code doesn't. A function of several ranges hashes as SHA-256 of the ranges' hex fingerprints joined with |; a function of one range hashes as that range, so its fingerprint is the same as before parts were counted. A site inside such a function is signed as the function's own signature plus add <offset>, so the check covers the place it was found. A signature's pattern leaves open (??) the bytes a rebuild moves without changing the code: rel32 call and jump targets, RIP-relative displacements, 64-bit immediates, the distance of a short jump (70..7F, EB), the size in sub rsp, imm and add rsp, imm, and displacements from RSP or RBP. Displacements from any other register (struct fields) stay fixed, so a code site's signature breaks when the layout moves; a function or data site that has no unique pattern that way is tried once more with them open. The fingerprints above don't change: they mask only rel32 targets, RIP-relative displacements and 64-bit immediates, as before. A function or global whose own bytes aren't unique is signed through an instruction that reaches it with a rel32 (a call, a jump or a RIP-relative operand): that instruction's signature plus rip <offset> <length>. A function that only a vtable or a table of callbacks points to is signed through that table: the vtable's RTTI signature, or the signature of an instruction that uses the table plus rip <offset> <length>, then ptr <the pointer's offset in the table>. A site with "vtable" and "slot" gets the same signature from the vtable site it names. When every instruction that reaches a function or global is repeated elsewhere (inlined code), one of them is found through the function it is in: that function's signature (its own bytes, or a caller's signature plus rip), then add <distance>, expect <the instruction's bytes> and rip <offset> <length>. The expect makes a changed function give no value rather than a wrong one. A function without a .pdata entry (a leaf function or a jump thunk) is fingerprinted up to the int3 padding after it, at most 4 KB.

cdal pack compile writes <name>-signatures.cdal and <name>-<build>.cdal in the runtime format above. In a build's file, a site with a fingerprint and no value (its code changed, or it was not found) has no signatures either, so the runtime can't find it by scanning on that build. Mods load them from CDAL/packs/<name>/ with cdal::Pack or cdal_pack_open, a database of their own next to CDAL's. On a build without its own file, the pack's signatures are scanned in one pass over the module: each pattern is filed under four consecutive fixed bytes and every position costs one table lookup. The matches are the same as scanning each pattern on its own (the rules above), and patterns without four fixed bytes in a row are scanned on their own.

Memory images (.cddump)

cdal-dump.exe and the resolver's optional dump write a PE32+ image in loaded layout: a byte's file offset is its RVA. Both normalize the headers before saving: PointerToRawData equals the section RVA, SizeOfRawData is its virtual size (or original raw size when virtual size is zero), clipped to SizeOfImage, FileAlignment equals SectionAlignment, and ImageBase is the actual load address. There is no separate dump wrapper or new format version.

Both tools read page by page and refuse the entire capture if any page cannot be read completely. The console or resolver log reports the unreadable-page count; no incomplete dump is written. Use the resolver JSON report when a complete image cannot be captured. Older resolver dumps kept disk section offsets despite storing bytes at RVAs; recapture those with the rebuilt resolver before using them for resolution.

The Python PE reader maps sections using these headers, for both disk executables and normalized dumps. It rejects a section whose declared raw bytes extend past the file, rather than substituting zeros that signatures could match. Zero bytes beyond SizeOfRawData up to VirtualSize are legitimate virtual tails and remain valid.

Session record (CDAL/session.json)

cdal.dll writes bin64\CDAL\session.json for each game run, from the first cdal_init (or first hook) in CrimsonDesert.exe. If an early cdal_init fails in the game (for example because no database could be loaded), it logs cdal_init failed once per process to bin64\CDAL\hooks.log. At the start of the next run a copy of the run goes into runs\ (Run history), then the file becomes session-prev.json, and hooks.log becomes hooks.old.log if it is over 1 MB. The same start adds a session start: line to hooks.log. The file is replaced through session.json.tmp, at most once a second while something changes, at once when a note is written, and when the game exits normally; if writing fails (such as a temporary file lock), cdal.dll logs once and retries on the next 1 s tick.

{
  "cdal_session": 1,
  "cdal": "0.8.1", "c_api": 8, "hooks_api": 2,
  "build": "1.0.0.1000", "build_matched": true,
  "pid": 4242, "started": "2026-01-01 14:03:09", "updated": "2026-01-01 14:05:12",
  "state": "running",
  "hooks": 12, "refused": 1, "longest_window_stall_s": 7,
  "modules": [{"file": "CrimsonFastLoad.asi", "owners": ["Crimson FastLoad"], "hooks": 3, "refused": 0}],
  "foreign_hooks": ["SomeOtherMod.asi"],
  "notes": ["crash-20260101-140512-4242.txt"],
  "features": [{"module": "CrimsonFastLoad.asi", "owner": "Crimson FastLoad", "feature": "Fast travel loading",
                "state": "off", "reason": "missing on 1.0.0.1000: Travel::QueueCall2: pattern not found"}],
  "duplicates": []
}
  • state: running while the game runs (and after it was killed from outside, since nothing runs then), exited after the game closed itself: through Windows' normal shutdown (ExitProcess), or through TerminateProcess or NtTerminateProcess on itself, which skips that shutdown (the game's own Exit does; an exit code from 0xC0000000 up, a crash handler's, leaves running), with an exit note when a mod was the nearest caller. crashed after a crash note, hung while the game's window doesn't answer after a hang note (back to running when it answers again). Neither crashed nor hung is changed when the game then ends itself.
  • A second copy of the game started while this one runs (state still running or hung, its pid alive, the same exe, created no later than started) leaves this file, the notes and runs\ alone: it keeps no session record and only logs session start skipped: ... in hooks.log.
  • longest_window_stall_s: the longest time this run that the game's window didn't answer Windows, in seconds. Windows reports a stall from 5 s, so 0 means none of 5 s or more.
  • hooks: hooks and patches placed through CDAL now; refused: hooks and patches CDAL refused this run.
  • modules: each module that hooked, patched or was refused, by file name (the module its code is in, or the one that asked), with the owner names it passed (at most 4), its hooks and patches placed now, and its refusals this run.
  • foreign_hooks: modules that had hooked a function before CDAL hooked it (hooks.log has where).
  • notes: the crash, hang and exit notes this run wrote, by file name.
  • features (C API 6): each feature a mod reported through cdal::Feature or cdal_report_feature, on or off with the reason, and each failed require() outside a reported feature ("feature": ""), once per module and ID set; such a row goes back on when the same module's require() of the same IDs succeeds later. A row's owner is the one reported, or else the first owner its module passed when it hooked.
  • duplicates: loaded non-Windows modules whose file name appears more than once (when at least one copy lives under the game folder or ends in .asi), with file and locations ((game folder), game-relative subfolder, or (outside game folder)). Each duplicate pair is also logged once to hooks.log (warning: duplicate module ...) and listed in crash, hang and exit notes when present.
  • Times are local. Only file names and game-relative subfolders appear, never full paths. Readers should ignore keys they don't know.

Run history (CDAL/runs/)

At each game start, before session.json becomes session-prev.json and before hooks.log rotates, cdal.dll copies the run in session.json into bin64\CDAL\runs\<yyyymmdd>-<hhmmss>-<pid>\, named after that run's started and pid, and adds a run history: the last session (<how it ended>) is kept in runs\<folder> line to hooks.log. A folder holds:

File What it is
session.json The run's session.json as it was.
The run's notes Copies of the notes in its notes array (crash-*.txt, hang-*.txt, exit-*.txt, or any later kind). The originals stay in CDAL\ with their own limit of 5 per kind.
hooks.log The run's own part of hooks.log: from its session start: line (the one with its pid) to the end, taken from hooks.old.log and hooks.log together when a rotation split it. Over 1 MB, it keeps its first 64 KB and its last part, with a [... N bytes cut by cdal.dll ...] line between.
bsx.log A copy of BSX\bsx.log as the run left it, its last 1 MB. BSX starts that log again only after its own cdal_init, which is later. Left out when bsx.log is older than the run, because BSX wasn't loaded then. BSX Lua scripts log there too.
binaries.json SHA-256, size, file version and date of cdal.dll, each BSX*.asi in bin64, each DLL in BSX\plugins, and each module the run named (in modules, foreign_hooks or features), except Windows' own DLLs.
run.json How the run ended and what was copied. Written last, so a folder with run.json is complete.
{"cdal_run": 1, "folder": "20260101-140309-4242", "started": "2026-01-01 14:03:09", "pid": 4242,
 "state": "crashed", "ended": "crashed", "failed": true, "kept": "2026-01-01 14:10:00",
 "hooks_log": "hooks.log", "bsx_log": "copied", "notes": ["crash-20260101-140512-4242.txt"], "notes_missing": []}
{"cdal_binaries": 1, "hashed": "2026-01-01 14:10:00", "run_started": "2026-01-01 14:03:09",
 "files": [{"file": "cdal.dll", "role": "cdal", "size": 843776, "sha256": "58bb...", "version": "0.8.1.0",
            "modified": "2026-01-01 09:12:40", "changed_since_run": false},
           {"file": "x.asi", "role": "module", "found": false}]}
  • ended: exited, exited, with notes, crashed, hung, unclean exit (still running at the next start) (the game was killed from outside, or ended in a way CDAL can't see), or unknown. failed is true for anything but exited, and whenever the run wrote a note.
  • hooks_log: hooks.log, hooks.old.log and hooks.log, or "" when the run's start line was in neither. bsx_log: copied, older than the run, absent or not readable. notes_missing: notes the run named that were no longer there.
  • binaries.json is written at the next start, so it shows the files as they were then. changed_since_run is true for a file changed after the run started (an update between the two starts), by its write time or its NTFS change time, since unzipping keeps the archive's write time; for cdal.dll also when its file version isn't the run's cdal. Its hash may not be the one the run ran. run.json, binaries.json and the pruning come once the new session is running; the copies before it. A module is looked up among the loaded modules, then in bin64, bin64\scripts, bin64\plugins and BSX\plugins; one found nowhere has "found": false. The file version is the FILEVERSION of the file's version resource, "" without one.
  • Kept: the 5 newest runs, and the 3 newest that went wrong (failed) even when they are older. Only folders named like a run are ever deleted.
  • Only file names appear in run.json and binaries.json, never paths. The copied logs are as the game and mods wrote them; the report tool redacts them.

In-game report (CDAL.Resolver.asi)

{"cdal_report": 1, "library": "0.8.1", "pe_timestamp": "0x...", "size_of_image": "0x...",
 "database_build": "1.0.0.0900", "exact_match": false,
 "entries": [{"id": 1, "name": "WorldSystem::sInstance", "kind": "data", "ok": true, "status": "scanned", "rva": "0x5CC0000", "matches": 1},
             {"id": 9, "name": "...", "kind": "code", "ok": false, "error": "pattern not found", "matches": 0}]}

An entry found behind another mod's hook (see "Hooked starts" above) also has "hooked": true.

import-report only accepts successful entries whose id, name and kind match the current database. Unknown IDs, renamed entries and failed entries are ignored. A known ID and name with a missing or mismatched kind is an error: nothing is imported. Offsets must supply value; functions, code, data and vtables must supply rva. A missing required value field also refuses the report before writing anything.