不输出常量的字段偏移

This commit is contained in:
Perfare 2020-07-23 06:06:59 +08:00
parent 737acae6c7
commit 9839d61cc7
2 changed files with 12 additions and 7 deletions

View file

@ -119,6 +119,7 @@ namespace Il2CppDumper
var fieldDef = metadata.fieldDefs[i];
var fieldType = il2Cpp.types[fieldDef.typeIndex];
var isStatic = false;
var isConst = false;
if (config.DumpAttribute)
{
writer.Write(GetCustomAttribute(imageDef, fieldDef.customAttributeIndex, fieldDef.token, "\t"));
@ -146,6 +147,7 @@ namespace Il2CppDumper
}
if ((fieldType.attrs & FIELD_ATTRIBUTE_LITERAL) != 0)
{
isConst = true;
writer.Write("const ");
}
else
@ -185,7 +187,7 @@ namespace Il2CppDumper
writer.Write($" /*Metadata offset 0x{value:X}*/");
}
}
if (config.DumpFieldOffset)
if (config.DumpFieldOffset && !isConst)
writer.Write("; // 0x{0:X}\n", il2Cpp.GetFieldOffsetFromIndex(typeDefIndex, i - typeDef.fieldStart, i, typeDef.IsValueType, isStatic));
else
writer.Write(";\n");

View file

@ -143,13 +143,16 @@ namespace Il2CppDumper
}
}
//fieldOffset
var fieldOffset = il2Cpp.GetFieldOffsetFromIndex(index, i - typeDef.fieldStart, i, typeDefinition.IsValueType, fieldDefinition.IsStatic);
if (fieldOffset >= 0)
if (!fieldDefinition.IsLiteral)
{
var customAttribute = new CustomAttribute(typeDefinition.Module.ImportReference(fieldOffsetAttribute));
var offset = new CustomAttributeNamedArgument("Offset", new CustomAttributeArgument(stringType, $"0x{fieldOffset:X}"));
customAttribute.Fields.Add(offset);
fieldDefinition.CustomAttributes.Add(customAttribute);
var fieldOffset = il2Cpp.GetFieldOffsetFromIndex(index, i - typeDef.fieldStart, i, typeDefinition.IsValueType, fieldDefinition.IsStatic);
if (fieldOffset >= 0)
{
var customAttribute = new CustomAttribute(typeDefinition.Module.ImportReference(fieldOffsetAttribute));
var offset = new CustomAttributeNamedArgument("Offset", new CustomAttributeArgument(stringType, $"0x{fieldOffset:X}"));
customAttribute.Fields.Add(offset);
fieldDefinition.CustomAttributes.Add(customAttribute);
}
}
}
//method