public void TestSymbolValue() { var stream = new FileStream("Binaries/base32", FileMode.Open, FileAccess.Read); var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness); ElfFile elfFile = ElfFile.ReadElfFile(reader); Assert.IsAssignableFrom <ElfSymbolTable>(elfFile.Sections[5]); ElfSymbolTable symbolTable = elfFile.Sections[5] as ElfSymbolTable; Assert.Equal(0x0000000000000000UL, symbolTable[0].Value); Assert.Equal(0x0000000000000000UL, symbolTable[1].Value); Assert.Equal(0x0000000000000000UL, symbolTable[2].Value); Assert.Equal(0x0000000000000000UL, symbolTable[3].Value); Assert.Equal(0x0000000000000000UL, symbolTable[4].Value); Assert.Equal(0x0000000000000000UL, symbolTable[5].Value); Assert.Equal(0x0000000000000000UL, symbolTable[14].Value); Assert.Equal(0x0000000000000000UL, symbolTable[16].Value); Assert.Equal(0x0000000000000000UL, symbolTable[19].Value); Assert.Equal(0x0000000000000000UL, symbolTable[23].Value); Assert.Equal(0x0000000000000000UL, symbolTable[35].Value); Assert.Equal(0x0000000000609288UL, symbolTable[60].Value); Assert.Equal(0x0000000000609280UL, symbolTable[65].Value); Assert.Equal(0x0000000000609298UL, symbolTable[67].Value); }
/*static uint GetMemorySize(Elf32File file, string memory) { * var flashSections = file.GetSectionsByMemoryType(memory); * var dataItems = flashSections.SelectMany(v => v.Items); * return (uint)dataItems.Aggregate<DwarfCompilationUnitItem, ulong>(0, (current, item) => current + item.Size); * }*/ static uint GetSectionSize(ElfFile file, string section) { var dataSection = file.GetSection(section); var dataItems = dataSection.Items; return((uint)dataItems.Aggregate <DwarfCompilationUnitItem, ulong>(0, (current, item) => current + item.Size)); }
public void TestFileExists() { var stream = new FileStream("Binaries/base32", FileMode.Open, FileAccess.Read); var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness); _ = ElfFile.ReadElfFile(reader); }
public void TestName() { var stream = new FileStream("Binaries/base32", FileMode.Open, FileAccess.Read); var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness); ElfFile elfFile = ElfFile.ReadElfFile(reader); Assert.IsAssignableFrom <ElfSymbolTable>(elfFile.Sections[5]); ElfSymbolTable symbolTable = elfFile.Sections[5] as ElfSymbolTable; Assert.Equal(string.Empty, symbolTable[0].Name); Assert.Equal("__uflow", symbolTable[1].Name); Assert.Equal("getenv", symbolTable[2].Name); Assert.Equal("free", symbolTable[3].Name); Assert.Equal("abort", symbolTable[4].Name); Assert.Equal("__errno_location", symbolTable[5].Name); Assert.Equal("__ctype_get_mb_cur_max", symbolTable[14].Name); Assert.Equal("__stack_chk_fail", symbolTable[16].Name); Assert.Equal("strchr", symbolTable[19].Name); Assert.Equal("__assert_fail", symbolTable[23].Name); Assert.Equal("__gmon_start__", symbolTable[35].Name); Assert.Equal("stdout", symbolTable[60].Name); Assert.Equal("program_invocation_short_name", symbolTable[65].Name); Assert.Equal("optind", symbolTable[67].Name); }
public void ExtractStrings() { try { using (var file = new ElfFile(StreamLoader.FromFile(ElfFilePath))) { if (file.Header.IsValid) { var strings = new List <string>(); foreach (var strSec in file.GetStringSections()) { foreach (var str in strSec) { if (str != null) { var n = str.Name; var idx = str.Index; var e = $"STRING ENTRY: {idx} :: {n}"; strings.Add(e); } } } File.WriteAllLines(@"strings.log", strings); } } } catch (Exception ex) { UiMessages.Error(ex.ToString()); } }
public void TestSymbolValue() { var stream = new FileStream("Binaries/base32", FileMode.Open, FileAccess.Read); var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness); ElfFile elfFile = ElfFile.ReadElfFile(reader); Assert.IsAssignableFrom <ElfRelocationSection>(elfFile.Sections[9]); ElfRelocationSection relocationSection9 = elfFile.Sections[9] as ElfRelocationSection; Assert.Equal(0x0000000000000000UL, relocationSection9[0].SymbolValue); Assert.Equal(0x0000000000609280UL, relocationSection9[1].SymbolValue); Assert.Equal(0x0000000000609288UL, relocationSection9[2].SymbolValue); Assert.Equal(0x0000000000609290UL, relocationSection9[3].SymbolValue); Assert.Equal(0x0000000000609298UL, relocationSection9[4].SymbolValue); Assert.Equal(0x00000000006092a0UL, relocationSection9[5].SymbolValue); Assert.Equal(0x00000000006092a8UL, relocationSection9[6].SymbolValue); Assert.Equal(0x00000000006092c0UL, relocationSection9[7].SymbolValue); Assert.IsAssignableFrom <ElfRelocationSection>(elfFile.Sections[10]); ElfRelocationSection relocationSection10 = elfFile.Sections[10] as ElfRelocationSection; Assert.Equal(0x0UL, relocationSection10[0].SymbolValue); Assert.Equal(0x0UL, relocationSection10[1].SymbolValue); Assert.Equal(0x0UL, relocationSection10[2].SymbolValue); Assert.Equal(0x0UL, relocationSection10[3].SymbolValue); Assert.Equal(0x0UL, relocationSection10[4].SymbolValue); Assert.Equal(0x0UL, relocationSection10[5].SymbolValue); Assert.Equal(0x0UL, relocationSection10[14].SymbolValue); Assert.Equal(0x0UL, relocationSection10[16].SymbolValue); Assert.Equal(0x0UL, relocationSection10[19].SymbolValue); Assert.Equal(0x0UL, relocationSection10[23].SymbolValue); }
public void TestBinding() { var stream = new FileStream("Binaries/base32", FileMode.Open, FileAccess.Read); var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness); ElfFile elfFile = ElfFile.ReadElfFile(reader); Assert.IsAssignableFrom <ElfSymbolTable>(elfFile.Sections[5]); ElfSymbolTable symbolTable = elfFile.Sections[5] as ElfSymbolTable; Assert.Equal(ElfSymbolBinding.Local, symbolTable[0].Binding); Assert.Equal(ElfSymbolBinding.Global, symbolTable[1].Binding); Assert.Equal(ElfSymbolBinding.Global, symbolTable[2].Binding); Assert.Equal(ElfSymbolBinding.Global, symbolTable[3].Binding); Assert.Equal(ElfSymbolBinding.Global, symbolTable[4].Binding); Assert.Equal(ElfSymbolBinding.Global, symbolTable[5].Binding); Assert.Equal(ElfSymbolBinding.Global, symbolTable[14].Binding); Assert.Equal(ElfSymbolBinding.Global, symbolTable[16].Binding); Assert.Equal(ElfSymbolBinding.Global, symbolTable[19].Binding); Assert.Equal(ElfSymbolBinding.Global, symbolTable[23].Binding); Assert.Equal(ElfSymbolBinding.Weak, symbolTable[35].Binding); Assert.Equal(ElfSymbolBinding.Global, symbolTable[60].Binding); Assert.Equal(ElfSymbolBinding.Weak, symbolTable[65].Binding); Assert.Equal(ElfSymbolBinding.Global, symbolTable[67].Binding); }
public void TestNameIndex() { var stream = new FileStream("Binaries/base32", FileMode.Open, FileAccess.Read); var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness); ElfFile elfFile = ElfFile.ReadElfFile(reader); Assert.IsAssignableFrom <ElfSymbolTable>(elfFile.Sections[5]); ElfSymbolTable symbolTable = elfFile.Sections[5] as ElfSymbolTable; Assert.Equal(0x000U, symbolTable[0].NameIndex); Assert.Equal(0x15fU, symbolTable[1].NameIndex); Assert.Equal(0x181U, symbolTable[2].NameIndex); Assert.Equal(0x26dU, symbolTable[3].NameIndex); Assert.Equal(0x080U, symbolTable[4].NameIndex); Assert.Equal(0x10fU, symbolTable[5].NameIndex); Assert.Equal(0x0bfU, symbolTable[14].NameIndex); Assert.Equal(0x05eU, symbolTable[16].NameIndex); Assert.Equal(0x1cdU, symbolTable[19].NameIndex); Assert.Equal(0x0b1U, symbolTable[23].NameIndex); Assert.Equal(0x29aU, symbolTable[35].NameIndex); Assert.Equal(0x135U, symbolTable[60].NameIndex); Assert.Equal(0x1d4U, symbolTable[65].NameIndex); Assert.Equal(0x03fU, symbolTable[67].NameIndex); }
public void TestMachineI386() { var stream = new FileStream("Binaries/helloworld32le", FileMode.Open, FileAccess.Read); var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness); ElfFile elfFile = ElfFile.ReadElfFile(reader); Assert.Equal(ElfMachine.I386, elfFile.Header.Machine); }
public void TestMachineX8664() { var stream = new FileStream("Binaries/base32", FileMode.Open, FileAccess.Read); var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness); ElfFile elfFile = ElfFile.ReadElfFile(reader); Assert.Equal(ElfMachine.X8664, elfFile.Header.Machine); }
public void TestType() { var stream = new FileStream("Binaries/base32", FileMode.Open, FileAccess.Read); var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness); ElfFile elfFile = ElfFile.ReadElfFile(reader); Assert.Equal(ElfType.Executable, elfFile.Header.Type); }
public void TestOSABIVersion() { var stream = new FileStream("Binaries/base32", FileMode.Open, FileAccess.Read); var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness); ElfFile elfFile = ElfFile.ReadElfFile(reader); Assert.Equal(0, elfFile.Header.OSABIVersion); }
public void TestEndiannessBE() { var stream = new FileStream("Binaries/helloworld64be", FileMode.Open, FileAccess.Read); var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness); ElfFile elfFile = ElfFile.ReadElfFile(reader); Assert.Equal(ElfData.Msb, elfFile.Header.Data); }
public void TestClass64() { var stream = new FileStream("Binaries/helloworld64le", FileMode.Open, FileAccess.Read); var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness); ElfFile elfFile = ElfFile.ReadElfFile(reader); Assert.Equal(ElfClass.Elf64, elfFile.Header.Class); }
public void TestProgramHeaderSize() { var stream = new FileStream("Binaries/base32", FileMode.Open, FileAccess.Read); var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness); ElfFile elfFile = ElfFile.ReadElfFile(reader); Assert.Equal(56, elfFile.Header.ProgramHeaderSize); }
public void TestEntryOffset() { var stream = new FileStream("Binaries/base32", FileMode.Open, FileAccess.Read); var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness); ElfFile elfFile = ElfFile.ReadElfFile(reader); Assert.Equal(0x4019e0UL, elfFile.Header.EntryOffset); }
public void TestCount() { var stream = new FileStream("Binaries/base32", FileMode.Open, FileAccess.Read); var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness); ElfFile elfFile = ElfFile.ReadElfFile(reader); Assert.Equal(29, elfFile.Sections.Count); }
public void TestSectionToSegmentMapping() { var stream = new FileStream("Binaries/base32", FileMode.Open, FileAccess.Read); var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness); ElfFile elfFile = ElfFile.ReadElfFile(reader); Assert.Equal(0, elfFile.Segments[0].Sections.Count); Assert.Equal(1, elfFile.Segments[1].Sections.Count); Assert.Equal(elfFile.Sections[1], elfFile.Segments[1].Sections[0]); Assert.Equal(18, elfFile.Segments[2].Sections.Count); Assert.Equal(elfFile.Sections[1], elfFile.Segments[2].Sections[0]); Assert.Equal(elfFile.Sections[2], elfFile.Segments[2].Sections[1]); Assert.Equal(elfFile.Sections[3], elfFile.Segments[2].Sections[2]); Assert.Equal(elfFile.Sections[4], elfFile.Segments[2].Sections[3]); Assert.Equal(elfFile.Sections[5], elfFile.Segments[2].Sections[4]); Assert.Equal(elfFile.Sections[6], elfFile.Segments[2].Sections[5]); Assert.Equal(elfFile.Sections[7], elfFile.Segments[2].Sections[6]); Assert.Equal(elfFile.Sections[8], elfFile.Segments[2].Sections[7]); Assert.Equal(elfFile.Sections[9], elfFile.Segments[2].Sections[8]); Assert.Equal(elfFile.Sections[10], elfFile.Segments[2].Sections[9]); Assert.Equal(elfFile.Sections[11], elfFile.Segments[2].Sections[10]); Assert.Equal(elfFile.Sections[12], elfFile.Segments[2].Sections[11]); Assert.Equal(elfFile.Sections[13], elfFile.Segments[2].Sections[12]); Assert.Equal(elfFile.Sections[14], elfFile.Segments[2].Sections[13]); Assert.Equal(elfFile.Sections[15], elfFile.Segments[2].Sections[14]); Assert.Equal(elfFile.Sections[16], elfFile.Segments[2].Sections[15]); Assert.Equal(elfFile.Sections[17], elfFile.Segments[2].Sections[16]); Assert.Equal(elfFile.Sections[18], elfFile.Segments[2].Sections[17]); Assert.Equal(8, elfFile.Segments[3].Sections.Count); Assert.Equal(elfFile.Sections[19], elfFile.Segments[3].Sections[0]); Assert.Equal(elfFile.Sections[20], elfFile.Segments[3].Sections[1]); Assert.Equal(elfFile.Sections[21], elfFile.Segments[3].Sections[2]); Assert.Equal(elfFile.Sections[22], elfFile.Segments[3].Sections[3]); Assert.Equal(elfFile.Sections[23], elfFile.Segments[3].Sections[4]); Assert.Equal(elfFile.Sections[24], elfFile.Segments[3].Sections[5]); Assert.Equal(elfFile.Sections[25], elfFile.Segments[3].Sections[6]); Assert.Equal(elfFile.Sections[26], elfFile.Segments[3].Sections[7]); Assert.Equal(1, elfFile.Segments[4].Sections.Count); Assert.Equal(elfFile.Sections[22], elfFile.Segments[4].Sections[0]); Assert.Equal(2, elfFile.Segments[5].Sections.Count); Assert.Equal(elfFile.Sections[2], elfFile.Segments[5].Sections[0]); Assert.Equal(elfFile.Sections[3], elfFile.Segments[5].Sections[1]); Assert.Equal(1, elfFile.Segments[6].Sections.Count); Assert.Equal(elfFile.Sections[17], elfFile.Segments[6].Sections[0]); Assert.Equal(0, elfFile.Segments[7].Sections.Count); Assert.Equal(5, elfFile.Segments[8].Sections.Count); Assert.Equal(elfFile.Sections[19], elfFile.Segments[8].Sections[0]); Assert.Equal(elfFile.Sections[20], elfFile.Segments[8].Sections[1]); Assert.Equal(elfFile.Sections[21], elfFile.Segments[8].Sections[2]); Assert.Equal(elfFile.Sections[22], elfFile.Segments[8].Sections[3]); Assert.Equal(elfFile.Sections[23], elfFile.Segments[8].Sections[4]); }
public void TestInvalidEndianness() { var stream = new FileStream("Binaries/invalidendianness", FileMode.Open, FileAccess.Read); var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness); void Action() => ElfFile.ReadElfFile(reader); Assert.Throws <FileFormatException>(Action); }
private static ISection get_decorated_section(ElfFile bf, ISection section, string add_to_name) { var decorated_name = section.Name + add_to_name; var sect = bf.FindSection(decorated_name); if (sect == null) { sect = bf.CopySectionType(section, decorated_name); } return(sect); }
public void TestCount() { var stream = new FileStream("Binaries/base32", FileMode.Open, FileAccess.Read); var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness); ElfFile elfFile = ElfFile.ReadElfFile(reader); Assert.IsAssignableFrom <ElfSymbolTable>(elfFile.Sections[5]); ElfSymbolTable symbolTable = elfFile.Sections[5] as ElfSymbolTable; Assert.Equal(69, symbolTable.Count); }
public void TestCount() { var stream = new FileStream("Binaries/base32", FileMode.Open, FileAccess.Read); var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness); ElfFile elfFile = ElfFile.ReadElfFile(reader); Assert.IsAssignableFrom <ElfDynamicSection>(elfFile.Sections[22]); ElfDynamicSection dynamicSection = elfFile.Sections[22] as ElfDynamicSection; Assert.Equal(24, dynamicSection.Count); }
public void TestName() { var stream = new FileStream("Binaries/base32", FileMode.Open, FileAccess.Read); var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness); ElfFile elfFile = ElfFile.ReadElfFile(reader); Assert.Equal(string.Empty, elfFile.Sections[0].Name); Assert.Equal(".dynsym", elfFile.Sections[5].Name); Assert.Equal(".plt.got", elfFile.Sections[13].Name); Assert.Equal(".dynamic", elfFile.Sections[22].Name); Assert.Equal(".got.plt", elfFile.Sections[24].Name); }
private ModuleInfo CreateModuleInfo(ElfLoadedImage img) { ElfFile file = img.Open(); return(new ModuleInfo { FileName = img.Path, FileSize = (uint)img.Size, ImageBase = (ulong)img.BaseAddress, BuildId = file?.BuildId, IsManaged = file == null }); }
public void TestName() { var stream = new FileStream("Binaries/base32", FileMode.Open, FileAccess.Read); var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness); ElfFile elfFile = ElfFile.ReadElfFile(reader); Assert.IsAssignableFrom <ElfDynamicSection>(elfFile.Sections[22]); ElfDynamicSection dynamicSection = elfFile.Sections[22] as ElfDynamicSection; Assert.Equal("libc.so.6", dynamicSection[0].Name); Assert.Equal(string.Empty, dynamicSection[1].Name); }
public void TestMemorySize() { var stream = new FileStream("Binaries/base32", FileMode.Open, FileAccess.Read); var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness); ElfFile elfFile = ElfFile.ReadElfFile(reader); Assert.Equal(0x00000000000001F8UL, elfFile.Segments[0].MemorySize); Assert.Equal(0x000000000000001CUL, elfFile.Segments[1].MemorySize); Assert.Equal(0x0000000000008164UL, elfFile.Segments[2].MemorySize); Assert.Equal(0x0000000000000630UL, elfFile.Segments[3].MemorySize); Assert.Equal(0x00000000000001D0UL, elfFile.Segments[4].MemorySize); Assert.Equal(0x0000000000000044UL, elfFile.Segments[5].MemorySize); }
public void TestPhysicalAddress() { var stream = new FileStream("Binaries/base32", FileMode.Open, FileAccess.Read); var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness); ElfFile elfFile = ElfFile.ReadElfFile(reader); Assert.Equal(0x0000000000400040UL, elfFile.Segments[0].VirtualAddress); Assert.Equal(0x0000000000400238UL, elfFile.Segments[1].VirtualAddress); Assert.Equal(0x0000000000400000UL, elfFile.Segments[2].VirtualAddress); Assert.Equal(0x0000000000608e10UL, elfFile.Segments[3].VirtualAddress); Assert.Equal(0x0000000000608e28UL, elfFile.Segments[4].VirtualAddress); Assert.Equal(0x0000000000400254UL, elfFile.Segments[5].VirtualAddress); }
public void TestType() { var stream = new FileStream("Binaries/base32", FileMode.Open, FileAccess.Read); var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness); ElfFile elfFile = ElfFile.ReadElfFile(reader); Assert.Equal(ElfSegmentType.PHdr, elfFile.Segments[0].Type); Assert.Equal(ElfSegmentType.Interp, elfFile.Segments[1].Type); Assert.Equal(ElfSegmentType.Load, elfFile.Segments[2].Type); Assert.Equal(ElfSegmentType.Load, elfFile.Segments[3].Type); Assert.Equal(ElfSegmentType.Dynamic, elfFile.Segments[4].Type); Assert.Equal(ElfSegmentType.Note, elfFile.Segments[5].Type); }
public void TestAlignment() { var stream = new FileStream("Binaries/base32", FileMode.Open, FileAccess.Read); var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness); ElfFile elfFile = ElfFile.ReadElfFile(reader); Assert.Equal(0x8UL, elfFile.Segments[0].Alignment); Assert.Equal(0x1UL, elfFile.Segments[1].Alignment); Assert.Equal(0x200000UL, elfFile.Segments[2].Alignment); Assert.Equal(0x200000UL, elfFile.Segments[3].Alignment); Assert.Equal(0x8UL, elfFile.Segments[4].Alignment); Assert.Equal(0x4UL, elfFile.Segments[5].Alignment); }
public void TestFlags() { var stream = new FileStream("Binaries/base32", FileMode.Open, FileAccess.Read); var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness); ElfFile elfFile = ElfFile.ReadElfFile(reader); Assert.Equal(ElfSegmentFlags.Read | ElfSegmentFlags.Exec, elfFile.Segments[0].Flags); Assert.Equal(ElfSegmentFlags.Read, elfFile.Segments[1].Flags); Assert.Equal(ElfSegmentFlags.Read | ElfSegmentFlags.Exec, elfFile.Segments[2].Flags); Assert.Equal(ElfSegmentFlags.Read | ElfSegmentFlags.Write, elfFile.Segments[3].Flags); Assert.Equal(ElfSegmentFlags.Read | ElfSegmentFlags.Write, elfFile.Segments[4].Flags); Assert.Equal(ElfSegmentFlags.Read, elfFile.Segments[5].Flags); }
private void LoadInternal(Thread thread, ElfFile file) { uint dataBase = 0; uint dataSize = 0; uint envAddr, argAddr; uint stackPtr; foreach (var phdr in file.ProgramHeaders) { if (phdr.P_type == ElfProgramHeader.P_Type.PT_LOAD && phdr.P_vaddr > dataBase) { dataBase = phdr.P_vaddr; dataSize = phdr.P_memsz; } } foreach (var shdr in file.SectionHeaders) { if (shdr.Sh_type == ElfSectionHeader.Sh_Type.SHT_PROGBITS || shdr.Sh_type == ElfSectionHeader.Sh_Type.SHT_NOBITS) { if (shdr.Sh_size > 0 && ((shdr.Sh_flags & ElfSectionHeader.Sh_Flags.SHF_ALLOC) != 0)) { MemoryAccessType perm = MemoryAccessType.Init | MemoryAccessType.Read; if ((shdr.Sh_flags & ElfSectionHeader.Sh_Flags.SHF_WRITE) != 0) { perm |= MemoryAccessType.Write; } if ((shdr.Sh_flags & ElfSectionHeader.Sh_Flags.SHF_EXECINSTR) != 0) { perm |= MemoryAccessType.Execute; } thread.Mem.Map (shdr.Sh_addr, (int)shdr.Sh_size, perm); if (shdr.Sh_type == ElfSectionHeader.Sh_Type.SHT_NOBITS) { thread.Mem.Zero(shdr.Sh_addr, (int)shdr.Sh_size); } else { thread.Mem.InitBlock(shdr.Sh_addr, (int)shdr.Sh_size, shdr.Content); } } } else if (shdr.Sh_type == ElfSectionHeader.Sh_Type.SHT_DYNAMIC || shdr.Sh_type == ElfSectionHeader.Sh_Type.SHT_DYNSYM) { Logger.Fatal (Logger.Categories.Elf, "dynamic linking is not supported"); } } this.ProgramEntry = file.Header.E_entry; thread.Mem.Map (STACK_BASE - STACK_SIZE, (int)STACK_SIZE, MemoryAccessType.Read | MemoryAccessType.Write); thread.Mem.Zero(STACK_BASE - STACK_SIZE, (int)STACK_SIZE); stackPtr = STACK_BASE - MAX_ENVIRON; thread.Regs.IntRegs[RegisterConstants.STACK_POINTER_REG] = stackPtr; thread.Mem.WriteWord (stackPtr, this.Argc); thread.SetSyscallArg (0, this.Argc); stackPtr += (uint)Marshal.SizeOf (typeof(uint)); argAddr = stackPtr; thread.SetSyscallArg (1, argAddr); stackPtr += (uint)((this.Argc + 1) * Marshal.SizeOf (typeof(uint))); envAddr = stackPtr; stackPtr += (uint)(this.Envs.Count * Marshal.SizeOf (typeof(uint)) + Marshal.SizeOf (typeof(uint))); for (int i = 0; i < this.Argc; i++) { thread.Mem.WriteWord ((uint)(argAddr + i * Marshal.SizeOf (typeof(uint))), stackPtr); int strLen = thread.Mem.WriteString(stackPtr, this.Args[i]); stackPtr += (uint)strLen; } for (int i = 0; i < this.Envs.Count; i++) { thread.Mem.WriteWord ((uint)(envAddr + i * Marshal.SizeOf (typeof(uint))), stackPtr); int strLen = thread.Mem.WriteString(stackPtr, this.Envs[i]); stackPtr += (uint)strLen; } if (stackPtr + Marshal.SizeOf (typeof(uint)) >= STACK_BASE) { Logger.Fatal (Logger.Categories.Process, "Environment overflow. Need to increase MAX_ENVIRON."); } uint abrk = dataBase + dataSize + MemoryConstants.PAGE_SIZE; abrk -= abrk % MemoryConstants.PAGE_SIZE; this.Brk = abrk; this.MmapBrk = MMAP_BASE; thread.Regs.Npc = this.ProgramEntry; thread.Regs.Nnpc = (uint)(thread.Regs.Npc + Marshal.SizeOf (typeof(uint))); }