public PeContainer(string filename, ushort groupIconName) { ValidateFilename(filename); // load pe var datafile = PInvoke.LoadDatafile(filename); if (datafile == IntPtr.Zero) throw new Win32Exception("Unable to load datafile", PInvoke.GetLastWin32Exception()); using (var disposableUpdate = new PInvoke.DisposableHandle(datafile, PInvoke.FreeLibrary)) { // load group icon data var groupIconBytes = PInvoke.LoadResourceBytes(datafile, (ushort)PInvoke.ResourceType.GROUP_ICON, groupIconName); // parse directory from data Directory = new PeDirectory(groupIconBytes); Images = new IconImage[Directory.Entries.Length]; // parse images from data for (var i = 0; i < Directory.Entries.Length; i++) { var imageBytes = PInvoke.LoadResourceBytes(datafile, (ushort)PInvoke.ResourceType.ICON, Directory.Entries[i].Id); Images[i] = new IconImage(imageBytes); } disposableUpdate.SuppressDispose(); } }
public PeContainer(string filename, ushort groupIconName) { ValidateFilename(filename); // load pe var datafile = PInvoke.LoadDatafile(filename); if (datafile == IntPtr.Zero) { throw new Win32Exception("Unable to load datafile", PInvoke.GetLastWin32Exception()); } using (var disposableUpdate = new PInvoke.DisposableHandle(datafile, PInvoke.FreeLibrary)) { // load group icon data var groupIconBytes = PInvoke.LoadResourceBytes(datafile, (ushort)PInvoke.ResourceType.GROUP_ICON, groupIconName); // parse directory from data Directory = new PeDirectory(groupIconBytes); Images = new IconImage[Directory.Entries.Length]; // parse images from data for (var i = 0; i < Directory.Entries.Length; i++) { var imageBytes = PInvoke.LoadResourceBytes(datafile, (ushort)PInvoke.ResourceType.ICON, Directory.Entries[i].Id); Images[i] = new IconImage(imageBytes); } disposableUpdate.SuppressDispose(); } }
// gets related busy icon names from file private ushort[] GetBusyIconNames(string filename, ushort groupIconName) { var datafile = LoadDatafile(filename); ushort[] busyNames; PeDirectory oldDirectory = null; using (new PInvoke.DisposableHandle(datafile, PInvoke.FreeLibrary)) { busyNames = PInvoke.GetResourceNames(datafile, (ushort)PInvoke.ResourceType.ICON); var directoryExists = PInvoke.GetResourceNames(datafile, (ushort)PInvoke.ResourceType.GROUP_ICON).Any(n => n == groupIconName); if (directoryExists) { var directoryBytes = PInvoke.LoadResourceBytes(datafile, (ushort)PInvoke.ResourceType.GROUP_ICON, groupIconName); oldDirectory = new PeDirectory(directoryBytes); } } if (oldDirectory != null) { var oldNames = oldDirectory.Entries.Select(e => e.Id); busyNames = busyNames.Except(oldNames).ToArray(); } return(busyNames); }
public PeContainer(IcoContainer container) : base(container) { if (container.Directory == null) throw new InvalidOperationException("Container Directory is null"); Directory = new PeDirectory(container.Directory); }
public PeContainer(IcoContainer container) : base(container) { if (container.Directory == null) { throw new InvalidOperationException("Container Directory is null"); } Directory = new PeDirectory(container.Directory); }
public static IcoDirectory ToIco(this PeDirectory directory) { if (directory == null) { throw new ArgumentNullException("directory"); } if (directory.Entries == null || directory.Entries.Any(e => e == null)) { throw new InvalidOperationException("Directory Entries are null"); } return(new IcoDirectory(directory) { Entries = directory.Entries.Select(e => e.ToIco()).ToArray() }); }
public PeContainer() { Directory = new PeDirectory(); }
// gets related busy icon names from file private ushort[] GetBusyIconNames(string filename, ushort groupIconName) { var datafile = LoadDatafile(filename); ushort[] busyNames; PeDirectory oldDirectory = null; using (new PInvoke.DisposableHandle(datafile, PInvoke.FreeLibrary)) { busyNames = PInvoke.GetResourceNames(datafile, (ushort)PInvoke.ResourceType.ICON); var directoryExists = PInvoke.GetResourceNames(datafile, (ushort)PInvoke.ResourceType.GROUP_ICON).Any(n => n == groupIconName); if (directoryExists) { var directoryBytes = PInvoke.LoadResourceBytes(datafile, (ushort)PInvoke.ResourceType.GROUP_ICON, groupIconName); oldDirectory = new PeDirectory(directoryBytes); } } if (oldDirectory != null) { var oldNames = oldDirectory.Entries.Select(e => e.Id); busyNames = busyNames.Except(oldNames).ToArray(); } return busyNames; }
public PeDirectory(PeDirectory directory) : base(directory) { Entries = directory.Entries.Select(e => new PeDirectoryEntry(e)).ToArray(); }