/// <summary> /// Constructor /// </summary> /// <param name="fileName">Name of the file</param> /// <param name="mapAsImage"><c>true</c> if we should map it as an executable</param> /// <param name="verify">Verify PE file data</param> public PEImage(string fileName, bool mapAsImage, bool verify) : this(ImageStreamCreator.Create(fileName, mapAsImage), mapAsImage ? ImageLayout.Memory : ImageLayout.File, verify) { try { if (mapAsImage && imageStreamCreator is MemoryMappedFileStreamCreator) { ((MemoryMappedFileStreamCreator)imageStreamCreator).Length = peInfo.GetImageSize(); ResetReader(); } } catch { Dispose(); throw; } }
static IImageStream OpenImageStream(string fileName) { try { if (!File.Exists(fileName)) { return(null); } return(ImageStreamCreator.CreateImageStream(fileName)); } catch (IOException) { } catch (UnauthorizedAccessException) { } catch (SecurityException) { } return(null); }