Пример #1
0
		/// <inheritdoc/>
		protected override void Dispose(bool disposing) {
			// Call base first since it will dispose of all the resources, which will
			// eventually use dnFile that we will dispose
			base.Dispose(disposing);
			if (disposing) {
				var dnf = dnFile;
				if (dnf != null)
					dnf.Dispose();
				dnFile = null;
			}
		}
Пример #2
0
		/// <summary>
		/// Creates a <see cref="ModuleDefMD"/> instance from a <see cref="DotNetFile"/>
		/// </summary>
		/// <param name="dnFile">The loaded .NET file</param>
		/// <param name="context">Module context or <c>null</c></param>
		/// <returns>A new <see cref="ModuleDefMD"/> instance that now owns <paramref name="dnFile"/></returns>
		public static ModuleDefMD Load(DotNetFile dnFile, ModuleContext context) {
			return new ModuleDefMD(dnFile, context);
		}
Пример #3
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="dnFile">The loaded .NET file</param>
		/// <param name="context">Module context or <c>null</c></param>
		/// <exception cref="ArgumentNullException">If <paramref name="dnFile"/> is <c>null</c></exception>
		ModuleDefMD(DotNetFile dnFile, ModuleContext context)
			: base(null, 1) {
#if DEBUG
			if (dnFile == null)
				throw new ArgumentNullException("dnFile");
#endif
			this.dnFile = dnFile;
			this.context = context;
			Initialize();

			this.Kind = GetKind();
			this.Characteristics = MetaData.PEImage.ImageNTHeaders.FileHeader.Characteristics;
			this.DllCharacteristics = MetaData.PEImage.ImageNTHeaders.OptionalHeader.DllCharacteristics;
			this.RuntimeVersion = MetaData.VersionString;
			this.Machine = MetaData.PEImage.ImageNTHeaders.FileHeader.Machine;
			this.Cor20HeaderFlags = MetaData.ImageCor20Header.Flags;
			this.Cor20HeaderRuntimeVersion = (uint)(MetaData.ImageCor20Header.MajorRuntimeVersion << 16) | MetaData.ImageCor20Header.MinorRuntimeVersion;
			this.TablesHeaderVersion = MetaData.TablesStream.Version;
		}
Пример #4
0
		/// <summary>
		/// Creates a <see cref="ModuleDefMD"/> instance from a <see cref="DotNetFile"/>
		/// </summary>
		/// <param name="dnFile">The loaded .NET file</param>
		/// <returns>A new <see cref="ModuleDefMD"/> instance that now owns <paramref name="dnFile"/></returns>
		public static ModuleDefMD Load(DotNetFile dnFile) {
			return Load(dnFile, null);
		}
Пример #5
0
		/// <summary>
		/// Creates a <see cref="ModuleDefMD"/> instance from a memory location
		/// </summary>
		/// <param name="addr">Address of a .NET module/assembly</param>
		/// <param name="context">Module context or <c>null</c></param>
		/// <param name="imageLayout">Image layout of the file in memory</param>
		/// <returns>A new <see cref="ModuleDefMD"/> instance</returns>
		public static ModuleDefMD Load(IntPtr addr, ModuleContext context, ImageLayout imageLayout) {
			DotNetFile dnFile = null;
			try {
				return Load(dnFile = DotNetFile.Load(addr, imageLayout), context);
			}
			catch {
				if (dnFile != null)
					dnFile.Dispose();
				throw;
			}
		}
Пример #6
0
		/// <summary>
		/// Creates a <see cref="ModuleDefMD"/> instance from a byte[]
		/// </summary>
		/// <param name="data">Contents of a .NET module/assembly</param>
		/// <param name="context">Module context or <c>null</c></param>
		/// <returns>A new <see cref="ModuleDefMD"/> instance</returns>
		public static ModuleDefMD Load(byte[] data, ModuleContext context) {
			DotNetFile dnFile = null;
			try {
				return Load(dnFile = DotNetFile.Load(data), context);
			}
			catch {
				if (dnFile != null)
					dnFile.Dispose();
				throw;
			}
		}
Пример #7
0
		/// <summary>
		/// Creates a <see cref="ModuleDefMD"/> instance from a file
		/// </summary>
		/// <param name="fileName">File name of an existing .NET module/assembly</param>
		/// <param name="context">Module context or <c>null</c></param>
		/// <returns>A new <see cref="ModuleDefMD"/> instance</returns>
		public static ModuleDefMD Load(string fileName, ModuleContext context) {
			DotNetFile dnFile = null;
			try {
				return Load(dnFile = DotNetFile.Load(fileName), context);
			}
			catch {
				if (dnFile != null)
					dnFile.Dispose();
				throw;
			}
		}
Пример #8
0
		public void Dispose() {
			if (ownPeImage) {
				if (dnFile != null)
					dnFile.Dispose();
				if (peImage != null)
					peImage.Dispose();
			}
			if (peStream != null)
				peStream.Dispose();

			dnFile = null;
			peImage = null;
			peStream = null;
		}