Consider this code:
struct A {
int64 member;
int32 member2;
virtual void f();
};
struct B {
int16 member3;
virtual void b();
};
struct C : A, B {
virtual void b() override;
};
I'm interested in finding the offset of B
in C
. Previously with other structs with no virtual inheritance and only one base class offsetof
of the first member seemed to work. I have decompiled some code (in IDA) and the base classes are nicely highlighted (hex) here:
In a function those exact baseclass offsets are used to cast void*
's to derived classes by adding the offset to the void*
(by casting to a char*
). The structs A
, B
and C
are similar to the one in the compiled code, which include classes with virtual functions and multiple base classes.
My question is how did they do that, and how can I do that? I've tried something like i32 offset = (i64)((B*)((C*)NULL));
but no luck.