Example #1
0
        public ProgramResourceInstance ReadResourceEntry(
            EndianImageReader rdr,
            string resourceId,
            string sLcid,
            ResourceType resourceType)
        {
            var rvaData    = rdr.ReadUInt32();
            var size       = rdr.ReadUInt32();
            var codepage   = rdr.ReadInt32();
            var padding    = rdr.ReadUInt32();
            var abResource = new byte[size];

            Array.Copy(imgLoaded.Bytes, (int)rvaData, abResource, 0, abResource.Length);

            if (resourceType == PeResourceType.BITMAP)
            {
                abResource = PostProcessBitmap(abResource);
            }

            string?encodingName = GetEncodingName(codepage);
            string?langTag      = GetLanguageTag(sLcid);

            return(new ProgramResourceInstance
            {
                Name = $"{resourceId}-{langTag}",
                Type = resourceType.Name,
                TextEncoding = encodingName,
                FileExtension = resourceType.FileExtension,
                Bytes = abResource,
            });
        }
Example #2
0
        public static Elf32_Rela Read(EndianImageReader rdr)
        {
            var o = rdr.ReadUInt32();
            var i = rdr.ReadUInt32();
            var a = rdr.ReadInt32();

            return(new Elf32_Rela
            {
                r_offset = o,
                r_info = i,
                r_addend = a
            });
        }
Example #3
0
        /// <summary>
        /// Reads a resource directory, starting at the position of the given image
        /// reader.
        /// </summary>
        /// <param name="rdr">A little endian <see cref="EndianImageReader"/>.</param>
        /// <returns>A list of the resources found in the directory.</returns>
        public List <ProgramResource> ReadResourceDirectory(EndianImageReader rdr)
        {
            const uint DIR_MASK     = 0x80000000;
            var        flags        = rdr.ReadUInt32();
            var        date         = rdr.ReadUInt32();
            var        version      = rdr.ReadUInt32();
            var        cNameEntries = rdr.ReadUInt16();
            var        cIdEntries   = rdr.ReadUInt16();
            var        entries      = new List <ProgramResource>();

            // Read the named entries.
            for (int i = 0; i < cNameEntries; ++i)
            {
                var rvaName  = rdr.ReadUInt32();
                var rvaEntry = rdr.ReadUInt32();
                var subRdr   = new LeImageReader(imgLoaded, rvaResources + (rvaEntry & ~DIR_MASK));
                if ((rvaEntry & DIR_MASK) == 0)
                {
                    throw new BadImageFormatException();
                }
                if ((rvaName & DIR_MASK) != 0)
                {
                    var e = new ProgramResourceGroup
                    {
                        //Name = ReadResourceString(rvaName),
                        Name = ReadResourceUtf16leString(rvaResources + (rvaName & ~DIR_MASK)),
                    };
                    e.Resources.AddRange(ReadNameDirectory(subRdr, PeResourceType.FromInt(0)));
                    entries.Add(e);
                }
            }
            // Read the entries accessed by numeric ID.
            for (int i = 0; i < cIdEntries; ++i)
            {
                var id       = rdr.ReadInt32();
                var rvaEntry = rdr.ReadUInt32();
                var subRdr   = new LeImageReader(imgLoaded, rvaResources + (rvaEntry & ~DIR_MASK));
                if ((rvaEntry & DIR_MASK) == 0)
                {
                    throw new BadImageFormatException();
                }
                var rt = PeResourceType.FromInt(id);
                var e  = new ProgramResourceGroup
                {
                    Name = rt.Name
                };
                e.Resources.AddRange(ReadNameDirectory(subRdr, rt));
                entries.Add(e);
            }
            return(entries);
        }
Example #4
0
        public List <ProgramResource> ReadLanguageDirectory(
            EndianImageReader rdr,
            ResourceType resourceType,
            string resourceId)
        {
            const uint DIR_MASK     = 0x80000000;
            var        flags        = rdr.ReadUInt32();
            var        date         = rdr.ReadUInt32();
            var        version      = rdr.ReadUInt32();
            var        cNameEntries = rdr.ReadUInt16();
            var        cIdEntries   = rdr.ReadUInt16();
            var        entries      = new List <ProgramResource>();

            for (int i = 0; i < cNameEntries; ++i)
            {
                var rvaName  = rdr.ReadUInt32();
                var rvaEntry = rdr.ReadUInt32();
                var subRdr   = new LeImageReader(imgLoaded, rvaResources + (rvaEntry & ~DIR_MASK));
                if ((rvaEntry & DIR_MASK) != 0)
                {
                    throw new BadImageFormatException();
                }
                entries.Add(ReadResourceEntry(subRdr, resourceId, ReadResourceString(rvaName), resourceType));
            }
            for (int i = 0; i < cIdEntries; ++i)
            {
                var id       = rdr.ReadInt32();
                var rvaEntry = rdr.ReadUInt32();
                var subRdr   = new LeImageReader(imgLoaded, rvaResources + (rvaEntry & ~DIR_MASK));
                if ((rvaEntry & DIR_MASK) != 0)
                {
                    throw new BadImageFormatException();
                }
                entries.Add(ReadResourceEntry(subRdr, resourceId, id.ToString(), resourceType));
            }
            return(entries);
        }
Example #5
0
 public override long ReadWord(EndianImageReader rdr)
 {
     return(rdr.ReadInt32());
 }