Ejemplo n.º 1
0
        public void Read(BinaryReader reader, bool isRoot, uint parentName)
        {
            ResourceDirectoryInfo = PEHeader.FromBinaryReader<ImageResourceDirectory>(reader);

            List<ImageResourceDirectoryEntry> dirs = new List<ImageResourceDirectoryEntry>();
            List<ImageResourceDataEntry> entrys = new List<ImageResourceDataEntry>();

            for (int i = 0; i < ResourceDirectoryInfo.NumberOfNamedEntries; i++)
            {
                entrys.Add(PEHeader.FromBinaryReader<ImageResourceDataEntry>(reader));
            }

            for (int i = 0; i < ResourceDirectoryInfo.NumberOfIdEntries; i++)
            {
                if (isRoot)
                {
                    ImageResourceDirectoryEntry dirEntry = PEHeader.FromBinaryReader<ImageResourceDirectoryEntry>(reader);

                    if (dirEntry.Name == (uint)Win32ResourceType.RT_ICON ||
                        dirEntry.Name == (uint)Win32ResourceType.RT_GROUP_ICON)
                    {
                        dirs.Add(dirEntry);
                    }
                }
                else
                {
                    dirs.Add(PEHeader.FromBinaryReader<ImageResourceDirectoryEntry>(reader));
                }
            }

            foreach (ImageResourceDataEntry e in entrys)
            {
                bool isDir;

                uint entryLoc = e.GetOffset(out isDir);
                uint entrySize = e.Size;

                ResourceEntry entryInfo = new ResourceEntry(e, m_Stream, parentName);

                Entries.Add(entryInfo);                 
            }

            foreach (ImageResourceDirectoryEntry d in dirs)
            {
                bool isDir;

                uint dirLoc = d.GetOffset(out isDir);
                
                ResourceDirectory dirInfo = new ResourceDirectory(d, m_Stream, m_BaseAddress);

                if (isDir)
                {
                    Directorys.Add(dirInfo);

                    dirInfo.Seek();

                    dirInfo.Read(reader ,false, d.Name != 0 ? d.Name : parentName);
                }
                else
                {
                    dirInfo.Seek();

                    ImageResourceDataEntry entry = PEHeader.FromBinaryReader<ImageResourceDataEntry>(reader);

                    uint entryLoc = entry.GetOffset(out isDir);
                    uint entrySize = entry.Size;

                    ResourceEntry entryInfo = new ResourceEntry(entry, m_Stream, parentName);

                    entryInfo.Seek();

                    Entries.Add(entryInfo);   
                }
            }
        }