Exemple #1
0
        static ResourceDirectory GetResourcesFor(string file, PEFile pe)
        {
            var stream = new MemoryStream(File.ReadAllBytes(file));
            var reader = new BinaryStreamReader(stream, new byte[1024]);
            pe.ReadFrom(reader);

            var resDataDir = pe.OptionalHeader.DataDirectories[(int)DataDirectoryKind.Resources];

            var rvaStream = new RvaStream(
                stream,
                pe.SectionHeaders.Select(
                s => new RvaStream.Range
                {
                    PhysicalAddress = s.PointerToRawData,
                    Size = s.VirtualSize,
                    VirtualAddress = s.VirtualAddress
                })
                .ToArray());

            rvaStream.Position = resDataDir.VirtualAddress;

            var sectionReader = new BinaryStreamReader(rvaStream, new byte[32]);

            var res = new ResourceDirectory();
            res.Read(sectionReader);

            return res;
        }
Exemple #2
0
        private static void Print(ResourceDirectory resources, int indent)
        {
            foreach (var dir in resources.Subdirectories)
            {
                Console.WriteLine(new string(' ', indent * 3) + "["+(dir.Name == null ? dir.IntegerID.ToString() : "'" + dir.Name + "'")+"]");
                Print(dir.Directory, indent + 1);
            }

            foreach (var d in resources.DataEntries)
            {
                Console.WriteLine(new string(' ', indent * 3) + (d.Name == null ? d.IntegerID.ToString() : "'" + d.Name + "'") + " : " + d.DataRVA.ToString("X") + ":" + d.Size.ToString("X") + "h");
            }
        }
Exemple #3
0
 private static void Print(ResourceDirectory resources)
 {
     Print(resources, 0);
     Console.WriteLine();
 }