(05-16-2013 07:44 PM)Eric Wrote: what kind of magic ? maybe simple prompt ? now i'm gonna google "how to get access to private class members c++ magic"
If you know the offsets of the members, just increment the pointer to the instance. Like this:
Code:
class MyClass
{
public:
int n;
private:
int n_;
};
MyClass a;
a.n = 3;
*(((void *)&a)+4) = 4; // a.n_ = 4;
If you don't know the offsets, but know their value at some point, memdump the class and look for it.
Keep in mind when calculating the offset, if a class has virtual functions, or is derived from a class that does, it will have a VFTP. They might also have a class ID stored somewhere.
Also, while this theoretically kills all platform independence, I think all Esenthel-supported compilers generate the same code, so it should work. Just be sure to use sizeof instead of magic numbers.
Finally, if you want the offset of a field you can access (this
might also work for privates, but don't count on it), you can use this macro:
Code:
#define OFFSET_OF(str, fld) ((int)(&((str*)0)->fld))
Even though you are doing (0)->fld, this will not generate an access violation, because you are only getting the address, so some compilers might allow it to work for private members as well.. Too lazy to test right now.