Exemple #1
0
        public Section(Elf32_Shdr header, byte[] data, LinkingView owner)
        {
            if (header != null)
            {
                this.header = header;
            }
            else
            {
                throw new ArgumentNullException("header");
            }

            if (data != null)
            {
                this.data = data;
            }
            else
            {
                throw new ArgumentNullException("data");
            }

            if (owner != null)
            {
                this.owner = owner;
            }
            else
            {
                throw new ArgumentNullException("owner");
            }
        }
Exemple #2
0
        public StrTabSection(Elf32_Shdr hdr, byte[] data, LinkingView owner)
            : base(hdr, data, owner)
        {
            int stringStart = 0;

            for (int i = 0; i < Header.sh_size; i++)
            {
                if (Data[i] == 0)
                {
                    offsets.Add(stringStart);
                    stringStart = i + 1;
                }
            }
        }
Exemple #3
0
 protected byte[] CollectSectionsData(ref int shoff, uint offset, int sectionIndex)
 {
     if (sectionIndex < Sections.Count)
     {
         Section    section = Sections[sectionIndex];
         Elf32_Shdr header  = section.Header;
         header.sh_offset = (header.sh_addralign > 1) ? (uint)Util.WideToFold(offset, header.sh_addralign) : offset;
         byte[] binaryData = CollectSectionsData(ref shoff, header.sh_offset + header.sh_size, sectionIndex + 1);
         Array.Copy(section.Data, 0, binaryData, header.sh_offset, header.sh_size);
         Marshal.StructureToPtr(header, Marshal.UnsafeAddrOfPinnedArrayElement(binaryData, (int)(shoff + sectionIndex * Header.e_shentsize)), false);
         return(binaryData);
     }
     else
     {
         shoff = (int)Util.WideToFold(offset, 4);
         return(new byte[shoff + Sections.Count * Header.e_shentsize]);
     }
 }
Exemple #4
0
        public LinkingView(byte[] binaryData) : this()
        {
            Marshal.PtrToStructure(Marshal.UnsafeAddrOfPinnedArrayElement(binaryData, 0), header);
            for (int section = 0; section < Header.e_shnum; section++)
            {
                Elf32_Shdr sectionHeader = (Elf32_Shdr)Marshal.PtrToStructure(Marshal.UnsafeAddrOfPinnedArrayElement(binaryData,
                                                                                                                     (int)(Header.e_shoff + section * Header.e_shentsize)), typeof(Elf32_Shdr));
                byte[] sectionData = new byte[sectionHeader.sh_size];
                Array.Copy(binaryData, sectionHeader.sh_offset, sectionData, 0, sectionHeader.sh_size);
                switch (sectionHeader.sh_type)
                {
                case (uint)SectionTypes.SHT_STRTAB: Sections.Add(new StrTabSection(sectionHeader, sectionData, this)); break;

                case (uint)SectionTypes.SHT_SYMTAB: Sections.Add(new SymTabSection(sectionHeader, sectionData, this)); break;

                default: Sections.Add(new Section(sectionHeader, sectionData, this)); break;
                }
            }
        }
Exemple #5
0
 public SymTabSection(Elf32_Shdr hdr, byte[] data, LinkingView owner)
     : base(hdr, data, owner)
 {
 }