diff --git a/Il2CppDumper/ExecutableFormats/Elf.cs b/Il2CppDumper/ExecutableFormats/Elf.cs index 1220a91..53fb5e4 100644 --- a/Il2CppDumper/ExecutableFormats/Elf.cs +++ b/Il2CppDumper/ExecutableFormats/Elf.cs @@ -54,7 +54,7 @@ namespace Il2CppDumper RelocationProcessing(); if (CheckProtection()) { - Console.WriteLine("ERROR: This file is protected."); + Console.WriteLine("ERROR: This file may be protected."); } } } @@ -185,10 +185,17 @@ namespace Il2CppDumper private void ReadSymbol() { - var dynsymOffset = MapVATR(dynamicSection.First(x => x.d_tag == DT_SYMTAB).d_un); - var dynstrOffset = MapVATR(dynamicSection.First(x => x.d_tag == DT_STRTAB).d_un); - var dynsymSize = dynstrOffset - dynsymOffset; - symbolTable = ReadClassArray(dynsymOffset, (long)dynsymSize / 16); + try + { + var dynsymOffset = MapVATR(dynamicSection.First(x => x.d_tag == DT_SYMTAB).d_un); + var dynstrOffset = MapVATR(dynamicSection.First(x => x.d_tag == DT_STRTAB).d_un); + var dynsymSize = dynstrOffset - dynsymOffset; + symbolTable = ReadClassArray(dynsymOffset, (long)dynsymSize / 16); + } + catch + { + // ignored + } } private void RelocationProcessing() @@ -243,7 +250,7 @@ namespace Il2CppDumper return true; } } - if (sectionTable.Any(x => x.sh_type == SHT_LOUSER)) + if (sectionTable != null && sectionTable.Any(x => x.sh_type == SHT_LOUSER)) { Console.WriteLine("WARNING: find SHT_LOUSER section"); return true; diff --git a/Il2CppDumper/ExecutableFormats/Elf64.cs b/Il2CppDumper/ExecutableFormats/Elf64.cs index 7a5c756..e0e0801 100644 --- a/Il2CppDumper/ExecutableFormats/Elf64.cs +++ b/Il2CppDumper/ExecutableFormats/Elf64.cs @@ -45,7 +45,7 @@ namespace Il2CppDumper RelocationProcessing(); if (CheckProtection()) { - Console.WriteLine("ERROR: This file is protected."); + Console.WriteLine("ERROR: This file may be protected."); } } } @@ -128,10 +128,17 @@ namespace Il2CppDumper private void ReadSymbol() { - var dynsymOffset = MapVATR(dynamicSection.First(x => x.d_tag == DT_SYMTAB).d_un); - var dynstrOffset = MapVATR(dynamicSection.First(x => x.d_tag == DT_STRTAB).d_un); - var dynsymSize = dynstrOffset - dynsymOffset; - symbolTable = ReadClassArray(dynsymOffset, (long)dynsymSize / 24L); + try + { + var dynsymOffset = MapVATR(dynamicSection.First(x => x.d_tag == DT_SYMTAB).d_un); + var dynstrOffset = MapVATR(dynamicSection.First(x => x.d_tag == DT_STRTAB).d_un); + var dynsymSize = dynstrOffset - dynsymOffset; + symbolTable = ReadClassArray(dynsymOffset, (long)dynsymSize / 24L); + } + catch + { + // ignored + } } private void RelocationProcessing() @@ -190,7 +197,7 @@ namespace Il2CppDumper return true; } } - if (sectionTable.Any(x => x.sh_type == SHT_LOUSER)) + if (sectionTable != null && sectionTable.Any(x => x.sh_type == SHT_LOUSER)) { Console.WriteLine("WARNING: find SHT_LOUSER section"); return true; diff --git a/Il2CppDumper/ExecutableFormats/Elf64Class.cs b/Il2CppDumper/ExecutableFormats/Elf64Class.cs deleted file mode 100644 index 328c0ba..0000000 --- a/Il2CppDumper/ExecutableFormats/Elf64Class.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Il2CppDumper -{ - public class Elf64_Ehdr - { - public uint ei_mag; - public byte ei_class; - public byte ei_data; - public byte ei_version; - public byte ei_osabi; - public byte ei_abiversion; - [ArrayLength(Length = 7)] - public byte[] ei_pad; - public ushort e_type; - public ushort e_machine; - public uint e_version; - public ulong e_entry; - public ulong e_phoff; - public ulong e_shoff; - public uint e_flags; - public ushort e_ehsize; - public ushort e_phentsize; - public ushort e_phnum; - public ushort e_shentsize; - public ushort e_shnum; - public ushort e_shtrndx; - } - - public class Elf64_Phdr - { - public uint p_type; - public uint p_flags; - public ulong p_offset; - public ulong p_vaddr; - public ulong p_paddr; - public ulong p_filesz; - public ulong p_memsz; - public ulong p_align; - } - - public class Elf64_Shdr - { - public uint sh_name; - public uint sh_type; - public ulong sh_flags; - public ulong sh_addr; - public ulong sh_offset; - public ulong sh_size; - public uint sh_link; - public uint sh_info; - public ulong sh_addralign; - public ulong sh_entsize; - } - - public class Elf64_Sym - { - public uint st_name; - public byte st_info; - public byte st_other; - public ushort st_shndx; - public ulong st_value; - public ulong st_size; - } - - public class Elf64_Dyn - { - public long d_tag; - public ulong d_un; - } - - public class Elf64_Rela - { - public ulong r_offset; - public ulong r_info; - public long r_addend; - } -} diff --git a/Il2CppDumper/ExecutableFormats/ElfClass.cs b/Il2CppDumper/ExecutableFormats/ElfClass.cs index a9f9eca..99c3bb1 100644 --- a/Il2CppDumper/ExecutableFormats/ElfClass.cs +++ b/Il2CppDumper/ExecutableFormats/ElfClass.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; namespace Il2CppDumper { @@ -78,4 +74,114 @@ namespace Il2CppDumper public uint r_offset; public uint r_info; } + + public class Elf64_Ehdr + { + public uint ei_mag; + public byte ei_class; + public byte ei_data; + public byte ei_version; + public byte ei_osabi; + public byte ei_abiversion; + [ArrayLength(Length = 7)] + public byte[] ei_pad; + public ushort e_type; + public ushort e_machine; + public uint e_version; + public ulong e_entry; + public ulong e_phoff; + public ulong e_shoff; + public uint e_flags; + public ushort e_ehsize; + public ushort e_phentsize; + public ushort e_phnum; + public ushort e_shentsize; + public ushort e_shnum; + public ushort e_shtrndx; + } + + public class Elf64_Phdr + { + public uint p_type; + public uint p_flags; + public ulong p_offset; + public ulong p_vaddr; + public ulong p_paddr; + public ulong p_filesz; + public ulong p_memsz; + public ulong p_align; + } + + public class Elf64_Shdr + { + public uint sh_name; + public uint sh_type; + public ulong sh_flags; + public ulong sh_addr; + public ulong sh_offset; + public ulong sh_size; + public uint sh_link; + public uint sh_info; + public ulong sh_addralign; + public ulong sh_entsize; + } + + public class Elf64_Sym + { + public uint st_name; + public byte st_info; + public byte st_other; + public ushort st_shndx; + public ulong st_value; + public ulong st_size; + } + + public class Elf64_Dyn + { + public long d_tag; + public ulong d_un; + } + + public class Elf64_Rela + { + public ulong r_offset; + public ulong r_info; + public long r_addend; + } + + public static class ElfConstants + { + public const int EM_386 = 3; + public const int EM_ARM = 40; + + public const int PT_LOAD = 1; + public const int PT_DYNAMIC = 2; + + public const int PF_X = 1; + + public const int DT_PLTGOT = 3; + public const int DT_HASH = 4; + public const int DT_STRTAB = 5; + public const int DT_SYMTAB = 6; + public const int DT_RELA = 7; + public const int DT_RELASZ = 8; + public const int DT_RELAENT = 9; + public const int DT_SYMENT = 11; + public const int DT_INIT = 12; + public const int DT_REL = 17; + public const int DT_RELSZ = 18; + public const int DT_JMPREL = 23; + public const int DT_INIT_ARRAY = 25; + public const int DT_FINI_ARRAY = 26; + public const int DT_INIT_ARRAYSZ = 27; + + public const uint SHT_LOUSER = 0x80000000; + + public const int R_ARM_ABS32 = 2; + + public const int R_386_32 = 1; + + public const int R_AARCH64_ABS64 = 257; + public const int R_AARCH64_RELATIVE = 1027; + } } diff --git a/Il2CppDumper/ExecutableFormats/ElfConstants.cs b/Il2CppDumper/ExecutableFormats/ElfConstants.cs deleted file mode 100644 index fb8b9e6..0000000 --- a/Il2CppDumper/ExecutableFormats/ElfConstants.cs +++ /dev/null @@ -1,38 +0,0 @@ -namespace Il2CppDumper -{ - static class ElfConstants - { - public const int EM_386 = 3; - public const int EM_ARM = 40; - - public const int PT_LOAD = 1; - public const int PT_DYNAMIC = 2; - - public const int PF_X = 1; - - public const int DT_PLTGOT = 3; - public const int DT_HASH = 4; - public const int DT_STRTAB = 5; - public const int DT_SYMTAB = 6; - public const int DT_RELA = 7; - public const int DT_RELASZ = 8; - public const int DT_RELAENT = 9; - public const int DT_SYMENT = 11; - public const int DT_INIT = 12; - public const int DT_REL = 17; - public const int DT_RELSZ = 18; - public const int DT_JMPREL = 23; - public const int DT_INIT_ARRAY = 25; - public const int DT_FINI_ARRAY = 26; - public const int DT_INIT_ARRAYSZ = 27; - - public const uint SHT_LOUSER = 0x80000000; - - public const int R_ARM_ABS32 = 2; - - public const int R_386_32 = 1; - - public const int R_AARCH64_ABS64 = 257; - public const int R_AARCH64_RELATIVE = 1027; - } -} \ No newline at end of file diff --git a/Il2CppDumper/ExecutableFormats/Metadata.cs b/Il2CppDumper/ExecutableFormats/Metadata.cs index 077833d..7da39f1 100644 --- a/Il2CppDumper/ExecutableFormats/Metadata.cs +++ b/Il2CppDumper/ExecutableFormats/Metadata.cs @@ -39,7 +39,7 @@ namespace Il2CppDumper metadataHeader = ReadClass(); if (metadataHeader.sanity != 0xFAB11BAF) { - throw new Exception("ERROR: Metadata file supplied is not valid metadata file."); + throw new InvalidDataException("ERROR: Metadata file supplied is not valid metadata file."); } switch (metadataHeader.version) { @@ -52,7 +52,7 @@ namespace Il2CppDumper case 24: break; default: - throw new Exception($"ERROR: Metadata file supplied is not a supported version[{version}]."); + throw new NotSupportedException($"ERROR: Metadata file supplied is not a supported version[{version}]."); } imageDefs = ReadMetadataClassArray(metadataHeader.imagesOffset, metadataHeader.imagesCount); typeDefs = ReadMetadataClassArray(metadataHeader.typeDefinitionsOffset, metadataHeader.typeDefinitionsCount); diff --git a/Il2CppDumper/ExecutableFormats/NSO.cs b/Il2CppDumper/ExecutableFormats/NSO.cs index b14afc1..a620100 100644 --- a/Il2CppDumper/ExecutableFormats/NSO.cs +++ b/Il2CppDumper/ExecutableFormats/NSO.cs @@ -90,10 +90,10 @@ namespace Il2CppDumper } } - public override ulong MapVATR(ulong uiAddr) + public override ulong MapVATR(ulong addr) { - var segment = segments.First(x => uiAddr >= x.MemoryOffset && uiAddr <= x.MemoryOffset + x.DecompressedSize); - return uiAddr - segment.MemoryOffset + segment.FileOffset; + var segment = segments.First(x => addr >= x.MemoryOffset && addr <= x.MemoryOffset + x.DecompressedSize); + return addr - segment.MemoryOffset + segment.FileOffset; } public override bool Search() diff --git a/Il2CppDumper/IO/BinaryStream.cs b/Il2CppDumper/IO/BinaryStream.cs index 8004c14..0804359 100644 --- a/Il2CppDumper/IO/BinaryStream.cs +++ b/Il2CppDumper/IO/BinaryStream.cs @@ -138,26 +138,27 @@ namespace Il2CppDumper if (version < versionAttribute.Min || version > versionAttribute.Max) continue; } - if (i.FieldType.IsPrimitive) + var fieldType = i.FieldType; + if (fieldType.IsPrimitive) { - i.SetValue(t, ReadPrimitive(i.FieldType)); + i.SetValue(t, ReadPrimitive(fieldType)); } - else if (i.FieldType.IsArray) + else if (fieldType.IsArray) { var arrayLengthAttribute = i.GetCustomAttribute(); - if (!genericMethodCache.TryGetValue(i.FieldType, out var methodInfo)) + if (!genericMethodCache.TryGetValue(fieldType, out var methodInfo)) { - methodInfo = readClassArray.MakeGenericMethod(i.FieldType.GetElementType()); - genericMethodCache.Add(i.FieldType, methodInfo); + methodInfo = readClassArray.MakeGenericMethod(fieldType.GetElementType()); + genericMethodCache.Add(fieldType, methodInfo); } i.SetValue(t, methodInfo.Invoke(this, new object[] { arrayLengthAttribute.Length })); } else { - if (!genericMethodCache.TryGetValue(i.FieldType, out var methodInfo)) + if (!genericMethodCache.TryGetValue(fieldType, out var methodInfo)) { - methodInfo = readClass.MakeGenericMethod(i.FieldType); - genericMethodCache.Add(i.FieldType, methodInfo); + methodInfo = readClass.MakeGenericMethod(fieldType); + genericMethodCache.Add(fieldType, methodInfo); } i.SetValue(t, methodInfo.Invoke(this, null)); } diff --git a/Il2CppDumper/Il2CppDumper.csproj b/Il2CppDumper/Il2CppDumper.csproj index f76dac0..12e8242 100644 --- a/Il2CppDumper/Il2CppDumper.csproj +++ b/Il2CppDumper/Il2CppDumper.csproj @@ -53,7 +53,6 @@ - @@ -70,7 +69,6 @@ - diff --git a/Il2CppDumper/Program.cs b/Il2CppDumper/Program.cs index 7fbe2f5..ff1fb49 100644 --- a/Il2CppDumper/Program.cs +++ b/Il2CppDumper/Program.cs @@ -106,7 +106,7 @@ namespace Il2CppDumper var sanity = BitConverter.ToUInt32(metadataBytes, 0); if (sanity != 0xFAB11BAF) { - throw new Exception("ERROR: Metadata file supplied is not valid metadata file."); + throw new InvalidDataException("ERROR: Metadata file supplied is not valid metadata file."); } float fixedMetadataVersion; var metadataVersion = BitConverter.ToInt32(metadataBytes, 4); @@ -136,7 +136,7 @@ namespace Il2CppDumper } catch { - throw new Exception("You must enter the correct Unity version number"); + throw new InvalidDataException("You must enter the correct Unity version number"); } } else @@ -154,7 +154,7 @@ namespace Il2CppDumper switch (il2cppMagic) { default: - throw new Exception("ERROR: il2cpp file not supported."); + throw new NotSupportedException("ERROR: il2cpp file not supported."); case 0x304F534E: isNSO = true; is64bit = true; @@ -255,11 +255,16 @@ namespace Il2CppDumper return false; } if (!flag) - throw new Exception(); + { + Console.WriteLine("ERROR: Can't use this mode to process file, try another mode."); + return false; + } } - catch + catch (Exception e) { - throw new Exception("ERROR: Can't use this mode to process file, try another mode."); + Console.WriteLine(e); + Console.WriteLine("ERROR: An error occurred while processing."); + return false; } return true; } diff --git a/Il2CppDumper/Utils/PlusSearch.cs b/Il2CppDumper/Utils/PlusSearch.cs index 8330d3e..7665636 100644 --- a/Il2CppDumper/Utils/PlusSearch.cs +++ b/Il2CppDumper/Utils/PlusSearch.cs @@ -22,7 +22,7 @@ namespace Il2CppDumper this.maxMetadataUsages = maxMetadataUsages; } - public void SetSection(SearchSectionType type, params Elf32_Phdr[] sections) + public void SetSection(SearchSectionType type, Elf32_Phdr[] sections) { var secs = new List(); foreach (var section in sections) @@ -41,7 +41,7 @@ namespace Il2CppDumper SetSection(type, secs); } - public void SetSection(SearchSectionType type, params Elf64_Phdr[] sections) + public void SetSection(SearchSectionType type, Elf64_Phdr[] sections) { var secs = new List(); foreach (var section in sections) @@ -60,7 +60,7 @@ namespace Il2CppDumper SetSection(type, secs); } - public void SetSection(SearchSectionType type, params MachoSection[] sections) + public void SetSection(SearchSectionType type, MachoSection[] sections) { var secs = new List(); foreach (var section in sections) @@ -79,7 +79,7 @@ namespace Il2CppDumper SetSection(type, secs); } - public void SetSection(SearchSectionType type, params MachoSection64Bit[] sections) + public void SetSection(SearchSectionType type, MachoSection64Bit[] sections) { var secs = new List(); foreach (var section in sections) @@ -98,7 +98,7 @@ namespace Il2CppDumper SetSection(type, secs); } - public void SetSection(SearchSectionType type, ulong imageBase, params SectionHeader[] sections) + public void SetSection(SearchSectionType type, ulong imageBase, SectionHeader[] sections) { var secs = new List(); foreach (var section in sections) @@ -117,22 +117,16 @@ namespace Il2CppDumper SetSection(type, secs); } - public void SetSection(SearchSectionType type, params NSOSegmentHeader[] sections) + public void SetSection(SearchSectionType type, NSOSegmentHeader section) { var secs = new List(); - foreach (var section in sections) + secs.Add(new SearchSection { - if (section != null) - { - secs.Add(new SearchSection - { - offset = section.FileOffset, - offsetEnd = section.FileOffset + section.DecompressedSize, - address = section.MemoryOffset, - addressEnd = section.MemoryOffset + section.DecompressedSize - }); - } - } + offset = section.FileOffset, + offsetEnd = section.FileOffset + section.DecompressedSize, + address = section.MemoryOffset, + addressEnd = section.MemoryOffset + section.DecompressedSize + }); SetSection(type, secs); }