From 2f1a4b2a149080a9e85ce8c1e2c1b76de8cc171d Mon Sep 17 00:00:00 2001 From: Perfare Date: Fri, 22 Apr 2022 09:28:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=89=B9=E6=AE=8A=E7=9A=8432?= =?UTF-8?q?=E4=BD=8Ddump=20elf=E6=96=87=E4=BB=B6=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E4=B8=8D=E5=AE=8C=E6=95=B4=E7=9A=84dump=20elf=E6=96=87?= =?UTF-8?q?=E4=BB=B6=20=E7=BB=86=E8=8A=82=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Il2CppDumper/Config.cs | 2 ++ Il2CppDumper/ExecutableFormats/Elf.cs | 2 +- Il2CppDumper/ExecutableFormats/Elf64.cs | 2 +- Il2CppDumper/ExecutableFormats/Macho.cs | 2 +- Il2CppDumper/ExecutableFormats/Macho64.cs | 2 +- Il2CppDumper/ExecutableFormats/NSO.cs | 2 +- Il2CppDumper/ExecutableFormats/PE.cs | 2 +- Il2CppDumper/ExecutableFormats/WebAssemblyMemory.cs | 2 +- Il2CppDumper/Il2Cpp/Il2Cpp.cs | 8 ++++---- Il2CppDumper/Il2Cpp/Metadata.cs | 9 +++++++-- Il2CppDumper/Outputs/StructGenerator.cs | 3 ++- Il2CppDumper/Program.cs | 11 +++++++---- Il2CppDumper/Utils/SectionHelper.cs | 11 ++++++----- Il2CppDumper/config.json | 4 +++- 14 files changed, 38 insertions(+), 24 deletions(-) diff --git a/Il2CppDumper/Config.cs b/Il2CppDumper/Config.cs index 4f4f109..9a83cfd 100644 --- a/Il2CppDumper/Config.cs +++ b/Il2CppDumper/Config.cs @@ -15,5 +15,7 @@ public bool RequireAnyKey = true; public bool ForceIl2CppVersion = false; public double ForceVersion = 24.3; + public bool ForceDump = false; + public bool NoRedirectedPointer = false; } } diff --git a/Il2CppDumper/ExecutableFormats/Elf.cs b/Il2CppDumper/ExecutableFormats/Elf.cs index a38149f..9d339ed 100644 --- a/Il2CppDumper/ExecutableFormats/Elf.cs +++ b/Il2CppDumper/ExecutableFormats/Elf.cs @@ -384,7 +384,7 @@ namespace Il2CppDumper } var data = dataList.ToArray(); var exec = execList.ToArray(); - var sectionHelper = new SectionHelper(this, methodCount, typeDefinitionsCount, maxMetadataUsages, imageCount); + var sectionHelper = new SectionHelper(this, methodCount, typeDefinitionsCount, metadataUsagesCount, imageCount); sectionHelper.SetSection(SearchSectionType.Exec, exec); sectionHelper.SetSection(SearchSectionType.Data, data); sectionHelper.SetSection(SearchSectionType.Bss, data); diff --git a/Il2CppDumper/ExecutableFormats/Elf64.cs b/Il2CppDumper/ExecutableFormats/Elf64.cs index 3e73929..b3e5009 100644 --- a/Il2CppDumper/ExecutableFormats/Elf64.cs +++ b/Il2CppDumper/ExecutableFormats/Elf64.cs @@ -328,7 +328,7 @@ namespace Il2CppDumper } var data = dataList.ToArray(); var exec = execList.ToArray(); - var sectionHelper = new SectionHelper(this, methodCount, typeDefinitionsCount, maxMetadataUsages, imageCount); + var sectionHelper = new SectionHelper(this, methodCount, typeDefinitionsCount, metadataUsagesCount, imageCount); sectionHelper.SetSection(SearchSectionType.Exec, exec); sectionHelper.SetSection(SearchSectionType.Data, data); sectionHelper.SetSection(SearchSectionType.Bss, data); diff --git a/Il2CppDumper/ExecutableFormats/Macho.cs b/Il2CppDumper/ExecutableFormats/Macho.cs index 7734877..e0e77da 100644 --- a/Il2CppDumper/ExecutableFormats/Macho.cs +++ b/Il2CppDumper/ExecutableFormats/Macho.cs @@ -197,7 +197,7 @@ namespace Il2CppDumper var data = sections.Where(x => x.sectname == "__const").ToArray(); var code = sections.Where(x => x.flags == 0x80000400).ToArray(); var bss = sections.Where(x => x.flags == 1u).ToArray(); - var sectionHelper = new SectionHelper(this, methodCount, typeDefinitionsCount, maxMetadataUsages, imageCount); + var sectionHelper = new SectionHelper(this, methodCount, typeDefinitionsCount, metadataUsagesCount, imageCount); sectionHelper.SetSection(SearchSectionType.Exec, code); sectionHelper.SetSection(SearchSectionType.Data, data); sectionHelper.SetSection(SearchSectionType.Bss, bss); diff --git a/Il2CppDumper/ExecutableFormats/Macho64.cs b/Il2CppDumper/ExecutableFormats/Macho64.cs index 4770f63..122f844 100644 --- a/Il2CppDumper/ExecutableFormats/Macho64.cs +++ b/Il2CppDumper/ExecutableFormats/Macho64.cs @@ -259,7 +259,7 @@ namespace Il2CppDumper var data = sections.Where(x => x.sectname == "__const" || x.sectname == "__cstring" || x.sectname == "__data").ToArray(); var code = sections.Where(x => x.flags == 0x80000400).ToArray(); var bss = sections.Where(x => x.flags == 1u).ToArray(); - var sectionHelper = new SectionHelper(this, methodCount, typeDefinitionsCount, maxMetadataUsages, imageCount); + var sectionHelper = new SectionHelper(this, methodCount, typeDefinitionsCount, metadataUsagesCount, imageCount); sectionHelper.SetSection(SearchSectionType.Exec, code); sectionHelper.SetSection(SearchSectionType.Data, data); sectionHelper.SetSection(SearchSectionType.Bss, bss); diff --git a/Il2CppDumper/ExecutableFormats/NSO.cs b/Il2CppDumper/ExecutableFormats/NSO.cs index bdeca45..f2bf513 100644 --- a/Il2CppDumper/ExecutableFormats/NSO.cs +++ b/Il2CppDumper/ExecutableFormats/NSO.cs @@ -322,7 +322,7 @@ namespace Il2CppDumper public override SectionHelper GetSectionHelper(int methodCount, int typeDefinitionsCount, int imageCount) { - var sectionHelper = new SectionHelper(this, methodCount, typeDefinitionsCount, maxMetadataUsages, imageCount); + var sectionHelper = new SectionHelper(this, methodCount, typeDefinitionsCount, metadataUsagesCount, imageCount); sectionHelper.SetSection(SearchSectionType.Exec, header.TextSegment); sectionHelper.SetSection(SearchSectionType.Data, header.DataSegment, header.RoDataSegment); sectionHelper.SetSection(SearchSectionType.Bss, header.BssSegment); diff --git a/Il2CppDumper/ExecutableFormats/PE.cs b/Il2CppDumper/ExecutableFormats/PE.cs index 5d31a2b..18f4d58 100644 --- a/Il2CppDumper/ExecutableFormats/PE.cs +++ b/Il2CppDumper/ExecutableFormats/PE.cs @@ -116,7 +116,7 @@ namespace Il2CppDumper break; } } - var sectionHelper = new SectionHelper(this, methodCount, typeDefinitionsCount, maxMetadataUsages, imageCount); + var sectionHelper = new SectionHelper(this, methodCount, typeDefinitionsCount, metadataUsagesCount, imageCount); var data = dataList.ToArray(); var exec = execList.ToArray(); sectionHelper.SetSection(SearchSectionType.Exec, ImageBase, exec); diff --git a/Il2CppDumper/ExecutableFormats/WebAssemblyMemory.cs b/Il2CppDumper/ExecutableFormats/WebAssemblyMemory.cs index 1585571..e96c3fa 100644 --- a/Il2CppDumper/ExecutableFormats/WebAssemblyMemory.cs +++ b/Il2CppDumper/ExecutableFormats/WebAssemblyMemory.cs @@ -60,7 +60,7 @@ namespace Il2CppDumper address = Length, addressEnd = long.MaxValue //hack }; - var sectionHelper = new SectionHelper(this, methodCount, typeDefinitionsCount, maxMetadataUsages, imageCount); + var sectionHelper = new SectionHelper(this, methodCount, typeDefinitionsCount, metadataUsagesCount, imageCount); sectionHelper.SetSection(SearchSectionType.Exec, exec); sectionHelper.SetSection(SearchSectionType.Data, data); sectionHelper.SetSection(SearchSectionType.Bss, bss); diff --git a/Il2CppDumper/Il2Cpp/Il2Cpp.cs b/Il2CppDumper/Il2Cpp/Il2Cpp.cs index ba82526..59535e5 100644 --- a/Il2CppDumper/Il2Cpp/Il2Cpp.cs +++ b/Il2CppDumper/Il2Cpp/Il2Cpp.cs @@ -26,7 +26,7 @@ namespace Il2CppDumper public Dictionary> methodDefinitionMethodSpecs = new Dictionary>(); public Dictionary methodSpecGenericMethodPointers = new Dictionary(); private bool fieldOffsetsArePointers; - protected long maxMetadataUsages; + protected long metadataUsagesCount; public Dictionary codeGenModules; public Dictionary codeGenModuleMethodPointers; public Dictionary> rgctxsDictionary; @@ -42,10 +42,10 @@ namespace Il2CppDumper protected Il2Cpp(Stream stream) : base(stream) { } - public void SetProperties(double version, long maxMetadataUsages) + public void SetProperties(double version, long metadataUsagesCount) { Version = version; - this.maxMetadataUsages = maxMetadataUsages; + this.metadataUsagesCount = metadataUsagesCount; } protected bool AutoPlusInit(ulong codeRegistration, ulong metadataRegistration) @@ -143,7 +143,7 @@ namespace Il2CppDumper } if (Version > 16 && Version < 27) { - metadataUsages = MapVATR(pMetadataRegistration.metadataUsages, maxMetadataUsages); + metadataUsages = MapVATR(pMetadataRegistration.metadataUsages, metadataUsagesCount); } if (Version >= 22) { diff --git a/Il2CppDumper/Il2Cpp/Metadata.cs b/Il2CppDumper/Il2Cpp/Metadata.cs index 129d023..35f32b2 100644 --- a/Il2CppDumper/Il2Cpp/Metadata.cs +++ b/Il2CppDumper/Il2Cpp/Metadata.cs @@ -28,7 +28,7 @@ namespace Il2CppDumper public int[] attributeTypes; public int[] interfaceIndices; public Dictionary> metadataUsageDic; - public long maxMetadataUsages; + public long metadataUsagesCount; public int[] nestedTypeIndices; public Il2CppEventDefinition[] eventDefs; public Il2CppGenericContainer[] genericContainers; @@ -221,13 +221,18 @@ namespace Il2CppDumper for (int i = 0; i < metadataUsageList.count; i++) { var offset = metadataUsageList.start + i; + if (offset >= metadataUsagePairs.Length) + { + continue; + } var metadataUsagePair = metadataUsagePairs[offset]; var usage = GetEncodedIndexType(metadataUsagePair.encodedSourceIndex); var decodedIndex = GetDecodedMethodIndex(metadataUsagePair.encodedSourceIndex); metadataUsageDic[(Il2CppMetadataUsage)usage][metadataUsagePair.destinationIndex] = decodedIndex; } } - maxMetadataUsages = metadataUsageDic.Max(x => x.Value.Select(y => y.Key).DefaultIfEmpty().Max()) + 1; + //metadataUsagesCount = metadataUsagePairs.Max(x => x.destinationIndex) + 1; + metadataUsagesCount = metadataUsageDic.Max(x => x.Value.Select(y => y.Key).DefaultIfEmpty().Max()) + 1; } public uint GetEncodedIndexType(uint index) diff --git a/Il2CppDumper/Outputs/StructGenerator.cs b/Il2CppDumper/Outputs/StructGenerator.cs index 66f4928..209191e 100644 --- a/Il2CppDumper/Outputs/StructGenerator.cs +++ b/Il2CppDumper/Outputs/StructGenerator.cs @@ -269,7 +269,8 @@ namespace Il2CppDumper foreach (var sec in sectionHelper.data) { il2Cpp.Position = sec.offset; - while (il2Cpp.Position < sec.offsetEnd - il2Cpp.PointerSize) + var end = Math.Min(sec.offsetEnd, il2Cpp.Length) - il2Cpp.PointerSize; + while (il2Cpp.Position < end) { var addr = il2Cpp.Position; var metadataValue = il2Cpp.ReadUIntPtr(); diff --git a/Il2CppDumper/Program.cs b/Il2CppDumper/Program.cs index 1e4a52f..7755b05 100644 --- a/Il2CppDumper/Program.cs +++ b/Il2CppDumper/Program.cs @@ -182,9 +182,9 @@ namespace Il2CppDumper break; } var version = config.ForceIl2CppVersion ? config.ForceVersion : metadata.Version; - il2Cpp.SetProperties(version, metadata.maxMetadataUsages); + il2Cpp.SetProperties(version, metadata.metadataUsagesCount); Console.WriteLine($"Il2Cpp Version: {il2Cpp.Version}"); - if (il2Cpp.CheckDump()) + if (config.ForceDump || il2Cpp.CheckDump()) { if (il2Cpp is ElfBase elf) { @@ -195,7 +195,10 @@ namespace Il2CppDumper { il2Cpp.ImageBase = DumpAddr; il2Cpp.IsDumped = true; - elf.Reload(); + if (!config.NoRedirectedPointer) + { + elf.Reload(); + } } } else @@ -214,7 +217,7 @@ namespace Il2CppDumper { Console.WriteLine("Use custom PE loader"); il2Cpp = PELoader.Load(il2cppPath); - il2Cpp.SetProperties(version, metadata.maxMetadataUsages); + il2Cpp.SetProperties(version, metadata.metadataUsagesCount); flag = il2Cpp.PlusSearch(metadata.methodDefs.Count(x => x.methodIndex >= 0), metadata.typeDefs.Length, metadata.imageDefs.Length); } } diff --git a/Il2CppDumper/Utils/SectionHelper.cs b/Il2CppDumper/Utils/SectionHelper.cs index 04e392a..7de135b 100644 --- a/Il2CppDumper/Utils/SectionHelper.cs +++ b/Il2CppDumper/Utils/SectionHelper.cs @@ -9,18 +9,18 @@ namespace Il2CppDumper private Il2Cpp il2Cpp; private int methodCount; private int typeDefinitionsCount; - private long maxMetadataUsages; + private long metadataUsagesCount; private int imageCount; public List exec; public List data; public List bss; - public SectionHelper(Il2Cpp il2Cpp, int methodCount, int typeDefinitionsCount, long maxMetadataUsages, int imageCount) + public SectionHelper(Il2Cpp il2Cpp, int methodCount, int typeDefinitionsCount, long metadataUsagesCount, int imageCount) { this.il2Cpp = il2Cpp; this.methodCount = methodCount; this.typeDefinitionsCount = typeDefinitionsCount; - this.maxMetadataUsages = maxMetadataUsages; + this.metadataUsagesCount = metadataUsagesCount; this.imageCount = imageCount; } @@ -231,7 +231,7 @@ namespace Il2CppDumper var pointer = il2Cpp.MapVATR(il2Cpp.ReadUIntPtr()); if (CheckPointerRangeDataRa(pointer)) { - var pointers = il2Cpp.ReadClassArray(pointer, maxMetadataUsages); + var pointers = il2Cpp.ReadClassArray(pointer, metadataUsagesCount); if (CheckPointerRangeBssVa(pointers)) { return addr - il2Cpp.PointerSize * 12 - section.offset + section.address; @@ -375,7 +375,8 @@ namespace Il2CppDumper foreach (var dataSec in data) { il2Cpp.Position = dataSec.offset; - while (il2Cpp.Position < dataSec.offsetEnd - il2Cpp.PointerSize) + var end = Math.Min(dataSec.offsetEnd, il2Cpp.Length) - il2Cpp.PointerSize; + while (il2Cpp.Position < end) { var offset = il2Cpp.Position; if (il2Cpp.ReadUIntPtr() == addr) diff --git a/Il2CppDumper/config.json b/Il2CppDumper/config.json index 474cb72..03184fc 100644 --- a/Il2CppDumper/config.json +++ b/Il2CppDumper/config.json @@ -11,5 +11,7 @@ "DummyDllAddToken": true, "RequireAnyKey": true, "ForceIl2CppVersion": false, - "ForceVersion": 16 + "ForceVersion": 16, + "ForceDump": false, + "NoRedirectedPointer": false } \ No newline at end of file