diff --git a/docs/dotnet/advanced-pe-image-building.rst b/docs/dotnet/advanced-pe-image-building.rst index db94d483c..8a5801013 100644 --- a/docs/dotnet/advanced-pe-image-building.rst +++ b/docs/dotnet/advanced-pe-image-building.rst @@ -12,7 +12,8 @@ The easiest way to write a .NET module to the disk is by using the ``Write`` met This method is essentially a shortcut for invoking the ``ManagedPEImageBuilder`` and ``ManagedPEFileBuilder`` classes, and will completely reconstruct the PE image, serialize it into a PE file and write the PE file to the disk. -While this is easy, and would probably work for most .NET module processing, it does not provide much flexibility. To get more control over the construction of the new PE image, it is therefore not recommended to use a different overload of the ``Write`` method, where we pass on a custom ``IPEFileBuilder``, or a configured ``ManagedPEImageBuilder``: +While this is easy, and would probably work for most .NET module processing, it does not provide much flexibility. +To get more control over the construction of the new PE image, it is therefore not recommended to use a different overload of the ``Write`` method that takes instances of ``IPEImageBuilder`` instead: .. code-block:: csharp @@ -22,7 +23,26 @@ While this is easy, and would probably work for most .NET module processing, it module.Write(@"C:\Path\To\Output\Binary.exe", imageBuilder); -Alternatively, it is possible to call the ``CreateImage`` method directly. This allows for inspecting all build artifacts, as well as post-processing of the constructed PE image before it is written to the disk. + +Alternatively, it is possible to call ``ModuleDefinition::ToPEImage`` to turn the module into a ``PEImage`` first, that can then later be post-processed and transformed into a ``PEFile`` to write it to the disk: + +.. code-block:: csharp + + var imageBuilder = new ManagedPEImageBuilder(); + + /* Configuration of imageBuilder here... */ + + // Construct image. + var image = module.ToPEImage(imageBuilder); + + // Write image to the disk. + var fileBuilder = new ManagedPEFileBuilder(); + var file = fileBuilder.CreateFile(image); + file.Write(@"C:\Path\To\Output\Binary.exe"); + + +To get even more control, it is possible to call the ``CreateImage`` method from the image builder directly. +This allows for inspecting all build artifacts, as well as post-processing of the constructed PE image before it is written to the disk. .. code-block:: csharp @@ -32,6 +52,10 @@ Alternatively, it is possible to call the ``CreateImage`` method directly. This // Construct image. var result = imageBuilder.CreateImage(module); + + /* Inspect build result ... */ + + // Obtain constructed PE image. var image = result.ConstructedImage; /* Post processing of image happens here... */ @@ -162,6 +186,13 @@ Below an example on how to preserve maximum stack depths for all methods in the ComputeMaxStackOnBuildOverride = false } + +.. warning:: + + Disabling max stack computation may have unexpected side-effects (such as rendering certain CIL method bodies invalid). + + + Strong name signing ------------------- @@ -194,26 +225,56 @@ After writing the module to an output stream, use the ``StrongNameSigner`` class Image Builder Diagnostics ------------------------- -.NET modules that contain invalid metadata and/or method bodies might cause problems upon serializing it to a PE image or file. To inspect all errors that occurred during the construction of a PE image, call the ``CreateImage`` method directly and get the value of the ``DiagnosticBag`` property. This is a collection that contains all the problems that occurred during the process: +.NET modules that contain invalid metadata and/or method bodies might cause problems upon serializing it to a PE image or file. +To inspect all errors that occurred during the construction of a PE image, call the ``CreateImage`` method with the ``ErrorListener`` property set to an instance of the ``DiagnosticBag`` property. +This is an implementation of ``IErrorListener`` that collects all the problems that occurred during the process: .. code-block:: csharp - var result = imageBuilder.CreateImage(module); + // Set up a diagnostic bag as an error listener. + var diagnosticBag = new DiagnosticBag(); + imageBuilder.ErrorListener = diagnosticBag; - Console.WriteLine("Construction finished with {0} errors.", result.DiagnosticBag.Exceptions.Count); + // Build image. + var result = imageBuilder.CreateImage(module); // Print all errors. - foreach (var error in result.DiagnosticBag.Exceptions) + Console.WriteLine("Construction finished with {0} errors.", diagnosticBag.Exceptions.Count); + foreach (var error in diagnosticBag.Exceptions) Console.WriteLine(error.Message); -Whenever a problem is reported, AsmResolver attempts to recover or fill in default data where corrupted data was encountered. To test whether any of the errors resulted in AsmResolver to abort the construction of the image, use the ``IsFatal`` property. If this property is set to ``false``, the image stored in the ``ConstructedImage`` property can be written to the disk: +Whenever a problem is reported, AsmResolver attempts to recover or fill in default data where corrupted data was encountered. +To simply build the PE image ignoring all diagnostic errors, it is also possible to pass in ``EmptyErrorListener.Instance`` instead: .. code-block:: csharp - if (!result.DiagnosticBag.IsFatal) + imageBuilder.ErrorListener = EmptyErrorListener.Instance; + + +.. warning:: + + Using ``EmptyErrorListener`` will surpress any non-critical builder errors, however these errors are typically indicative of an invalid executable being constructed. + Therefore, even if an output file is produced, it may have unexpected side-effects (such as the file not functioning properly). + + +.. note:: + + Setting an instance of ``IErrorListener`` in the image builder will only affect the building process. + If the input module is initialized from a file containing invalid metadata, you may still experience reader errors, even if an ``EmptyErrorListener`` is specified. + See :ref:`dotnet-advanced-module-reading` for handling reader diagnostics. + + +To test whether any of the errors resulted in AsmResolver to abort the construction of the image, use the ``PEImageBuildResult::HasFailed`` property. +If this property is set to ``false``, the image stored in the ``ConstructedImage`` property can be written to the disk: + +.. code-block:: csharp + + if (!result.HasFailed) { var fileBuilder = new ManagedPEFileBuilder(); var file = fileBuilder.CreateFile(result.ConstructedImage); file.Write("output.exe"); - } \ No newline at end of file + } + + diff --git a/src/AsmResolver.DotNet/Builder/DotNetDirectoryFactory.cs b/src/AsmResolver.DotNet/Builder/DotNetDirectoryFactory.cs index be0f359bd..7f2e56455 100644 --- a/src/AsmResolver.DotNet/Builder/DotNetDirectoryFactory.cs +++ b/src/AsmResolver.DotNet/Builder/DotNetDirectoryFactory.cs @@ -76,13 +76,13 @@ public StrongNamePrivateKey? StrongNamePrivateKey public virtual DotNetDirectoryBuildResult CreateDotNetDirectory( ModuleDefinition module, INativeSymbolsProvider symbolsProvider, - DiagnosticBag diagnosticBag) + IErrorListener errorListener) { // Find all members in the module. var discoveryResult = DiscoverMemberDefinitionsInModule(module); // Creat new .NET dir buffer. - var buffer = CreateDotNetDirectoryBuffer(module, symbolsProvider, diagnosticBag); + var buffer = CreateDotNetDirectoryBuffer(module, symbolsProvider, errorListener); buffer.DefineModule(module); // When specified, import existing AssemblyRef, ModuleRef, TypeRef and MemberRef prior to adding any other @@ -164,10 +164,10 @@ private MemberDiscoveryResult DiscoverMemberDefinitionsInModule(ModuleDefinition private DotNetDirectoryBuffer CreateDotNetDirectoryBuffer( ModuleDefinition module, INativeSymbolsProvider symbolsProvider, - DiagnosticBag diagnosticBag) + IErrorListener errorListener) { var metadataBuffer = CreateMetadataBuffer(module); - return new DotNetDirectoryBuffer(module, MethodBodySerializer, symbolsProvider, metadataBuffer, diagnosticBag); + return new DotNetDirectoryBuffer(module, MethodBodySerializer, symbolsProvider, metadataBuffer, errorListener); } private IMetadataBuffer CreateMetadataBuffer(ModuleDefinition module) diff --git a/src/AsmResolver.DotNet/Builder/IDotNetDirectoryFactory.cs b/src/AsmResolver.DotNet/Builder/IDotNetDirectoryFactory.cs index ce0df8d2f..97ba5fd96 100644 --- a/src/AsmResolver.DotNet/Builder/IDotNetDirectoryFactory.cs +++ b/src/AsmResolver.DotNet/Builder/IDotNetDirectoryFactory.cs @@ -13,9 +13,9 @@ public interface IDotNetDirectoryFactory /// /// The module to serialize to a .NET data directory. /// The object responsible for providing references to native symbols. - /// The bag that is used to collect all diagnostic information during the building process. + /// The listener that is used to collect all diagnostic information during the building process. /// The serialized data directory. /// Occurs when the metadata builder encounters an error. - DotNetDirectoryBuildResult CreateDotNetDirectory(ModuleDefinition module, INativeSymbolsProvider symbolsProvider, DiagnosticBag diagnosticBag); + DotNetDirectoryBuildResult CreateDotNetDirectory(ModuleDefinition module, INativeSymbolsProvider symbolsProvider, IErrorListener errorListener); } -} \ No newline at end of file +} diff --git a/src/AsmResolver.DotNet/Builder/ManagedPEImageBuilder.cs b/src/AsmResolver.DotNet/Builder/ManagedPEImageBuilder.cs index c67b17956..d918ba2a0 100644 --- a/src/AsmResolver.DotNet/Builder/ManagedPEImageBuilder.cs +++ b/src/AsmResolver.DotNet/Builder/ManagedPEImageBuilder.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; using AsmResolver.DotNet.Code.Native; using AsmResolver.PE; @@ -31,11 +31,30 @@ public ManagedPEImageBuilder(MetadataBuilderFlags metadataBuilderFlags) /// /// Creates a new instance of the class, using the provided - /// .NET data directory flags. + /// .NET data directory factory. /// public ManagedPEImageBuilder(IDotNetDirectoryFactory factory) + : this(factory, new DiagnosticBag()) { - DotNetDirectoryFactory = factory ?? throw new ArgumentNullException(nameof(factory)); + } + + /// + /// Creates a new instance of the class, using the provided + /// .NET data directory factory. + /// + public ManagedPEImageBuilder(IErrorListener errorListener) + : this(new DotNetDirectoryFactory(), errorListener) + { + } + + /// + /// Creates a new instance of the class, using the provided + /// .NET data directory factory and error listener. + /// + public ManagedPEImageBuilder(IDotNetDirectoryFactory factory, IErrorListener errorListener) + { + DotNetDirectoryFactory = factory; + ErrorListener = errorListener; } /// @@ -47,10 +66,19 @@ public IDotNetDirectoryFactory DotNetDirectoryFactory set; } + /// + /// Gets or sets the object responsible for keeping track of diagnostics during the building process. + /// + public IErrorListener ErrorListener + { + get; + set; + } + /// public PEImageBuildResult CreateImage(ModuleDefinition module) { - var context = new PEImageBuildContext(); + var context = new PEImageBuildContext(ErrorListener); PEImage? image = null; ITokenMapping? tokenMapping = null; @@ -74,7 +102,7 @@ public PEImageBuildResult CreateImage(ModuleDefinition module) var result = DotNetDirectoryFactory.CreateDotNetDirectory( module, symbolProvider, - context.DiagnosticBag); + context.ErrorListener); image.DotNetDirectory = result.Directory; tokenMapping = result.TokenMapping; @@ -108,12 +136,12 @@ public PEImageBuildResult CreateImage(ModuleDefinition module) } catch (Exception ex) { - context.DiagnosticBag.RegisterException(ex); - context.DiagnosticBag.MarkAsFatal(); + context.ErrorListener.RegisterException(ex); + context.ErrorListener.MarkAsFatal(); } tokenMapping ??= new TokenMapping(); - return new PEImageBuildResult(image, context.DiagnosticBag, tokenMapping); + return new PEImageBuildResult(image, context.ErrorListener, tokenMapping); } } } diff --git a/src/AsmResolver.DotNet/Builder/PEImageBuildContext.cs b/src/AsmResolver.DotNet/Builder/PEImageBuildContext.cs index 4947ae819..b56dd6b26 100644 --- a/src/AsmResolver.DotNet/Builder/PEImageBuildContext.cs +++ b/src/AsmResolver.DotNet/Builder/PEImageBuildContext.cs @@ -1,35 +1,50 @@ -using System; - -namespace AsmResolver.DotNet.Builder -{ - /// - /// Provides a context in which a PE image construction takes place in. - /// - public class PEImageBuildContext - { - /// - /// Creates a new empty build context. - /// - public PEImageBuildContext() - { - DiagnosticBag = new DiagnosticBag(); - } - - /// - /// Creates a new build context. - /// - /// The diagnostic bag to use. - public PEImageBuildContext(DiagnosticBag diagnosticBag) - { - DiagnosticBag = diagnosticBag ?? throw new ArgumentNullException(nameof(diagnosticBag)); - } - - /// - /// Gets the bag that collects all diagnostic information during the building process. - /// - public DiagnosticBag DiagnosticBag - { - get; - } - } -} \ No newline at end of file +using System; + +namespace AsmResolver.DotNet.Builder +{ + /// + /// Provides a context in which a PE image construction takes place in. + /// + public class PEImageBuildContext + { + /// + /// Creates a new empty build context. + /// + public PEImageBuildContext() + { + ErrorListener = new DiagnosticBag(); + } + + /// + /// Creates a new build context. + /// + /// The diagnostic bag to use. + public PEImageBuildContext(DiagnosticBag diagnosticBag) + { + ErrorListener = diagnosticBag ?? throw new ArgumentNullException(nameof(diagnosticBag)); + } + + /// + /// Creates a new build context. + /// + /// The diagnostic bag to use. + public PEImageBuildContext(IErrorListener errorListener) + { + ErrorListener = errorListener ?? throw new ArgumentNullException(nameof(errorListener)); + } + + /// + /// Gets the bag that collects all diagnostic information during the building process. + /// + [Obsolete("Use ErrorListener instead.")] + public DiagnosticBag? DiagnosticBag => ErrorListener as DiagnosticBag; + + /// + /// Gets the error listener that handles all diagnostic information during the building process. + /// + public IErrorListener ErrorListener + { + get; + } + } +} diff --git a/src/AsmResolver.DotNet/Builder/PEImageBuildResult.cs b/src/AsmResolver.DotNet/Builder/PEImageBuildResult.cs index 95aef83eb..928614a5a 100644 --- a/src/AsmResolver.DotNet/Builder/PEImageBuildResult.cs +++ b/src/AsmResolver.DotNet/Builder/PEImageBuildResult.cs @@ -1,55 +1,75 @@ -using System; -using System.Diagnostics.CodeAnalysis; -using AsmResolver.PE; - -namespace AsmResolver.DotNet.Builder -{ - /// - /// Describes the result of the construction of a from a . - /// - public class PEImageBuildResult - { - /// - /// Creates a new instance of the class. - /// - /// The constructed image, or null if the construction failed. - /// The diagnostics that were collected during the construction of the image. - /// An object that maps metadata members to their newly assigned tokens. - public PEImageBuildResult(IPEImage? image, DiagnosticBag diagnosticBag, ITokenMapping tokenMapping) - { - ConstructedImage = image; - DiagnosticBag = diagnosticBag ?? throw new ArgumentNullException(nameof(diagnosticBag)); - TokenMapping = tokenMapping ?? throw new ArgumentNullException(nameof(tokenMapping)); - } - - /// - /// Gets the constructed image, or null if the construction failed. - /// - public IPEImage? ConstructedImage - { - get; - } - - /// - /// Gets a value indicating whether the image was constructed successfully or not. - /// - [MemberNotNullWhen(false, nameof(ConstructedImage))] - public bool HasFailed => DiagnosticBag.IsFatal; - - /// - /// Gets the bag containing the diagnostics that were collected during the construction of the image. - /// - public DiagnosticBag DiagnosticBag - { - get; - } - - /// - /// Gets an object that maps metadata members to their newly assigned tokens. - /// - public ITokenMapping TokenMapping - { - get; - } - } -} +using System; +using System.Diagnostics.CodeAnalysis; +using AsmResolver.PE; + +namespace AsmResolver.DotNet.Builder +{ + /// + /// Describes the result of the construction of a from a . + /// + public class PEImageBuildResult + { + /// + /// Creates a new instance of the class. + /// + /// The constructed image, or null if the construction failed. + /// The diagnostics that were collected during the construction of the image. + /// An object that maps metadata members to their newly assigned tokens. + [Obsolete] + public PEImageBuildResult(IPEImage? image, DiagnosticBag diagnosticBag, ITokenMapping tokenMapping) + { + ConstructedImage = image; + ErrorListener = diagnosticBag ?? throw new ArgumentNullException(nameof(diagnosticBag)); + TokenMapping = tokenMapping ?? throw new ArgumentNullException(nameof(tokenMapping)); + } + + /// + /// Creates a new instance of the class. + /// + /// The constructed image, or null if the construction failed. + /// The diagnostics that were collected during the construction of the image. + /// An object that maps metadata members to their newly assigned tokens. + public PEImageBuildResult(IPEImage? image, IErrorListener errorListener, ITokenMapping tokenMapping) + { + ConstructedImage = image; + ErrorListener = errorListener ?? throw new ArgumentNullException(nameof(errorListener)); + TokenMapping = tokenMapping ?? throw new ArgumentNullException(nameof(tokenMapping)); + } + + /// + /// Gets the constructed image, or null if the construction failed. + /// + public IPEImage? ConstructedImage + { + get; + } + + /// + /// Gets a value indicating whether the image was constructed successfully or not. + /// + [MemberNotNullWhen(false, nameof(ConstructedImage))] + public bool HasFailed => ConstructedImage is null; + + /// + /// Gets the bag containing the diagnostics that were collected during the construction of the image (if available). + /// + [Obsolete("Use the ErrorListener property instead.")] + public DiagnosticBag? DiagnosticBag => ErrorListener as DiagnosticBag; + + /// + /// Gets the error listener handling the diagnostics that were collected during the construction of the image. + /// + public IErrorListener ErrorListener + { + get; + } + + /// + /// Gets an object that maps metadata members to their newly assigned tokens. + /// + public ITokenMapping TokenMapping + { + get; + } + } +} diff --git a/src/AsmResolver.DotNet/ModuleDefinition.cs b/src/AsmResolver.DotNet/ModuleDefinition.cs index 710745aa4..209a23a17 100644 --- a/src/AsmResolver.DotNet/ModuleDefinition.cs +++ b/src/AsmResolver.DotNet/ModuleDefinition.cs @@ -1284,25 +1284,55 @@ public void Write(IBinaryStreamWriter writer, IPEImageBuilder imageBuilder, IPEF /// /// IPEImage built using by default /// Occurs when the construction of the image threw exceptions. - public IPEImage ToPEImage() => ToPEImage(new ManagedPEImageBuilder()); + public IPEImage ToPEImage() => ToPEImage(new ManagedPEImageBuilder(), true); /// /// Rebuilds the .NET module to a portable executable file and returns the IPEImage. /// /// The engine to use for reconstructing a PE image. /// IPEImage built by the specified IPEImageBuilder - /// Occurs when the construction of the image threw exceptions. - public IPEImage ToPEImage(IPEImageBuilder imageBuilder) + /// + /// Occurs when the construction of the image threw exceptions, and the used error listener is an instance of + /// a . + /// + /// + /// Occurs when the construction of the PE image failed completely. + /// + public IPEImage ToPEImage(IPEImageBuilder imageBuilder) => ToPEImage(imageBuilder, true); + + /// + /// Rebuilds the .NET module to a portable executable file and returns the IPEImage. + /// + /// The engine to use for reconstructing a PE image. + /// + /// true if non-fatal errors should be thrown as an exception, false otherwise. + /// + /// IPEImage built by the specified IPEImageBuilder + /// + /// Occurs when the construction of the image threw exceptions, and the used error listener is an instance of + /// a . + /// + /// + /// Occurs when the construction of the PE image failed completely. + /// + public IPEImage ToPEImage(IPEImageBuilder imageBuilder, bool throwOnNonFatalError) { var result = imageBuilder.CreateImage(this); - if (result.DiagnosticBag.HasErrors) + + // If the error listener is a diagnostic bag, we can pull out the exceptions that were thrown. + if (result.ErrorListener is DiagnosticBag {HasErrors: true} diagnosticBag && throwOnNonFatalError) { throw new AggregateException( "Construction of the PE image failed with one or more errors.", - result.DiagnosticBag.Exceptions); + diagnosticBag.Exceptions); } - return result.ConstructedImage!; + // If we still failed but we don't have special handling for the provided error listener, just throw a + // simple exception instead. + if (result.HasFailed) + throw new MetadataBuilderException("Construction of the PE image failed."); + + return result.ConstructedImage; } } } diff --git a/test/AsmResolver.DotNet.Tests/Builder/ManagedPEImageBuilderTest.cs b/test/AsmResolver.DotNet.Tests/Builder/ManagedPEImageBuilderTest.cs index 82c2630e5..942981055 100644 --- a/test/AsmResolver.DotNet.Tests/Builder/ManagedPEImageBuilderTest.cs +++ b/test/AsmResolver.DotNet.Tests/Builder/ManagedPEImageBuilderTest.cs @@ -1,8 +1,11 @@ +using System; using System.IO; using System.Linq; using AsmResolver.DotNet.Builder; +using AsmResolver.DotNet.Builder.Metadata; using AsmResolver.PE; using AsmResolver.PE.DotNet.Metadata; +using AsmResolver.PE.DotNet.Metadata.Tables.Rows; using Xunit; namespace AsmResolver.DotNet.Tests.Builder @@ -147,5 +150,29 @@ public void PreserveUnknownStreamsAndStreamOrder() newImage.DotNetDirectory!.Metadata!.GetStream("#Custom")); Assert.Equal(data, Assert.IsAssignableFrom(newStream.Contents).ToArray()); } + + [Fact] + public void BuildInvalidImageShouldRegisterDiagnostics() + { + // Prepare temp assembly. + var assembly = new AssemblyDefinition("Assembly", new Version(1, 0, 0, 0)); + var module = new ModuleDefinition("Module"); + assembly.Modules.Add(module); + + // Add some field with an non-imported field type. + module.GetOrCreateModuleType().Fields.Add(new FieldDefinition( + "Field", + FieldAttributes.Static, + new TypeReference(null, "NonImportedNamespace", "NonImportedType").ToTypeSignature())); + + // Build. + var bag = new DiagnosticBag(); + var image = module.ToPEImage(new ManagedPEImageBuilder(bag), false); + + // Verify diagnostics. + Assert.NotNull(image); + Assert.Contains(bag.Exceptions, x => x is MemberNotImportedException); + } + } } diff --git a/test/AsmResolver.DotNet.Tests/Builder/TokenPreservation/TokenPreservationTestBase.cs b/test/AsmResolver.DotNet.Tests/Builder/TokenPreservation/TokenPreservationTestBase.cs index 3adf1bd7e..1ca3a70f5 100644 --- a/test/AsmResolver.DotNet.Tests/Builder/TokenPreservation/TokenPreservationTestBase.cs +++ b/test/AsmResolver.DotNet.Tests/Builder/TokenPreservation/TokenPreservationTestBase.cs @@ -32,14 +32,15 @@ protected static List GetMembers(ModuleDefinition module, Tabl protected static ModuleDefinition RebuildAndReloadModule(ModuleDefinition module, MetadataBuilderFlags builderFlags) { - var builder = new ManagedPEImageBuilder - { - DotNetDirectoryFactory = new DotNetDirectoryFactory(builderFlags) - }; + var builder = new ManagedPEImageBuilder(builderFlags); var result = builder.CreateImage(module); if (result.HasFailed) - throw new AggregateException(result.DiagnosticBag.Exceptions); + { + if (result.ErrorListener is DiagnosticBag diagnosticBag) + throw new AggregateException(diagnosticBag.Exceptions); + throw new Exception("Image creation failed."); + } var newImage = result.ConstructedImage; diff --git a/test/AsmResolver.DotNet.Tests/Code/Cil/CilMethodBodyTest.cs b/test/AsmResolver.DotNet.Tests/Code/Cil/CilMethodBodyTest.cs index a3626ba04..5102359aa 100644 --- a/test/AsmResolver.DotNet.Tests/Code/Cil/CilMethodBodyTest.cs +++ b/test/AsmResolver.DotNet.Tests/Code/Cil/CilMethodBodyTest.cs @@ -32,10 +32,7 @@ private static CilMethodBody GetMethodBodyInModule(ModuleDefinition module, stri private CilMethodBody RebuildAndLookup(CilMethodBody methodBody) { - var module = methodBody.Owner.Module; - - string tempFile = Path.GetTempFileName(); - module.Write(tempFile); + var module = methodBody.Owner.Module!; var stream = new MemoryStream(); module.Write(stream); diff --git a/test/AsmResolver.DotNet.Tests/ConstantTest.cs b/test/AsmResolver.DotNet.Tests/ConstantTest.cs index 1fd9770d8..d455f2cdd 100644 --- a/test/AsmResolver.DotNet.Tests/ConstantTest.cs +++ b/test/AsmResolver.DotNet.Tests/ConstantTest.cs @@ -21,9 +21,6 @@ private static Constant GetFieldConstantInModule(ModuleDefinition module, string private Constant RebuildAndLookup(ModuleDefinition module, string name) { - string tempFile = Path.GetTempFileName(); - module.Write(tempFile); - var stream = new MemoryStream(); module.Write(stream); diff --git a/test/AsmResolver.DotNet.Tests/ModuleDefinitionTest.cs b/test/AsmResolver.DotNet.Tests/ModuleDefinitionTest.cs index db9a460ae..27621415a 100644 --- a/test/AsmResolver.DotNet.Tests/ModuleDefinitionTest.cs +++ b/test/AsmResolver.DotNet.Tests/ModuleDefinitionTest.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Reflection; using System.Runtime.InteropServices; -using AsmResolver.DotNet.Builder; using AsmResolver.DotNet.Signatures; using AsmResolver.DotNet.TestCases.NestedClasses; using AsmResolver.IO;