commit 6126dc368b7cef99e8ecb369ed671904a2b1e0c3
parent 80db1369f46a98e1d961bb741a7ae4240b04794b
Author: anon <anon@example.com>
Date: Thu, 15 Oct 2026 12:25:48 +0000
Implement legacy type_info equality on Linux
Diffstat:
2 files changed, 44 insertions(+), 1 deletion(-)
diff --git a/decompiled/runtime/guest_rtti.c b/decompiled/runtime/guest_rtti.c
@@ -5,6 +5,13 @@ static int same_type(uint32_t left, uint32_t right)
return left == right || !strcmp((const char *)ADDR(left + 8), (const char *)ADDR(right + 8));
}
+static void type_info_equal(void)
+{
+ uint32_t other = MEM32(g_esp + 4);
+ g_eax = g_ecx == other || !strcmp((const char *)ADDR(g_ecx + 9), (const char *)ADDR(other + 9));
+ g_esp += 8; /* type_info::operator== is thiscall. */
+}
+
static uint32_t base_address(uint32_t object, uint32_t descriptor)
{
uint32_t result = object + MEM32(descriptor + 8);
@@ -72,5 +79,6 @@ static void dynamic_cast(void)
recomp_func_t guest_rtti_lookup(const char *name)
{
if (!strcmp(name, "__RTDynamicCast")) return dynamic_cast;
+ if (!strcmp(name, "??8type_info@@QBEHABV0@@Z")) return type_info_equal;
return NULL;
}
diff --git a/decompiled/tests/rtti.c b/decompiled/tests/rtti.c
@@ -134,6 +134,40 @@ static void vfptr_and_construction_displacements_adjust_the_complete_object(void
assert(cast(0x50007028, 0, 1, 0, 0) == 0x50007000);
}
+static void type_info_equality_uses_names(void)
+{
+ type(7, "!?AVRDBObject_t@@");
+ type(8, ".?AVrDBObject_t@@");
+ const unsigned pairs[][3] = {{1, 1, 1}, {1, 6, 1}, {6, 1, 1}, {1, 7, 1}, {1, 8, 0}, {1, 2, 0}};
+#ifdef _WIN32
+ int (__thiscall *equal)(void *, void *) =
+ (void *)GetProcAddress(LoadLibraryA("msvcrt.dll"), "??8type_info@@QBEHABV0@@Z");
+ assert(equal);
+#endif
+ for (unsigned i = 0; i < sizeof(pairs) / sizeof(pairs[0]); ++i) {
+ uint32_t left = 0x50001000 + pairs[i][0] * 64;
+ uint32_t right = 0x50001000 + pairs[i][1] * 64;
+ MEM32(left) = 0x12345678; MEM32(left + 4) = 0x87654321;
+ MEM32(right) = 0x23456789; MEM32(right + 4) = 0x98765432;
+
+#ifdef _WIN32
+ int result = equal((void *)(uintptr_t)left, (void *)(uintptr_t)right);
+#else
+ g_esp = 0x5000ff00;
+ MEM32(g_esp + 4) = right;
+ g_ecx = left;
+ g_ebx = 123; g_esi = 234; g_edi = 345; g_ebp = 456;
+ guest_rtti_lookup("??8type_info@@QBEHABV0@@Z")();
+ int result = g_eax;
+ assert(g_esp == 0x5000ff08);
+ assert(g_ebx == 123 && g_esi == 234 && g_edi == 345 && g_ebp == 456);
+#endif
+
+ assert(result == (int)pairs[i][2]);
+ assert(MEM32(right) == 0x23456789 && MEM32(right + 4) == 0x98765432);
+ }
+}
+
int main(void)
{
#ifdef _WIN32
@@ -154,6 +188,7 @@ int main(void)
repeated_bases_select_the_source_branch();
virtual_base_displacement_locates_the_shared_base();
vfptr_and_construction_displacements_adjust_the_complete_object();
- puts("RTTI: public multiple/virtual inheritance, repeated bases, cross-DLL names, null/failure and ABI passed");
+ type_info_equality_uses_names();
+ puts("RTTI: public multiple/virtual inheritance, repeated bases, cross-DLL names, type_info equality, null/failure and ABI passed");
return 0;
}