Represents a resource directory entry in the resource data directory of a windows assembly image.
Наследование: FileSegment
Пример #1
0
        internal static ImageResourceDirectoryEntry FromReadingContext(ReadingContext context)
        {
            var reader            = context.Reader;
            var resourceDirectory =
                context.Assembly.NtHeaders.OptionalHeader.DataDirectories[ImageDataDirectory.ResourceDirectoryIndex];

            var entry = new ImageResourceDirectoryEntry
            {
                StartOffset  = reader.Position,
                NameId       = reader.ReadUInt32(),
                OffsetToData = reader.ReadUInt32(),
            };

            entry.HasData = (entry.OffsetToData >> 31) == 0;

            uint actualDataOffset = entry.OffsetToData & ~(1 << 31);

            entry.HasName = (entry.NameId >> 31) == 1;
            if (entry.HasName)
            {
                entry._nameReadingContext =
                    context.CreateSubContext(context.Assembly.RvaToFileOffset(resourceDirectory.VirtualAddress) +
                                             (entry.NameId & ~(1 << 31)));
            }

            entry._dataReadingContext =
                context.CreateSubContext(context.Assembly.RvaToFileOffset(resourceDirectory.VirtualAddress) +
                                         actualDataOffset);
            return(entry);
        }
Пример #2
0
        internal static ImageResourceDirectory FromReadingContext(ReadingContext context)
        {
            var reader = context.Reader;

            var directory = new ImageResourceDirectory
            {
                StartOffset     = reader.Position,
                Characteristics = reader.ReadUInt32(),
                TimeDateStamp   = reader.ReadUInt32(),
                MajorVersion    = reader.ReadUInt16(),
                MinorVersion    = reader.ReadUInt16(),
            };

            var numberOfNamedEntries = reader.ReadUInt16();
            var numberOfIdEntries    = reader.ReadUInt16();

            for (int i = 0; i < numberOfNamedEntries; i++)
            {
                directory.Entries.Add(ImageResourceDirectoryEntry.FromReadingContext(context));
            }

            for (int i = 0; i < numberOfIdEntries; i++)
            {
                directory.Entries.Add(ImageResourceDirectoryEntry.FromReadingContext(context));
            }

            return(directory);
        }
        internal static ImageResourceDirectoryEntry FromReadingContext(ReadingContext context)
        {
            var reader = context.Reader;
            var resourceDirectory =
                context.Assembly.NtHeaders.OptionalHeader.DataDirectories[ImageDataDirectory.ResourceDirectoryIndex];

            var entry = new ImageResourceDirectoryEntry
            {
                StartOffset = reader.Position,
                NameId = reader.ReadUInt32(),
                OffsetToData = reader.ReadUInt32(),
            };

            entry.HasData = (entry.OffsetToData >> 31) == 0;

            uint actualDataOffset = entry.OffsetToData & ~(1 << 31);

            entry.HasName = (entry.NameId >> 31) == 1;
            if (entry.HasName)
            {
                entry._nameReadingContext =
                    context.CreateSubContext(context.Assembly.RvaToFileOffset(resourceDirectory.VirtualAddress) +
                                             (entry.NameId & ~(1 << 31)));
            }

            entry._dataReadingContext =
                context.CreateSubContext(context.Assembly.RvaToFileOffset(resourceDirectory.VirtualAddress) +
                                         actualDataOffset);
            return entry;
        }