重命名

This commit is contained in:
Perfare 2019-04-07 09:25:21 +08:00
parent 0dabcce8dc
commit 69abc36737
4 changed files with 100 additions and 124 deletions

View file

@ -71,7 +71,7 @@ namespace Il2CppDumper
} }
} }
//先单独处理,因为不知道会不会有问题 //先单独处理,因为不知道会不会有问题
for (var index = 0; index < metadata.uiNumTypes; ++index) for (var index = 0; index < metadata.typeDefs.Length; ++index)
{ {
var typeDef = metadata.typeDefs[index]; var typeDef = metadata.typeDefs[index];
var typeDefinition = typeDefinitionDic[index]; var typeDefinition = typeDefinitionDic[index];
@ -91,7 +91,7 @@ namespace Il2CppDumper
} }
} }
//处理field, method, property等等 //处理field, method, property等等
for (var index = 0; index < metadata.uiNumTypes; ++index) for (var index = 0; index < metadata.typeDefs.Length; ++index)
{ {
var typeDef = metadata.typeDefs[index]; var typeDef = metadata.typeDefs[index];
var typeDefinition = typeDefinitionDic[index]; var typeDefinition = typeDefinitionDic[index];
@ -297,81 +297,81 @@ namespace Il2CppDumper
} }
} }
private TypeReference GetTypeReference(MemberReference memberReference, Il2CppType pType) private TypeReference GetTypeReference(MemberReference memberReference, Il2CppType il2CppType)
{ {
var moduleDefinition = memberReference.Module; var moduleDefinition = memberReference.Module;
switch (pType.type) switch (il2CppType.type)
{ {
case Il2CppTypeEnum.IL2CPP_TYPE_OBJECT: case Il2CppTypeEnum.IL2CPP_TYPE_OBJECT:
return moduleDefinition.Import(typeof(Object)); return moduleDefinition.Import(typeof(object));
case Il2CppTypeEnum.IL2CPP_TYPE_VOID: case Il2CppTypeEnum.IL2CPP_TYPE_VOID:
return moduleDefinition.Import(typeof(void)); return moduleDefinition.Import(typeof(void));
case Il2CppTypeEnum.IL2CPP_TYPE_BOOLEAN: case Il2CppTypeEnum.IL2CPP_TYPE_BOOLEAN:
return moduleDefinition.Import(typeof(Boolean)); return moduleDefinition.Import(typeof(bool));
case Il2CppTypeEnum.IL2CPP_TYPE_CHAR: case Il2CppTypeEnum.IL2CPP_TYPE_CHAR:
return moduleDefinition.Import(typeof(Char)); return moduleDefinition.Import(typeof(char));
case Il2CppTypeEnum.IL2CPP_TYPE_I1: case Il2CppTypeEnum.IL2CPP_TYPE_I1:
return moduleDefinition.Import(typeof(SByte)); return moduleDefinition.Import(typeof(sbyte));
case Il2CppTypeEnum.IL2CPP_TYPE_U1: case Il2CppTypeEnum.IL2CPP_TYPE_U1:
return moduleDefinition.Import(typeof(Byte)); return moduleDefinition.Import(typeof(byte));
case Il2CppTypeEnum.IL2CPP_TYPE_I2: case Il2CppTypeEnum.IL2CPP_TYPE_I2:
return moduleDefinition.Import(typeof(Int16)); return moduleDefinition.Import(typeof(short));
case Il2CppTypeEnum.IL2CPP_TYPE_U2: case Il2CppTypeEnum.IL2CPP_TYPE_U2:
return moduleDefinition.Import(typeof(UInt16)); return moduleDefinition.Import(typeof(ushort));
case Il2CppTypeEnum.IL2CPP_TYPE_I4: case Il2CppTypeEnum.IL2CPP_TYPE_I4:
return moduleDefinition.Import(typeof(Int32)); return moduleDefinition.Import(typeof(int));
case Il2CppTypeEnum.IL2CPP_TYPE_U4: case Il2CppTypeEnum.IL2CPP_TYPE_U4:
return moduleDefinition.Import(typeof(UInt32)); return moduleDefinition.Import(typeof(uint));
case Il2CppTypeEnum.IL2CPP_TYPE_I: case Il2CppTypeEnum.IL2CPP_TYPE_I:
return moduleDefinition.Import(typeof(IntPtr)); return moduleDefinition.Import(typeof(IntPtr));
case Il2CppTypeEnum.IL2CPP_TYPE_U: case Il2CppTypeEnum.IL2CPP_TYPE_U:
return moduleDefinition.Import(typeof(UIntPtr)); return moduleDefinition.Import(typeof(UIntPtr));
case Il2CppTypeEnum.IL2CPP_TYPE_I8: case Il2CppTypeEnum.IL2CPP_TYPE_I8:
return moduleDefinition.Import(typeof(Int64)); return moduleDefinition.Import(typeof(long));
case Il2CppTypeEnum.IL2CPP_TYPE_U8: case Il2CppTypeEnum.IL2CPP_TYPE_U8:
return moduleDefinition.Import(typeof(UInt64)); return moduleDefinition.Import(typeof(ulong));
case Il2CppTypeEnum.IL2CPP_TYPE_R4: case Il2CppTypeEnum.IL2CPP_TYPE_R4:
return moduleDefinition.Import(typeof(Single)); return moduleDefinition.Import(typeof(float));
case Il2CppTypeEnum.IL2CPP_TYPE_R8: case Il2CppTypeEnum.IL2CPP_TYPE_R8:
return moduleDefinition.Import(typeof(Double)); return moduleDefinition.Import(typeof(double));
case Il2CppTypeEnum.IL2CPP_TYPE_STRING: case Il2CppTypeEnum.IL2CPP_TYPE_STRING:
return moduleDefinition.Import(typeof(String)); return moduleDefinition.Import(typeof(string));
case Il2CppTypeEnum.IL2CPP_TYPE_TYPEDBYREF: case Il2CppTypeEnum.IL2CPP_TYPE_TYPEDBYREF:
return moduleDefinition.Import(typeof(TypedReference)); return moduleDefinition.Import(typeof(TypedReference));
case Il2CppTypeEnum.IL2CPP_TYPE_CLASS: case Il2CppTypeEnum.IL2CPP_TYPE_CLASS:
case Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE: case Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE:
{ {
var typeDefinition = typeDefinitionDic[pType.data.klassIndex]; var typeDefinition = typeDefinitionDic[il2CppType.data.klassIndex];
return moduleDefinition.Import(typeDefinition); return moduleDefinition.Import(typeDefinition);
} }
case Il2CppTypeEnum.IL2CPP_TYPE_ARRAY: case Il2CppTypeEnum.IL2CPP_TYPE_ARRAY:
{ {
var arrayType = il2cpp.MapVATR<Il2CppArrayType>(pType.data.array); var arrayType = il2cpp.MapVATR<Il2CppArrayType>(il2CppType.data.array);
var type = il2cpp.GetIl2CppType(arrayType.etype); var oriType = il2cpp.GetIl2CppType(arrayType.etype);
return new ArrayType(GetTypeReference(memberReference, type), arrayType.rank); return new ArrayType(GetTypeReference(memberReference, oriType), arrayType.rank);
} }
case Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST: case Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST:
{ {
var generic_class = il2cpp.MapVATR<Il2CppGenericClass>(pType.data.generic_class); var genericClass = il2cpp.MapVATR<Il2CppGenericClass>(il2CppType.data.generic_class);
var typeDefinition = typeDefinitionDic[generic_class.typeDefinitionIndex]; var typeDefinition = typeDefinitionDic[genericClass.typeDefinitionIndex];
var genericInstanceType = new GenericInstanceType(moduleDefinition.Import(typeDefinition)); var genericInstanceType = new GenericInstanceType(moduleDefinition.Import(typeDefinition));
var pInst = il2cpp.MapVATR<Il2CppGenericInst>(generic_class.context.class_inst); var genericInst = il2cpp.MapVATR<Il2CppGenericInst>(genericClass.context.class_inst);
var pointers = il2cpp.GetPointers(pInst.type_argv, (long)pInst.type_argc); var pointers = il2cpp.GetPointers(genericInst.type_argv, (long)genericInst.type_argc);
foreach (var pointer in pointers) foreach (var pointer in pointers)
{ {
var pOriType = il2cpp.GetIl2CppType(pointer); var oriType = il2cpp.GetIl2CppType(pointer);
genericInstanceType.GenericArguments.Add(GetTypeReference(memberReference, pOriType)); genericInstanceType.GenericArguments.Add(GetTypeReference(memberReference, oriType));
} }
return genericInstanceType; return genericInstanceType;
} }
case Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY: case Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY:
{ {
var type = il2cpp.GetIl2CppType(pType.data.type); var oriType = il2cpp.GetIl2CppType(il2CppType.data.type);
return new ArrayType(GetTypeReference(memberReference, type)); return new ArrayType(GetTypeReference(memberReference, oriType));
} }
case Il2CppTypeEnum.IL2CPP_TYPE_VAR: case Il2CppTypeEnum.IL2CPP_TYPE_VAR:
{ {
if (genericParameterDic.TryGetValue(pType, out var genericParameter)) if (genericParameterDic.TryGetValue(il2CppType, out var genericParameter))
{ {
return genericParameter; return genericParameter;
} }
@ -380,19 +380,19 @@ namespace Il2CppDumper
var genericName = "T" + (methodDefinition.DeclaringType.GenericParameters.Count + 1); var genericName = "T" + (methodDefinition.DeclaringType.GenericParameters.Count + 1);
genericParameter = new GenericParameter(genericName, methodDefinition.DeclaringType); genericParameter = new GenericParameter(genericName, methodDefinition.DeclaringType);
methodDefinition.DeclaringType.GenericParameters.Add(genericParameter); methodDefinition.DeclaringType.GenericParameters.Add(genericParameter);
genericParameterDic.Add(pType, genericParameter); genericParameterDic.Add(il2CppType, genericParameter);
return genericParameter; return genericParameter;
} }
var typeDefinition = (TypeDefinition)memberReference; var typeDefinition = (TypeDefinition)memberReference;
var genericName2 = "T" + (typeDefinition.GenericParameters.Count + 1); var genericName2 = "T" + (typeDefinition.GenericParameters.Count + 1);
genericParameter = new GenericParameter(genericName2, typeDefinition); genericParameter = new GenericParameter(genericName2, typeDefinition);
typeDefinition.GenericParameters.Add(genericParameter); typeDefinition.GenericParameters.Add(genericParameter);
genericParameterDic.Add(pType, genericParameter); genericParameterDic.Add(il2CppType, genericParameter);
return genericParameter; return genericParameter;
} }
case Il2CppTypeEnum.IL2CPP_TYPE_MVAR: case Il2CppTypeEnum.IL2CPP_TYPE_MVAR:
{ {
if (genericParameterDic.TryGetValue(pType, out var genericParameter)) if (genericParameterDic.TryGetValue(il2CppType, out var genericParameter))
{ {
return genericParameter; return genericParameter;
} }
@ -400,16 +400,16 @@ namespace Il2CppDumper
var genericName = "T" + (methodDefinition.GenericParameters.Count + 1); var genericName = "T" + (methodDefinition.GenericParameters.Count + 1);
genericParameter = new GenericParameter(genericName, methodDefinition); genericParameter = new GenericParameter(genericName, methodDefinition);
methodDefinition.GenericParameters.Add(genericParameter); methodDefinition.GenericParameters.Add(genericParameter);
genericParameterDic.Add(pType, genericParameter); genericParameterDic.Add(il2CppType, genericParameter);
return genericParameter; return genericParameter;
} }
case Il2CppTypeEnum.IL2CPP_TYPE_PTR: case Il2CppTypeEnum.IL2CPP_TYPE_PTR:
{ {
var type = il2cpp.GetIl2CppType(pType.data.type); var oriType = il2cpp.GetIl2CppType(il2CppType.data.type);
return new PointerType(GetTypeReference(memberReference, type)); return new PointerType(GetTypeReference(memberReference, oriType));
} }
default: default:
return moduleDefinition.Import(typeof(Object)); return moduleDefinition.Import(typeof(object));
} }
} }
@ -418,9 +418,9 @@ namespace Il2CppDumper
var pointer = metadata.GetDefaultValueFromIndex(dataIndex); var pointer = metadata.GetDefaultValueFromIndex(dataIndex);
if (pointer > 0) if (pointer > 0)
{ {
var pTypeToUse = il2cpp.types[typeIndex]; var defaultValueType = il2cpp.types[typeIndex];
metadata.Position = pointer; metadata.Position = pointer;
switch (pTypeToUse.type) switch (defaultValueType.type)
{ {
case Il2CppTypeEnum.IL2CPP_TYPE_BOOLEAN: case Il2CppTypeEnum.IL2CPP_TYPE_BOOLEAN:
return metadata.ReadBoolean(); return metadata.ReadBoolean();
@ -447,8 +447,8 @@ namespace Il2CppDumper
case Il2CppTypeEnum.IL2CPP_TYPE_R8: case Il2CppTypeEnum.IL2CPP_TYPE_R8:
return metadata.ReadDouble(); return metadata.ReadDouble();
case Il2CppTypeEnum.IL2CPP_TYPE_STRING: case Il2CppTypeEnum.IL2CPP_TYPE_STRING:
var uiLen = metadata.ReadInt32(); var len = metadata.ReadInt32();
return Encoding.UTF8.GetString(metadata.ReadBytes(uiLen)); return Encoding.UTF8.GetString(metadata.ReadBytes(len));
} }
} }
return null; return null;

View file

@ -130,14 +130,14 @@ namespace Il2CppDumper
return fieldOffsets[fieldIndex]; return fieldOffsets[fieldIndex];
} }
public T[] MapVATR<T>(dynamic uiAddr, long count) where T : new() public T[] MapVATR<T>(dynamic addr, long count) where T : new()
{ {
return ReadClassArray<T>(MapVATR(uiAddr), count); return ReadClassArray<T>(MapVATR(addr), count);
} }
public T MapVATR<T>(dynamic uiAddr) where T : new() public T MapVATR<T>(dynamic addr) where T : new()
{ {
return ReadClass<T>(MapVATR(uiAddr)); return ReadClass<T>(MapVATR(addr));
} }
public Il2CppType GetIl2CppType(ulong pointer) public Il2CppType GetIl2CppType(ulong pointer)

View file

@ -8,9 +8,7 @@ namespace Il2CppDumper
{ {
public sealed class Metadata : MyBinaryReader public sealed class Metadata : MyBinaryReader
{ {
private Il2CppGlobalMetadataHeader pMetadataHdr; private Il2CppGlobalMetadataHeader metadataHeader;
public int uiImageCount;
public int uiNumTypes;
public Il2CppImageDefinition[] imageDefs; public Il2CppImageDefinition[] imageDefs;
public Il2CppTypeDefinition[] typeDefs; public Il2CppTypeDefinition[] typeDefs;
public Il2CppMethodDefinition[] methodDefs; public Il2CppMethodDefinition[] methodDefs;
@ -35,13 +33,12 @@ namespace Il2CppDumper
public Metadata(Stream stream, float version) : base(stream) public Metadata(Stream stream, float version) : base(stream)
{ {
this.version = version; this.version = version;
//pMetadataHdr metadataHeader = ReadClass<Il2CppGlobalMetadataHeader>();
pMetadataHdr = ReadClass<Il2CppGlobalMetadataHeader>(); if (metadataHeader.sanity != 0xFAB11BAF)
if (pMetadataHdr.sanity != 0xFAB11BAF)
{ {
throw new Exception("ERROR: Metadata file supplied is not valid metadata file."); throw new Exception("ERROR: Metadata file supplied is not valid metadata file.");
} }
switch (pMetadataHdr.version) switch (metadataHeader.version)
{ {
case 16: case 16:
case 19: case 19:
@ -54,52 +51,32 @@ namespace Il2CppDumper
default: default:
throw new Exception($"ERROR: Metadata file supplied is not a supported version[{version}]."); throw new Exception($"ERROR: Metadata file supplied is not a supported version[{version}].");
} }
//ImageDefinition imageDefs = ReadMetadataClassArray<Il2CppImageDefinition>(metadataHeader.imagesOffset, metadataHeader.imagesCount);
uiImageCount = pMetadataHdr.imagesCount / MySizeOf(typeof(Il2CppImageDefinition)); typeDefs = ReadMetadataClassArray<Il2CppTypeDefinition>(metadataHeader.typeDefinitionsOffset, metadataHeader.typeDefinitionsCount);
uiNumTypes = pMetadataHdr.typeDefinitionsCount / MySizeOf(typeof(Il2CppTypeDefinition)); methodDefs = ReadMetadataClassArray<Il2CppMethodDefinition>(metadataHeader.methodsOffset, metadataHeader.methodsCount);
imageDefs = ReadClassArray<Il2CppImageDefinition>(pMetadataHdr.imagesOffset, uiImageCount); parameterDefs = ReadMetadataClassArray<Il2CppParameterDefinition>(metadataHeader.parametersOffset, metadataHeader.parametersCount);
//GetTypeDefinitionFromIndex fieldDefs = ReadMetadataClassArray<Il2CppFieldDefinition>(metadataHeader.fieldsOffset, metadataHeader.fieldsCount);
typeDefs = ReadClassArray<Il2CppTypeDefinition>(pMetadataHdr.typeDefinitionsOffset, uiNumTypes); fieldDefaultValues = ReadMetadataClassArray<Il2CppFieldDefaultValue>(metadataHeader.fieldDefaultValuesOffset, metadataHeader.fieldDefaultValuesCount);
//GetMethodDefinitionFromIndex parameterDefaultValues = ReadMetadataClassArray<Il2CppParameterDefaultValue>(metadataHeader.parameterDefaultValuesOffset, metadataHeader.parameterDefaultValuesCount);
methodDefs = ReadClassArray<Il2CppMethodDefinition>(pMetadataHdr.methodsOffset, pMetadataHdr.methodsCount / MySizeOf(typeof(Il2CppMethodDefinition))); propertyDefs = ReadMetadataClassArray<Il2CppPropertyDefinition>(metadataHeader.propertiesOffset, metadataHeader.propertiesCount);
//GetParameterDefinitionFromIndex interfaceIndices = ReadClassArray<int>(metadataHeader.interfacesOffset, metadataHeader.interfacesCount / 4);
parameterDefs = ReadClassArray<Il2CppParameterDefinition>(pMetadataHdr.parametersOffset, pMetadataHdr.parametersCount / MySizeOf(typeof(Il2CppParameterDefinition))); nestedTypeIndices = ReadClassArray<int>(metadataHeader.nestedTypesOffset, metadataHeader.nestedTypesCount / 4);
//GetFieldDefinitionFromIndex eventDefs = ReadMetadataClassArray<Il2CppEventDefinition>(metadataHeader.eventsOffset, metadataHeader.eventsCount);
fieldDefs = ReadClassArray<Il2CppFieldDefinition>(pMetadataHdr.fieldsOffset, pMetadataHdr.fieldsCount / MySizeOf(typeof(Il2CppFieldDefinition))); genericContainers = ReadMetadataClassArray<Il2CppGenericContainer>(metadataHeader.genericContainersOffset, metadataHeader.genericContainersCount);
//FieldDefaultValue
fieldDefaultValues = ReadClassArray<Il2CppFieldDefaultValue>(pMetadataHdr.fieldDefaultValuesOffset, pMetadataHdr.fieldDefaultValuesCount / MySizeOf(typeof(Il2CppFieldDefaultValue)));
//ParameterDefaultValue
parameterDefaultValues = ReadClassArray<Il2CppParameterDefaultValue>(pMetadataHdr.parameterDefaultValuesOffset, pMetadataHdr.parameterDefaultValuesCount / MySizeOf(typeof(Il2CppParameterDefaultValue)));
//GetPropertyDefinitionFromIndex
propertyDefs = ReadClassArray<Il2CppPropertyDefinition>(pMetadataHdr.propertiesOffset, pMetadataHdr.propertiesCount / MySizeOf(typeof(Il2CppPropertyDefinition)));
//GetInterfaceFromIndex
interfaceIndices = ReadClassArray<int>(pMetadataHdr.interfacesOffset, pMetadataHdr.interfacesCount / 4);
//GetNestedTypeFromIndex
nestedTypeIndices = ReadClassArray<int>(pMetadataHdr.nestedTypesOffset, pMetadataHdr.nestedTypesCount / 4);
//GetEventDefinitionFromIndex
eventDefs = ReadClassArray<Il2CppEventDefinition>(pMetadataHdr.eventsOffset, pMetadataHdr.eventsCount / MySizeOf(typeof(Il2CppEventDefinition)));
//GetGenericContainerFromIndex
genericContainers = ReadClassArray<Il2CppGenericContainer>(pMetadataHdr.genericContainersOffset, pMetadataHdr.genericContainersCount / MySizeOf(typeof(Il2CppGenericContainer)));
if (version > 16) if (version > 16)
{ {
//Il2CppStringLiteral stringLiterals = ReadMetadataClassArray<Il2CppStringLiteral>(metadataHeader.stringLiteralOffset, metadataHeader.stringLiteralCount);
stringLiterals = ReadClassArray<Il2CppStringLiteral>(pMetadataHdr.stringLiteralOffset, pMetadataHdr.stringLiteralCount / MySizeOf(typeof(Il2CppStringLiteral))); metadataUsageLists = ReadMetadataClassArray<Il2CppMetadataUsageList>(metadataHeader.metadataUsageListsOffset, metadataHeader.metadataUsageListsCount);
//Il2CppMetadataUsageList metadataUsagePairs = ReadMetadataClassArray<Il2CppMetadataUsagePair>(metadataHeader.metadataUsagePairsOffset, metadataHeader.metadataUsagePairsCount);
metadataUsageLists = ReadClassArray<Il2CppMetadataUsageList>(pMetadataHdr.metadataUsageListsOffset, pMetadataHdr.metadataUsageListsCount / MySizeOf(typeof(Il2CppMetadataUsageList)));
//Il2CppMetadataUsagePair
metadataUsagePairs = ReadClassArray<Il2CppMetadataUsagePair>(pMetadataHdr.metadataUsagePairsOffset, pMetadataHdr.metadataUsagePairsCount / MySizeOf(typeof(Il2CppMetadataUsagePair)));
CreateStringLiteralDic(); CreateStringLiteralDic();
//Il2CppFieldRef fieldRefs = ReadMetadataClassArray<Il2CppFieldRef>(metadataHeader.fieldRefsOffset, metadataHeader.fieldRefsCount);
fieldRefs = ReadMetadataClassArray<Il2CppFieldRef>(pMetadataHdr.fieldRefsOffset, pMetadataHdr.fieldRefsCount);
} }
if (version > 20) if (version > 20)
{ {
//CustomAttributeTypeRange attributeTypeRanges = ReadMetadataClassArray<Il2CppCustomAttributeTypeRange>(metadataHeader.attributesInfoOffset, metadataHeader.attributesInfoCount);
attributeTypeRanges = ReadClassArray<Il2CppCustomAttributeTypeRange>(pMetadataHdr.attributesInfoOffset, pMetadataHdr.attributesInfoCount / MySizeOf(typeof(Il2CppCustomAttributeTypeRange))); attributeTypes = ReadClassArray<int>(metadataHeader.attributeTypesOffset, metadataHeader.attributeTypesCount / 4);
//AttributeTypes
attributeTypes = ReadClassArray<int>(pMetadataHdr.attributeTypesOffset, pMetadataHdr.attributeTypesCount / 4);
} }
} }
@ -120,12 +97,12 @@ namespace Il2CppDumper
public int GetDefaultValueFromIndex(int index) public int GetDefaultValueFromIndex(int index)
{ {
return pMetadataHdr.fieldAndParameterDefaultValueDataOffset + index; return metadataHeader.fieldAndParameterDefaultValueDataOffset + index;
} }
public string GetStringFromIndex(int index) public string GetStringFromIndex(int index)
{ {
return ReadStringToNull(pMetadataHdr.stringOffset + index); return ReadStringToNull(metadataHeader.stringOffset + index);
} }
public int GetCustomAttributeIndex(Il2CppImageDefinition imageDef, int customAttributeIndex, uint token) public int GetCustomAttributeIndex(Il2CppImageDefinition imageDef, int customAttributeIndex, uint token)
@ -151,7 +128,7 @@ namespace Il2CppDumper
public string GetStringLiteralFromIndex(uint index) public string GetStringLiteralFromIndex(uint index)
{ {
var stringLiteral = stringLiterals[index]; var stringLiteral = stringLiterals[index];
Position = pMetadataHdr.stringLiteralDataOffset + stringLiteral.dataIndex; Position = metadataHeader.stringLiteralDataOffset + stringLiteral.dataIndex;
return Encoding.UTF8.GetString(ReadBytes((int)stringLiteral.length)); return Encoding.UTF8.GetString(ReadBytes((int)stringLiteral.length));
} }
@ -176,7 +153,6 @@ namespace Il2CppDumper
maxMetadataUsages = metadataUsageDic[5].Last().Key + 1; maxMetadataUsages = metadataUsageDic[5].Last().Key + 1;
} }
private uint GetEncodedIndexType(uint index) private uint GetEncodedIndexType(uint index)
{ {
return (index & 0xE0000000) >> 29; return (index & 0xE0000000) >> 29;

View file

@ -33,14 +33,14 @@ namespace Il2CppDumper
{ {
if (args[0] == "-h" || args[0] == "--help" || args[0] == "/?" || args[0] == "/h") if (args[0] == "-h" || args[0] == "--help" || args[0] == "/?" || args[0] == "/h")
{ {
ShowHelp(System.AppDomain.CurrentDomain.FriendlyName); ShowHelp(AppDomain.CurrentDomain.FriendlyName);
return; return;
} }
} }
if (args.Length > 2) if (args.Length > 2)
{ {
ShowHelp(System.AppDomain.CurrentDomain.FriendlyName); ShowHelp(AppDomain.CurrentDomain.FriendlyName);
return; return;
} }
@ -236,7 +236,7 @@ namespace Il2CppDumper
var scriptwriter = new StreamWriter(new FileStream("script.py", FileMode.Create), new UTF8Encoding(false)); var scriptwriter = new StreamWriter(new FileStream("script.py", FileMode.Create), new UTF8Encoding(false));
scriptwriter.WriteLine(Resource1.ida); scriptwriter.WriteLine(Resource1.ida);
//dump image //dump image
for (var imageIndex = 0; imageIndex < metadata.uiImageCount; imageIndex++) for (var imageIndex = 0; imageIndex < metadata.imageDefs.Length; imageIndex++)
{ {
var imageDef = metadata.imageDefs[imageIndex]; var imageDef = metadata.imageDefs[imageIndex];
writer.Write($"// Image {imageIndex}: {metadata.GetStringFromIndex(imageDef.nameIndex)} - {imageDef.typeStart}\n"); writer.Write($"// Image {imageIndex}: {metadata.GetStringFromIndex(imageDef.nameIndex)} - {imageDef.typeStart}\n");
@ -331,7 +331,7 @@ namespace Il2CppDumper
//dump_field(i, idx, i - typeDef.fieldStart); //dump_field(i, idx, i - typeDef.fieldStart);
var fieldDef = metadata.fieldDefs[i]; var fieldDef = metadata.fieldDefs[i];
var fieldType = il2cpp.types[fieldDef.typeIndex]; var fieldType = il2cpp.types[fieldDef.typeIndex];
var fieldDefault = metadata.GetFieldDefaultValueFromIndex(i); var fieldDefaultValue = metadata.GetFieldDefaultValueFromIndex(i);
writer.Write(GetCustomAttribute(imageDef, fieldDef.customAttributeIndex, fieldDef.token, "\t")); writer.Write(GetCustomAttribute(imageDef, fieldDef.customAttributeIndex, fieldDef.token, "\t"));
writer.Write("\t"); writer.Write("\t");
var access = fieldType.attrs & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK; var access = fieldType.attrs & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK;
@ -366,15 +366,15 @@ namespace Il2CppDumper
writer.Write("readonly "); writer.Write("readonly ");
} }
writer.Write($"{GetTypeName(fieldType)} {metadata.GetStringFromIndex(fieldDef.nameIndex)}"); writer.Write($"{GetTypeName(fieldType)} {metadata.GetStringFromIndex(fieldDef.nameIndex)}");
if (fieldDefault != null && fieldDefault.dataIndex != -1) if (fieldDefaultValue != null && fieldDefaultValue.dataIndex != -1)
{ {
var pointer = metadata.GetDefaultValueFromIndex(fieldDefault.dataIndex); var pointer = metadata.GetDefaultValueFromIndex(fieldDefaultValue.dataIndex);
if (pointer > 0) if (pointer > 0)
{ {
var fieldDefaultType = il2cpp.types[fieldDefault.typeIndex]; var fieldDefaultValueType = il2cpp.types[fieldDefaultValue.typeIndex];
metadata.Position = pointer; metadata.Position = pointer;
object val = null; object val = null;
switch (fieldDefaultType.type) switch (fieldDefaultValueType.type)
{ {
case Il2CppTypeEnum.IL2CPP_TYPE_BOOLEAN: case Il2CppTypeEnum.IL2CPP_TYPE_BOOLEAN:
val = metadata.ReadBoolean(); val = metadata.ReadBoolean();
@ -543,9 +543,9 @@ namespace Il2CppDumper
} }
scriptwriter.WriteLine("print('Make method name done')"); scriptwriter.WriteLine("print('Make method name done')");
//Script - MetadataUsage //Script - MetadataUsage
scriptwriter.WriteLine("print('Setting MetadataUsage...')");
if (il2cpp.version > 16) if (il2cpp.version > 16)
{ {
scriptwriter.WriteLine("print('Setting MetadataUsage...')");
foreach (var i in metadata.metadataUsageDic[1]) //kIl2CppMetadataUsageTypeInfo foreach (var i in metadata.metadataUsageDic[1]) //kIl2CppMetadataUsageTypeInfo
{ {
var type = il2cpp.types[i.Value]; var type = il2cpp.types[i.Value];
@ -614,8 +614,8 @@ namespace Il2CppDumper
} }
scriptwriter.WriteLine($"idc.MakeComm(0x{il2cpp.metadataUsages[i.Key]:X}, r'0x{methodPointer:X}')"); scriptwriter.WriteLine($"idc.MakeComm(0x{il2cpp.metadataUsages[i.Key]:X}, r'0x{methodPointer:X}')");
} }
scriptwriter.WriteLine("print('Set MetadataUsage done')");
} }
scriptwriter.WriteLine("print('Set MetadataUsage done')");
//Script - MakeFunction //Script - MakeFunction
if (config.MakeFunction) if (config.MakeFunction)
{ {
@ -656,15 +656,15 @@ namespace Il2CppDumper
} }
} }
private static string GetTypeName(Il2CppType pType, bool fullName = false) private static string GetTypeName(Il2CppType type, bool fullName = false)
{ {
string ret; string ret;
switch (pType.type) switch (type.type)
{ {
case Il2CppTypeEnum.IL2CPP_TYPE_CLASS: case Il2CppTypeEnum.IL2CPP_TYPE_CLASS:
case Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE: case Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE:
{ {
var typeDef = metadata.typeDefs[pType.data.klassIndex]; var typeDef = metadata.typeDefs[type.data.klassIndex];
ret = string.Empty; ret = string.Empty;
if (fullName) if (fullName)
{ {
@ -679,41 +679,41 @@ namespace Il2CppDumper
} }
case Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST: case Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST:
{ {
var generic_class = il2cpp.MapVATR<Il2CppGenericClass>(pType.data.generic_class); var generic_class = il2cpp.MapVATR<Il2CppGenericClass>(type.data.generic_class);
var pMainDef = metadata.typeDefs[generic_class.typeDefinitionIndex]; var typeDef = metadata.typeDefs[generic_class.typeDefinitionIndex];
ret = metadata.GetStringFromIndex(pMainDef.nameIndex); ret = metadata.GetStringFromIndex(typeDef.nameIndex);
var typeNames = new List<string>(); var typeNames = new List<string>();
var pInst = il2cpp.MapVATR<Il2CppGenericInst>(generic_class.context.class_inst); var genericInst = il2cpp.MapVATR<Il2CppGenericInst>(generic_class.context.class_inst);
var pointers = il2cpp.GetPointers(pInst.type_argv, (long)pInst.type_argc); var pointers = il2cpp.GetPointers(genericInst.type_argv, (long)genericInst.type_argc);
for (uint i = 0; i < pInst.type_argc; ++i) for (uint i = 0; i < genericInst.type_argc; ++i)
{ {
var pOriType = il2cpp.GetIl2CppType(pointers[i]); var oriType = il2cpp.GetIl2CppType(pointers[i]);
typeNames.Add(GetTypeName(pOriType)); typeNames.Add(GetTypeName(oriType));
} }
ret += $"<{string.Join(", ", typeNames)}>"; ret += $"<{string.Join(", ", typeNames)}>";
break; break;
} }
case Il2CppTypeEnum.IL2CPP_TYPE_ARRAY: case Il2CppTypeEnum.IL2CPP_TYPE_ARRAY:
{ {
var arrayType = il2cpp.MapVATR<Il2CppArrayType>(pType.data.array); var arrayType = il2cpp.MapVATR<Il2CppArrayType>(type.data.array);
var type = il2cpp.GetIl2CppType(arrayType.etype); var oriType = il2cpp.GetIl2CppType(arrayType.etype);
ret = $"{GetTypeName(type)}[{new string(',', arrayType.rank - 1)}]"; ret = $"{GetTypeName(oriType)}[{new string(',', arrayType.rank - 1)}]";
break; break;
} }
case Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY: case Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY:
{ {
var type = il2cpp.GetIl2CppType(pType.data.type); var oriType = il2cpp.GetIl2CppType(type.data.type);
ret = $"{GetTypeName(type)}[]"; ret = $"{GetTypeName(oriType)}[]";
break; break;
} }
case Il2CppTypeEnum.IL2CPP_TYPE_PTR: case Il2CppTypeEnum.IL2CPP_TYPE_PTR:
{ {
var type = il2cpp.GetIl2CppType(pType.data.type); var oriType = il2cpp.GetIl2CppType(type.data.type);
ret = $"{GetTypeName(type)}*"; ret = $"{GetTypeName(oriType)}*";
break; break;
} }
default: default:
ret = TypeString[(int)pType.type]; ret = TypeString[(int)type.type];
break; break;
} }