Replace the partial mechanics transcriptions with a separate, readable C11 reconstruction of the complete Win16 image while preserving the original raw Ghidra export as immutable evidence. Cover all ordinary and overlapping entry points, Borland runtime behavior, Win16 imports, segmented data, callbacks, resources, indirect control flow, physics, rendering, persistence, and startup/shutdown lifecycles. Add deterministic extraction and audit tooling plus address-linked ledgers for functions, imports, DGROUP ranges and objects, relocations, resources, and callbacks. The final gate records zero raw, partial, restored, unknown, blocked, or unclassified required units. Keep the semantic-fidelity boundary explicit: the portable C is not claimed to reproduce a byte-identical Borland NE build. Add strict focused harnesses for every reconstructed C unit, exact resource round-trip checks, and a 16-bit Borland Real48 reference probe. No Rust source or Cargo metadata is changed in this phase. Test Plan: - `bash original/tools/test_reconstructed_c.sh` -- passed - `bash original/tools/probe_real48_reference.sh` -- passed bit-for-bit - `python3 original/tools/audit_reconstruction.py --require-complete` -- passed - `git diff --cached --check` -- passed - `git diff HEAD -- '*.rs' Cargo.toml Cargo.lock` -- empty
67 lines
2.5 KiB
C
67 lines
2.5 KiB
C
#include "../tdkpin_resources.h"
|
|
|
|
#include <assert.h>
|
|
#include <string.h>
|
|
|
|
static void hash_u16(uint64_t *hash, uint16_t value)
|
|
{
|
|
for (unsigned byte = 0; byte < 2; byte++) {
|
|
*hash ^= (uint8_t)(value >> (byte * 8));
|
|
*hash *= UINT64_C(1099511628211);
|
|
}
|
|
}
|
|
|
|
static void hash_u32(uint64_t *hash, uint32_t value)
|
|
{
|
|
for (unsigned byte = 0; byte < 4; byte++) {
|
|
*hash ^= (uint8_t)(value >> (byte * 8));
|
|
*hash *= UINT64_C(1099511628211);
|
|
}
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
size_t direct = 0;
|
|
size_t system_resolved = 0;
|
|
size_t linked_unused = 0;
|
|
uint64_t manifest_fields_hash = UINT64_C(14695981039346656037);
|
|
for (size_t index = 0; index < TDKPIN_RESOURCE_COUNT; index++) {
|
|
const TdkpinResourceDescriptor *entry = &tdkpin_resource_catalog[index];
|
|
assert(entry->meaningful_size > 0);
|
|
assert(entry->meaningful_size <= entry->allocated_size);
|
|
assert(entry->role != NULL && entry->role[0] != '\0');
|
|
for (size_t earlier = 0; earlier < index; earlier++) {
|
|
assert(entry->type != tdkpin_resource_catalog[earlier].type ||
|
|
entry->id != tdkpin_resource_catalog[earlier].id);
|
|
}
|
|
if (entry->disposition == TDKPIN_RESOURCE_DIRECT) {
|
|
direct++;
|
|
} else if (entry->disposition == TDKPIN_RESOURCE_SYSTEM_RESOLVED) {
|
|
system_resolved++;
|
|
} else {
|
|
assert(entry->disposition == TDKPIN_RESOURCE_LINKED_UNUSED);
|
|
linked_unused++;
|
|
}
|
|
hash_u16(&manifest_fields_hash, (uint16_t)entry->type);
|
|
hash_u16(&manifest_fields_hash, entry->id);
|
|
hash_u32(&manifest_fields_hash, entry->file_offset);
|
|
hash_u32(&manifest_fields_hash, entry->allocated_size);
|
|
hash_u32(&manifest_fields_hash, entry->meaningful_size);
|
|
hash_u16(&manifest_fields_hash, entry->flags);
|
|
hash_u16(&manifest_fields_hash, entry->width);
|
|
hash_u16(&manifest_fields_hash, entry->height);
|
|
hash_u32(&manifest_fields_hash, entry->sample_rate);
|
|
}
|
|
assert(direct == 57);
|
|
assert(system_resolved == 2);
|
|
assert(linked_unused == 4);
|
|
assert(manifest_fields_hash == UINT64_C(0x29d77e86100b5e75));
|
|
assert(tdkpin_resource_catalog[0].type == TDKPIN_RESOURCE_DAT);
|
|
assert(tdkpin_resource_catalog[0].id == 400);
|
|
assert(tdkpin_resource_catalog[62].type == TDKPIN_RESOURCE_DIALOG);
|
|
assert(tdkpin_resource_catalog[62].id == 32517);
|
|
assert(strcmp(tdkpin_resource_catalog[54].role,
|
|
"image selected by GROUP_ICON 996") == 0);
|
|
return 0;
|
|
}
|