使用正确的方式获取符号数量

This commit is contained in:
Perfare 2021-07-06 15:36:30 +08:00
parent 2bc03a5fd2
commit d6995999d0
3 changed files with 83 additions and 6 deletions

View file

@ -190,10 +190,48 @@ namespace Il2CppDumper
{
try
{
var symbolCount = 0u;
var hash = dynamicSection.FirstOrDefault(x => x.d_tag == DT_HASH);
if (hash != null)
{
var addr = MapVATR(hash.d_un);
Position = addr;
var nbucket = ReadUInt32();
var nchain = ReadUInt32();
symbolCount = nchain;
}
else
{
hash = dynamicSection.First(x => x.d_tag == DT_GNU_HASH);
var addr = MapVATR(hash.d_un);
Position = addr;
var nbuckets = ReadUInt32();
var symoffset = ReadUInt32();
var bloom_size = ReadUInt32();
var bloom_shift = ReadUInt32();
var buckets_address = addr + 16 + (4 * bloom_size);
var buckets = ReadClassArray<uint>(buckets_address, nbuckets);
var last_symbol = buckets.Max();
if (last_symbol < symoffset)
{
symbolCount = symoffset;
}
else
{
var chains_base_address = buckets_address + 4 * nbuckets;
Position = chains_base_address + (last_symbol - symoffset) * 4;
while (true)
{
var chain_entry = ReadUInt32();
++last_symbol;
if ((chain_entry & 1) != 0)
break;
}
symbolCount = last_symbol;
}
}
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);
symbolTable = ReadClassArray<Elf32_Sym>(dynsymOffset, symbolCount);
}
catch
{

View file

@ -130,10 +130,48 @@ namespace Il2CppDumper
{
try
{
var symbolCount = 0u;
var hash = dynamicSection.FirstOrDefault(x => x.d_tag == DT_HASH);
if (hash != null)
{
var addr = MapVATR(hash.d_un);
Position = addr;
var nbucket = ReadUInt32();
var nchain = ReadUInt32();
symbolCount = nchain;
}
else
{
hash = dynamicSection.First(x => x.d_tag == DT_GNU_HASH);
var addr = MapVATR(hash.d_un);
Position = addr;
var nbuckets = ReadUInt32();
var symoffset = ReadUInt32();
var bloom_size = ReadUInt32();
var bloom_shift = ReadUInt32();
var buckets_address = addr + 16 + (8 * bloom_size);
var buckets = ReadClassArray<uint>(buckets_address, nbuckets);
var last_symbol = buckets.Max();
if (last_symbol < symoffset)
{
symbolCount = symoffset;
}
else
{
var chains_base_address = buckets_address + 4 * nbuckets;
Position = chains_base_address + (last_symbol - symoffset) * 4;
while (true)
{
var chain_entry = ReadUInt32();
++last_symbol;
if ((chain_entry & 1) != 0)
break;
}
symbolCount = last_symbol;
}
}
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);
symbolTable = ReadClassArray<Elf64_Sym>(dynsymOffset, symbolCount);
}
catch
{

View file

@ -172,6 +172,7 @@ namespace Il2CppDumper
public const int DT_JMPREL = 23;
public const int DT_INIT_ARRAY = 25;
public const int DT_FINI_ARRAY = 26;
public const int DT_GNU_HASH = 0x6ffffef5;
public const uint SHT_LOUSER = 0x80000000;