/// <summary> /// /// </summary> /// <param name="bytes"></param> /// <param name="IconFilePath"></param> /// <returns></returns> private static bool TryExtractIcon(byte[] bytes, string IconFilePath) { try { PEHeader header = new PEHeader(bytes); return(header.TryExtractIconFromExe(bytes, IconFilePath)); } catch { return(false); } }
/// <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> public bool Read(BinaryReader reader, List <ResourceEntry> iconImageData) { try { Group = PEHeader.FromBinaryReader <GRPICONDIR>(reader); if (Group.idReserved != 0) { RC.WriteWarning(0109, Rpx.Strings.Error_0109); return(false); } if (Group.idType != 1) { RC.WriteWarning(0110, Rpx.Strings.Error_0110); return(false); } for (int i = 0; i < Group.idCount; i++) { GRPICONDIRENTRY entry = PEHeader.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 (Exception ex) { RC.WriteException(0111, Rpx.Strings.Error_0111, ex); return(false); } }
/// <summary> /// /// </summary> /// <param name="bytes"></param> /// <param name="SubsystemType"></param> /// <returns></returns> private static bool TryGetSubsystemType(byte[] bytes, out SubsystemTypes SubsystemType) { SubsystemType = SubsystemTypes.Unknown; try { PEHeader header = new PEHeader(bytes); SubsystemType = header.SubsystemType; return(true); } catch { return(false); } }
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); } } }