public virtual void Load(Stream fileStream, string name) { fileStream = new MemoryStream(fileStream.ReadAll()); FileStream = fileStream; Header = fileStream.ReadStruct <Elf.HeaderStruct>(); if (Header.Magic != Elf.HeaderStruct.MagicEnum.ExpectedValue) { throw new InvalidProgramException($"Not an ELF File \'{name}\'"); } if (Header.Machine != Elf.HeaderStruct.MachineEnum.Allegrex) { throw new InvalidProgramException("Invalid Elf.Header.Machine"); } ProgramHeaders = fileStream.ReadStructVectorAt <Elf.ProgramHeader>(Header.ProgramHeaderOffset, Header.ProgramHeaderCount, Header.ProgramHeaderEntrySize); SectionHeaders = fileStream.ReadStructVectorAt <Elf.SectionHeader>(Header.SectionHeaderOffset, Header.SectionHeaderCount, Header.SectionHeaderEntrySize); NamesSectionHeader = SectionHeaders[Header.SectionHeaderStringTable]; StringTable = fileStream.SliceWithLength(NamesSectionHeader.Offset, NamesSectionHeader.Size) .ReadAll(); SectionHeadersByName = new Dictionary <string, Elf.SectionHeader>(); foreach (var sectionHeader in SectionHeaders) { var sectionHeaderName = GetStringFromStringTable(sectionHeader.Name); SectionHeadersByName[sectionHeaderName] = sectionHeader; } Console.WriteLine("ProgramHeaders:{0}", ProgramHeaders.Length); foreach (var programHeader in ProgramHeaders) { Console.WriteLine("{0}", programHeader.ToStringDefault()); } Console.WriteLine("SectionHeaders:{0}", SectionHeaders.Length); foreach (var sectionHeader in SectionHeaders) { Console.WriteLine("{0}:{1}", GetStringFromStringTable(sectionHeader.Name), sectionHeader.ToStringDefault()); } if (NeedsRelocation && ProgramHeaders.Length > 1) { //throw (new NotImplementedException("Not implemented several ProgramHeaders yet using relocation")); } }
virtual public void Load(Stream FileStream) { FileStream = new MemoryStream(FileStream.ReadAll()); this.FileStream = FileStream; this.Header = FileStream.ReadStruct <Elf.HeaderStruct>(); if (this.Header.Magic != Elf.HeaderStruct.MagicEnum.ExpectedValue) { throw(new InvalidProgramException("Not an ELF File")); } if (this.Header.Machine != Elf.HeaderStruct.MachineEnum.ALLEGREX) { throw (new InvalidProgramException("Invalid Elf.Header.Machine")); } this.ProgramHeaders = FileStream.ReadStructVectorAt <Elf.ProgramHeader>(Header.ProgramHeaderOffset, Header.ProgramHeaderCount, Header.ProgramHeaderEntrySize); this.SectionHeaders = FileStream.ReadStructVectorAt <Elf.SectionHeader>(Header.SectionHeaderOffset, Header.SectionHeaderCount, Header.SectionHeaderEntrySize); this.NamesSectionHeader = this.SectionHeaders[Header.SectionHeaderStringTable]; this.StringTable = FileStream.SliceWithLength(this.NamesSectionHeader.Offset, this.NamesSectionHeader.Size).ReadAll(); this.SectionHeadersByName = new Dictionary <string, Elf.SectionHeader>(); foreach (var SectionHeader in this.SectionHeaders) { var SectionHeaderName = GetStringFromStringTable(SectionHeader.Name); this.SectionHeadersByName[SectionHeaderName] = SectionHeader; } Console.WriteLine("ProgramHeaders:{0}", this.ProgramHeaders.Length); foreach (var ProgramHeader in ProgramHeaders) { Console.WriteLine("{0}", ProgramHeader.ToStringDefault()); } Console.WriteLine("SectionHeaders:{0}", this.SectionHeaders.Length); foreach (var SectionHeader in SectionHeaders) { Console.WriteLine("{0}:{1}", GetStringFromStringTable(SectionHeader.Name), SectionHeader.ToStringDefault()); } if (NeedsRelocation && this.ProgramHeaders.Length > 1) { //throw (new NotImplementedException("Not implemented several ProgramHeaders yet using relocation")); } }