Exemplo n.º 1
0
        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"));
            }
        }