Beispiel #1
0
        /// <summary>Get all relocations in the section</summary>
        /// <returns>Stream of all relocations from current section</returns>
        public IEnumerator <RelocationSectionItem> GetEnumerator()
        {
            UInt64 offset       = base.Section.sh_offset;
            UInt64 maxOffset    = base.Section.sh_offset + base.Section.sh_size;
            UInt64 sizeOfStruct = this.SizeOfStruct;
            UInt64 itemsCount   = (maxOffset - offset) / sizeOfStruct;

            ElfHeader header  = base.Section.File.Header;
            Boolean   is64Bit = header.Is64Bit;

            for (UInt64 loop = 0; loop < itemsCount; loop++)
            {
                if (is64Bit)
                {
                    Elf.Elf64_Rel rel = header.PtrToStructure <Elf.Elf64_Rel>(offset);
                    yield return(new RelocationSectionItem(rel));
                }
                else
                {
                    Elf.Elf32_Rel rel = header.PtrToStructure <Elf.Elf32_Rel>(offset);
                    yield return(new RelocationSectionItem(rel));
                }
                offset += sizeOfStruct;
            }
        }
Beispiel #2
0
        /// <summary>Get all symbols in the section</summary>
        /// <returns>Stream of all symbols in the current section</returns>
        public IEnumerator <SymbolSectionItem> GetEnumerator()
        {
            //Byte[] payload = this._section.GetData();

            UInt64 offset       = base.Section.sh_offset;
            UInt64 maxOffset    = base.Section.sh_offset + base.Section.sh_size;
            UInt64 sizeOfStruct = this.SizeOfStruct;
            UInt64 itemsCount   = (maxOffset - offset) / sizeOfStruct;

            ElfHeader     header      = base.Section.File.Header;
            StringSection stringTable = this.SectionSymbolNames;
            Boolean       is64Bit     = header.Is64Bit;

            for (UInt64 loop = 0; loop < itemsCount; loop++)
            {
                SymbolSectionItem result;
                if (is64Bit)
                {
                    Elf.Elf64_Sym symbol = header.PtrToStructure <Elf.Elf64_Sym>(offset);
                    result = new SymbolSectionItem(symbol);
                }
                else
                {
                    Elf.Elf32_Sym symbol = header.PtrToStructure <Elf.Elf32_Sym>(offset);
                    result = new SymbolSectionItem(symbol);
                }

                result.Name = stringTable[result.st_name];

                yield return(result);

                offset += sizeOfStruct;
            }
        }
Beispiel #3
0
 /// <summary>Dispose managed objects</summary>
 /// <param name="disposing">Dispose managed objects</param>
 protected virtual void Dispose(Boolean disposing)
 {
     if (disposing && this._header != null)
     {
         this._header.Dispose();
         this._header = null;
     }
 }
Beispiel #4
0
        private Header(ElfHeader header)
        {
            if (header == null)
            {
                throw new ArgumentNullException("header");
            }

            this._header = header;
        }
Beispiel #5
0
        /// <summary>Create instance of the ELF file reader</summary>
        /// <param name="loader">Stream of data</param>
        /// <exception cref="InvalidOperationException">Invalid ELF header</exception>
        public ElfFile(IImageLoader loader)
        {
            this._header = new ElfHeader(loader);

            if (!this.Header.IsValid)
            {
                throw new InvalidOperationException("Invalid ELF header");
            }
        }
Beispiel #6
0
 internal Header(ElfHeader header, Elf.Elf64_Ehdr header64)
     : this(header)
 {
     this.e_type      = header64.e_type;
     this.e_machine   = header64.e_machine;
     this.e_version   = header64.e_version;
     this.e_entry     = header64.e_entry;
     this.e_phoff     = header64.e_phoff;
     this.e_shoff     = header64.e_shoff;
     this.e_flags     = header64.e_flags;
     this.e_ehsize    = header64.e_ehsize;
     this.e_phentsize = header64.e_phentsize;
     this.e_phnum     = header64.e_phnum;
     this.e_shentsize = header64.e_shentsize;
     this.e_shnum     = header64.e_shnum;
     this.e_shstrndx  = header64.e_shstrndx;
 }
Beispiel #7
0
        /// <summary>Get all notes from current section</summary>
        /// <returns>Stream of notes from current section</returns>
        public IEnumerator <NoteSectionItem> GetEnumerator()
        {
            //Byte[] data = base.Section.GetData();


            UInt64    offset    = base.Section.sh_offset;
            UInt64    maxOffset = offset + base.Section.sh_size;
            ElfHeader header    = base.Section.File.Header;

            while (offset < maxOffset)
            {
                UInt64 namesz = header.ReadInt(ref offset);
                if (namesz == 0)
                {
                    break;
                }
                if (namesz + offset > maxOffset)
                {
                    break;                    //TODO:mystem.so -> ...overflow error... Int32/Int64 (?)
                }
                UInt64 descsz = header.ReadInt(ref offset);

                UInt64 type = header.ReadInt(ref offset);

                String name = header.PtrToStringAnsi(offset);
                offset += namesz;

                String descriptor = header.PtrToStringAnsi(offset);
                offset += descsz;

                UInt64 p       = header.SizeOfInt;
                UInt64 padding = ((offset) % p) != 0 ? (p - (offset) % p) : 0;
                offset += padding;                //TODO: Check it

                yield return(new NoteSectionItem(type, name, descriptor));
            }
        }