FFXi.dll build 2026-08-22: R1 function discovery for static recompilation
=====================================================================

Retail file   FFXi.dll, from a retail install's FINAL FANTASY XI folder
SHA-256       b1e7e53a53640d7b56ca82d42700745b089f2466ffe55965511cbf5168804d7b
Image         reverse-engineering/unpacked/FFXi.unpacked.dll (base 0x10000000, SizeOfImage 0x2c000,
              .text 0x10001000-0x10011998, real entry 0x10007f1b = CRT _DllMainCRTStartup)
Metadata      reverse-engineering/recomp/FFXi.2026-08-22.meta.json (ffxi-recomp-meta/1, module FFXi.dll)
              373 functions, 42 switches, 17 tail jumps. Addresses and shapes only.

Method
------
Same pipeline as FFXiMain (docs/client-native-arm64.md, R1 progress), Ghidra 11.3.2 headless, scratch
project. Import + auto-analysis, then each script re-run until it changes nothing:
Discover (38, then 2 created) -> Discover2 (41 created: 29 pointer targets, 8 aligned starts, 4 after-ret;
0 rolled back) -> Switches -> SwitchAudit -> Conflicts -> BogusCheck -> BogusCheck APPLY -> fixpoint again
-> Classify / Diagnose / RecompStats -> Export.

Per-module manual verdicts are now selected by the imported image's name ('ffximain' / 'ffxi');
FFXiMain's lists are unchanged. FFXi.dll needed one:
  NOT_CODE 0x100067d0, REDECODE 0x100067c8. An aligned-start false start inside the 11-byte stub at
  0x100067c8 (`jmp [eax+0xe90]`: the displacement byte 0x90 looked like nop padding), the same
  class as FFXiMain's 0x10310f40. Recorded in BogusCheck.py and Discover2.py. Switches.py needs no
  OVERRIDES for FFXi.dll. Export.py now takes the module name from the image name (or a 4th argument).

Results
-------
                                        Ghidra auto-analysis     after discovery
functions in .text                      292                      373
instruction bytes                       56,430 (82.9%)           57,555 (84.5%)
instructions outside any function       1,249                    0
data->code pointer targets (89)         24 at entry, 36 orphan,  89 at a function entry
                                        29 never decoded
decode conflicts / bogus functions      -                        0 / 0
scaled-index switches                   42                       42, SwitchAudit review 0

.text immediates (from the private relocation table) that point into .text: 16 at function entries,
the rest are switch/index table bases, plus one classified inside a function: 0x10009c08
(`push 0x10009c08` in the CRT's 0x10009bf0, the RtlUnwind continuation label of __global_unwind2).

Switches. All 42 have Ghidra-attached targets that match their bounds. Switches.py reports 32 as
BAD_TABLE/UNBOUNDED; that is expected. They are the VC6 memcpy and memmove (0x10009e10, 0x1000c270),
whose indices are bounded by `and r,3` or `cmp ecx,8 / jc`, not by the `cmp/ja` guard the script reads.
Each one was checked by hand: 4, 3 or 8 targets. The other 10 are `cmp/ja` switches, 7 of them
through byte index tables.

Unresolved computed jumps: 14, all tail calls (10 x `jmp [eax+off]` stubs, 4 x `jmp [IAT]`);
tail_jumps in the metadata lists 17.

.text outside functions (10.5 KB):
  7,279 B  unused call-through stubs `mov eax,[0x10018b40]; jmp [eax+off]` (see below)
    934 B  nop/int3 padding
    684 B  unused import thunks (`jmp [IAT]` runs at 0x10005636, 0x1001185a, 0x100118ae)
    547 B  switch jump tables (plus about 0.3 KB of byte index tables and lea/nop filler)
  ~0.7 KB  unreferenced code: no call, pointer or relocation reaches it, for example
           0x10001000 (+112, the first bytes of .text; Discover2's aligned scan starts at offset 16),
           0x10008e7e, 0x10010e02, 0x1000bfc5 (CRT/library routines nothing calls)

Recompiler
----------
python recomp/recomp.py --meta <FFXi meta> --image FFXi.unpacked.dll --retail <retail FFXi.dll>
       --module ffxi --out <scratch> --all --stats
  -> module ffxi: translated 373 functions (0 with unimplemented instructions). Exit 0.
     table.c: rt_module_ffxi, oep 0x10007f1b, text_size 0x10998, packed_len 0xafd0, reloc_rva 0x2a000.

Relocations
-----------
.reloc (0x1002a000, 0x18c4 bytes) has the same layout as FFXiMain's:
  private .text table   0x2a000-0x2b478, 17 blocks (pages 0x1000-0x11000), 2,545 HIGHLOW entries
  PE directory          0x2b478, size 0x44c, 7 blocks, 518 HIGHLOW entries:
                        .rdata 0x12000/0x13000 (161), .data 0x14000/0x15000/0x17000/0x18000 (356),
                        and 1 in the packer's stub (0x10028fed)
  recomp.py text_relocations() reads exactly the 2,545 (it stops at the first page >= .text end).
  The directory covers .rdata and .data; it has no .text entries.

The stub's delta is not hard-coded to 0. The stub (entry 0x10028fd0) does `mov esi,0x10000000 ;
mov edi,0 ; add esi,edi`. The one directory relocation in the stub is the immediate of that
`mov edi,0` (0x10028fed). The Windows loader therefore writes the load delta into edi, and the stub
applies the private .text table with the real delta (it skips the walk only when the delta is 0).
FFXiMain is built the same way: its directory relocates 0x10bb1a7d, the same offset (+0x1d) from its
entry 0x10bb1a60. So retail relocates .text correctly at any base. The claim "delta hard-coded to 0",
in docs/client-native-arm64.md (the packer paragraph) and in the unpack.py docstring, is wrong and
should be corrected.

Notes
-----
- Role: COM in-process server. Exports DllCanUnloadNow, DllGetClassObject, DllRegisterServer,
  DllUnregisterServer. Imports KERNEL32 (91), ADVAPI32 (10, registry), ole32 (7: CoCreateInstance x4,
  CoInitialize, CoTaskMem*), OLEAUT32 (5: LoadTypeLib/RegisterTypeLib, BSTR), USER32 (CharNextA only).
  No D3D, sound, input or Winsock imports. LoadLibraryA x2, LoadLibraryExA + FindResourceA (resources
  from another module), GetProcAddress x1, CreateMutexA, SetPriorityClass, SetCurrentDirectoryA.
- Call-through table: 672 stubs at 0x100057a0-0x10007480 jump through a function table whose pointer
  lives in 0x10018b40. That pointer is filled by a COM call (0x10005240/0x10005310/0x100053e0:
  obj->vtbl[7](obj, &0x10018b40)), so it points into another module's table, the same kind of stub as
  FFXiMain's. 10 stubs are used and are functions; 662 are dead. Every used one is a tail call through
  guest memory: the runtime must resolve the other module's addresses.
- Threads: none. There is no CreateThread import, so the CRT has no _beginthread either.
- SEH / C++ EH: 11 functions install fs:[0] frames, and one `mov eax,FuncInfo; jmp 0x1000e2ff`
  (__CxxFrameHandler-style) EH stub. RtlUnwind and __global_unwind2 are in the CRT. These are the
  same intrinsics FFXiMain needs.
- No x87 instructions and no MMX/SSE.
- Statically linked VC6 CRT: 0x10007480-0x10011998 (256 of 373 functions). All 63 call sites of
  CRT-only imports are in that block. The only CRT->game call is _DllMainCRTStartup (0x10007f1b)
  -> DllMain (0x100031c0). Game code calls 14 CRT functions from 90 sites. 0x10007480/0x1000748b are
  probably operator delete/new (24 and 3 sites; the same 11-byte spacing as FFXiMain), not confirmed.
  Layout: game/COM code 0x10001000-0x100057a0 (107 functions), stubs 0x100057a0-0x10007480, CRT.
