mirror of
https://github.com/Perfare/Il2CppDumper.git
synced 2025-01-25 02:03:02 -03:00
细节优化
This commit is contained in:
parent
79f60bd73a
commit
021dcce9c7
11 changed files with 174 additions and 175 deletions
|
@ -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<Elf32_Sym>(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<Elf32_Sym>(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;
|
||||
|
|
|
@ -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<Elf64_Sym>(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<Elf64_Sym>(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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -39,7 +39,7 @@ namespace Il2CppDumper
|
|||
metadataHeader = ReadClass<Il2CppGlobalMetadataHeader>();
|
||||
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<Il2CppImageDefinition>(metadataHeader.imagesOffset, metadataHeader.imagesCount);
|
||||
typeDefs = ReadMetadataClassArray<Il2CppTypeDefinition>(metadataHeader.typeDefinitionsOffset, metadataHeader.typeDefinitionsCount);
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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<ArrayLengthAttribute>();
|
||||
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));
|
||||
}
|
||||
|
|
|
@ -53,7 +53,6 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="Attributes\ArrayLengthAttribute.cs" />
|
||||
<Compile Include="Extensions\BoyerMooreHorspool.cs" />
|
||||
<Compile Include="ExecutableFormats\ElfConstants.cs" />
|
||||
<Compile Include="Extensions\HexExtensions.cs" />
|
||||
<Compile Include="Outputs\DummyAssemblyExporter.cs" />
|
||||
<Compile Include="Outputs\Il2CppDecompiler.cs" />
|
||||
|
@ -70,7 +69,6 @@
|
|||
<Compile Include="Utils\DummyAssemblyGenerator.cs" />
|
||||
<Compile Include="ExecutableFormats\Elf.cs" />
|
||||
<Compile Include="ExecutableFormats\Elf64.cs" />
|
||||
<Compile Include="ExecutableFormats\Elf64Class.cs" />
|
||||
<Compile Include="ExecutableFormats\Il2CppClass.cs" />
|
||||
<Compile Include="ExecutableFormats\Il2Cpp.cs" />
|
||||
<Compile Include="ExecutableFormats\Macho.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;
|
||||
}
|
||||
|
|
|
@ -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<SearchSection>();
|
||||
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<SearchSection>();
|
||||
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<SearchSection>();
|
||||
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<SearchSection>();
|
||||
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<SearchSection>();
|
||||
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<SearchSection>();
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue