From d6995999d08deb04374b6189110db1c6de49e980 Mon Sep 17 00:00:00 2001 From: Perfare Date: Tue, 6 Jul 2021 15:36:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=AD=A3=E7=A1=AE=E7=9A=84?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E8=8E=B7=E5=8F=96=E7=AC=A6=E5=8F=B7=E6=95=B0?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Il2CppDumper/ExecutableFormats/Elf.cs | 44 ++++++++++++++++++++-- Il2CppDumper/ExecutableFormats/Elf64.cs | 44 ++++++++++++++++++++-- Il2CppDumper/ExecutableFormats/ElfClass.cs | 1 + 3 files changed, 83 insertions(+), 6 deletions(-) diff --git a/Il2CppDumper/ExecutableFormats/Elf.cs b/Il2CppDumper/ExecutableFormats/Elf.cs index ce7d63b..5109fd2 100644 --- a/Il2CppDumper/ExecutableFormats/Elf.cs +++ b/Il2CppDumper/ExecutableFormats/Elf.cs @@ -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(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(dynsymOffset, (long)dynsymSize / 16); + symbolTable = ReadClassArray(dynsymOffset, symbolCount); } catch { diff --git a/Il2CppDumper/ExecutableFormats/Elf64.cs b/Il2CppDumper/ExecutableFormats/Elf64.cs index 0bf3850..274781f 100644 --- a/Il2CppDumper/ExecutableFormats/Elf64.cs +++ b/Il2CppDumper/ExecutableFormats/Elf64.cs @@ -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(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(dynsymOffset, (long)dynsymSize / 24L); + symbolTable = ReadClassArray(dynsymOffset, symbolCount); } catch { diff --git a/Il2CppDumper/ExecutableFormats/ElfClass.cs b/Il2CppDumper/ExecutableFormats/ElfClass.cs index 07a703e..525bba5 100644 --- a/Il2CppDumper/ExecutableFormats/ElfClass.cs +++ b/Il2CppDumper/ExecutableFormats/ElfClass.cs @@ -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;