public void Read(BinaryReader reader, bool isRoot, uint parentName) { ResourceDirectoryInfo = PeReader.FromBinaryReader <ImageResourceDirectory>(reader); List <ImageResourceDirectoryEntry> dirs = new List <ImageResourceDirectoryEntry>(); List <ImageResourceDataEntry> entrys = new List <ImageResourceDataEntry>(); for (int i = 0; i <= ResourceDirectoryInfo.NumberOfNamedEntries - 1; i++) { entrys.Add(PeReader.FromBinaryReader <ImageResourceDataEntry>(reader)); } for (int i = 0; i <= ResourceDirectoryInfo.NumberOfIdEntries - 1; i++) { if (isRoot) { ImageResourceDirectoryEntry dirEntry = PeReader.FromBinaryReader <ImageResourceDirectoryEntry>(reader); if (dirEntry.Name == Convert.ToUInt32(Win32ResourceType.RT_ICON) || dirEntry.Name == Convert.ToUInt32(Win32ResourceType.RT_GROUP_ICON)) { dirs.Add(dirEntry); } } else { dirs.Add(PeReader.FromBinaryReader <ImageResourceDirectoryEntry>(reader)); } } foreach (ImageResourceDataEntry e in entrys) { bool isDir = false; uint entryLoc = e.GetOffset(ref isDir); uint entrySize = e.Size; ResourceEntry entryInfo = new ResourceEntry(e, m_Stream, parentName); Entries.Add(entryInfo); } foreach (ImageResourceDirectoryEntry d in dirs) { bool isDir = false; uint dirLoc = d.GetOffset(ref 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 = PeReader.FromBinaryReader <ImageResourceDataEntry>(reader); uint entryLoc = entry.GetOffset(ref isDir); uint entrySize = entry.Size; ResourceEntry entryInfo = new ResourceEntry(entry, m_Stream, parentName); entryInfo.Seek(); Entries.Add(entryInfo); } } }
/// <summary> /// Read icon group from PE file header /// </summary> /// <param name="reader">reader that holds the PE image</param> /// <param name="iconImageData">all the ResourceEntry objects that hold the image data for the icon</param> internal bool Read(BinaryReader reader, List <ResourceEntry> iconImageData) { try { Group = PeReader.FromBinaryReader <GRPICONDIR>(reader); if (Group.idReserved != 0) { return(false); } if (Group.idType != 1) { return(false); } for (int i = 0; i <= Group.idCount - 1; i++) { GRPICONDIRENTRY entry = PeReader.FromBinaryReader <GRPICONDIRENTRY>(reader); IconImage image = new IconImage(); image.Entry = entry; foreach (ResourceEntry bmp in iconImageData) { if (bmp.Name == entry.ID) { image.Resource = bmp; Entries.Add(image); break; } } } return(true); } catch { return(false); } }