修改构造函数逻辑

This commit is contained in:
Perfare 2020-04-09 13:02:06 +08:00
parent aa9d43ada0
commit d30070c60f
12 changed files with 30 additions and 46 deletions

View file

@ -25,7 +25,7 @@ namespace Il2CppDumper
private static readonly string ARMFeatureBytes = "? 0x10 ? 0xE7 ? 0x00 ? 0xE0 ? 0x20 ? 0xE0"; private static readonly string ARMFeatureBytes = "? 0x10 ? 0xE7 ? 0x00 ? 0xE0 ? 0x20 ? 0xE0";
private static readonly string X86FeatureBytes = "? 0x10 ? 0xE7 ? 0x00 ? 0xE0 ? 0x20 ? 0xE0"; //TODO private static readonly string X86FeatureBytes = "? 0x10 ? 0xE7 ? 0x00 ? 0xE0 ? 0x20 ? 0xE0"; //TODO
public Elf(Stream stream, float version, long maxMetadataUsages) : base(stream, version, maxMetadataUsages) public Elf(Stream stream) : base(stream)
{ {
Is32Bit = true; Is32Bit = true;
elfHeader = ReadClass<Elf32_Ehdr>(); elfHeader = ReadClass<Elf32_Ehdr>();

View file

@ -17,7 +17,7 @@ namespace Il2CppDumper
private bool isDumped; private bool isDumped;
private ulong dumpAddr; private ulong dumpAddr;
public Elf64(Stream stream, float version, long maxMetadataUsages) : base(stream, version, maxMetadataUsages) public Elf64(Stream stream) : base(stream)
{ {
elfHeader = ReadClass<Elf64_Ehdr>(); elfHeader = ReadClass<Elf64_Ehdr>();
programSegment = ReadClassArray<Elf64_Phdr>(elfHeader.e_phoff, elfHeader.e_phnum); programSegment = ReadClassArray<Elf64_Phdr>(elfHeader.e_phoff, elfHeader.e_phnum);

View file

@ -14,7 +14,7 @@ namespace Il2CppDumper
private static readonly byte[] FeatureBytes2 = { 0x78, 0x44, 0x79, 0x44 };//ADD R0, PC and ADD R1, PC private static readonly byte[] FeatureBytes2 = { 0x78, 0x44, 0x79, 0x44 };//ADD R0, PC and ADD R1, PC
private ulong vmaddr; private ulong vmaddr;
public Macho(Stream stream, float version, long maxMetadataUsages) : base(stream, version, maxMetadataUsages) public Macho(Stream stream) : base(stream)
{ {
Is32Bit = true; Is32Bit = true;
Position += 16; //skip magic, cputype, cpusubtype, filetype Position += 16; //skip magic, cputype, cpusubtype, filetype

View file

@ -14,7 +14,7 @@ namespace Il2CppDumper
private static readonly byte[] FeatureBytes2 = { 0x3, 0x0, 0x80, 0x52 };//MOV W3, #0 private static readonly byte[] FeatureBytes2 = { 0x3, 0x0, 0x80, 0x52 };//MOV W3, #0
private ulong vmaddr; private ulong vmaddr;
public Macho64(Stream stream, float version, long maxMetadataUsages) : base(stream, version, maxMetadataUsages) public Macho64(Stream stream) : base(stream)
{ {
Position += 16; //skip magic, cputype, cpusubtype, filetype Position += 16; //skip magic, cputype, cpusubtype, filetype
var ncmds = ReadUInt32(); var ncmds = ReadUInt32();

View file

@ -16,7 +16,7 @@ namespace Il2CppDumper
private bool isCompressed => isTextCompressed || isRoDataCompressed || isDataCompressed; private bool isCompressed => isTextCompressed || isRoDataCompressed || isDataCompressed;
public NSO(Stream stream, float version, long maxMetadataUsages) : base(stream, version, maxMetadataUsages) public NSO(Stream stream) : base(stream)
{ {
header = new NSOHeader(); header = new NSOHeader();
header.Magic = ReadUInt32(); header.Magic = ReadUInt32();
@ -200,7 +200,7 @@ namespace Il2CppDumper
} }
writer.Flush(); writer.Flush();
unCompressedStream.Position = 0; unCompressedStream.Position = 0;
return new NSO(unCompressedStream, Version, maxMetadataUsages); return new NSO(unCompressedStream);
} }
return this; return this;
} }

View file

@ -11,7 +11,7 @@ namespace Il2CppDumper
private SectionHeader[] sections; private SectionHeader[] sections;
private ulong imageBase; private ulong imageBase;
public PE(Stream stream, float version, long maxMetadataUsages) : base(stream, version, maxMetadataUsages) public PE(Stream stream) : base(stream)
{ {
var dosHeader = ReadClass<DosHeader>(); var dosHeader = ReadClass<DosHeader>();
if (dosHeader.Magic != 0x5A4D) if (dosHeader.Magic != 0x5A4D)

View file

@ -33,7 +33,9 @@ namespace Il2CppDumper
public abstract bool PlusSearch(int methodCount, int typeDefinitionsCount); public abstract bool PlusSearch(int methodCount, int typeDefinitionsCount);
public abstract bool SymbolSearch(); public abstract bool SymbolSearch();
protected Il2Cpp(Stream stream, float version, long maxMetadataUsages) : base(stream) protected Il2Cpp(Stream stream) : base(stream) { }
public void SetProperties(float version, long maxMetadataUsages)
{ {
Version = version; Version = version;
this.maxMetadataUsages = maxMetadataUsages; this.maxMetadataUsages = maxMetadataUsages;

View file

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;net46</TargetFrameworks> <TargetFrameworks>net472;netcoreapp3.1</TargetFrameworks>
<Version>1.0.0</Version> <Version>1.0.0</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion> <AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion> <FileVersion>1.0.0.0</FileVersion>
@ -14,7 +14,7 @@
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net46'"> <ItemGroup Condition="'$(TargetFramework)' == 'net472'">
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
</ItemGroup> </ItemGroup>

View file

@ -87,7 +87,8 @@ namespace Il2CppDumper
{ {
Console.WriteLine(e); Console.WriteLine(e);
} }
if (config.RequireAnyKey) { if (config.RequireAnyKey)
{
Console.WriteLine("Press any key to exit..."); Console.WriteLine("Press any key to exit...");
Console.ReadKey(true); Console.ReadKey(true);
} }
@ -108,28 +109,29 @@ namespace Il2CppDumper
Console.WriteLine("Initializing metadata..."); Console.WriteLine("Initializing metadata...");
metadata = new Metadata(new MemoryStream(metadataBytes)); metadata = new Metadata(new MemoryStream(metadataBytes));
Console.WriteLine($"Metadata Version: {metadata.Version}"); Console.WriteLine($"Metadata Version: {metadata.Version}");
//判断il2cpp的magic
Console.WriteLine("Initializing il2cpp file...");
var il2cppMagic = BitConverter.ToUInt32(il2cppBytes, 0); var il2cppMagic = BitConverter.ToUInt32(il2cppBytes, 0);
var isElf = false; var il2CppMemory = new MemoryStream(il2cppBytes);
var isPE = false;
var is64bit = false;
var isNSO = false;
switch (il2cppMagic) switch (il2cppMagic)
{ {
default: default:
throw new NotSupportedException("ERROR: il2cpp file not supported."); throw new NotSupportedException("ERROR: il2cpp file not supported.");
case 0x304F534E: case 0x304F534E:
isNSO = true; var nso = new NSO(il2CppMemory);
is64bit = true; il2Cpp = nso.UnCompress();
break; break;
case 0x905A4D: //PE case 0x905A4D: //PE
isPE = true; il2Cpp = new PE(il2CppMemory);
break; break;
case 0x464c457f: //ELF case 0x464c457f: //ELF
isElf = true;
if (il2cppBytes[4] == 2) //ELF64 if (il2cppBytes[4] == 2) //ELF64
{ {
is64bit = true; il2Cpp = new Elf64(il2CppMemory);
}
else
{
il2Cpp = new Elf(il2CppMemory);
} }
break; break;
case 0xCAFEBABE: //FAT Mach-O case 0xCAFEBABE: //FAT Mach-O
@ -146,40 +148,20 @@ namespace Il2CppDumper
var index = int.Parse(key.KeyChar.ToString()) - 1; var index = int.Parse(key.KeyChar.ToString()) - 1;
var magic = machofat.fats[index % 2].magic; var magic = machofat.fats[index % 2].magic;
il2cppBytes = machofat.GetMacho(index % 2); il2cppBytes = machofat.GetMacho(index % 2);
il2CppMemory = new MemoryStream(il2cppBytes);
if (magic == 0xFEEDFACF) if (magic == 0xFEEDFACF)
goto case 0xFEEDFACF; goto case 0xFEEDFACF;
else else
goto case 0xFEEDFACE; goto case 0xFEEDFACE;
case 0xFEEDFACF: // 64bit Mach-O case 0xFEEDFACF: // 64bit Mach-O
is64bit = true; il2Cpp = new Macho64(il2CppMemory);
break; break;
case 0xFEEDFACE: // 32bit Mach-O case 0xFEEDFACE: // 32bit Mach-O
il2Cpp = new Macho(il2CppMemory);
break; break;
} }
var version = config.ForceIl2CppVersion ? config.ForceVersion : metadata.Version; var version = config.ForceIl2CppVersion ? config.ForceVersion : metadata.Version;
Console.WriteLine("Initializing il2cpp file..."); il2Cpp.SetProperties(version, metadata.maxMetadataUsages);
var il2CppMemory = new MemoryStream(il2cppBytes);
if (isNSO)
{
var nso = new NSO(il2CppMemory, version, metadata.maxMetadataUsages);
il2Cpp = nso.UnCompress();
}
else if (isPE)
{
il2Cpp = new PE(il2CppMemory, version, metadata.maxMetadataUsages);
}
else if (isElf)
{
if (is64bit)
il2Cpp = new Elf64(il2CppMemory, version, metadata.maxMetadataUsages);
else
il2Cpp = new Elf(il2CppMemory, version, metadata.maxMetadataUsages);
}
else if (is64bit)
il2Cpp = new Macho64(il2CppMemory, version, metadata.maxMetadataUsages);
else
il2Cpp = new Macho(il2CppMemory, version, metadata.maxMetadataUsages);
Console.WriteLine($"Il2Cpp Version: {il2Cpp.Version}"); Console.WriteLine($"Il2Cpp Version: {il2Cpp.Version}");
Console.WriteLine("Searching..."); Console.WriteLine("Searching...");