Ejemplo n.º 1
0
        public HintNameEntry Read(IStructReader reader, IPE32PlusContext image)
        {
            var  exportNameTableIndex = reader.Read <ushort>();
            var  nameBuilder          = new StringBuilder();
            char nextChar;

            while ((nextChar = (char)reader.Read <byte>()) != '\0')
            {
                nameBuilder.Append(nextChar);
            }
            return(new HintNameEntry(exportNameTableIndex, nameBuilder.ToString()));
        }
Ejemplo n.º 2
0
        public RelocationTable Read(IStructReader reader, IPE32PlusContext image)
        {
            var relocationTableSize = image.OptionalHeader.DataDirectories.BaseRelocationTable.Size;
            var relocationTableEnd  = reader.Offset + relocationTableSize;
            var relocationTable     = new Dictionary <BaseRelocationBlockHeader, BaseRelocationBlockEntry[]>();

            while (reader.Offset < relocationTableEnd)
            {
                var header    = reader.Read <BaseRelocationBlockHeader>();
                var noEntries = (header.BlockSize - 8) / 2; // 8 bytes header, 2 bytes for each entry
                var entries   = new BaseRelocationBlockEntry[noEntries];
                for (var i = 0; i < noEntries; i++)
                {
                    entries[i] = reader.Read <BaseRelocationBlockEntry>();
                }
                relocationTable[header] = entries;
            }

            return(new RelocationTable(relocationTable));
        }
Ejemplo n.º 3
0
 public T Read(IStructReader reader, IPE32PlusContext image) => reader.Read <T>();
        //public static void Write<T>(this IStructWriter writer, T item, IPEReader<T> itemReader)
        //{
        //    if (writer == null)
        //        throw new ArgumentNullException(nameof(writer));
        //    if (item == null)
        //        throw new ArgumentNullException(nameof(item));
        //    if (itemReader == null)
        //        throw new ArgumentNullException(nameof(itemReader));

        //    itemReader.Write(item, writer);
        //}

        //public static void WriteArray<T>(this IStructWriter writer, T[] items, IPEReader<T> itemMapper)
        //{
        //    if (writer == null)
        //        throw new ArgumentNullException(nameof(writer));
        //    if (items == null)
        //        throw new ArgumentNullException(nameof(items));
        //    if (itemMapper == null)
        //        throw new ArgumentNullException(nameof(itemMapper));

        //    foreach (var item in items)
        //        itemMapper.Write(item, writer);
        //}

        public static T[] ReadArray <T>(this IStructReader reader, IPEReader <T> itemMapper, IPE32PlusContext image, int count)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }
            if (itemMapper == null)
            {
                throw new ArgumentNullException(nameof(itemMapper));
            }
            if (count <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(count));
            }

            var readItems = new T[count];

            for (var i = 0; i < readItems.Length; i++)
            {
                readItems[i] = itemMapper.Read(reader, image);
            }
            return(readItems);
        }
Ejemplo n.º 5
0
 protected TestsUsingHeaders(byte[] testFile)
 {
     TestFile = testFile;
     _reader  = new ArrayStructReaderWriter(TestFile);
     Image    = new PE32PlusReaderContext(_reader);
 }