Search code examples
c++memorysizestructureallocation

Structure size definition


Found a few similar posts but none that target my specific issue.

I'm trying to read a data structure from an external processes memory. I've used OpenProcess to get a handle, and my function for reading memory is pretty neat, but after assembling the first structure to be read, which should be 0xC0 bytes, I'm calling sizeof(structure) and getting double that value. The structure is below, if it helps. Hope someone can point me in the right direction.

Thanks

struct BattleListEntry
{
    int CID;
    wstring Name;
    byte* unknown[16];
    int z, y, x;
    byte* unknown2[8];
    int Direction;
    int TimeLastMoved;
    int rnd3, rnd4, rnd5, rnd6;
    int isWalking;
    byte* unknown3[12];
    int Outfit1, Outfit2, Outfit3, Outfit4, Outfit5;
    byte* unknown4[24];
    int HpPct; // 40 * 4 from start
    int rnd7;
    int rnd8;
    //byte* unknown5[12];
    int rnd9, rnd10, rnd11, rnd12, rnd13, rnd14, rnd15, rnd16, rnd17, rnd18;
};

Solution

  • You seem to believe that byte* unknown[16] is 16 bytes large. In fact, it's 16*sizeof(void*) bytes large. It's not an array of bytes, it's an array of pointers.