修改构造函数逻辑

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 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;
elfHeader = ReadClass<Elf32_Ehdr>();

View file

@ -17,7 +17,7 @@ namespace Il2CppDumper
private bool isDumped;
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>();
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 ulong vmaddr;
public Macho(Stream stream, float version, long maxMetadataUsages) : base(stream, version, maxMetadataUsages)
public Macho(Stream stream) : base(stream)
{
Is32Bit = true;
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 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
var ncmds = ReadUInt32();

View file

@ -16,7 +16,7 @@ namespace Il2CppDumper
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.Magic = ReadUInt32();
@ -200,7 +200,7 @@ namespace Il2CppDumper
}
writer.Flush();
unCompressedStream.Position = 0;
return new NSO(unCompressedStream, Version, maxMetadataUsages);
return new NSO(unCompressedStream);
}
return this;
}

View file

@ -11,7 +11,7 @@ namespace Il2CppDumper
private SectionHeader[] sections;
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>();
if (dosHeader.Magic != 0x5A4D)

View file

@ -33,7 +33,9 @@ namespace Il2CppDumper
public abstract bool PlusSearch(int methodCount, int typeDefinitionsCount);
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;
this.maxMetadataUsages = maxMetadataUsages;

View file

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

View file

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