Skip to content

Commit

Permalink
Fixed #230
Browse files Browse the repository at this point in the history
  • Loading branch information
Perfare committed Mar 6, 2020
1 parent 5e61444 commit 4525df6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
29 changes: 24 additions & 5 deletions Il2CppDumper/ExecutableFormats/Elf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ public Elf(Stream stream, float version, long maxMetadataUsages) : base(stream,
Is32Bit = true;
elfHeader = ReadClass<Elf32_Ehdr>();
programSegment = ReadClassArray<Elf32_Phdr>(elfHeader.e_phoff, elfHeader.e_phnum);
try
{
sectionTable = ReadClassArray<Elf32_Shdr>(elfHeader.e_shoff, elfHeader.e_shnum);
}
catch
if (!CheckSection())
{
Console.WriteLine("Detected this may be a dump file. If not, it must be protected.");
isDumped = true;
Expand All @@ -59,6 +55,29 @@ public Elf(Stream stream, float version, long maxMetadataUsages) : base(stream,
}
}

public bool CheckSection()
{
try
{
var names = new List<string>();
sectionTable = ReadClassArray<Elf32_Shdr>(elfHeader.e_shoff, elfHeader.e_shnum);
var shstrndx = sectionTable[elfHeader.e_shstrndx].sh_offset;
foreach (var section in sectionTable)
{
names.Add(ReadStringToNull(shstrndx + section.sh_name));
}
if (!names.Contains(".text"))
{
return false;
}
return true; ;
}
catch
{
return false;
}
}

public override ulong MapVATR(ulong addr)
{
var phdr = programSegment.First(x => addr >= x.p_vaddr && addr <= x.p_vaddr + x.p_memsz);
Expand Down
29 changes: 24 additions & 5 deletions Il2CppDumper/ExecutableFormats/Elf64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ public Elf64(Stream stream, float version, long maxMetadataUsages) : base(stream
{
elfHeader = ReadClass<Elf64_Ehdr>();
programSegment = ReadClassArray<Elf64_Phdr>(elfHeader.e_phoff, elfHeader.e_phnum);
try
{
sectionTable = ReadClassArray<Elf64_Shdr>(elfHeader.e_shoff, elfHeader.e_shnum);
}
catch
if(!CheckSection())
{
Console.WriteLine("Detected this may be a dump file. If not, it must be protected.");
isDumped = true;
Expand All @@ -50,6 +46,29 @@ public Elf64(Stream stream, float version, long maxMetadataUsages) : base(stream
}
}

public bool CheckSection()
{
try
{
var names = new List<string>();
sectionTable = ReadClassArray<Elf64_Shdr>(elfHeader.e_shoff, elfHeader.e_shnum);
var shstrndx = sectionTable[elfHeader.e_shstrndx].sh_offset;
foreach (var section in sectionTable)
{
names.Add(ReadStringToNull(shstrndx + section.sh_name));
}
if (!names.Contains(".text"))
{
return false;
}
return true; ;
}
catch
{
return false;
}
}

public override ulong MapVATR(ulong addr)
{
var phdr = programSegment.First(x => addr >= x.p_vaddr && addr <= x.p_vaddr + x.p_memsz);
Expand Down
4 changes: 2 additions & 2 deletions Il2CppDumper/ExecutableFormats/ElfClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Elf32_Ehdr
public ushort e_phnum;
public ushort e_shentsize;
public ushort e_shnum;
public ushort e_shtrndx;
public ushort e_shstrndx;
}

public class Elf32_Phdr
Expand Down Expand Up @@ -97,7 +97,7 @@ public class Elf64_Ehdr
public ushort e_phnum;
public ushort e_shentsize;
public ushort e_shnum;
public ushort e_shtrndx;
public ushort e_shstrndx;
}

public class Elf64_Phdr
Expand Down

0 comments on commit 4525df6

Please sign in to comment.