private ElfSymbol GetSymbol(IMemoryManager memory, long address, long strTblAddr) { int nameIndex = memory.ReadInt32(address + 0); int info = memory.ReadByte(address + 4); int other = memory.ReadByte(address + 5); int shIdx = memory.ReadInt16(address + 6); long value = memory.ReadInt64(address + 8); long size = memory.ReadInt64(address + 16); string name = string.Empty; for (int chr; (chr = memory.ReadByte(strTblAddr + nameIndex++)) != 0;) { name += (char)chr; } return(new ElfSymbol(name, info, other, shIdx, value, size)); }
private void LoadMod0Symbols(IMemoryManager memory, long textOffset) { long mod0Offset = textOffset + memory.ReadUInt32(textOffset + 4); if (mod0Offset < textOffset || !memory.IsMapped(mod0Offset) || (mod0Offset & 3) != 0) { return; } Dictionary <ElfDynamicTag, long> dynamic = new Dictionary <ElfDynamicTag, long>(); int mod0Magic = memory.ReadInt32(mod0Offset + 0x0); if (mod0Magic != Mod0) { return; } long dynamicOffset = memory.ReadInt32(mod0Offset + 0x4) + mod0Offset; long bssStartOffset = memory.ReadInt32(mod0Offset + 0x8) + mod0Offset; long bssEndOffset = memory.ReadInt32(mod0Offset + 0xc) + mod0Offset; long ehHdrStartOffset = memory.ReadInt32(mod0Offset + 0x10) + mod0Offset; long ehHdrEndOffset = memory.ReadInt32(mod0Offset + 0x14) + mod0Offset; long modObjOffset = memory.ReadInt32(mod0Offset + 0x18) + mod0Offset; // TODO: Elf32. while (true) { long tagVal = memory.ReadInt64(dynamicOffset + 0); long value = memory.ReadInt64(dynamicOffset + 8); dynamicOffset += 0x10; ElfDynamicTag tag = (ElfDynamicTag)tagVal; if (tag == ElfDynamicTag.DT_NULL) { break; } dynamic[tag] = value; } if (!dynamic.TryGetValue(ElfDynamicTag.DT_STRTAB, out long strTab) || !dynamic.TryGetValue(ElfDynamicTag.DT_SYMTAB, out long symTab) || !dynamic.TryGetValue(ElfDynamicTag.DT_SYMENT, out long symEntSize)) { return; } long strTblAddr = textOffset + strTab; long symTblAddr = textOffset + symTab; List <ElfSymbol> symbols = new List <ElfSymbol>(); while ((ulong)symTblAddr < (ulong)strTblAddr) { ElfSymbol sym = GetSymbol(memory, symTblAddr, strTblAddr); symbols.Add(sym); symTblAddr += symEntSize; } lock (_images) { _images.Add(new Image(textOffset, symbols.OrderBy(x => x.Value).ToArray())); } }