Skip to content

Commit

Permalink
优化v27以上Metadata处理
Browse files Browse the repository at this point in the history
  • Loading branch information
Perfare committed Jun 23, 2021
1 parent 2d70941 commit 1852783
Show file tree
Hide file tree
Showing 11 changed files with 235 additions and 186 deletions.
66 changes: 36 additions & 30 deletions Il2CppDumper/ExecutableFormats/Elf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,36 +150,9 @@ public override bool Search()

public override bool PlusSearch(int methodCount, int typeDefinitionsCount, int imageCount)
{
var dataList = new List<Elf32_Phdr>();
var execList = new List<Elf32_Phdr>();
foreach (var phdr in programSegment)
{
if (phdr.p_memsz != 0ul)
{
switch (phdr.p_flags)
{
case 1u: //PF_X
case 3u:
case 5u:
case 7u:
execList.Add(phdr);
break;
case 2u: //PF_W && PF_R
case 4u:
case 6u:
dataList.Add(phdr);
break;
}
}
}
var data = dataList.ToArray();
var exec = execList.ToArray();
var plusSearch = new PlusSearch(this, methodCount, typeDefinitionsCount, maxMetadataUsages, imageCount);
plusSearch.SetSection(SearchSectionType.Exec, exec);
plusSearch.SetSection(SearchSectionType.Data, data);
plusSearch.SetSection(SearchSectionType.Bss, data);
var codeRegistration = plusSearch.FindCodeRegistration();
var metadataRegistration = plusSearch.FindMetadataRegistration();
var sectionHelper = GetSectionHelper(methodCount, typeDefinitionsCount, imageCount);
var codeRegistration = sectionHelper.FindCodeRegistration();
var metadataRegistration = sectionHelper.FindMetadataRegistration();
return AutoPlusInit(codeRegistration, metadataRegistration);
}

Expand Down Expand Up @@ -338,5 +311,38 @@ private void FixedDynamicSection()
}
}
}

public override SectionHelper GetSectionHelper(int methodCount, int typeDefinitionsCount, int imageCount)
{
var dataList = new List<Elf32_Phdr>();
var execList = new List<Elf32_Phdr>();
foreach (var phdr in programSegment)
{
if (phdr.p_memsz != 0ul)
{
switch (phdr.p_flags)
{
case 1u: //PF_X
case 3u:
case 5u:
case 7u:
execList.Add(phdr);
break;
case 2u: //PF_W && PF_R
case 4u:
case 6u:
dataList.Add(phdr);
break;
}
}
}
var data = dataList.ToArray();
var exec = execList.ToArray();
var sectionHelper = new SectionHelper(this, methodCount, typeDefinitionsCount, maxMetadataUsages, imageCount);
sectionHelper.SetSection(SearchSectionType.Exec, exec);
sectionHelper.SetSection(SearchSectionType.Data, data);
sectionHelper.SetSection(SearchSectionType.Bss, data);
return sectionHelper;
}
}
}
66 changes: 36 additions & 30 deletions Il2CppDumper/ExecutableFormats/Elf64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,36 +90,9 @@ public override bool Search()

public override bool PlusSearch(int methodCount, int typeDefinitionsCount, int imageCount)
{
var dataList = new List<Elf64_Phdr>();
var execList = new List<Elf64_Phdr>();
foreach (var phdr in programSegment)
{
if (phdr.p_memsz != 0ul)
{
switch (phdr.p_flags)
{
case 1u: //PF_X
case 3u:
case 5u:
case 7u:
execList.Add(phdr);
break;
case 2u: //PF_W && PF_R
case 4u:
case 6u:
dataList.Add(phdr);
break;
}
}
}
var data = dataList.ToArray();
var exec = execList.ToArray();
var plusSearch = new PlusSearch(this, methodCount, typeDefinitionsCount, maxMetadataUsages, imageCount);
plusSearch.SetSection(SearchSectionType.Exec, exec);
plusSearch.SetSection(SearchSectionType.Data, data);
plusSearch.SetSection(SearchSectionType.Bss, data);
var codeRegistration = plusSearch.FindCodeRegistration();
var metadataRegistration = plusSearch.FindMetadataRegistration();
var sectionHelper = GetSectionHelper(methodCount, typeDefinitionsCount, imageCount);
var codeRegistration = sectionHelper.FindCodeRegistration();
var metadataRegistration = sectionHelper.FindMetadataRegistration();
return AutoPlusInit(codeRegistration, metadataRegistration);
}

Expand Down Expand Up @@ -282,5 +255,38 @@ private void FixedDynamicSection()
}
}
}

public override SectionHelper GetSectionHelper(int methodCount, int typeDefinitionsCount, int imageCount)
{
var dataList = new List<Elf64_Phdr>();
var execList = new List<Elf64_Phdr>();
foreach (var phdr in programSegment)
{
if (phdr.p_memsz != 0ul)
{
switch (phdr.p_flags)
{
case 1u: //PF_X
case 3u:
case 5u:
case 7u:
execList.Add(phdr);
break;
case 2u: //PF_W && PF_R
case 4u:
case 6u:
dataList.Add(phdr);
break;
}
}
}
var data = dataList.ToArray();
var exec = execList.ToArray();
var sectionHelper = new SectionHelper(this, methodCount, typeDefinitionsCount, maxMetadataUsages, imageCount);
sectionHelper.SetSection(SearchSectionType.Exec, exec);
sectionHelper.SetSection(SearchSectionType.Data, data);
sectionHelper.SetSection(SearchSectionType.Bss, data);
return sectionHelper;
}
}
}
25 changes: 15 additions & 10 deletions Il2CppDumper/ExecutableFormats/Macho.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,9 @@ public override bool Search()

public override bool PlusSearch(int methodCount, int typeDefinitionsCount, int imageCount)
{
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 plusSearch = new PlusSearch(this, methodCount, typeDefinitionsCount, maxMetadataUsages, imageCount);
plusSearch.SetSection(SearchSectionType.Exec, code);
plusSearch.SetSection(SearchSectionType.Data, data);
plusSearch.SetSection(SearchSectionType.Bss, bss);
var codeRegistration = plusSearch.FindCodeRegistration();
var metadataRegistration = plusSearch.FindMetadataRegistration();
var sectionHelper = GetSectionHelper(methodCount, typeDefinitionsCount, imageCount);
var codeRegistration = sectionHelper.FindCodeRegistration();
var metadataRegistration = sectionHelper.FindMetadataRegistration();
return AutoPlusInit(codeRegistration, metadataRegistration);
}

Expand All @@ -198,5 +191,17 @@ public override ulong GetRVA(ulong pointer)
{
return pointer - vmaddr;
}

public override SectionHelper GetSectionHelper(int methodCount, int typeDefinitionsCount, int imageCount)
{
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);
sectionHelper.SetSection(SearchSectionType.Exec, code);
sectionHelper.SetSection(SearchSectionType.Data, data);
sectionHelper.SetSection(SearchSectionType.Bss, bss);
return sectionHelper;
}
}
}
25 changes: 15 additions & 10 deletions Il2CppDumper/ExecutableFormats/Macho64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,9 @@ public override bool Search()

public override bool PlusSearch(int methodCount, int typeDefinitionsCount, int imageCount)
{
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 plusSearch = new PlusSearch(this, methodCount, typeDefinitionsCount, maxMetadataUsages, imageCount);
plusSearch.SetSection(SearchSectionType.Exec, code);
plusSearch.SetSection(SearchSectionType.Data, data);
plusSearch.SetSection(SearchSectionType.Bss, bss);
var codeRegistration = plusSearch.FindCodeRegistration();
var metadataRegistration = plusSearch.FindMetadataRegistration();
var sectionHelper = GetSectionHelper(methodCount, typeDefinitionsCount, imageCount);
var codeRegistration = sectionHelper.FindCodeRegistration();
var metadataRegistration = sectionHelper.FindMetadataRegistration();
return AutoPlusInit(codeRegistration, metadataRegistration);
}

Expand All @@ -260,5 +253,17 @@ public override ulong GetRVA(ulong pointer)
{
return pointer - vmaddr;
}

public override SectionHelper GetSectionHelper(int methodCount, int typeDefinitionsCount, int imageCount)
{
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);
sectionHelper.SetSection(SearchSectionType.Exec, code);
sectionHelper.SetSection(SearchSectionType.Data, data);
sectionHelper.SetSection(SearchSectionType.Bss, bss);
return sectionHelper;
}
}
}
18 changes: 12 additions & 6 deletions Il2CppDumper/ExecutableFormats/NSO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,9 @@ public override bool Search()

public override bool PlusSearch(int methodCount, int typeDefinitionsCount, int imageCount)
{
var plusSearch = new PlusSearch(this, methodCount, typeDefinitionsCount, maxMetadataUsages, imageCount);
plusSearch.SetSection(SearchSectionType.Exec, header.TextSegment);
plusSearch.SetSection(SearchSectionType.Data, header.DataSegment, header.RoDataSegment);
plusSearch.SetSection(SearchSectionType.Bss, header.BssSegment);
var codeRegistration = plusSearch.FindCodeRegistration();
var metadataRegistration = plusSearch.FindMetadataRegistration();
var sectionHelper = GetSectionHelper(methodCount, typeDefinitionsCount, imageCount);
var codeRegistration = sectionHelper.FindCodeRegistration();
var metadataRegistration = sectionHelper.FindMetadataRegistration();
return AutoPlusInit(codeRegistration, metadataRegistration);
}

Expand Down Expand Up @@ -214,5 +211,14 @@ public NSO UnCompress()
}
return this;
}

public override SectionHelper GetSectionHelper(int methodCount, int typeDefinitionsCount, int imageCount)
{
var sectionHelper = new SectionHelper(this, methodCount, typeDefinitionsCount, maxMetadataUsages, imageCount);
sectionHelper.SetSection(SearchSectionType.Exec, header.TextSegment);
sectionHelper.SetSection(SearchSectionType.Data, header.DataSegment, header.RoDataSegment);
sectionHelper.SetSection(SearchSectionType.Bss, header.BssSegment);
return sectionHelper;
}
}
}
40 changes: 23 additions & 17 deletions Il2CppDumper/ExecutableFormats/PE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,24 @@ public override bool Search()
}

public override bool PlusSearch(int methodCount, int typeDefinitionsCount, int imageCount)
{
var sectionHelper = GetSectionHelper(methodCount, typeDefinitionsCount, imageCount);
var codeRegistration = sectionHelper.FindCodeRegistration();
var metadataRegistration = sectionHelper.FindMetadataRegistration();
return AutoPlusInit(codeRegistration, metadataRegistration);
}

public override bool SymbolSearch()
{
return false;
}

public override ulong GetRVA(ulong pointer)
{
return pointer - imageBase;
}

public override SectionHelper GetSectionHelper(int methodCount, int typeDefinitionsCount, int imageCount)
{
var execList = new List<SectionHeader>();
var dataList = new List<SectionHeader>();
Expand All @@ -99,25 +117,13 @@ public override bool PlusSearch(int methodCount, int typeDefinitionsCount, int i
break;
}
}
var plusSearch = new PlusSearch(this, methodCount, typeDefinitionsCount, maxMetadataUsages, imageCount);
var sectionHelper = new SectionHelper(this, methodCount, typeDefinitionsCount, maxMetadataUsages, imageCount);
var data = dataList.ToArray();
var exec = execList.ToArray();
plusSearch.SetSection(SearchSectionType.Exec, imageBase, exec);
plusSearch.SetSection(SearchSectionType.Data, imageBase, data);
plusSearch.SetSection(SearchSectionType.Bss, imageBase, data);
var codeRegistration = plusSearch.FindCodeRegistration();
var metadataRegistration = plusSearch.FindMetadataRegistration();
return AutoPlusInit(codeRegistration, metadataRegistration);
}

public override bool SymbolSearch()
{
return false;
}

public override ulong GetRVA(ulong pointer)
{
return pointer - imageBase;
sectionHelper.SetSection(SearchSectionType.Exec, imageBase, exec);
sectionHelper.SetSection(SearchSectionType.Data, imageBase, data);
sectionHelper.SetSection(SearchSectionType.Bss, imageBase, data);
return sectionHelper;
}
}
}
40 changes: 23 additions & 17 deletions Il2CppDumper/ExecutableFormats/WebAssemblyMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ public override ulong MapRTVA(ulong addr)
}

public override bool PlusSearch(int methodCount, int typeDefinitionsCount, int imageCount)
{
var sectionHelper = GetSectionHelper(methodCount, typeDefinitionsCount, imageCount);
var codeRegistration = sectionHelper.FindCodeRegistration();
var metadataRegistration = sectionHelper.FindMetadataRegistration();
return AutoPlusInit(codeRegistration, metadataRegistration);
}

public override bool Search()
{
return false;
}

public override bool SymbolSearch()
{
return false;
}

public override SectionHelper GetSectionHelper(int methodCount, int typeDefinitionsCount, int imageCount)
{
var exec = new SearchSection
{
Expand All @@ -42,23 +60,11 @@ public override bool PlusSearch(int methodCount, int typeDefinitionsCount, int i
address = Length,
addressEnd = long.MaxValue //hack
};
var plusSearch = new PlusSearch(this, methodCount, typeDefinitionsCount, maxMetadataUsages, imageCount);
plusSearch.SetSection(SearchSectionType.Exec, exec);
plusSearch.SetSection(SearchSectionType.Data, data);
plusSearch.SetSection(SearchSectionType.Bss, bss);
var codeRegistration = plusSearch.FindCodeRegistration();
var metadataRegistration = plusSearch.FindMetadataRegistration();
return AutoPlusInit(codeRegistration, metadataRegistration);
}

public override bool Search()
{
return false;
}

public override bool SymbolSearch()
{
return false;
var sectionHelper = new SectionHelper(this, methodCount, typeDefinitionsCount, maxMetadataUsages, imageCount);
sectionHelper.SetSection(SearchSectionType.Exec, exec);
sectionHelper.SetSection(SearchSectionType.Data, data);
sectionHelper.SetSection(SearchSectionType.Bss, bss);
return sectionHelper;
}
}
}
1 change: 1 addition & 0 deletions Il2CppDumper/Il2Cpp/Il2Cpp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public abstract class Il2Cpp : BinaryStream
public abstract bool Search();
public abstract bool PlusSearch(int methodCount, int typeDefinitionsCount, int imageCount);
public abstract bool SymbolSearch();
public abstract SectionHelper GetSectionHelper(int methodCount, int typeDefinitionsCount, int imageCount);

protected Il2Cpp(Stream stream) : base(stream) { }

Expand Down
Loading

0 comments on commit 1852783

Please sign in to comment.