There are some codes in dexdump located in file DexClass.c
DexClassData* dexReadAndVerifyClassData(const u1** pData, const u1* pLimit) {
......
size_t resultSize = sizeof(DexClassData) +
(header.staticFieldsSize * sizeof(DexField)) +
(header.instanceFieldsSize * sizeof(DexField)) +
(header.directMethodsSize * sizeof(DexMethod)) +
(header.virtualMethodsSize * sizeof(DexMethod));
DexClassData* result = malloc(resultSize);
u1* ptr = ((u1*) result) + sizeof(DexClassData);// I have problem here!
......
result->header = header;
if (header.staticFieldsSize != 0) {
result->staticFields = (DexField*) ptr;
ptr += header.staticFieldsSize * sizeof(DexField);
} else {
result->staticFields = NULL;
}
The codes "u1* ptr = ((u1*)result) + sizeof(DexClassData); " is to make the pointer ptr point to staticField(I think that, but I'm not sure), but why sizeof(DexClassData)? I think it supposes to be sizeof(DexClassDataHeader). I don't figure it out. Can somebody tell me?
typedef struct DexClassDataHeader
{
u4 staticFieldSize;
u4 instanceFieldSize;
u4 directMethodSize;
u4 virtualMethodSize;
}DexClassDataHeader;
typedef struct DexClassData
{
DexClassDataHeader header;
DexField* staticField;
DexField* instanceFiled;
DexMethod* directMethod;
DexMethod* vitualMethod;
}DexClassData;