From c7bc9f609fa4e24e293507a0d223c96be53afc5b Mon Sep 17 00:00:00 2001 From: Washi Date: Fri, 7 Jun 2024 16:16:53 +0200 Subject: [PATCH] Move IBinaryStreamWriter and BinaryStreamWriterExtensions into BinaryStreamWriter. Fix signed compressed integer parsing/writing. --- .../Metadata/MetadataStreamBufferHelper.cs | 2 +- .../Builder/Metadata/StringsStreamBlob.cs | 2 +- .../Bundles/BundleManifest.cs | 12 +- .../Code/Cil/CilMethodBodySerializer.cs | 2 +- src/AsmResolver.DotNet/ModuleDefinition.cs | 2 +- .../DefaultResourceDataSerializer.cs | 2 +- .../Resources/IResourceDataSerializer.cs | 2 +- .../Resources/ResourceManagerHeader.cs | 2 +- .../Resources/ResourceSet.cs | 4 +- .../Resources/ResourceSetEntry.cs | 6 +- .../Resources/ResourceSetEntryHeader.cs | 2 +- .../Signatures/ArrayTypeSignature.cs | 8 +- .../Signatures/BlobSerializationContext.cs | 4 +- src/AsmResolver.PE.File/DataDirectory.cs | 2 +- src/AsmResolver.PE.File/DosHeader.cs | 2 +- src/AsmResolver.PE.File/FileHeader.cs | 2 +- src/AsmResolver.PE.File/OptionalHeader.cs | 2 +- src/AsmResolver.PE.File/PEFile.cs | 2 +- src/AsmResolver.PE.File/PESection.cs | 2 +- src/AsmResolver.PE.File/SectionHeader.cs | 2 +- .../Icon/IconEntry.cs | 2 +- .../Icon/IconGroupDirectory.cs | 2 +- .../Icon/IconGroupDirectoryEntry.cs | 2 +- .../Version/FixedVersionInfo.cs | 4 +- .../Version/StringFileInfo.cs | 2 +- .../Version/StringTable.cs | 4 +- .../Version/VarFileInfo.cs | 2 +- .../Version/VarTable.cs | 2 +- .../Version/VersionInfoResource.cs | 2 +- .../Version/VersionTableEntry.cs | 4 +- .../Version/VersionTableEntryHeader.cs | 2 +- .../Builder/MethodBodyTableBuffer.cs | 2 +- .../Builder/TrampolineTableBuffer.cs | 2 +- .../Certificates/AttributeCertificate.cs | 4 +- .../Certificates/CertificateCollection.cs | 2 +- .../CustomAttributeCertificate.cs | 2 +- src/AsmResolver.PE/Code/CodeSegment.cs | 2 +- .../Debug/Builder/DebugDirectoryBuffer.cs | 2 +- .../Debug/CustomDebugDataSegment.cs | 2 +- src/AsmResolver.PE/Debug/DebugDataEntry.cs | 2 +- src/AsmResolver.PE/Debug/RsdsDataSegment.cs | 2 +- src/AsmResolver.PE/DotNet/Cil/CilAssembler.cs | 8 +- .../DotNet/Cil/CilExtraSection.cs | 2 +- src/AsmResolver.PE/DotNet/Cil/CilOpCode.cs | 5 + .../DotNet/Cil/CilRawFatMethodBody.cs | 2 +- .../DotNet/Cil/CilRawTinyMethodBody.cs | 2 +- .../DotNet/CustomManagedNativeHeader.cs | 2 +- src/AsmResolver.PE/DotNet/DotNetDirectory.cs | 2 +- .../DotNet/Metadata/CustomMetadataStream.cs | 2 +- .../DotNet/Metadata/MetadataDirectory.cs | 6 +- .../DotNet/Metadata/PdbStream.cs | 2 +- .../DotNet/Metadata/SerializedBlobStream.cs | 2 +- .../DotNet/Metadata/SerializedGuidStream.cs | 2 +- .../Metadata/SerializedStringsStream.cs | 2 +- .../Metadata/SerializedUserStringsStream.cs | 2 +- .../Metadata/Tables/AssemblyDefinitionRow.cs | 2 +- .../DotNet/Metadata/Tables/AssemblyOSRow.cs | 2 +- .../Metadata/Tables/AssemblyProcessorRow.cs | 2 +- .../Metadata/Tables/AssemblyRefOSRow.cs | 2 +- .../Tables/AssemblyRefProcessorRow.cs | 2 +- .../Metadata/Tables/AssemblyReferenceRow.cs | 2 +- .../DotNet/Metadata/Tables/ClassLayoutRow.cs | 2 +- .../DotNet/Metadata/Tables/ConstantRow.cs | 2 +- .../Metadata/Tables/CustomAttributeRow.cs | 2 +- .../Tables/CustomDebugInformationRow.cs | 2 +- .../DotNet/Metadata/Tables/DocumentRow.cs | 2 +- .../DotNet/Metadata/Tables/EncLogRow.cs | 2 +- .../DotNet/Metadata/Tables/EncMapRow.cs | 2 +- .../Metadata/Tables/EventDefinitionRow.cs | 2 +- .../DotNet/Metadata/Tables/EventMapRow.cs | 2 +- .../DotNet/Metadata/Tables/EventPointerRow.cs | 2 +- .../DotNet/Metadata/Tables/ExportedTypeRow.cs | 2 +- .../Metadata/Tables/FieldDefinitionRow.cs | 2 +- .../DotNet/Metadata/Tables/FieldLayoutRow.cs | 2 +- .../DotNet/Metadata/Tables/FieldMarshalRow.cs | 2 +- .../DotNet/Metadata/Tables/FieldPointerRow.cs | 2 +- .../DotNet/Metadata/Tables/FieldRvaRow.cs | 2 +- .../Metadata/Tables/FileReferenceRow.cs | 2 +- .../Tables/GenericParameterConstraintRow.cs | 2 +- .../Metadata/Tables/GenericParameterRow.cs | 2 +- .../DotNet/Metadata/Tables/IMetadataRow.cs | 2 +- .../DotNet/Metadata/Tables/IMetadataTable.cs | 2 +- .../Metadata/Tables/ImplementationMapRow.cs | 2 +- .../DotNet/Metadata/Tables/ImportScopeRow.cs | 2 +- .../Tables/InterfaceImplementationRow.cs | 2 +- .../Metadata/Tables/LocalConstantRow.cs | 2 +- .../DotNet/Metadata/Tables/LocalScopeRow.cs | 2 +- .../Metadata/Tables/LocalVariableRow.cs | 2 +- .../Metadata/Tables/ManifestResourceRow.cs | 2 +- .../Metadata/Tables/MemberReferenceRow.cs | 2 +- .../DotNet/Metadata/Tables/MetadataTable.cs | 2 +- .../Tables/MethodDebugInformationRow.cs | 2 +- .../Metadata/Tables/MethodDefinitionRow.cs | 2 +- .../Tables/MethodImplementationRow.cs | 2 +- .../Metadata/Tables/MethodPointerRow.cs | 2 +- .../Metadata/Tables/MethodSemanticsRow.cs | 2 +- .../Metadata/Tables/MethodSpecificationRow.cs | 2 +- .../Metadata/Tables/ModuleDefinitionRow.cs | 2 +- .../Metadata/Tables/ModuleReferenceRow.cs | 2 +- .../DotNet/Metadata/Tables/NestedClassRow.cs | 2 +- .../Metadata/Tables/ParameterDefinitionRow.cs | 2 +- .../Metadata/Tables/ParameterPointerRow.cs | 2 +- .../Metadata/Tables/PropertyDefinitionRow.cs | 2 +- .../DotNet/Metadata/Tables/PropertyMapRow.cs | 2 +- .../Metadata/Tables/PropertyPointerRow.cs | 2 +- .../Metadata/Tables/SecurityDeclarationRow.cs | 2 +- .../Metadata/Tables/StandAloneSignatureRow.cs | 2 +- .../Metadata/Tables/StateMachineMethodRow.cs | 2 +- .../Metadata/Tables/TypeDefinitionRow.cs | 2 +- .../Metadata/Tables/TypeReferenceRow.cs | 2 +- .../Metadata/Tables/TypeSpecificationRow.cs | 2 +- .../DotNet/Metadata/TablesStream.cs | 6 +- .../ReadyToRun/CompilerIdentifierSection.cs | 2 +- .../ReadyToRun/CustomReadyToRunSection.cs | 2 +- .../DotNet/ReadyToRun/DebugInfo.cs | 2 +- .../DotNet/ReadyToRun/DebugInfoSection.cs | 2 +- .../DotNet/ReadyToRun/ImportSection.cs | 2 +- .../ReadyToRun/ImportSectionsSection.cs | 2 +- .../DotNet/ReadyToRun/MethodEntryPoint.cs | 2 +- .../ReadyToRun/MethodEntryPointsSection.cs | 2 +- .../DotNet/ReadyToRun/NativeArray.cs | 6 +- .../DotNet/ReadyToRun/NativeFormat.cs | 2 +- .../DotNet/ReadyToRun/NibbleWriter.cs | 4 +- .../DotNet/ReadyToRun/ReadyToRunDirectory.cs | 2 +- .../ReadyToRun/RuntimeFunctionsSection.cs | 2 +- .../SerializedDotNetResourcesDirectory.cs | 2 +- .../StrongName/StrongNameKeyStructure.cs | 2 +- .../DotNet/StrongName/StrongNamePrivateKey.cs | 2 +- .../DotNet/StrongName/StrongNamePublicKey.cs | 2 +- .../DotNet/VTableFixups/VTableFixup.cs | 2 +- .../VTableFixups/VTableFixupsDirectory.cs | 2 +- .../VTableFixups/VTableTokenCollection.cs | 2 +- .../Exceptions/X64RuntimeFunction.cs | 2 +- .../Exceptions/X64UnwindInfo.cs | 2 +- .../Builder/ExportAddressTableBuffer.cs | 2 +- .../Exports/Builder/ExportDirectoryBuffer.cs | 4 +- .../Exports/Builder/NameTableBuffer.cs | 2 +- .../Builder/OrdinalNamePointerTableBuffer.cs | 6 +- .../Imports/Builder/HintNameTableBuffer.cs | 6 +- .../Imports/Builder/ImportDirectoryBuffer.cs | 8 +- .../Builder/ImportDirectoryBufferBase.cs | 2 +- .../Imports/Builder/ThunkTableBuffer.cs | 2 +- .../Platforms/AddressTableInitializerStub.cs | 2 +- .../Relocations/Builder/RelocationBlock.cs | 2 +- .../Relocations/Builder/RelocationEntry.cs | 2 +- .../Builder/RelocationsDirectoryBuffer.cs | 2 +- .../Relocations/RelocatableSegmentBuilder.cs | 2 +- src/AsmResolver.PE/Tls/TlsDirectory.cs | 2 +- .../Builder/ResourceDataTableBuffer.cs | 4 +- .../Builder/ResourceDirectoryBuffer.cs | 2 +- .../Builder/ResourceDirectoryTableBuffer.cs | 6 +- .../Builder/ResourceNameTableBuffer.cs | 2 +- .../Metadata/Dbi/DbiStream.cs | 18 +- .../Metadata/Dbi/ModuleDescriptor.cs | 2 +- .../Metadata/Dbi/SectionContribution.cs | 2 +- .../Metadata/Dbi/SectionMap.cs | 2 +- .../Metadata/Info/InfoStream.cs | 2 +- .../Metadata/Modi/ModiStream.cs | 2 +- .../Metadata/PdbHashTable.cs | 2 +- .../Metadata/Tpi/SerializedTpiStream.cs | 2 +- .../Metadata/Tpi/TpiStream.cs | 6 +- .../Msf/Builder/FreeBlockMap.cs | 2 +- .../Msf/Builder/MsfFileBuffer.cs | 2 +- src/AsmResolver.Symbols.Pdb/Msf/MsfFile.cs | 4 +- .../Msf/MsfSuperBlock.cs | 2 +- .../Records/LocalAddressGap.cs | 2 +- .../Records/LocalAddressRange.cs | 2 +- src/AsmResolver/Collections/ReferenceTable.cs | 2 +- src/AsmResolver/DataSegment.cs | 2 +- src/AsmResolver/DataSourceSegment.cs | 2 +- src/AsmResolver/IO/BinaryStreamReader.cs | 75 +++- src/AsmResolver/IO/BinaryStreamWriter.cs | 365 +++++++++++++++--- src/AsmResolver/IO/IBinaryStreamWriter.cs | 342 ---------------- src/AsmResolver/IO/ISpanBinaryStreamWriter.cs | 18 - src/AsmResolver/IO/MemoryStreamWriterPool.cs | 4 +- src/AsmResolver/IWritable.cs | 2 +- src/AsmResolver/Patching/PatchContext.cs | 4 +- src/AsmResolver/Patching/PatchedSegment.cs | 4 +- src/AsmResolver/SegmentBase.cs | 2 +- src/AsmResolver/SegmentBuilder.cs | 2 +- src/AsmResolver/VirtualSegment.cs | 2 +- src/AsmResolver/ZeroesSegment.cs | 2 +- .../DotNet/ReadyToRun/NativeArrayTest.cs | 2 +- .../IO/BinaryStreamReaderTest.cs | 30 ++ .../IO/BinaryStreamWriterTest.cs | 59 +++ 185 files changed, 708 insertions(+), 644 deletions(-) delete mode 100644 src/AsmResolver/IO/IBinaryStreamWriter.cs delete mode 100644 src/AsmResolver/IO/ISpanBinaryStreamWriter.cs diff --git a/src/AsmResolver.DotNet/Builder/Metadata/MetadataStreamBufferHelper.cs b/src/AsmResolver.DotNet/Builder/Metadata/MetadataStreamBufferHelper.cs index ec47018ea..de2a86794 100644 --- a/src/AsmResolver.DotNet/Builder/Metadata/MetadataStreamBufferHelper.cs +++ b/src/AsmResolver.DotNet/Builder/Metadata/MetadataStreamBufferHelper.cs @@ -8,7 +8,7 @@ internal static class MetadataStreamBufferHelper { public delegate void IndexBlobAction(uint originalIndex, uint newIndex); - public static void CloneBlobHeap(IMetadataStream stream, IBinaryStreamWriter writer, + public static void CloneBlobHeap(IMetadataStream stream, BinaryStreamWriter writer, IndexBlobAction indexAction) { if (!stream.CanRead) diff --git a/src/AsmResolver.DotNet/Builder/Metadata/StringsStreamBlob.cs b/src/AsmResolver.DotNet/Builder/Metadata/StringsStreamBlob.cs index 48425688f..137950f14 100644 --- a/src/AsmResolver.DotNet/Builder/Metadata/StringsStreamBlob.cs +++ b/src/AsmResolver.DotNet/Builder/Metadata/StringsStreamBlob.cs @@ -36,7 +36,7 @@ public StringsStreamBlobFlags Flags public uint GetPhysicalSize() => (uint) (Blob.ByteCount + (IsZeroTerminated ? 1 : 0)); /// - public void Write(IBinaryStreamWriter writer) + public void Write(BinaryStreamWriter writer) { writer.WriteBytes(Blob.GetBytesUnsafe()); if (IsZeroTerminated) diff --git a/src/AsmResolver.DotNet/Bundles/BundleManifest.cs b/src/AsmResolver.DotNet/Bundles/BundleManifest.cs index 1fa911e33..d2e9b2ad3 100644 --- a/src/AsmResolver.DotNet/Bundles/BundleManifest.cs +++ b/src/AsmResolver.DotNet/Bundles/BundleManifest.cs @@ -367,7 +367,7 @@ public void WriteUsingTemplate(Stream outputStream, in BundlerParameters paramet /// /// The output stream to write to. /// The parameters to use for bundling all files into a single executable. - public void WriteUsingTemplate(IBinaryStreamWriter writer, BundlerParameters parameters) + public void WriteUsingTemplate(BinaryStreamWriter writer, BundlerParameters parameters) { // Verify entry point assembly exists within the bundle and is a correct length. var appBinaryEntry = Files.FirstOrDefault(f => f.RelativePath == parameters.ApplicationBinaryPath); @@ -483,7 +483,7 @@ private static void EnsureAppHostPEHeadersAreUpToDate(ref BundlerParameters para /// without a host application that invokes the manifest. If you want to produce a runnable executable, use one /// of the WriteUsingTemplate methods instead. /// - public ulong WriteManifest(IBinaryStreamWriter writer, bool isArm64Linux) + public ulong WriteManifest(BinaryStreamWriter writer, bool isArm64Linux) { WriteFileContents(writer, isArm64Linux ? 4096u @@ -495,7 +495,7 @@ public ulong WriteManifest(IBinaryStreamWriter writer, bool isArm64Linux) return headerAddress; } - private void WriteFileContents(IBinaryStreamWriter writer, uint alignment) + private void WriteFileContents(BinaryStreamWriter writer, uint alignment) { for (int i = 0; i < Files.Count; i++) { @@ -509,7 +509,7 @@ private void WriteFileContents(IBinaryStreamWriter writer, uint alignment) } } - private void WriteManifestHeader(IBinaryStreamWriter writer) + private void WriteManifestHeader(BinaryStreamWriter writer) { writer.WriteUInt32(MajorVersion); writer.WriteUInt32(MinorVersion); @@ -528,7 +528,7 @@ private void WriteManifestHeader(IBinaryStreamWriter writer) WriteFileHeaders(writer); } - private void WriteFileHeaders(IBinaryStreamWriter writer) + private void WriteFileHeaders(BinaryStreamWriter writer) { for (int i = 0; i < Files.Count; i++) { @@ -544,7 +544,7 @@ private void WriteFileHeaders(IBinaryStreamWriter writer) } } - private static void WriteFileOffsetSizePair(IBinaryStreamWriter writer, BundleFile? file) + private static void WriteFileOffsetSizePair(BinaryStreamWriter writer, BundleFile? file) { if (file is not null) { diff --git a/src/AsmResolver.DotNet/Code/Cil/CilMethodBodySerializer.cs b/src/AsmResolver.DotNet/Code/Cil/CilMethodBodySerializer.cs index 43c98d62d..f0aca1acb 100644 --- a/src/AsmResolver.DotNet/Code/Cil/CilMethodBodySerializer.cs +++ b/src/AsmResolver.DotNet/Code/Cil/CilMethodBodySerializer.cs @@ -170,7 +170,7 @@ private byte[] SerializeExceptionHandlers(MethodBodySerializationContext context return rentedWriter.GetData(); } - private void WriteExceptionHandler(MethodBodySerializationContext context, IBinaryStreamWriter writer, CilExceptionHandler handler, bool useFatFormat) + private void WriteExceptionHandler(MethodBodySerializationContext context, BinaryStreamWriter writer, CilExceptionHandler handler, bool useFatFormat) { if (handler.IsFat && !useFatFormat) throw new InvalidOperationException("Can only serialize fat exception handlers in fat format."); diff --git a/src/AsmResolver.DotNet/ModuleDefinition.cs b/src/AsmResolver.DotNet/ModuleDefinition.cs index 1e0b32082..aa8f6e10c 100644 --- a/src/AsmResolver.DotNet/ModuleDefinition.cs +++ b/src/AsmResolver.DotNet/ModuleDefinition.cs @@ -1301,7 +1301,7 @@ public void Write(Stream outputStream, IPEImageBuilder imageBuilder, IPEFileBuil /// The engine to use for reconstructing a PE image. /// The engine to use for reconstructing a PE file. /// Occurs when the construction of the image threw exceptions. - public void Write(IBinaryStreamWriter writer, IPEImageBuilder imageBuilder, IPEFileBuilder fileBuilder) + public void Write(BinaryStreamWriter writer, IPEImageBuilder imageBuilder, IPEFileBuilder fileBuilder) { ToPEImage(imageBuilder).ToPEFile(fileBuilder).Write(writer); } diff --git a/src/AsmResolver.DotNet/Resources/DefaultResourceDataSerializer.cs b/src/AsmResolver.DotNet/Resources/DefaultResourceDataSerializer.cs index 61451e563..24090348d 100644 --- a/src/AsmResolver.DotNet/Resources/DefaultResourceDataSerializer.cs +++ b/src/AsmResolver.DotNet/Resources/DefaultResourceDataSerializer.cs @@ -18,7 +18,7 @@ public static DefaultResourceDataSerializer Instance } = new(); /// - public virtual void Serialize(IBinaryStreamWriter writer, ResourceType type, object? value) + public virtual void Serialize(BinaryStreamWriter writer, ResourceType type, object? value) { switch (value) { diff --git a/src/AsmResolver.DotNet/Resources/IResourceDataSerializer.cs b/src/AsmResolver.DotNet/Resources/IResourceDataSerializer.cs index 762136913..228552616 100644 --- a/src/AsmResolver.DotNet/Resources/IResourceDataSerializer.cs +++ b/src/AsmResolver.DotNet/Resources/IResourceDataSerializer.cs @@ -13,7 +13,7 @@ public interface IResourceDataSerializer /// The output stream to write to. /// The type of the resource. /// The object to serialize. - void Serialize(IBinaryStreamWriter writer, ResourceType type, object? value); + void Serialize(BinaryStreamWriter writer, ResourceType type, object? value); /// /// Reads a resource object from the input stream. diff --git a/src/AsmResolver.DotNet/Resources/ResourceManagerHeader.cs b/src/AsmResolver.DotNet/Resources/ResourceManagerHeader.cs index 7d20c298f..be4e4579d 100644 --- a/src/AsmResolver.DotNet/Resources/ResourceManagerHeader.cs +++ b/src/AsmResolver.DotNet/Resources/ResourceManagerHeader.cs @@ -112,7 +112,7 @@ public uint GetPhysicalSize() } /// - public void Write(IBinaryStreamWriter writer) + public void Write(BinaryStreamWriter writer) { writer.WriteUInt32(Magic); writer.WriteUInt32(1); diff --git a/src/AsmResolver.DotNet/Resources/ResourceSet.cs b/src/AsmResolver.DotNet/Resources/ResourceSet.cs index dd91e55aa..57339a733 100644 --- a/src/AsmResolver.DotNet/Resources/ResourceSet.cs +++ b/src/AsmResolver.DotNet/Resources/ResourceSet.cs @@ -87,7 +87,7 @@ protected override void Initialize() /// /// The output stream. /// Occurs when an invalid or unsupported version is specified in . - public void Write(IBinaryStreamWriter writer) => Write(writer, DefaultResourceDataSerializer.Instance); + public void Write(BinaryStreamWriter writer) => Write(writer, DefaultResourceDataSerializer.Instance); /// /// Serializes the resource set and writes it to the provided output stream. @@ -95,7 +95,7 @@ protected override void Initialize() /// The output stream. /// The object responsible for serializing user-defined types. /// Occurs when an invalid or unsupported version is specified in . - public void Write(IBinaryStreamWriter writer, IResourceDataSerializer serializer) + public void Write(BinaryStreamWriter writer, IResourceDataSerializer serializer) { if (FormatVersion is not 1 and not 2) throw new NotSupportedException($"Invalid or unsupported format version {FormatVersion}."); diff --git a/src/AsmResolver.DotNet/Resources/ResourceSetEntry.cs b/src/AsmResolver.DotNet/Resources/ResourceSetEntry.cs index d8be45eee..e2ffe8b4b 100644 --- a/src/AsmResolver.DotNet/Resources/ResourceSetEntry.cs +++ b/src/AsmResolver.DotNet/Resources/ResourceSetEntry.cs @@ -97,7 +97,7 @@ public object? Data /// public override string ToString() => $"{Name} : {Type.FullName}"; - internal void Write(IBinaryStreamWriter writer, int formatVersion, int typeCode, IResourceDataSerializer serializer) + internal void Write(BinaryStreamWriter writer, int formatVersion, int typeCode, IResourceDataSerializer serializer) { writer.Write7BitEncodedInt32(typeCode); @@ -116,7 +116,7 @@ internal void Write(IBinaryStreamWriter writer, int formatVersion, int typeCode, } } - private void WriteV1(IBinaryStreamWriter writer, IResourceDataSerializer serializer) + private void WriteV1(BinaryStreamWriter writer, IResourceDataSerializer serializer) { if (Data is null) return; @@ -182,7 +182,7 @@ private void WriteV1(IBinaryStreamWriter writer, IResourceDataSerializer seriali } } - private void WriteV2(IBinaryStreamWriter writer, IResourceDataSerializer serializer) + private void WriteV2(BinaryStreamWriter writer, IResourceDataSerializer serializer) { if (Data is null) return; diff --git a/src/AsmResolver.DotNet/Resources/ResourceSetEntryHeader.cs b/src/AsmResolver.DotNet/Resources/ResourceSetEntryHeader.cs index 33e58035d..c86781b7c 100644 --- a/src/AsmResolver.DotNet/Resources/ResourceSetEntryHeader.cs +++ b/src/AsmResolver.DotNet/Resources/ResourceSetEntryHeader.cs @@ -29,7 +29,7 @@ public uint Offset public uint GetPhysicalSize() => Name.GetBinaryFormatterSize(Encoding.Unicode) + sizeof(uint); /// - public void Write(IBinaryStreamWriter writer) + public void Write(BinaryStreamWriter writer) { writer.WriteBinaryFormatterString(Name, Encoding.Unicode); writer.WriteUInt32(Offset); diff --git a/src/AsmResolver.DotNet/Signatures/ArrayTypeSignature.cs b/src/AsmResolver.DotNet/Signatures/ArrayTypeSignature.cs index 9bf44e7a3..0b6e26c4e 100644 --- a/src/AsmResolver.DotNet/Signatures/ArrayTypeSignature.cs +++ b/src/AsmResolver.DotNet/Signatures/ArrayTypeSignature.cs @@ -110,10 +110,10 @@ public IList Dimensions return signature; } - var loBounds = new List((int) numLoBounds); + var loBounds = new List((int) numLoBounds); for (int i = 0; i < numLoBounds; i++) { - if (!reader.TryReadCompressedUInt32(out uint bound)) + if (!reader.TryReadCompressedInt32(out int bound)) { context.ReaderContext.BadImage($"Lower bound {i.ToString()} of array type signature is invalid."); return signature; @@ -130,7 +130,7 @@ public IList Dimensions if (i < numSizes) size = (int) sizes[i]; if (i < numLoBounds) - lowerBound = (int) loBounds[i]; + lowerBound = loBounds[i]; signature.Dimensions.Add(new ArrayDimension(size, lowerBound)); } @@ -237,7 +237,7 @@ protected override void WriteContents(in BlobSerializationContext context) .ToArray(); writer.WriteCompressedUInt32((uint) boundedDimensions.Length); foreach (var boundedDimension in boundedDimensions) - writer.WriteCompressedUInt32((uint) boundedDimension.LowerBound!.Value); + writer.WriteCompressedInt32(boundedDimension.LowerBound!.Value); } } } diff --git a/src/AsmResolver.DotNet/Signatures/BlobSerializationContext.cs b/src/AsmResolver.DotNet/Signatures/BlobSerializationContext.cs index d53819ff3..384180007 100644 --- a/src/AsmResolver.DotNet/Signatures/BlobSerializationContext.cs +++ b/src/AsmResolver.DotNet/Signatures/BlobSerializationContext.cs @@ -14,7 +14,7 @@ public readonly struct BlobSerializationContext /// The output stream to write the raw data to. /// The object responsible for obtaining coded indices to types. /// The object responsible for collecting diagnostic information during the serialization process. - public BlobSerializationContext(IBinaryStreamWriter writer, ITypeCodedIndexProvider indexProvider, IErrorListener errorListener) + public BlobSerializationContext(BinaryStreamWriter writer, ITypeCodedIndexProvider indexProvider, IErrorListener errorListener) { Writer = writer ?? throw new ArgumentNullException(nameof(writer)); IndexProvider = indexProvider ?? throw new ArgumentNullException(nameof(indexProvider)); @@ -24,7 +24,7 @@ public BlobSerializationContext(IBinaryStreamWriter writer, ITypeCodedIndexProvi /// /// Gets the output stream to write the raw data to. /// - public IBinaryStreamWriter Writer + public BinaryStreamWriter Writer { get; } diff --git a/src/AsmResolver.PE.File/DataDirectory.cs b/src/AsmResolver.PE.File/DataDirectory.cs index ace1668ea..7f37971b2 100644 --- a/src/AsmResolver.PE.File/DataDirectory.cs +++ b/src/AsmResolver.PE.File/DataDirectory.cs @@ -73,7 +73,7 @@ public static DataDirectory CreateForSegment(ISegment? segment) public uint GetPhysicalSize() => DataDirectorySize; /// - public void Write(IBinaryStreamWriter writer) + public void Write(BinaryStreamWriter writer) { writer.WriteUInt32(VirtualAddress); writer.WriteUInt32(Size); diff --git a/src/AsmResolver.PE.File/DosHeader.cs b/src/AsmResolver.PE.File/DosHeader.cs index 8618beca7..277318937 100644 --- a/src/AsmResolver.PE.File/DosHeader.cs +++ b/src/AsmResolver.PE.File/DosHeader.cs @@ -111,7 +111,7 @@ public uint NextHeaderOffset public override uint GetPhysicalSize() => (uint) _stub.Length; /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { writer.WriteBytes(_stub, 0, NextHeaderFieldOffset); writer.WriteUInt32(NextHeaderOffset); diff --git a/src/AsmResolver.PE.File/FileHeader.cs b/src/AsmResolver.PE.File/FileHeader.cs index f575c70b1..3c189c713 100644 --- a/src/AsmResolver.PE.File/FileHeader.cs +++ b/src/AsmResolver.PE.File/FileHeader.cs @@ -102,7 +102,7 @@ public Characteristics Characteristics public override uint GetPhysicalSize() => FileHeaderSize; /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { writer.WriteUInt16((ushort)Machine); writer.WriteUInt16(NumberOfSections); diff --git a/src/AsmResolver.PE.File/OptionalHeader.cs b/src/AsmResolver.PE.File/OptionalHeader.cs index 7b9ba0ae9..196b33a64 100644 --- a/src/AsmResolver.PE.File/OptionalHeader.cs +++ b/src/AsmResolver.PE.File/OptionalHeader.cs @@ -438,7 +438,7 @@ public override uint GetPhysicalSize() } /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { ulong start = writer.Offset; diff --git a/src/AsmResolver.PE.File/PEFile.cs b/src/AsmResolver.PE.File/PEFile.cs index 889ec40be..960649b09 100644 --- a/src/AsmResolver.PE.File/PEFile.cs +++ b/src/AsmResolver.PE.File/PEFile.cs @@ -604,7 +604,7 @@ public void Write(string filePath) /// Writes the PE file to the provided output stream. /// /// The output stream to write to. - public void Write(IBinaryStreamWriter writer) + public void Write(BinaryStreamWriter writer) { UpdateHeaders(); diff --git a/src/AsmResolver.PE.File/PESection.cs b/src/AsmResolver.PE.File/PESection.cs index f22a80b67..8528ff410 100644 --- a/src/AsmResolver.PE.File/PESection.cs +++ b/src/AsmResolver.PE.File/PESection.cs @@ -292,6 +292,6 @@ public ulong RvaToFileOffset(uint rva) public override string ToString() => Name; /// - public void Write(IBinaryStreamWriter writer) => Contents?.Write(writer); + public void Write(BinaryStreamWriter writer) => Contents?.Write(writer); } } diff --git a/src/AsmResolver.PE.File/SectionHeader.cs b/src/AsmResolver.PE.File/SectionHeader.cs index 85ab79dd0..202b7e2e9 100644 --- a/src/AsmResolver.PE.File/SectionHeader.cs +++ b/src/AsmResolver.PE.File/SectionHeader.cs @@ -239,7 +239,7 @@ public ulong RvaToFileOffset(uint rva) } /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { writer.WriteBytes(Name.GetBytesUnsafe()); writer.WriteZeroes(8 - Name.ByteCount); diff --git a/src/AsmResolver.PE.Win32Resources/Icon/IconEntry.cs b/src/AsmResolver.PE.Win32Resources/Icon/IconEntry.cs index 136632ded..3fd3a91e2 100644 --- a/src/AsmResolver.PE.Win32Resources/Icon/IconEntry.cs +++ b/src/AsmResolver.PE.Win32Resources/Icon/IconEntry.cs @@ -40,7 +40,7 @@ public static IconEntry FromReader(ref BinaryStreamReader reader) public override uint GetPhysicalSize() => (uint)RawIcon.Length; /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { writer.WriteBytes(RawIcon, 0, RawIcon.Length); } diff --git a/src/AsmResolver.PE.Win32Resources/Icon/IconGroupDirectory.cs b/src/AsmResolver.PE.Win32Resources/Icon/IconGroupDirectory.cs index 6f89417e0..8e3fdf611 100644 --- a/src/AsmResolver.PE.Win32Resources/Icon/IconGroupDirectory.cs +++ b/src/AsmResolver.PE.Win32Resources/Icon/IconGroupDirectory.cs @@ -140,7 +140,7 @@ public override uint GetPhysicalSize() } /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { writer.WriteUInt16(Reserved); writer.WriteUInt16(Type); diff --git a/src/AsmResolver.PE.Win32Resources/Icon/IconGroupDirectoryEntry.cs b/src/AsmResolver.PE.Win32Resources/Icon/IconGroupDirectoryEntry.cs index 41aba058c..43aee8adc 100644 --- a/src/AsmResolver.PE.Win32Resources/Icon/IconGroupDirectoryEntry.cs +++ b/src/AsmResolver.PE.Win32Resources/Icon/IconGroupDirectoryEntry.cs @@ -116,7 +116,7 @@ public override uint GetPhysicalSize() } /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { writer.WriteByte(Width); writer.WriteByte((Height)); diff --git a/src/AsmResolver.PE.Win32Resources/Version/FixedVersionInfo.cs b/src/AsmResolver.PE.Win32Resources/Version/FixedVersionInfo.cs index d698bca04..77eff7443 100644 --- a/src/AsmResolver.PE.Win32Resources/Version/FixedVersionInfo.cs +++ b/src/AsmResolver.PE.Win32Resources/Version/FixedVersionInfo.cs @@ -141,7 +141,7 @@ public override uint GetPhysicalSize() => + sizeof(ulong); // FileDate /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { writer.WriteUInt32(Signature); writer.WriteUInt32(DefaultStructVersion); @@ -155,7 +155,7 @@ public override void Write(IBinaryStreamWriter writer) writer.WriteUInt64(FileDate); } - private static void WriteVersion(IBinaryStreamWriter writer, System.Version version) + private static void WriteVersion(BinaryStreamWriter writer, System.Version version) { writer.WriteUInt16((ushort) version.Minor); writer.WriteUInt16((ushort) version.Major); diff --git a/src/AsmResolver.PE.Win32Resources/Version/StringFileInfo.cs b/src/AsmResolver.PE.Win32Resources/Version/StringFileInfo.cs index 2802453fb..70d35a3f7 100644 --- a/src/AsmResolver.PE.Win32Resources/Version/StringFileInfo.cs +++ b/src/AsmResolver.PE.Win32Resources/Version/StringFileInfo.cs @@ -67,7 +67,7 @@ public override uint GetPhysicalSize() protected override uint GetValueLength() => 0; /// - protected override void WriteValue(IBinaryStreamWriter writer) + protected override void WriteValue(BinaryStreamWriter writer) { for (int i = 0; i < Tables.Count; i++) Tables[i].Write(writer); diff --git a/src/AsmResolver.PE.Win32Resources/Version/StringTable.cs b/src/AsmResolver.PE.Win32Resources/Version/StringTable.cs index 0db9a0e10..1ac78299f 100644 --- a/src/AsmResolver.PE.Win32Resources/Version/StringTable.cs +++ b/src/AsmResolver.PE.Win32Resources/Version/StringTable.cs @@ -215,7 +215,7 @@ private static uint CalculateEntryValueSize(string value) protected override uint GetValueLength() => 0u; /// - protected override void WriteValue(IBinaryStreamWriter writer) + protected override void WriteValue(BinaryStreamWriter writer) { foreach (var entry in _entries) { @@ -224,7 +224,7 @@ protected override void WriteValue(IBinaryStreamWriter writer) } } - private static void WriteEntry(IBinaryStreamWriter writer, KeyValuePair entry) + private static void WriteEntry(BinaryStreamWriter writer, KeyValuePair entry) { var header = new VersionTableEntryHeader(entry.Key) { diff --git a/src/AsmResolver.PE.Win32Resources/Version/VarFileInfo.cs b/src/AsmResolver.PE.Win32Resources/Version/VarFileInfo.cs index 07699efe2..d5bbd9485 100644 --- a/src/AsmResolver.PE.Win32Resources/Version/VarFileInfo.cs +++ b/src/AsmResolver.PE.Win32Resources/Version/VarFileInfo.cs @@ -67,7 +67,7 @@ public override uint GetPhysicalSize() protected override uint GetValueLength() => 0; /// - protected override void WriteValue(IBinaryStreamWriter writer) + protected override void WriteValue(BinaryStreamWriter writer) { for (int i = 0; i < Tables.Count; i++) Tables[i].Write(writer); diff --git a/src/AsmResolver.PE.Win32Resources/Version/VarTable.cs b/src/AsmResolver.PE.Win32Resources/Version/VarTable.cs index b23c4deff..19ca73b70 100644 --- a/src/AsmResolver.PE.Win32Resources/Version/VarTable.cs +++ b/src/AsmResolver.PE.Win32Resources/Version/VarTable.cs @@ -67,7 +67,7 @@ public override uint GetPhysicalSize() protected override uint GetValueLength() => (uint) (Values.Count * sizeof(uint)); /// - protected override void WriteValue(IBinaryStreamWriter writer) + protected override void WriteValue(BinaryStreamWriter writer) { foreach (uint value in Values) writer.WriteUInt32(value); diff --git a/src/AsmResolver.PE.Win32Resources/Version/VersionInfoResource.cs b/src/AsmResolver.PE.Win32Resources/Version/VersionInfoResource.cs index caa861561..e685a4d31 100644 --- a/src/AsmResolver.PE.Win32Resources/Version/VersionInfoResource.cs +++ b/src/AsmResolver.PE.Win32Resources/Version/VersionInfoResource.cs @@ -259,7 +259,7 @@ public override uint GetPhysicalSize() protected override uint GetValueLength() => FixedVersionInfo.GetPhysicalSize(); /// - protected override void WriteValue(IBinaryStreamWriter writer) + protected override void WriteValue(BinaryStreamWriter writer) { FixedVersionInfo.Write(writer); foreach (var entry in _entries.Values) diff --git a/src/AsmResolver.PE.Win32Resources/Version/VersionTableEntry.cs b/src/AsmResolver.PE.Win32Resources/Version/VersionTableEntry.cs index 5dba05393..c7b0854d8 100644 --- a/src/AsmResolver.PE.Win32Resources/Version/VersionTableEntry.cs +++ b/src/AsmResolver.PE.Win32Resources/Version/VersionTableEntry.cs @@ -37,7 +37,7 @@ protected VersionTableEntryHeader CreateHeader() => protected abstract uint GetValueLength(); /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { var header = CreateHeader(); header.Write(writer); @@ -49,6 +49,6 @@ public override void Write(IBinaryStreamWriter writer) /// Writes the value field of the version structure. /// /// The output stream. - protected abstract void WriteValue(IBinaryStreamWriter writer); + protected abstract void WriteValue(BinaryStreamWriter writer); } } diff --git a/src/AsmResolver.PE.Win32Resources/Version/VersionTableEntryHeader.cs b/src/AsmResolver.PE.Win32Resources/Version/VersionTableEntryHeader.cs index d879d4753..236442f72 100644 --- a/src/AsmResolver.PE.Win32Resources/Version/VersionTableEntryHeader.cs +++ b/src/AsmResolver.PE.Win32Resources/Version/VersionTableEntryHeader.cs @@ -101,7 +101,7 @@ public static uint GetHeaderSize(string key) public override uint GetPhysicalSize() => GetHeaderSize(Key); /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { writer.WriteUInt16(Length); writer.WriteUInt16(ValueLength); diff --git a/src/AsmResolver.PE/Builder/MethodBodyTableBuffer.cs b/src/AsmResolver.PE/Builder/MethodBodyTableBuffer.cs index 3b966d2f5..196dce8d8 100644 --- a/src/AsmResolver.PE/Builder/MethodBodyTableBuffer.cs +++ b/src/AsmResolver.PE/Builder/MethodBodyTableBuffer.cs @@ -71,6 +71,6 @@ public uint GetPhysicalSize() public uint GetVirtualSize() => _segments.GetVirtualSize(); /// - public void Write(IBinaryStreamWriter writer) => _segments.Write(writer); + public void Write(BinaryStreamWriter writer) => _segments.Write(writer); } } diff --git a/src/AsmResolver.PE/Builder/TrampolineTableBuffer.cs b/src/AsmResolver.PE/Builder/TrampolineTableBuffer.cs index bff5fb30f..ed999b545 100644 --- a/src/AsmResolver.PE/Builder/TrampolineTableBuffer.cs +++ b/src/AsmResolver.PE/Builder/TrampolineTableBuffer.cs @@ -159,7 +159,7 @@ public override void UpdateOffsets(in RelocationParameters parameters) public override uint GetPhysicalSize() => _contents.GetPhysicalSize(); /// - public override void Write(IBinaryStreamWriter writer) => _contents.Write(writer); + public override void Write(BinaryStreamWriter writer) => _contents.Write(writer); private static bool TryGetSectionContainingRva( IList sections, diff --git a/src/AsmResolver.PE/Certificates/AttributeCertificate.cs b/src/AsmResolver.PE/Certificates/AttributeCertificate.cs index 23a0c224a..3957b60ec 100644 --- a/src/AsmResolver.PE/Certificates/AttributeCertificate.cs +++ b/src/AsmResolver.PE/Certificates/AttributeCertificate.cs @@ -58,7 +58,7 @@ public abstract bool CanRead protected abstract uint GetContentsSize(); /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { writer.WriteUInt32(GetPhysicalSize()); writer.WriteUInt16((ushort) Revision); @@ -70,6 +70,6 @@ public override void Write(IBinaryStreamWriter writer) /// Writes the contents of the certificate to the provided output stream. /// /// The output stream. - protected abstract void WriteContents(IBinaryStreamWriter writer); + protected abstract void WriteContents(BinaryStreamWriter writer); } } diff --git a/src/AsmResolver.PE/Certificates/CertificateCollection.cs b/src/AsmResolver.PE/Certificates/CertificateCollection.cs index 65b07150c..b3ab34265 100644 --- a/src/AsmResolver.PE/Certificates/CertificateCollection.cs +++ b/src/AsmResolver.PE/Certificates/CertificateCollection.cs @@ -53,7 +53,7 @@ public uint GetPhysicalSize() public uint GetVirtualSize() => GetPhysicalSize(); /// - public void Write(IBinaryStreamWriter writer) + public void Write(BinaryStreamWriter writer) { for (int i = 0; i < Items.Count; i++) { diff --git a/src/AsmResolver.PE/Certificates/CustomAttributeCertificate.cs b/src/AsmResolver.PE/Certificates/CustomAttributeCertificate.cs index 3f9ecd92b..00156ad0f 100644 --- a/src/AsmResolver.PE/Certificates/CustomAttributeCertificate.cs +++ b/src/AsmResolver.PE/Certificates/CustomAttributeCertificate.cs @@ -75,6 +75,6 @@ public override void UpdateOffsets(in RelocationParameters parameters) protected override uint GetContentsSize() => Contents?.GetPhysicalSize() ?? 0; /// - protected override void WriteContents(IBinaryStreamWriter writer) => Contents?.Write(writer); + protected override void WriteContents(BinaryStreamWriter writer) => Contents?.Write(writer); } } diff --git a/src/AsmResolver.PE/Code/CodeSegment.cs b/src/AsmResolver.PE/Code/CodeSegment.cs index f6dba5c0c..1a276bbb6 100644 --- a/src/AsmResolver.PE/Code/CodeSegment.cs +++ b/src/AsmResolver.PE/Code/CodeSegment.cs @@ -69,7 +69,7 @@ public override void UpdateOffsets(in RelocationParameters parameters) public override uint GetPhysicalSize() => (uint) Code.Length; /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { writer.WriteBytes(Code); diff --git a/src/AsmResolver.PE/Debug/Builder/DebugDirectoryBuffer.cs b/src/AsmResolver.PE/Debug/Builder/DebugDirectoryBuffer.cs index e5afa4e88..2cc85880d 100644 --- a/src/AsmResolver.PE/Debug/Builder/DebugDirectoryBuffer.cs +++ b/src/AsmResolver.PE/Debug/Builder/DebugDirectoryBuffer.cs @@ -47,7 +47,7 @@ public void AddEntry(DebugDataEntry entry) public uint GetPhysicalSize() => _headers.GetPhysicalSize(); /// - public void Write(IBinaryStreamWriter writer) => _headers.Write(writer); + public void Write(BinaryStreamWriter writer) => _headers.Write(writer); /// public uint GetVirtualSize() => _headers.GetVirtualSize(); diff --git a/src/AsmResolver.PE/Debug/CustomDebugDataSegment.cs b/src/AsmResolver.PE/Debug/CustomDebugDataSegment.cs index 98af4faf0..5ece9d55e 100644 --- a/src/AsmResolver.PE/Debug/CustomDebugDataSegment.cs +++ b/src/AsmResolver.PE/Debug/CustomDebugDataSegment.cs @@ -60,6 +60,6 @@ public void UpdateOffsets(in RelocationParameters parameters) public uint GetVirtualSize() => Contents?.GetPhysicalSize() ?? 0; /// - public void Write(IBinaryStreamWriter writer) => Contents?.Write(writer); + public void Write(BinaryStreamWriter writer) => Contents?.Write(writer); } } diff --git a/src/AsmResolver.PE/Debug/DebugDataEntry.cs b/src/AsmResolver.PE/Debug/DebugDataEntry.cs index 533948854..bcac55baa 100644 --- a/src/AsmResolver.PE/Debug/DebugDataEntry.cs +++ b/src/AsmResolver.PE/Debug/DebugDataEntry.cs @@ -98,7 +98,7 @@ public IDebugDataSegment? Contents public override uint GetPhysicalSize() => DebugDataEntryHeaderSize; /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { writer.WriteUInt32(Characteristics); writer.WriteUInt32(TimeDateStamp); diff --git a/src/AsmResolver.PE/Debug/RsdsDataSegment.cs b/src/AsmResolver.PE/Debug/RsdsDataSegment.cs index 05b914d72..e26e19c33 100644 --- a/src/AsmResolver.PE/Debug/RsdsDataSegment.cs +++ b/src/AsmResolver.PE/Debug/RsdsDataSegment.cs @@ -87,7 +87,7 @@ public override uint GetPhysicalSize() } /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { writer.WriteUInt32((uint) Signature); writer.WriteBytes(Guid.ToByteArray()); diff --git a/src/AsmResolver.PE/DotNet/Cil/CilAssembler.cs b/src/AsmResolver.PE/DotNet/Cil/CilAssembler.cs index d53d4153f..037bd2e48 100644 --- a/src/AsmResolver.PE/DotNet/Cil/CilAssembler.cs +++ b/src/AsmResolver.PE/DotNet/Cil/CilAssembler.cs @@ -11,7 +11,7 @@ namespace AsmResolver.PE.DotNet.Cil /// public class CilAssembler { - private readonly IBinaryStreamWriter _writer; + private readonly BinaryStreamWriter _writer; private readonly ICilOperandBuilder _operandBuilder; private readonly Func? _getMethodBodyName; private readonly IErrorListener _errorListener; @@ -22,7 +22,7 @@ public class CilAssembler /// /// The output stream to write the encoded instructions to. /// The object to use for creating raw operands. - public CilAssembler(IBinaryStreamWriter writer, ICilOperandBuilder operandBuilder) + public CilAssembler(BinaryStreamWriter writer, ICilOperandBuilder operandBuilder) : this(writer, operandBuilder, default(string), ThrowErrorListener.Instance) { } @@ -35,7 +35,7 @@ public CilAssembler(IBinaryStreamWriter writer, ICilOperandBuilder operandBuilde /// The name of the method that is being serialized. /// The object used for recording error listener. public CilAssembler( - IBinaryStreamWriter writer, + BinaryStreamWriter writer, ICilOperandBuilder operandBuilder, string? methodBodyName, IErrorListener errorListener) @@ -56,7 +56,7 @@ public CilAssembler( /// A delegate that is used for lazily obtaining the name of the method body. /// The object used for recording error listener. public CilAssembler( - IBinaryStreamWriter writer, + BinaryStreamWriter writer, ICilOperandBuilder operandBuilder, Func? getMethodBodyName, IErrorListener errorListener) diff --git a/src/AsmResolver.PE/DotNet/Cil/CilExtraSection.cs b/src/AsmResolver.PE/DotNet/Cil/CilExtraSection.cs index 48eed91dc..cdf19f81b 100644 --- a/src/AsmResolver.PE/DotNet/Cil/CilExtraSection.cs +++ b/src/AsmResolver.PE/DotNet/Cil/CilExtraSection.cs @@ -132,7 +132,7 @@ public static CilExtraSection FromReader(ref BinaryStreamReader reader) public override uint GetPhysicalSize() => (uint) Data.Length + 4; /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { writer.WriteByte((byte) Attributes); diff --git a/src/AsmResolver.PE/DotNet/Cil/CilOpCode.cs b/src/AsmResolver.PE/DotNet/Cil/CilOpCode.cs index b10e2f377..deabc296d 100644 --- a/src/AsmResolver.PE/DotNet/Cil/CilOpCode.cs +++ b/src/AsmResolver.PE/DotNet/Cil/CilOpCode.cs @@ -62,6 +62,11 @@ internal CilOpCode(uint value) CilOpCodes.SingleByteOpCodes[Byte1] = this; } + /// + /// Gets a value indicating whether the opcode is valid and interpreted by the runtime. + /// + public bool IsValid => _value != 0 && Mnemonic != "unused"; + /// /// Gets the mnemonic of the operation code. /// diff --git a/src/AsmResolver.PE/DotNet/Cil/CilRawFatMethodBody.cs b/src/AsmResolver.PE/DotNet/Cil/CilRawFatMethodBody.cs index bc70ed255..56182da40 100644 --- a/src/AsmResolver.PE/DotNet/Cil/CilRawFatMethodBody.cs +++ b/src/AsmResolver.PE/DotNet/Cil/CilRawFatMethodBody.cs @@ -212,7 +212,7 @@ public override uint GetPhysicalSize() } /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { writer.WriteUInt16((ushort) ((ushort) _attributes | 0x3000)); writer.WriteUInt16(MaxStack); diff --git a/src/AsmResolver.PE/DotNet/Cil/CilRawTinyMethodBody.cs b/src/AsmResolver.PE/DotNet/Cil/CilRawTinyMethodBody.cs index 852af652b..1e49d4b39 100644 --- a/src/AsmResolver.PE/DotNet/Cil/CilRawTinyMethodBody.cs +++ b/src/AsmResolver.PE/DotNet/Cil/CilRawTinyMethodBody.cs @@ -73,7 +73,7 @@ public override void UpdateOffsets(in RelocationParameters parameters) public override uint GetPhysicalSize() => sizeof(byte) + Code.GetPhysicalSize(); /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { uint codeSize = Code.GetPhysicalSize(); if (codeSize > 0x3F) diff --git a/src/AsmResolver.PE/DotNet/CustomManagedNativeHeader.cs b/src/AsmResolver.PE/DotNet/CustomManagedNativeHeader.cs index 3f01f3818..abe4f914a 100644 --- a/src/AsmResolver.PE/DotNet/CustomManagedNativeHeader.cs +++ b/src/AsmResolver.PE/DotNet/CustomManagedNativeHeader.cs @@ -43,7 +43,7 @@ public override void UpdateOffsets(in RelocationParameters parameters) public override uint GetPhysicalSize() => sizeof(ManagedNativeHeaderSignature) + Contents.GetPhysicalSize(); /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { writer.WriteUInt32((uint) Signature); Contents.Write(writer); diff --git a/src/AsmResolver.PE/DotNet/DotNetDirectory.cs b/src/AsmResolver.PE/DotNet/DotNetDirectory.cs index f731eee4f..c46e00a52 100644 --- a/src/AsmResolver.PE/DotNet/DotNetDirectory.cs +++ b/src/AsmResolver.PE/DotNet/DotNetDirectory.cs @@ -156,7 +156,7 @@ public override uint GetPhysicalSize() => + 6 * DataDirectory.DataDirectorySize; // data directories. /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { writer.WriteUInt32(GetPhysicalSize()); writer.WriteUInt16(MajorRuntimeVersion); diff --git a/src/AsmResolver.PE/DotNet/Metadata/CustomMetadataStream.cs b/src/AsmResolver.PE/DotNet/Metadata/CustomMetadataStream.cs index 056f2b274..4655f7912 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/CustomMetadataStream.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/CustomMetadataStream.cs @@ -77,6 +77,6 @@ public BinaryStreamReader CreateReader() public uint GetVirtualSize() => GetPhysicalSize(); /// - public void Write(IBinaryStreamWriter writer) => Contents.Write(writer); + public void Write(BinaryStreamWriter writer) => Contents.Write(writer); } } diff --git a/src/AsmResolver.PE/DotNet/Metadata/MetadataDirectory.cs b/src/AsmResolver.PE/DotNet/Metadata/MetadataDirectory.cs index 0663d355b..1acc4aaf5 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/MetadataDirectory.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/MetadataDirectory.cs @@ -147,7 +147,7 @@ public override uint GetPhysicalSize() } /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { ulong start = writer.Offset; @@ -202,7 +202,7 @@ private uint GetSizeOfStreamHeaders() /// /// The output stream to write to. /// The headers to write. - protected virtual void WriteStreamHeaders(IBinaryStreamWriter writer, MetadataStreamHeader[] headers) + protected virtual void WriteStreamHeaders(BinaryStreamWriter writer, MetadataStreamHeader[] headers) { for (int i = 0; i < headers.Length; i++) { @@ -221,7 +221,7 @@ protected virtual void WriteStreamHeaders(IBinaryStreamWriter writer, MetadataSt /// Writes the contents of all streams to an output stream. /// /// The output stream to write to. - protected virtual void WriteStreams(IBinaryStreamWriter writer) + protected virtual void WriteStreams(BinaryStreamWriter writer) { for (int i = 0; i < Streams.Count; i++) Streams[i].Write(writer); diff --git a/src/AsmResolver.PE/DotNet/Metadata/PdbStream.cs b/src/AsmResolver.PE/DotNet/Metadata/PdbStream.cs index 2bc07c4d5..331da3b5c 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/PdbStream.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/PdbStream.cs @@ -111,7 +111,7 @@ public override uint GetPhysicalSize() } /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { writer.WriteBytes(Id); writer.WriteUInt32(EntryPoint.ToUInt32()); diff --git a/src/AsmResolver.PE/DotNet/Metadata/SerializedBlobStream.cs b/src/AsmResolver.PE/DotNet/Metadata/SerializedBlobStream.cs index 654b153c0..5c29a1097 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/SerializedBlobStream.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/SerializedBlobStream.cs @@ -52,7 +52,7 @@ public SerializedBlobStream(string name, in BinaryStreamReader reader) public override uint GetPhysicalSize() => _reader.Length; /// - public override void Write(IBinaryStreamWriter writer) => _reader.Fork().WriteToOutput(writer); + public override void Write(BinaryStreamWriter writer) => _reader.Fork().WriteToOutput(writer); /// public override byte[]? GetBlobByIndex(uint index) => TryGetBlobReaderByIndex(index, out var reader) diff --git a/src/AsmResolver.PE/DotNet/Metadata/SerializedGuidStream.cs b/src/AsmResolver.PE/DotNet/Metadata/SerializedGuidStream.cs index 3637b2178..9866141b2 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/SerializedGuidStream.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/SerializedGuidStream.cs @@ -55,7 +55,7 @@ public SerializedGuidStream(string name, in BinaryStreamReader reader) public override uint GetPhysicalSize() => _reader.Length; /// - public override void Write(IBinaryStreamWriter writer) => _reader.Fork().WriteToOutput(writer); + public override void Write(BinaryStreamWriter writer) => _reader.Fork().WriteToOutput(writer); /// public override System.Guid GetGuidByIndex(uint index) diff --git a/src/AsmResolver.PE/DotNet/Metadata/SerializedStringsStream.cs b/src/AsmResolver.PE/DotNet/Metadata/SerializedStringsStream.cs index 225ebf2f1..141381bf3 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/SerializedStringsStream.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/SerializedStringsStream.cs @@ -53,7 +53,7 @@ public SerializedStringsStream(string name, in BinaryStreamReader reader) public override uint GetPhysicalSize() => _reader.Length; /// - public override void Write(IBinaryStreamWriter writer) => _reader.Fork().WriteToOutput(writer); + public override void Write(BinaryStreamWriter writer) => _reader.Fork().WriteToOutput(writer); /// public override Utf8String? GetStringByIndex(uint index) diff --git a/src/AsmResolver.PE/DotNet/Metadata/SerializedUserStringsStream.cs b/src/AsmResolver.PE/DotNet/Metadata/SerializedUserStringsStream.cs index 5f8d7d635..2a78acc30 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/SerializedUserStringsStream.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/SerializedUserStringsStream.cs @@ -54,7 +54,7 @@ public SerializedUserStringsStream(string name, BinaryStreamReader reader) public override uint GetPhysicalSize() => _reader.Length; /// - public override void Write(IBinaryStreamWriter writer) => _reader.Fork().WriteToOutput(writer); + public override void Write(BinaryStreamWriter writer) => _reader.Fork().WriteToOutput(writer); /// public override string? GetStringByIndex(uint index) diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/AssemblyDefinitionRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/AssemblyDefinitionRow.cs index 84328f4cc..24fbd7ad6 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/AssemblyDefinitionRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/AssemblyDefinitionRow.cs @@ -168,7 +168,7 @@ public uint Culture } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteUInt32((uint) HashAlgorithm); writer.WriteUInt16(MajorVersion); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/AssemblyOSRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/AssemblyOSRow.cs index 48d93972b..817199691 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/AssemblyOSRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/AssemblyOSRow.cs @@ -80,7 +80,7 @@ public uint MinorVersion } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteUInt32(PlatformId); writer.WriteUInt32(MajorVersion); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/AssemblyProcessorRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/AssemblyProcessorRow.cs index c01846b9b..5f548edc5 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/AssemblyProcessorRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/AssemblyProcessorRow.cs @@ -53,7 +53,7 @@ public uint ProcessorId } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteUInt32(ProcessorId); } diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/AssemblyRefOSRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/AssemblyRefOSRow.cs index e994ebf36..b911bdbcb 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/AssemblyRefOSRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/AssemblyRefOSRow.cs @@ -95,7 +95,7 @@ public uint AssemblyReference } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteUInt32(PlatformId); writer.WriteUInt32(MajorVersion); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/AssemblyRefProcessorRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/AssemblyRefProcessorRow.cs index e7e697aeb..4092e3c07 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/AssemblyRefProcessorRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/AssemblyRefProcessorRow.cs @@ -68,7 +68,7 @@ public uint AssemblyReference } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteUInt32(ProcessorId); writer.WriteIndex(AssemblyReference, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/AssemblyReferenceRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/AssemblyReferenceRow.cs index 08f1e726a..a758ed1a7 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/AssemblyReferenceRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/AssemblyReferenceRow.cs @@ -167,7 +167,7 @@ public uint HashValue } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteUInt16(MajorVersion); writer.WriteUInt16(MinorVersion); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/ClassLayoutRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/ClassLayoutRow.cs index 39b91175e..9ee56eccd 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/ClassLayoutRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/ClassLayoutRow.cs @@ -83,7 +83,7 @@ public uint Parent } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteUInt16(PackingSize); writer.WriteUInt32(ClassSize); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/ConstantRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/ConstantRow.cs index 34535fa25..287dfbb4d 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/ConstantRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/ConstantRow.cs @@ -124,7 +124,7 @@ public bool Equals(ConstantRow other) } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteByte((byte) Type); writer.WriteByte(Padding); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/CustomAttributeRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/CustomAttributeRow.cs index acf421619..611fb50f0 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/CustomAttributeRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/CustomAttributeRow.cs @@ -97,7 +97,7 @@ public bool Equals(CustomAttributeRow other) } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteIndex(Parent, (IndexSize) layout.Columns[0].Size); writer.WriteIndex(Type, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/CustomDebugInformationRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/CustomDebugInformationRow.cs index 3de968bc1..195c17e00 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/CustomDebugInformationRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/CustomDebugInformationRow.cs @@ -86,7 +86,7 @@ public static CustomDebugInformationRow FromReader(ref BinaryStreamReader reader } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteIndex(Parent, (IndexSize) layout.Columns[0].Size); writer.WriteIndex(Kind, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/DocumentRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/DocumentRow.cs index 0fbf9db19..4dd91a449 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/DocumentRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/DocumentRow.cs @@ -93,7 +93,7 @@ public static DocumentRow FromReader(ref BinaryStreamReader reader, TableLayout } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteIndex(Name, (IndexSize) layout.Columns[0].Size); writer.WriteIndex(HashAlgorithm, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/EncLogRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/EncLogRow.cs index 640860699..90176ec0a 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/EncLogRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/EncLogRow.cs @@ -78,7 +78,7 @@ public bool Equals(EncLogRow other) } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteUInt32(Token.ToUInt32()); writer.WriteUInt32((uint) FuncCode); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/EncMapRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/EncMapRow.cs index 6e948f519..406f50064 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/EncMapRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/EncMapRow.cs @@ -63,7 +63,7 @@ public bool Equals(EncMapRow other) } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteUInt32(Token.ToUInt32()); } diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/EventDefinitionRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/EventDefinitionRow.cs index c9f58e049..51f9d4f26 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/EventDefinitionRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/EventDefinitionRow.cs @@ -85,7 +85,7 @@ public uint EventType } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteUInt16((ushort) Attributes); writer.WriteIndex(Name, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/EventMapRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/EventMapRow.cs index 14e8719ad..69d6c7c2c 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/EventMapRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/EventMapRow.cs @@ -67,7 +67,7 @@ public uint EventList } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteIndex(Parent, (IndexSize) layout.Columns[0].Size); writer.WriteIndex(EventList, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/EventPointerRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/EventPointerRow.cs index d06261bf5..b5e5cbf72 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/EventPointerRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/EventPointerRow.cs @@ -53,7 +53,7 @@ public uint Event } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteIndex(Event,(IndexSize) layout.Columns[0].Size); } diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/ExportedTypeRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/ExportedTypeRow.cs index e7fe4dd68..33fd41128 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/ExportedTypeRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/ExportedTypeRow.cs @@ -119,7 +119,7 @@ public uint Implementation } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteUInt32((uint) Attributes); writer.WriteUInt32(TypeDefinitionId); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/FieldDefinitionRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/FieldDefinitionRow.cs index 31ca31bbb..854bd3da3 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/FieldDefinitionRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/FieldDefinitionRow.cs @@ -85,7 +85,7 @@ public uint Signature } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteUInt16((ushort) Attributes); writer.WriteIndex(Name, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/FieldLayoutRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/FieldLayoutRow.cs index 41cff1cdb..225ea0989 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/FieldLayoutRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/FieldLayoutRow.cs @@ -67,7 +67,7 @@ public uint Field } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteUInt32(Offset); writer.WriteIndex(Field, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/FieldMarshalRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/FieldMarshalRow.cs index cf3869c04..542c0c71d 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/FieldMarshalRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/FieldMarshalRow.cs @@ -69,7 +69,7 @@ public uint NativeType } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteIndex(Parent, (IndexSize) layout.Columns[0].Size); writer.WriteIndex(NativeType, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/FieldPointerRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/FieldPointerRow.cs index 7ae477e82..2eb01e517 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/FieldPointerRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/FieldPointerRow.cs @@ -53,7 +53,7 @@ public uint Field } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteIndex(Field, (IndexSize) layout.Columns[0].Size); } diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/FieldRvaRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/FieldRvaRow.cs index 336aabaa1..332faac98 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/FieldRvaRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/FieldRvaRow.cs @@ -73,7 +73,7 @@ public uint Field } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteUInt32(Data.Rva); writer.WriteIndex(Field, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/FileReferenceRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/FileReferenceRow.cs index 25a17f469..1fccd1688 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/FileReferenceRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/FileReferenceRow.cs @@ -80,7 +80,7 @@ public uint HashValue } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteUInt32((uint) Attributes); writer.WriteIndex(Name, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/GenericParameterConstraintRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/GenericParameterConstraintRow.cs index 578eda988..be33dcbc5 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/GenericParameterConstraintRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/GenericParameterConstraintRow.cs @@ -69,7 +69,7 @@ public uint Constraint } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteIndex(Owner, (IndexSize) layout.Columns[0].Size); writer.WriteIndex(Constraint, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/GenericParameterRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/GenericParameterRow.cs index a8de934dd..ba439806a 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/GenericParameterRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/GenericParameterRow.cs @@ -94,7 +94,7 @@ public uint Name } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteUInt16(Number); writer.WriteUInt16((ushort) Attributes); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/IMetadataRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/IMetadataRow.cs index d4f31d4bb..1765cfdaa 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/IMetadataRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/IMetadataRow.cs @@ -47,6 +47,6 @@ uint this[int index] /// /// The output stream writer. /// The new layout of the table. - void Write(IBinaryStreamWriter writer, TableLayout layout); + void Write(BinaryStreamWriter writer, TableLayout layout); } } diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/IMetadataTable.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/IMetadataTable.cs index bb3210ca2..12ca00e23 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/IMetadataTable.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/IMetadataTable.cs @@ -92,6 +92,6 @@ bool IsSorted /// Serializes the table to an output stream, according to the table layout provided in . /// /// The output stream to write to. - void Write(IBinaryStreamWriter writer); + void Write(BinaryStreamWriter writer); } } diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/ImplementationMapRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/ImplementationMapRow.cs index 209e0eeda..83829a711 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/ImplementationMapRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/ImplementationMapRow.cs @@ -94,7 +94,7 @@ public uint ImportScope } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteUInt16((ushort) Attributes); writer.WriteIndex(MemberForwarded, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/ImportScopeRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/ImportScopeRow.cs index a143b5bd2..d4dfd399c 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/ImportScopeRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/ImportScopeRow.cs @@ -70,7 +70,7 @@ public static ImportScopeRow FromReader(ref BinaryStreamReader reader, TableLayo } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteIndex(Parent, (IndexSize) layout.Columns[0].Size); writer.WriteIndex(Imports, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/InterfaceImplementationRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/InterfaceImplementationRow.cs index d50fb163a..67cbdc0ec 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/InterfaceImplementationRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/InterfaceImplementationRow.cs @@ -69,7 +69,7 @@ public uint Interface } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteIndex(Class, (IndexSize) layout.Columns[0].Size); writer.WriteIndex(Interface, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/LocalConstantRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/LocalConstantRow.cs index 90201d550..b900ef40b 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/LocalConstantRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/LocalConstantRow.cs @@ -68,7 +68,7 @@ public static LocalConstantRow FromReader(ref BinaryStreamReader reader, TableLa } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteIndex(Name, (IndexSize) layout.Columns[0].Size); writer.WriteIndex(Signature, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/LocalScopeRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/LocalScopeRow.cs index e14fcdfda..d46b694a5 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/LocalScopeRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/LocalScopeRow.cs @@ -119,7 +119,7 @@ public static LocalScopeRow FromReader(ref BinaryStreamReader reader, TableLayou } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteIndex(Method, (IndexSize) layout.Columns[0].Size); writer.WriteIndex(ImportScope, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/LocalVariableRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/LocalVariableRow.cs index 12f904d10..55377c93c 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/LocalVariableRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/LocalVariableRow.cs @@ -80,7 +80,7 @@ public static LocalVariableRow FromReader(ref BinaryStreamReader reader, TableLa } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteUInt16((ushort) Attributes); writer.WriteUInt16(Index); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/ManifestResourceRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/ManifestResourceRow.cs index 59cf92796..d9b59e241 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/ManifestResourceRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/ManifestResourceRow.cs @@ -98,7 +98,7 @@ public uint Implementation } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteUInt32(Offset); writer.WriteUInt32((uint) Attributes); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/MemberReferenceRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/MemberReferenceRow.cs index d43c84be0..07dd8e538 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/MemberReferenceRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/MemberReferenceRow.cs @@ -89,7 +89,7 @@ public uint Signature } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteIndex(Parent, (IndexSize) layout.Columns[0].Size); writer.WriteIndex(Name, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/MetadataTable.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/MetadataTable.cs index d807916fd..acc593951 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/MetadataTable.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/MetadataTable.cs @@ -291,7 +291,7 @@ public virtual void UpdateTableLayout(TableLayout layout) } /// - public void Write(IBinaryStreamWriter writer) + public void Write(BinaryStreamWriter writer) { for (int i = 0; i < Rows.Count; i++) Rows[i].Write(writer, Layout); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/MethodDebugInformationRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/MethodDebugInformationRow.cs index 36f26d156..ad3e73619 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/MethodDebugInformationRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/MethodDebugInformationRow.cs @@ -73,7 +73,7 @@ public static MethodDebugInformationRow FromReader(ref BinaryStreamReader reader } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteIndex(Document, (IndexSize) layout.Columns[0].Size); writer.WriteIndex(SequencePoints, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/MethodDefinitionRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/MethodDefinitionRow.cs index 5d52117c7..caa3c57c0 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/MethodDefinitionRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/MethodDefinitionRow.cs @@ -139,7 +139,7 @@ public uint ParameterList } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteUInt32(Body?.Rva ?? 0); writer.WriteUInt16((ushort) ImplAttributes); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/MethodImplementationRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/MethodImplementationRow.cs index b3a5906ef..3deb32be0 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/MethodImplementationRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/MethodImplementationRow.cs @@ -83,7 +83,7 @@ public uint MethodDeclaration } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteIndex(Class, (IndexSize) layout.Columns[0].Size); writer.WriteIndex(MethodBody, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/MethodPointerRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/MethodPointerRow.cs index bc3a5fb96..b23e30a24 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/MethodPointerRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/MethodPointerRow.cs @@ -53,7 +53,7 @@ public uint Method } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteIndex(Method, (IndexSize) layout.Columns[0].Size); } diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/MethodSemanticsRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/MethodSemanticsRow.cs index cb9cca3d1..2b3ce720f 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/MethodSemanticsRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/MethodSemanticsRow.cs @@ -83,7 +83,7 @@ public uint Association } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteUInt16((ushort) Attributes); writer.WriteIndex(Method, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/MethodSpecificationRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/MethodSpecificationRow.cs index 234b6521b..647e23f41 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/MethodSpecificationRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/MethodSpecificationRow.cs @@ -67,7 +67,7 @@ public uint Instantiation } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteIndex(Method, (IndexSize) layout.Columns[0].Size); writer.WriteIndex(Instantiation,(IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/ModuleDefinitionRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/ModuleDefinitionRow.cs index fb048c0d6..b840b7b38 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/ModuleDefinitionRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/ModuleDefinitionRow.cs @@ -112,7 +112,7 @@ public uint EncBaseId } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteUInt16(Generation); writer.WriteIndex(Name, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/ModuleReferenceRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/ModuleReferenceRow.cs index c582991a7..a87812160 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/ModuleReferenceRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/ModuleReferenceRow.cs @@ -54,7 +54,7 @@ public uint Name } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteIndex(Name, (IndexSize) layout.Columns[0].Size); } diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/NestedClassRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/NestedClassRow.cs index 90cc03447..c07903f06 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/NestedClassRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/NestedClassRow.cs @@ -67,7 +67,7 @@ public uint EnclosingClass } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteIndex(NestedClass, (IndexSize) layout.Columns[0].Size); writer.WriteIndex(EnclosingClass, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/ParameterDefinitionRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/ParameterDefinitionRow.cs index 41c773c7e..5ec4a35a1 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/ParameterDefinitionRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/ParameterDefinitionRow.cs @@ -83,7 +83,7 @@ public uint Name } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteUInt16((ushort) Attributes); writer.WriteUInt16(Sequence); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/ParameterPointerRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/ParameterPointerRow.cs index 710b20578..c33d24859 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/ParameterPointerRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/ParameterPointerRow.cs @@ -53,7 +53,7 @@ public uint Parameter } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteIndex(Parameter, (IndexSize) layout.Columns[0].Size); } diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/PropertyDefinitionRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/PropertyDefinitionRow.cs index ec4cc2ac2..739bd6093 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/PropertyDefinitionRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/PropertyDefinitionRow.cs @@ -84,7 +84,7 @@ public uint Type } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteUInt16((ushort) Attributes); writer.WriteIndex(Name, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/PropertyMapRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/PropertyMapRow.cs index 32d4077ff..66a5da8a4 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/PropertyMapRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/PropertyMapRow.cs @@ -68,7 +68,7 @@ public uint PropertyList } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteIndex(Parent, (IndexSize) layout.Columns[0].Size); writer.WriteIndex(PropertyList, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/PropertyPointerRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/PropertyPointerRow.cs index 687ef9f5f..8e625f6fc 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/PropertyPointerRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/PropertyPointerRow.cs @@ -53,7 +53,7 @@ public uint Property } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteIndex(Property, (IndexSize) layout.Columns[0].Size); } diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/SecurityDeclarationRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/SecurityDeclarationRow.cs index 9be33482d..7f6952eba 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/SecurityDeclarationRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/SecurityDeclarationRow.cs @@ -81,7 +81,7 @@ public uint PermissionSet } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteUInt16((ushort) Action); writer.WriteIndex(Parent, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/StandAloneSignatureRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/StandAloneSignatureRow.cs index 60fd452d8..8a0298829 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/StandAloneSignatureRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/StandAloneSignatureRow.cs @@ -53,7 +53,7 @@ public uint Signature } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteIndex(Signature, (IndexSize) layout.Columns[0].Size); } diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/StateMachineMethodRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/StateMachineMethodRow.cs index bfdfc3240..6193a2b77 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/StateMachineMethodRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/StateMachineMethodRow.cs @@ -71,7 +71,7 @@ public static StateMachineMethodRow FromReader(ref BinaryStreamReader reader, Ta } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteIndex(MoveNextMethod, (IndexSize) layout.Columns[0].Size); writer.WriteIndex(KickoffMethod, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/TypeDefinitionRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/TypeDefinitionRow.cs index e8fa33e89..0e6b26404 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/TypeDefinitionRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/TypeDefinitionRow.cs @@ -128,7 +128,7 @@ public uint MethodList } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteUInt32((uint) Attributes); writer.WriteIndex(Name, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/TypeReferenceRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/TypeReferenceRow.cs index c14beefc1..062c7c831 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/TypeReferenceRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/TypeReferenceRow.cs @@ -88,7 +88,7 @@ public uint Namespace } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteIndex(ResolutionScope, (IndexSize) layout.Columns[0].Size); writer.WriteIndex(Name, (IndexSize) layout.Columns[1].Size); diff --git a/src/AsmResolver.PE/DotNet/Metadata/Tables/TypeSpecificationRow.cs b/src/AsmResolver.PE/DotNet/Metadata/Tables/TypeSpecificationRow.cs index bcfc04d53..89c482081 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/Tables/TypeSpecificationRow.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/Tables/TypeSpecificationRow.cs @@ -54,7 +54,7 @@ public uint Signature } /// - public void Write(IBinaryStreamWriter writer, TableLayout layout) + public void Write(BinaryStreamWriter writer, TableLayout layout) { writer.WriteIndex(Signature, (IndexSize) layout.Columns[0].Size); } diff --git a/src/AsmResolver.PE/DotNet/Metadata/TablesStream.cs b/src/AsmResolver.PE/DotNet/Metadata/TablesStream.cs index 18f85bb07..eb516b1c6 100644 --- a/src/AsmResolver.PE/DotNet/Metadata/TablesStream.cs +++ b/src/AsmResolver.PE/DotNet/Metadata/TablesStream.cs @@ -309,7 +309,7 @@ public override uint GetPhysicalSize() } /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { SynchronizeTableLayoutsWithFlags(); @@ -436,7 +436,7 @@ protected virtual uint GetTablesSize(ulong validBitmask) /// /// The output stream to write to. /// The valid bitmask, indicating all present tables in the stream. - protected virtual void WriteRowCounts(IBinaryStreamWriter writer, ulong validBitmask) + protected virtual void WriteRowCounts(BinaryStreamWriter writer, ulong validBitmask) { for (TableIndex i = 0; i <= TableIndex.Max; i++) { @@ -450,7 +450,7 @@ protected virtual void WriteRowCounts(IBinaryStreamWriter writer, ulong validBit /// /// The output stream to write to. /// The valid bitmask, indicating all present tables in the stream. - protected virtual void WriteTables(IBinaryStreamWriter writer, ulong validBitmask) + protected virtual void WriteTables(BinaryStreamWriter writer, ulong validBitmask) { for (TableIndex i = 0; i < (TableIndex) Tables.Count; i++) { diff --git a/src/AsmResolver.PE/DotNet/ReadyToRun/CompilerIdentifierSection.cs b/src/AsmResolver.PE/DotNet/ReadyToRun/CompilerIdentifierSection.cs index 736b2aeaf..c9cc0d7ac 100644 --- a/src/AsmResolver.PE/DotNet/ReadyToRun/CompilerIdentifierSection.cs +++ b/src/AsmResolver.PE/DotNet/ReadyToRun/CompilerIdentifierSection.cs @@ -42,7 +42,7 @@ public string Identifier public override uint GetPhysicalSize() => (uint) Encoding.ASCII.GetByteCount(Identifier) + sizeof(byte); /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { writer.WriteAsciiString(Identifier); writer.WriteByte(0); diff --git a/src/AsmResolver.PE/DotNet/ReadyToRun/CustomReadyToRunSection.cs b/src/AsmResolver.PE/DotNet/ReadyToRun/CustomReadyToRunSection.cs index 4f7a32ea8..7bd708f93 100644 --- a/src/AsmResolver.PE/DotNet/ReadyToRun/CustomReadyToRunSection.cs +++ b/src/AsmResolver.PE/DotNet/ReadyToRun/CustomReadyToRunSection.cs @@ -44,7 +44,7 @@ public ISegment Contents public override uint GetPhysicalSize() => Contents.GetPhysicalSize(); /// - public override void Write(IBinaryStreamWriter writer) => Contents.Write(writer); + public override void Write(BinaryStreamWriter writer) => Contents.Write(writer); /// public BinaryStreamReader CreateReader() diff --git a/src/AsmResolver.PE/DotNet/ReadyToRun/DebugInfo.cs b/src/AsmResolver.PE/DotNet/ReadyToRun/DebugInfo.cs index de2a60cd2..916531df5 100644 --- a/src/AsmResolver.PE/DotNet/ReadyToRun/DebugInfo.cs +++ b/src/AsmResolver.PE/DotNet/ReadyToRun/DebugInfo.cs @@ -79,7 +79,7 @@ public override uint GetPhysicalSize() } /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { _serialized ??= Serialize(); writer.WriteBytes(_serialized); diff --git a/src/AsmResolver.PE/DotNet/ReadyToRun/DebugInfoSection.cs b/src/AsmResolver.PE/DotNet/ReadyToRun/DebugInfoSection.cs index d27a2050b..b0afc6778 100644 --- a/src/AsmResolver.PE/DotNet/ReadyToRun/DebugInfoSection.cs +++ b/src/AsmResolver.PE/DotNet/ReadyToRun/DebugInfoSection.cs @@ -53,6 +53,6 @@ public override void UpdateOffsets(in RelocationParameters parameters) public override uint GetPhysicalSize() => Entries.GetPhysicalSize(); /// - public override void Write(IBinaryStreamWriter writer) => Entries.Write(writer); + public override void Write(BinaryStreamWriter writer) => Entries.Write(writer); } } diff --git a/src/AsmResolver.PE/DotNet/ReadyToRun/ImportSection.cs b/src/AsmResolver.PE/DotNet/ReadyToRun/ImportSection.cs index 99ff71ee0..ea3b311a8 100644 --- a/src/AsmResolver.PE/DotNet/ReadyToRun/ImportSection.cs +++ b/src/AsmResolver.PE/DotNet/ReadyToRun/ImportSection.cs @@ -111,7 +111,7 @@ public ISegmentReference AuxiliaryData public uint GetPhysicalSize() => ImportSectionSize; /// - public void Write(IBinaryStreamWriter writer) + public void Write(BinaryStreamWriter writer) { writer.WriteUInt32(Slots.Rva); writer.WriteUInt32(Slots.GetPhysicalSize()); diff --git a/src/AsmResolver.PE/DotNet/ReadyToRun/ImportSectionsSection.cs b/src/AsmResolver.PE/DotNet/ReadyToRun/ImportSectionsSection.cs index 1d90f7415..b4b987a8c 100644 --- a/src/AsmResolver.PE/DotNet/ReadyToRun/ImportSectionsSection.cs +++ b/src/AsmResolver.PE/DotNet/ReadyToRun/ImportSectionsSection.cs @@ -47,7 +47,7 @@ public IList Sections public override uint GetPhysicalSize() => (uint) Sections.Count * ImportSection.ImportSectionSize; /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { for (int i = 0; i < Sections.Count; i++) Sections[i].Write(writer); diff --git a/src/AsmResolver.PE/DotNet/ReadyToRun/MethodEntryPoint.cs b/src/AsmResolver.PE/DotNet/ReadyToRun/MethodEntryPoint.cs index e0a087d07..b0ba1f0e8 100644 --- a/src/AsmResolver.PE/DotNet/ReadyToRun/MethodEntryPoint.cs +++ b/src/AsmResolver.PE/DotNet/ReadyToRun/MethodEntryPoint.cs @@ -113,7 +113,7 @@ public override uint GetPhysicalSize() } /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { _serialized ??= Serialize(); writer.WriteBytes(_serialized); diff --git a/src/AsmResolver.PE/DotNet/ReadyToRun/MethodEntryPointsSection.cs b/src/AsmResolver.PE/DotNet/ReadyToRun/MethodEntryPointsSection.cs index 7da2c46e3..0be2cc167 100644 --- a/src/AsmResolver.PE/DotNet/ReadyToRun/MethodEntryPointsSection.cs +++ b/src/AsmResolver.PE/DotNet/ReadyToRun/MethodEntryPointsSection.cs @@ -55,6 +55,6 @@ public override void UpdateOffsets(in RelocationParameters parameters) public override uint GetPhysicalSize() => EntryPoints.GetPhysicalSize(); /// - public override void Write(IBinaryStreamWriter writer) => EntryPoints.Write(writer); + public override void Write(BinaryStreamWriter writer) => EntryPoints.Write(writer); } } diff --git a/src/AsmResolver.PE/DotNet/ReadyToRun/NativeArray.cs b/src/AsmResolver.PE/DotNet/ReadyToRun/NativeArray.cs index 3592367fc..cdc8f0b78 100644 --- a/src/AsmResolver.PE/DotNet/ReadyToRun/NativeArray.cs +++ b/src/AsmResolver.PE/DotNet/ReadyToRun/NativeArray.cs @@ -140,7 +140,7 @@ public void UpdateOffsets(in RelocationParameters parameters) public uint GetVirtualSize() => GetPhysicalSize(); /// - public void Write(IBinaryStreamWriter writer) + public void Write(BinaryStreamWriter writer) { uint header = Header; uint headerSize = NativeFormat.GetEncodedUnsignedSize(header); @@ -153,7 +153,7 @@ public void Write(IBinaryStreamWriter writer) root.Write(writer); } - private void WriteRootNodeHeader(IBinaryStreamWriter writer, Node root, uint headerSize) + private void WriteRootNodeHeader(BinaryStreamWriter writer, Node root, uint headerSize) { uint offset = (uint) (root.Offset - headerSize - Offset); switch (_entryIndexSize) @@ -256,7 +256,7 @@ public override void UpdateOffsets(in RelocationParameters parameters) public override uint GetPhysicalSize() => _size; - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { System.Diagnostics.Debug.Assert(writer.Offset == Offset); diff --git a/src/AsmResolver.PE/DotNet/ReadyToRun/NativeFormat.cs b/src/AsmResolver.PE/DotNet/ReadyToRun/NativeFormat.cs index 926603a67..4d05510d8 100644 --- a/src/AsmResolver.PE/DotNet/ReadyToRun/NativeFormat.cs +++ b/src/AsmResolver.PE/DotNet/ReadyToRun/NativeFormat.cs @@ -56,7 +56,7 @@ public static uint DecodeUnsigned(ref BinaryStreamReader reader) return value; } - public static void EncodeUnsigned(IBinaryStreamWriter writer, uint value) + public static void EncodeUnsigned(BinaryStreamWriter writer, uint value) { switch (GetEncodedUnsignedSize(value)) { diff --git a/src/AsmResolver.PE/DotNet/ReadyToRun/NibbleWriter.cs b/src/AsmResolver.PE/DotNet/ReadyToRun/NibbleWriter.cs index 51bd0e3d6..f05429528 100644 --- a/src/AsmResolver.PE/DotNet/ReadyToRun/NibbleWriter.cs +++ b/src/AsmResolver.PE/DotNet/ReadyToRun/NibbleWriter.cs @@ -4,10 +4,10 @@ namespace AsmResolver.PE.DotNet.ReadyToRun { internal struct NibbleWriter { - private readonly IBinaryStreamWriter _writer; + private readonly BinaryStreamWriter _writer; private byte? _buffer; - public NibbleWriter(IBinaryStreamWriter writer) + public NibbleWriter(BinaryStreamWriter writer) { _writer = writer; _buffer = null; diff --git a/src/AsmResolver.PE/DotNet/ReadyToRun/ReadyToRunDirectory.cs b/src/AsmResolver.PE/DotNet/ReadyToRun/ReadyToRunDirectory.cs index 3d14f4d46..28b8f7097 100644 --- a/src/AsmResolver.PE/DotNet/ReadyToRun/ReadyToRunDirectory.cs +++ b/src/AsmResolver.PE/DotNet/ReadyToRun/ReadyToRunDirectory.cs @@ -153,7 +153,7 @@ public override uint GetPhysicalSize() } /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { writer.WriteUInt32((uint) Signature); writer.WriteUInt16(MajorVersion); diff --git a/src/AsmResolver.PE/DotNet/ReadyToRun/RuntimeFunctionsSection.cs b/src/AsmResolver.PE/DotNet/ReadyToRun/RuntimeFunctionsSection.cs index 1866d8f2f..723d58062 100644 --- a/src/AsmResolver.PE/DotNet/ReadyToRun/RuntimeFunctionsSection.cs +++ b/src/AsmResolver.PE/DotNet/ReadyToRun/RuntimeFunctionsSection.cs @@ -69,7 +69,7 @@ public override uint GetPhysicalSize() => Functions.Count > 0 : 0; /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { for (int i = 0; i < Functions.Count; i++) Functions[i].Write(writer); diff --git a/src/AsmResolver.PE/DotNet/Resources/SerializedDotNetResourcesDirectory.cs b/src/AsmResolver.PE/DotNet/Resources/SerializedDotNetResourcesDirectory.cs index dfa63b4ce..113072aff 100644 --- a/src/AsmResolver.PE/DotNet/Resources/SerializedDotNetResourcesDirectory.cs +++ b/src/AsmResolver.PE/DotNet/Resources/SerializedDotNetResourcesDirectory.cs @@ -38,7 +38,7 @@ public SerializedDotNetResourcesDirectory(IReadableSegment contents) public override uint GetPhysicalSize() => _reader.Length; /// - public override void Write(IBinaryStreamWriter writer) => _reader.Fork().WriteToOutput(writer); + public override void Write(BinaryStreamWriter writer) => _reader.Fork().WriteToOutput(writer); /// public override byte[]? GetManifestResourceData(uint offset) diff --git a/src/AsmResolver.PE/DotNet/StrongName/StrongNameKeyStructure.cs b/src/AsmResolver.PE/DotNet/StrongName/StrongNameKeyStructure.cs index 557145c64..6eef86aa9 100644 --- a/src/AsmResolver.PE/DotNet/StrongName/StrongNameKeyStructure.cs +++ b/src/AsmResolver.PE/DotNet/StrongName/StrongNameKeyStructure.cs @@ -72,7 +72,7 @@ public override uint GetPhysicalSize() } /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { writer.WriteByte((byte) Type); writer.WriteByte(Version); diff --git a/src/AsmResolver.PE/DotNet/StrongName/StrongNamePrivateKey.cs b/src/AsmResolver.PE/DotNet/StrongName/StrongNamePrivateKey.cs index d004e5059..471eb3cc6 100644 --- a/src/AsmResolver.PE/DotNet/StrongName/StrongNamePrivateKey.cs +++ b/src/AsmResolver.PE/DotNet/StrongName/StrongNamePrivateKey.cs @@ -213,7 +213,7 @@ public override uint GetPhysicalSize() } /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { base.Write(writer); writer.WriteBytes(P); diff --git a/src/AsmResolver.PE/DotNet/StrongName/StrongNamePublicKey.cs b/src/AsmResolver.PE/DotNet/StrongName/StrongNamePublicKey.cs index 0ec412f80..2fd727d60 100644 --- a/src/AsmResolver.PE/DotNet/StrongName/StrongNamePublicKey.cs +++ b/src/AsmResolver.PE/DotNet/StrongName/StrongNamePublicKey.cs @@ -173,7 +173,7 @@ public override uint GetPhysicalSize() } /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { base.Write(writer); writer.WriteUInt32((uint) Magic); diff --git a/src/AsmResolver.PE/DotNet/VTableFixups/VTableFixup.cs b/src/AsmResolver.PE/DotNet/VTableFixups/VTableFixup.cs index 4b2ebcbe4..8e5c41a4f 100644 --- a/src/AsmResolver.PE/DotNet/VTableFixups/VTableFixup.cs +++ b/src/AsmResolver.PE/DotNet/VTableFixups/VTableFixup.cs @@ -61,7 +61,7 @@ public override uint GetPhysicalSize() => + sizeof(ushort); // Type /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { writer.WriteUInt32(Tokens.Rva); writer.WriteUInt16((ushort) Tokens.Count); diff --git a/src/AsmResolver.PE/DotNet/VTableFixups/VTableFixupsDirectory.cs b/src/AsmResolver.PE/DotNet/VTableFixups/VTableFixupsDirectory.cs index acf7c4db5..724376eb5 100644 --- a/src/AsmResolver.PE/DotNet/VTableFixups/VTableFixupsDirectory.cs +++ b/src/AsmResolver.PE/DotNet/VTableFixups/VTableFixupsDirectory.cs @@ -37,7 +37,7 @@ public void UpdateOffsets(in RelocationParameters parameters) public uint GetPhysicalSize() => (uint) this.Sum(v => v.GetPhysicalSize()); /// - public void Write(IBinaryStreamWriter writer) + public void Write(BinaryStreamWriter writer) { for (int i = 0; i < Count; i++) this[i].Write(writer); diff --git a/src/AsmResolver.PE/DotNet/VTableFixups/VTableTokenCollection.cs b/src/AsmResolver.PE/DotNet/VTableFixups/VTableTokenCollection.cs index 4420f1fc2..c3fa816c4 100644 --- a/src/AsmResolver.PE/DotNet/VTableFixups/VTableTokenCollection.cs +++ b/src/AsmResolver.PE/DotNet/VTableFixups/VTableTokenCollection.cs @@ -59,7 +59,7 @@ public uint GetPhysicalSize() => : sizeof(ulong)); /// - public void Write(IBinaryStreamWriter writer) + public void Write(BinaryStreamWriter writer) { for (int i = 0; i < Items.Count; i++) { diff --git a/src/AsmResolver.PE/Exceptions/X64RuntimeFunction.cs b/src/AsmResolver.PE/Exceptions/X64RuntimeFunction.cs index 5a02168c9..4620394d8 100644 --- a/src/AsmResolver.PE/Exceptions/X64RuntimeFunction.cs +++ b/src/AsmResolver.PE/Exceptions/X64RuntimeFunction.cs @@ -75,7 +75,7 @@ public static X64RuntimeFunction FromReader(PEReaderContext context, ref BinaryS public uint GetPhysicalSize() => EntrySize; /// - public void Write(IBinaryStreamWriter writer) + public void Write(BinaryStreamWriter writer) { writer.WriteUInt32(Begin.Rva); writer.WriteUInt32(End.Rva); diff --git a/src/AsmResolver.PE/Exceptions/X64UnwindInfo.cs b/src/AsmResolver.PE/Exceptions/X64UnwindInfo.cs index b3ec79d27..39aa7b821 100644 --- a/src/AsmResolver.PE/Exceptions/X64UnwindInfo.cs +++ b/src/AsmResolver.PE/Exceptions/X64UnwindInfo.cs @@ -202,7 +202,7 @@ public override uint GetPhysicalSize() } /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { writer.WriteByte(_firstByte); writer.WriteByte(SizeOfProlog); diff --git a/src/AsmResolver.PE/Exports/Builder/ExportAddressTableBuffer.cs b/src/AsmResolver.PE/Exports/Builder/ExportAddressTableBuffer.cs index 73043915b..2c08a9f46 100644 --- a/src/AsmResolver.PE/Exports/Builder/ExportAddressTableBuffer.cs +++ b/src/AsmResolver.PE/Exports/Builder/ExportAddressTableBuffer.cs @@ -31,7 +31,7 @@ public ExportAddressTableBuffer(NameTableBuffer nameTableBuffer) public override uint GetPhysicalSize() => (uint) (_entries.Count * sizeof(uint)); /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { foreach (var entry in _entries) { diff --git a/src/AsmResolver.PE/Exports/Builder/ExportDirectoryBuffer.cs b/src/AsmResolver.PE/Exports/Builder/ExportDirectoryBuffer.cs index b95067cb9..a6854245f 100644 --- a/src/AsmResolver.PE/Exports/Builder/ExportDirectoryBuffer.cs +++ b/src/AsmResolver.PE/Exports/Builder/ExportDirectoryBuffer.cs @@ -97,13 +97,13 @@ public override void UpdateOffsets(in RelocationParameters parameters) public override uint GetPhysicalSize() => ExportDirectoryHeaderSize + _contentsBuilder.GetPhysicalSize(); /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { WriteExportDirectoryHeader(writer); _contentsBuilder.Write(writer); } - private void WriteExportDirectoryHeader(IBinaryStreamWriter writer) + private void WriteExportDirectoryHeader(BinaryStreamWriter writer) { _exportDirectory ??= new ExportDirectory(string.Empty); writer.WriteUInt32(_exportDirectory.ExportFlags); diff --git a/src/AsmResolver.PE/Exports/Builder/NameTableBuffer.cs b/src/AsmResolver.PE/Exports/Builder/NameTableBuffer.cs index e9a7fd89b..227c84a5f 100644 --- a/src/AsmResolver.PE/Exports/Builder/NameTableBuffer.cs +++ b/src/AsmResolver.PE/Exports/Builder/NameTableBuffer.cs @@ -50,7 +50,7 @@ public uint GetNameRva(string? name) => name is not null public override uint GetPhysicalSize() => _length; /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { foreach (string value in _entries) { diff --git a/src/AsmResolver.PE/Exports/Builder/OrdinalNamePointerTableBuffer.cs b/src/AsmResolver.PE/Exports/Builder/OrdinalNamePointerTableBuffer.cs index 92e2f4b27..f28a4caa0 100644 --- a/src/AsmResolver.PE/Exports/Builder/OrdinalNamePointerTableBuffer.cs +++ b/src/AsmResolver.PE/Exports/Builder/OrdinalNamePointerTableBuffer.cs @@ -63,19 +63,19 @@ public void AddSymbol(ExportedSymbol symbol) public override uint GetPhysicalSize() => OrdinalTableSize + NamePointerTableSize; /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { WriteOrdinalTable(writer); WriteNamePointerTable(writer); } - private void WriteNamePointerTable(IBinaryStreamWriter writer) + private void WriteNamePointerTable(BinaryStreamWriter writer) { foreach (var entry in _namedEntries) writer.WriteUInt32(_nameTableBuffer.GetNameRva(entry.Name)); } - private void WriteOrdinalTable(IBinaryStreamWriter writer) + private void WriteOrdinalTable(BinaryStreamWriter writer) { foreach (ushort ordinal in _ordinals) writer.WriteUInt16(ordinal); diff --git a/src/AsmResolver.PE/Imports/Builder/HintNameTableBuffer.cs b/src/AsmResolver.PE/Imports/Builder/HintNameTableBuffer.cs index 832463199..02ff23c4c 100644 --- a/src/AsmResolver.PE/Imports/Builder/HintNameTableBuffer.cs +++ b/src/AsmResolver.PE/Imports/Builder/HintNameTableBuffer.cs @@ -77,7 +77,7 @@ public void AddModule(ImportedModule module) public override uint GetPhysicalSize() => _length; /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { foreach (var module in _modules) { @@ -91,7 +91,7 @@ public override void Write(IBinaryStreamWriter writer) } } - private static void WriteHintName(IBinaryStreamWriter writer, ushort hint, string name) + private static void WriteHintName(BinaryStreamWriter writer, ushort hint, string name) { writer.WriteUInt16(hint); writer.WriteAsciiString(name); @@ -99,7 +99,7 @@ private static void WriteHintName(IBinaryStreamWriter writer, ushort hint, strin writer.Align(2); } - private static void WriteModuleName(IBinaryStreamWriter writer, ImportedModule module) + private static void WriteModuleName(BinaryStreamWriter writer, ImportedModule module) { writer.WriteAsciiString(module.Name ?? string.Empty); writer.WriteByte(0); diff --git a/src/AsmResolver.PE/Imports/Builder/ImportDirectoryBuffer.cs b/src/AsmResolver.PE/Imports/Builder/ImportDirectoryBuffer.cs index ec210fb93..d7655a499 100644 --- a/src/AsmResolver.PE/Imports/Builder/ImportDirectoryBuffer.cs +++ b/src/AsmResolver.PE/Imports/Builder/ImportDirectoryBuffer.cs @@ -69,21 +69,21 @@ public override void UpdateOffsets(in RelocationParameters parameters) public override uint GetPhysicalSize() => _entriesLength + base.GetPhysicalSize() + HintNameTable.GetPhysicalSize(); /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { WriteModuleImportEntries(writer); base.Write(writer); HintNameTable.Write(writer); } - private void WriteModuleImportEntries(IBinaryStreamWriter writer) + private void WriteModuleImportEntries(BinaryStreamWriter writer) { foreach (var module in Modules) WriteModuleImportEntry(writer, module); WriteModuleImportEntry(writer, 0, 0, 0, 0, 0); } - private void WriteModuleImportEntry(IBinaryStreamWriter writer, ImportedModule module) + private void WriteModuleImportEntry(BinaryStreamWriter writer, ImportedModule module) { WriteModuleImportEntry(writer, GetModuleThunkTable(module).Rva, @@ -93,7 +93,7 @@ private void WriteModuleImportEntry(IBinaryStreamWriter writer, ImportedModule m ImportAddressDirectory.GetModuleThunkTable(module).Rva); } - private static void WriteModuleImportEntry(IBinaryStreamWriter writer, uint oft, uint timeDateStamp, + private static void WriteModuleImportEntry(BinaryStreamWriter writer, uint oft, uint timeDateStamp, uint forwarderChain, uint moduleNameRva, uint ft) { writer.WriteUInt32(oft); diff --git a/src/AsmResolver.PE/Imports/Builder/ImportDirectoryBufferBase.cs b/src/AsmResolver.PE/Imports/Builder/ImportDirectoryBufferBase.cs index aab509d3d..790177fdb 100644 --- a/src/AsmResolver.PE/Imports/Builder/ImportDirectoryBufferBase.cs +++ b/src/AsmResolver.PE/Imports/Builder/ImportDirectoryBufferBase.cs @@ -104,7 +104,7 @@ protected virtual ThunkTableBuffer CreateThunkTable() => public override uint GetPhysicalSize() => _lookupTablesLength; /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { foreach (var module in Modules) _lookupTables[module].Write(writer); diff --git a/src/AsmResolver.PE/Imports/Builder/ThunkTableBuffer.cs b/src/AsmResolver.PE/Imports/Builder/ThunkTableBuffer.cs index a80e100a4..efa9a43e9 100644 --- a/src/AsmResolver.PE/Imports/Builder/ThunkTableBuffer.cs +++ b/src/AsmResolver.PE/Imports/Builder/ThunkTableBuffer.cs @@ -75,7 +75,7 @@ public void AddMember(ImportedSymbol entry) public override uint GetPhysicalSize() => _length; /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { foreach (var member in _members) { diff --git a/src/AsmResolver.PE/Platforms/AddressTableInitializerStub.cs b/src/AsmResolver.PE/Platforms/AddressTableInitializerStub.cs index 9500f5d40..09475a6a5 100644 --- a/src/AsmResolver.PE/Platforms/AddressTableInitializerStub.cs +++ b/src/AsmResolver.PE/Platforms/AddressTableInitializerStub.cs @@ -99,5 +99,5 @@ public IEnumerable GetRequiredBaseRelocations() public uint GetVirtualSize() => _contents.GetVirtualSize(); /// - public void Write(IBinaryStreamWriter writer) => _contents.Write(writer); + public void Write(BinaryStreamWriter writer) => _contents.Write(writer); } diff --git a/src/AsmResolver.PE/Relocations/Builder/RelocationBlock.cs b/src/AsmResolver.PE/Relocations/Builder/RelocationBlock.cs index 650794aa2..53a36a08e 100644 --- a/src/AsmResolver.PE/Relocations/Builder/RelocationBlock.cs +++ b/src/AsmResolver.PE/Relocations/Builder/RelocationBlock.cs @@ -39,7 +39,7 @@ public IList Entries public override uint GetPhysicalSize() => (uint) (Entries.Count + 1) * sizeof(ushort) + 2 * sizeof(uint); /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { writer.WriteUInt32(PageRva); writer.WriteUInt32(GetPhysicalSize()); diff --git a/src/AsmResolver.PE/Relocations/Builder/RelocationEntry.cs b/src/AsmResolver.PE/Relocations/Builder/RelocationEntry.cs index 776ff9660..6cc559611 100644 --- a/src/AsmResolver.PE/Relocations/Builder/RelocationEntry.cs +++ b/src/AsmResolver.PE/Relocations/Builder/RelocationEntry.cs @@ -51,6 +51,6 @@ public RelocationEntry(RelocationType type, int offset) public uint GetPhysicalSize() => sizeof(ushort); /// - public void Write(IBinaryStreamWriter writer) => writer.WriteUInt16(_value); + public void Write(BinaryStreamWriter writer) => writer.WriteUInt16(_value); } } diff --git a/src/AsmResolver.PE/Relocations/Builder/RelocationsDirectoryBuffer.cs b/src/AsmResolver.PE/Relocations/Builder/RelocationsDirectoryBuffer.cs index 9de62b16b..e1009f301 100644 --- a/src/AsmResolver.PE/Relocations/Builder/RelocationsDirectoryBuffer.cs +++ b/src/AsmResolver.PE/Relocations/Builder/RelocationsDirectoryBuffer.cs @@ -77,7 +77,7 @@ public override uint GetPhysicalSize() } /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { EnsureBlocksCreated(); for (int i = 0; i < _blocks!.Count; i++) diff --git a/src/AsmResolver.PE/Relocations/RelocatableSegmentBuilder.cs b/src/AsmResolver.PE/Relocations/RelocatableSegmentBuilder.cs index 6d907cccf..e6efad2d2 100644 --- a/src/AsmResolver.PE/Relocations/RelocatableSegmentBuilder.cs +++ b/src/AsmResolver.PE/Relocations/RelocatableSegmentBuilder.cs @@ -66,7 +66,7 @@ public void Add(RelocatableSegment segment, uint alignment) public uint GetPhysicalSize() => _contents.GetPhysicalSize(); /// - public void Write(IBinaryStreamWriter writer) => _contents.Write(writer); + public void Write(BinaryStreamWriter writer) => _contents.Write(writer); /// public uint GetVirtualSize() => _contents.GetVirtualSize(); diff --git a/src/AsmResolver.PE/Tls/TlsDirectory.cs b/src/AsmResolver.PE/Tls/TlsDirectory.cs index b2135a22c..b5b890b24 100644 --- a/src/AsmResolver.PE/Tls/TlsDirectory.cs +++ b/src/AsmResolver.PE/Tls/TlsDirectory.cs @@ -140,7 +140,7 @@ public override uint GetPhysicalSize() } /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { ulong imageBase = _imageBase; bool is32Bit = _is32Bit; diff --git a/src/AsmResolver.PE/Win32Resources/Builder/ResourceDataTableBuffer.cs b/src/AsmResolver.PE/Win32Resources/Builder/ResourceDataTableBuffer.cs index bfeb45d72..9b8d0dfd1 100644 --- a/src/AsmResolver.PE/Win32Resources/Builder/ResourceDataTableBuffer.cs +++ b/src/AsmResolver.PE/Win32Resources/Builder/ResourceDataTableBuffer.cs @@ -20,13 +20,13 @@ public ResourceDataTableBuffer(ISegment parentBuffer) public override uint GetEntrySize(ResourceData entry) => SerializedResourceData.ResourceDataEntrySize; /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { for (int i = 0; i < Entries.Count; i++) WriteDataEntry(writer, Entries[i]); } - private static void WriteDataEntry(IBinaryStreamWriter writer, ResourceData entry) + private static void WriteDataEntry(BinaryStreamWriter writer, ResourceData entry) { if (entry.Contents is null) { diff --git a/src/AsmResolver.PE/Win32Resources/Builder/ResourceDirectoryBuffer.cs b/src/AsmResolver.PE/Win32Resources/Builder/ResourceDirectoryBuffer.cs index 7314ea401..6e674b6c7 100644 --- a/src/AsmResolver.PE/Win32Resources/Builder/ResourceDirectoryBuffer.cs +++ b/src/AsmResolver.PE/Win32Resources/Builder/ResourceDirectoryBuffer.cs @@ -118,6 +118,6 @@ private void AddDataEntry(IResourceEntry entry) public uint GetVirtualSize() => _segments.GetVirtualSize(); /// - public void Write(IBinaryStreamWriter writer) => _segments.Write(writer); + public void Write(BinaryStreamWriter writer) => _segments.Write(writer); } } diff --git a/src/AsmResolver.PE/Win32Resources/Builder/ResourceDirectoryTableBuffer.cs b/src/AsmResolver.PE/Win32Resources/Builder/ResourceDirectoryTableBuffer.cs index 9f8caca8b..8fc0380c3 100644 --- a/src/AsmResolver.PE/Win32Resources/Builder/ResourceDirectoryTableBuffer.cs +++ b/src/AsmResolver.PE/Win32Resources/Builder/ResourceDirectoryTableBuffer.cs @@ -34,13 +34,13 @@ public override uint GetEntrySize(ResourceDirectory entry) => + (uint) entry.Entries.Count * ResourceDirectoryEntry.EntrySize; /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { foreach (var entry in Entries) WriteDirectory(writer, entry); } - private void WriteDirectory(IBinaryStreamWriter writer, ResourceDirectory directory) + private void WriteDirectory(BinaryStreamWriter writer, ResourceDirectory directory) { ushort namedEntries = (ushort) directory.Entries.Count(e => e.Name != null); ushort idEntries = (ushort) (directory.Entries.Count - namedEntries); @@ -56,7 +56,7 @@ private void WriteDirectory(IBinaryStreamWriter writer, ResourceDirectory direct WriteEntry(writer, entry); } - private void WriteEntry(IBinaryStreamWriter writer, IResourceEntry entry) + private void WriteEntry(BinaryStreamWriter writer, IResourceEntry entry) { writer.WriteUInt32(entry.Name != null ? _nameTable.GetEntryOffset(entry.Name) | 0x8000_0000 diff --git a/src/AsmResolver.PE/Win32Resources/Builder/ResourceNameTableBuffer.cs b/src/AsmResolver.PE/Win32Resources/Builder/ResourceNameTableBuffer.cs index 08e59e688..9293a6b68 100644 --- a/src/AsmResolver.PE/Win32Resources/Builder/ResourceNameTableBuffer.cs +++ b/src/AsmResolver.PE/Win32Resources/Builder/ResourceNameTableBuffer.cs @@ -21,7 +21,7 @@ public ResourceNameTableBuffer(ISegment parentBuffer) public override uint GetEntrySize(string entry) => sizeof(ushort) + (uint) Encoding.Unicode.GetByteCount(entry); /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { foreach (string name in Entries) {; diff --git a/src/AsmResolver.Symbols.Pdb/Metadata/Dbi/DbiStream.cs b/src/AsmResolver.Symbols.Pdb/Metadata/Dbi/DbiStream.cs index 0dbf1bf81..0a05274f8 100644 --- a/src/AsmResolver.Symbols.Pdb/Metadata/Dbi/DbiStream.cs +++ b/src/AsmResolver.Symbols.Pdb/Metadata/Dbi/DbiStream.cs @@ -452,7 +452,7 @@ private uint GetECStreamSize() } /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { WriteHeader(writer); WriteModuleStream(writer); @@ -464,7 +464,7 @@ public override void Write(IBinaryStreamWriter writer) WriteOptionalDebugStream(writer); } - private void WriteHeader(IBinaryStreamWriter writer) + private void WriteHeader(BinaryStreamWriter writer) { writer.WriteInt32(VersionSignature); writer.WriteUInt32((uint) VersionHeader); @@ -493,7 +493,7 @@ private void WriteHeader(IBinaryStreamWriter writer) writer.WriteUInt32(0); } - private void WriteModuleStream(IBinaryStreamWriter writer) + private void WriteModuleStream(BinaryStreamWriter writer) { var modules = Modules; for (int i = 0; i < modules.Count; i++) @@ -502,7 +502,7 @@ private void WriteModuleStream(IBinaryStreamWriter writer) writer.Align(sizeof(uint)); } - private void WriteSectionContributionStream(IBinaryStreamWriter writer) + private void WriteSectionContributionStream(BinaryStreamWriter writer) { // TODO: make customizable writer.WriteUInt32((uint) SectionContributionStreamVersion.Ver60); @@ -514,7 +514,7 @@ private void WriteSectionContributionStream(IBinaryStreamWriter writer) writer.Align(sizeof(uint)); } - private void WriteSectionMapStream(IBinaryStreamWriter writer) + private void WriteSectionMapStream(BinaryStreamWriter writer) { var maps = SectionMaps; @@ -529,7 +529,7 @@ private void WriteSectionMapStream(IBinaryStreamWriter writer) writer.Align(sizeof(uint)); } - private void WriteSourceInfoStream(IBinaryStreamWriter writer) + private void WriteSourceInfoStream(BinaryStreamWriter writer) { var sourceFiles = SourceFiles; int totalFileCount = sourceFiles.Sum(x => x.Count); @@ -577,13 +577,13 @@ private void WriteSourceInfoStream(IBinaryStreamWriter writer) writer.Align(sizeof(uint)); } - private void WriteTypeServerMapStream(IBinaryStreamWriter writer) + private void WriteTypeServerMapStream(BinaryStreamWriter writer) { TypeServerMapStream?.Write(writer); writer.Align(sizeof(uint)); } - private void WriteOptionalDebugStream(IBinaryStreamWriter writer) + private void WriteOptionalDebugStream(BinaryStreamWriter writer) { var extraIndices = ExtraStreamIndices; @@ -591,5 +591,5 @@ private void WriteOptionalDebugStream(IBinaryStreamWriter writer) writer.WriteUInt16(extraIndices[i]); } - private void WriteECStream(IBinaryStreamWriter writer) => ECStream?.Write(writer); + private void WriteECStream(BinaryStreamWriter writer) => ECStream?.Write(writer); } diff --git a/src/AsmResolver.Symbols.Pdb/Metadata/Dbi/ModuleDescriptor.cs b/src/AsmResolver.Symbols.Pdb/Metadata/Dbi/ModuleDescriptor.cs index 174ec2dab..63c310d10 100644 --- a/src/AsmResolver.Symbols.Pdb/Metadata/Dbi/ModuleDescriptor.cs +++ b/src/AsmResolver.Symbols.Pdb/Metadata/Dbi/ModuleDescriptor.cs @@ -179,7 +179,7 @@ public uint GetPhysicalSize() } /// - public void Write(IBinaryStreamWriter writer) + public void Write(BinaryStreamWriter writer) { writer.WriteUInt32(0); SectionContribution.Write(writer); diff --git a/src/AsmResolver.Symbols.Pdb/Metadata/Dbi/SectionContribution.cs b/src/AsmResolver.Symbols.Pdb/Metadata/Dbi/SectionContribution.cs index 6e6febe47..7f74dc447 100644 --- a/src/AsmResolver.Symbols.Pdb/Metadata/Dbi/SectionContribution.cs +++ b/src/AsmResolver.Symbols.Pdb/Metadata/Dbi/SectionContribution.cs @@ -113,7 +113,7 @@ public static SectionContribution FromReader(ref BinaryStreamReader reader) public uint GetPhysicalSize() => EntrySize; /// - public void Write(IBinaryStreamWriter writer) + public void Write(BinaryStreamWriter writer) { writer.WriteUInt16(Section); writer.WriteUInt16(0); diff --git a/src/AsmResolver.Symbols.Pdb/Metadata/Dbi/SectionMap.cs b/src/AsmResolver.Symbols.Pdb/Metadata/Dbi/SectionMap.cs index bf43a7e56..b6f859e69 100644 --- a/src/AsmResolver.Symbols.Pdb/Metadata/Dbi/SectionMap.cs +++ b/src/AsmResolver.Symbols.Pdb/Metadata/Dbi/SectionMap.cs @@ -117,7 +117,7 @@ public static SectionMap FromReader(ref BinaryStreamReader reader) public uint GetPhysicalSize() => EntrySize; /// - public void Write(IBinaryStreamWriter writer) + public void Write(BinaryStreamWriter writer) { writer.WriteUInt16((ushort) Attributes); writer.WriteUInt16(LogicalOverlayNumber); diff --git a/src/AsmResolver.Symbols.Pdb/Metadata/Info/InfoStream.cs b/src/AsmResolver.Symbols.Pdb/Metadata/Info/InfoStream.cs index eae02174c..2c3d6819b 100644 --- a/src/AsmResolver.Symbols.Pdb/Metadata/Info/InfoStream.cs +++ b/src/AsmResolver.Symbols.Pdb/Metadata/Info/InfoStream.cs @@ -142,7 +142,7 @@ public override uint GetPhysicalSize() } /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { // Write basic info stream header. writer.WriteUInt32((uint) Version); diff --git a/src/AsmResolver.Symbols.Pdb/Metadata/Modi/ModiStream.cs b/src/AsmResolver.Symbols.Pdb/Metadata/Modi/ModiStream.cs index c4d6bde40..31e79d005 100644 --- a/src/AsmResolver.Symbols.Pdb/Metadata/Modi/ModiStream.cs +++ b/src/AsmResolver.Symbols.Pdb/Metadata/Modi/ModiStream.cs @@ -133,7 +133,7 @@ public override uint GetPhysicalSize() } /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { writer.WriteUInt32(Signature); Symbols?.Write(writer); diff --git a/src/AsmResolver.Symbols.Pdb/Metadata/PdbHashTable.cs b/src/AsmResolver.Symbols.Pdb/Metadata/PdbHashTable.cs index fb58f25be..dcef75d22 100644 --- a/src/AsmResolver.Symbols.Pdb/Metadata/PdbHashTable.cs +++ b/src/AsmResolver.Symbols.Pdb/Metadata/PdbHashTable.cs @@ -81,7 +81,7 @@ public static uint GetPdbHashTableSize( /// The type of values in the input dictionary. public static void WriteAsPdbHashTable( this IDictionary dictionary, - IBinaryStreamWriter writer, + BinaryStreamWriter writer, Func hasher, Func mapper) where TKey : notnull diff --git a/src/AsmResolver.Symbols.Pdb/Metadata/Tpi/SerializedTpiStream.cs b/src/AsmResolver.Symbols.Pdb/Metadata/Tpi/SerializedTpiStream.cs index 3a4c144c7..087d6fa61 100644 --- a/src/AsmResolver.Symbols.Pdb/Metadata/Tpi/SerializedTpiStream.cs +++ b/src/AsmResolver.Symbols.Pdb/Metadata/Tpi/SerializedTpiStream.cs @@ -87,7 +87,7 @@ public override bool TryGetLeafRecordReader(uint typeIndex, out BinaryStreamRead } /// - protected override void WriteTypeRecords(IBinaryStreamWriter writer) + protected override void WriteTypeRecords(BinaryStreamWriter writer) { _recordsReader.Fork().WriteToOutput(writer); } diff --git a/src/AsmResolver.Symbols.Pdb/Metadata/Tpi/TpiStream.cs b/src/AsmResolver.Symbols.Pdb/Metadata/Tpi/TpiStream.cs index 1f7b18927..0119f5c81 100644 --- a/src/AsmResolver.Symbols.Pdb/Metadata/Tpi/TpiStream.cs +++ b/src/AsmResolver.Symbols.Pdb/Metadata/Tpi/TpiStream.cs @@ -205,13 +205,13 @@ public BinaryStreamReader GetLeafRecordReader(uint typeIndex) public override uint GetPhysicalSize() => TpiStreamHeaderSize + TypeRecordsByteCount; /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { WriteHeader(writer); WriteTypeRecords(writer); } - private void WriteHeader(IBinaryStreamWriter writer) + private void WriteHeader(BinaryStreamWriter writer) { writer.WriteUInt32((uint) Version); writer.WriteUInt32(TpiStreamHeaderSize); @@ -234,5 +234,5 @@ private void WriteHeader(IBinaryStreamWriter writer) /// Writes all type records stored in the TPI stream to the provided output stream. /// /// The output stream. - protected abstract void WriteTypeRecords(IBinaryStreamWriter writer); + protected abstract void WriteTypeRecords(BinaryStreamWriter writer); } diff --git a/src/AsmResolver.Symbols.Pdb/Msf/Builder/FreeBlockMap.cs b/src/AsmResolver.Symbols.Pdb/Msf/Builder/FreeBlockMap.cs index dea1712e0..65743a11b 100644 --- a/src/AsmResolver.Symbols.Pdb/Msf/Builder/FreeBlockMap.cs +++ b/src/AsmResolver.Symbols.Pdb/Msf/Builder/FreeBlockMap.cs @@ -29,7 +29,7 @@ public BitArray BitField public override uint GetPhysicalSize() => (uint) (BitField.Count / 8); /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { byte[] data = new byte[BitField.Count / 8]; BitField.CopyTo(data, 0); diff --git a/src/AsmResolver.Symbols.Pdb/Msf/Builder/MsfFileBuffer.cs b/src/AsmResolver.Symbols.Pdb/Msf/Builder/MsfFileBuffer.cs index 865715037..91ea999cd 100644 --- a/src/AsmResolver.Symbols.Pdb/Msf/Builder/MsfFileBuffer.cs +++ b/src/AsmResolver.Symbols.Pdb/Msf/Builder/MsfFileBuffer.cs @@ -187,7 +187,7 @@ public MsfStream CreateStreamDirectoryMap(MsfStream streamDirectory) public override uint GetPhysicalSize() => SuperBlock.BlockCount * SuperBlock.BlockSize; /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { foreach (var block in _blocks) { diff --git a/src/AsmResolver.Symbols.Pdb/Msf/MsfFile.cs b/src/AsmResolver.Symbols.Pdb/Msf/MsfFile.cs index a58775dd5..d839e5ce6 100644 --- a/src/AsmResolver.Symbols.Pdb/Msf/MsfFile.cs +++ b/src/AsmResolver.Symbols.Pdb/Msf/MsfFile.cs @@ -126,12 +126,12 @@ public void Write(string path) /// Reconstructs and writes the MSF file to an output stream. /// /// The output stream. - public void Write(IBinaryStreamWriter writer) => Write(writer, SequentialMsfFileBuilder.Instance); + public void Write(BinaryStreamWriter writer) => Write(writer, SequentialMsfFileBuilder.Instance); /// /// Reconstructs and writes the MSF file to an output stream. /// /// The output stream. /// The builder to use for reconstructing the MSF file. - public void Write(IBinaryStreamWriter writer, IMsfFileBuilder builder) => builder.CreateFile(this).Write(writer); + public void Write(BinaryStreamWriter writer, IMsfFileBuilder builder) => builder.CreateFile(this).Write(writer); } diff --git a/src/AsmResolver.Symbols.Pdb/Msf/MsfSuperBlock.cs b/src/AsmResolver.Symbols.Pdb/Msf/MsfSuperBlock.cs index cba31d1c8..b7afc27c3 100644 --- a/src/AsmResolver.Symbols.Pdb/Msf/MsfSuperBlock.cs +++ b/src/AsmResolver.Symbols.Pdb/Msf/MsfSuperBlock.cs @@ -118,7 +118,7 @@ public static MsfSuperBlock FromReader(ref BinaryStreamReader reader) public override uint GetPhysicalSize() => (uint) BigMsfSignature.Length + sizeof(uint) * 6; /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { writer.WriteBytes(Signature); writer.WriteUInt32(BlockSize); diff --git a/src/AsmResolver.Symbols.Pdb/Records/LocalAddressGap.cs b/src/AsmResolver.Symbols.Pdb/Records/LocalAddressGap.cs index a6c159db5..b7381f4b1 100644 --- a/src/AsmResolver.Symbols.Pdb/Records/LocalAddressGap.cs +++ b/src/AsmResolver.Symbols.Pdb/Records/LocalAddressGap.cs @@ -36,7 +36,7 @@ public static LocalAddressGap FromReader(ref BinaryStreamReader reader) public uint GetPhysicalSize() => Size; /// - public void Write(IBinaryStreamWriter writer) + public void Write(BinaryStreamWriter writer) { writer.WriteUInt16(Start); writer.WriteUInt16(Length); diff --git a/src/AsmResolver.Symbols.Pdb/Records/LocalAddressRange.cs b/src/AsmResolver.Symbols.Pdb/Records/LocalAddressRange.cs index 459eb9d8b..3aa8b251c 100644 --- a/src/AsmResolver.Symbols.Pdb/Records/LocalAddressRange.cs +++ b/src/AsmResolver.Symbols.Pdb/Records/LocalAddressRange.cs @@ -38,7 +38,7 @@ public static LocalAddressRange FromReader(ref BinaryStreamReader reader) public uint GetPhysicalSize() => EntrySize; /// - public void Write(IBinaryStreamWriter writer) + public void Write(BinaryStreamWriter writer) { writer.WriteUInt32(Start); writer.WriteUInt16(SectionStart); diff --git a/src/AsmResolver/Collections/ReferenceTable.cs b/src/AsmResolver/Collections/ReferenceTable.cs index c8f87968b..c2ef78297 100644 --- a/src/AsmResolver/Collections/ReferenceTable.cs +++ b/src/AsmResolver/Collections/ReferenceTable.cs @@ -114,7 +114,7 @@ public uint GetPhysicalSize() public uint GetVirtualSize() => GetPhysicalSize(); /// - public void Write(IBinaryStreamWriter writer) + public void Write(BinaryStreamWriter writer) { for (int i = 0; i < Items.Count; i++) { diff --git a/src/AsmResolver/DataSegment.cs b/src/AsmResolver/DataSegment.cs index d6c79396e..1b4ba25cc 100644 --- a/src/AsmResolver/DataSegment.cs +++ b/src/AsmResolver/DataSegment.cs @@ -61,7 +61,7 @@ public byte[] Data public override uint GetPhysicalSize() => (uint) Data.Length; /// - public override void Write(IBinaryStreamWriter writer) + public override void Write(BinaryStreamWriter writer) { writer.WriteBytes(Data, 0, Data.Length); } diff --git a/src/AsmResolver/DataSourceSegment.cs b/src/AsmResolver/DataSourceSegment.cs index 8b237906e..060543feb 100644 --- a/src/AsmResolver/DataSourceSegment.cs +++ b/src/AsmResolver/DataSourceSegment.cs @@ -39,7 +39,7 @@ public override void UpdateOffsets(in RelocationParameters parameters) public override uint GetPhysicalSize() => _originalSize; /// - public override void Write(IBinaryStreamWriter writer) => + public override void Write(BinaryStreamWriter writer) => CreateReader(Offset, _originalSize).WriteToOutput(writer); /// diff --git a/src/AsmResolver/IO/BinaryStreamReader.cs b/src/AsmResolver/IO/BinaryStreamReader.cs index 532b54616..d167e523a 100644 --- a/src/AsmResolver/IO/BinaryStreamReader.cs +++ b/src/AsmResolver/IO/BinaryStreamReader.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel; using System.Diagnostics; using System.IO; using System.Text; @@ -489,9 +490,43 @@ public uint ReadCompressedUInt32() return (uint)(((firstByte & 0x7F) << 8) | ReadByte()); return (uint) (((firstByte & 0x3F) << 0x18) | - (ReadByte() << 0x10) | - (ReadByte() << 0x08) | - ReadByte()); + (ReadByte() << 0x10) | + (ReadByte() << 0x08) | + ReadByte()); + } + + /// + /// Reads a compressed unsigned integer from the stream. + /// + /// The signed integer that was read from the stream. + public int ReadCompressedInt32() + { + byte firstByte = ReadByte(); + uint rotated; + int mask; + + if ((firstByte & 0x80) == 0) + { + rotated = firstByte; + mask = (rotated & 1) != 0 ? -0x40 : 0; + } + else if ((firstByte & 0x40) == 0) + { + rotated = (uint) ((firstByte & 0x3F) << 8 | ReadByte()); + mask = (rotated & 1) != 0 ? -0x2000 : 0; + } + else + { + rotated = (uint) ( + (firstByte & 0x1F) << 0x18 + | ReadByte() << 0x10 + | ReadByte() << 0x08 + | ReadByte() + ); + mask = (rotated & 1) != 0 ? -0x1000_0000 : 0; + } + + return (int) (rotated >> 1) | mask; } /// @@ -508,9 +543,9 @@ public bool TryReadCompressedUInt32(out uint value) byte firstByte = ReadByte(); Offset--; - if ((firstByte & 0x80) == 0 && CanRead(sizeof(byte)) || - (firstByte & 0x40) == 0 && CanRead(sizeof(ushort)) || - CanRead(sizeof(uint))) + if ((firstByte & 0x80) == 0 && CanRead(sizeof(byte)) + || (firstByte & 0x40) == 0 && CanRead(sizeof(ushort)) + || CanRead(sizeof(uint))) { value = ReadCompressedUInt32(); return true; @@ -519,6 +554,32 @@ public bool TryReadCompressedUInt32(out uint value) return false; } + /// + /// Tries to reads a compressed signed integer from the stream. + /// + /// The signed integer that was read from the stream. + /// True if the method succeeded, false otherwise. + public bool TryReadCompressedInt32(out int value) + { + value = 0; + + if (!CanRead(sizeof(byte))) + return false; + + byte firstByte = ReadByte(); + Offset--; + + if ((firstByte & 0x80) == 0 && CanRead(sizeof(byte)) + || (firstByte & 0x40) == 0 && CanRead(sizeof(ushort)) + || CanRead(sizeof(uint))) + { + value = ReadCompressedInt32(); + return true; + } + + return true; + } + /// /// Reads a 7-bit encoded 32-bit integer from the stream. /// @@ -702,7 +763,7 @@ public void ChangeSize(uint newSize) /// Consumes and copies the remainder of the contents to the provided output stream. /// /// The output stream. - public void WriteToOutput(IBinaryStreamWriter writer) + public void WriteToOutput(BinaryStreamWriter writer) { byte[] buffer = new byte[4096]; while (RelativeOffset < Length) diff --git a/src/AsmResolver/IO/BinaryStreamWriter.cs b/src/AsmResolver/IO/BinaryStreamWriter.cs index fb8c0aa93..404bb5e83 100644 --- a/src/AsmResolver/IO/BinaryStreamWriter.cs +++ b/src/AsmResolver/IO/BinaryStreamWriter.cs @@ -1,16 +1,21 @@ using System; using System.IO; +using System.Text; namespace AsmResolver.IO { /// - /// Provides a default implementation of a binary writer that writes the data to an output stream. + /// Provides methods for writing data to an output stream. /// - public class BinaryStreamWriter : IBinaryStreamWriter -#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_1_OR_GREATER - , ISpanBinaryStreamWriter -#endif + public sealed class BinaryStreamWriter { + private const int ZeroBufferLength = 16; + private static readonly byte[] ZeroBuffer = new byte[ZeroBufferLength]; + + // Buffer to reduce individual IO ops. + // Initialize this buffer in reverse order to prevent JIT emitting range checks for every byte. + private readonly byte[] _buffer = new byte[8]; + /// /// Creates a new binary stream writer using the provided output stream. /// @@ -28,7 +33,9 @@ public Stream BaseStream get; } - /// + /// + /// Gets or sets the current position of the + /// public ulong Offset { get => (uint) BaseStream.Position; @@ -41,106 +48,155 @@ public ulong Offset } } - /// + /// + /// Gets or sets the current length of the stream. + /// public uint Length => (uint) BaseStream.Length; - /// + /// + /// Writes a buffer of data to the stream. + /// + /// The buffer to write to the stream. + /// The index to start reading from the buffer. + /// The amount of bytes of the buffer to write. public void WriteBytes(byte[] buffer, int startIndex, int count) { BaseStream.Write(buffer, startIndex, count); } #if NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_1_OR_GREATER - /// + /// + /// Writes a buffer of data to the stream. + /// + /// The buffer to write to the stream. public void WriteBytes(ReadOnlySpan buffer) { BaseStream.Write(buffer); } #endif - /// + /// + /// Writes a single byte to the stream. + /// + /// The byte to write. public void WriteByte(byte value) { BaseStream.WriteByte(value); } - /// + /// + /// Writes an unsigned 16-bit integer to the stream. + /// + /// The unsigned 16-bit integer to write. public void WriteUInt16(ushort value) { - BaseStream.WriteByte((byte) (value & 0xFF)); - BaseStream.WriteByte((byte) ((value >> 8) & 0xFF)); + _buffer[1] = (byte) ((value >> 8) & 0xFF); + _buffer[0] = (byte) (value & 0xFF); + BaseStream.Write(_buffer, 0, 2); } - /// + /// + /// Writes an unsigned 32-bit integer to the stream. + /// + /// The unsigned 32-bit integer to write. public void WriteUInt32(uint value) { - BaseStream.WriteByte((byte) (value & 0xFF)); - BaseStream.WriteByte((byte) ((value >> 8) & 0xFF)); - BaseStream.WriteByte((byte) ((value >> 16) & 0xFF)); - BaseStream.WriteByte((byte) ((value >> 24) & 0xFF)); + _buffer[3] = (byte) ((value >> 24) & 0xFF); + _buffer[2] = (byte) ((value >> 16) & 0xFF); + _buffer[1] = (byte) ((value >> 8) & 0xFF); + _buffer[0] = (byte) (value & 0xFF); + BaseStream.Write(_buffer, 0, 4); } - /// + /// + /// Writes an unsigned 64-bit integer to the stream. + /// + /// The unsigned 64-bit integer to write. public void WriteUInt64(ulong value) { - BaseStream.WriteByte((byte) (value & 0xFF)); - BaseStream.WriteByte((byte) ((value >> 8) & 0xFF)); - BaseStream.WriteByte((byte) ((value >> 16) & 0xFF)); - BaseStream.WriteByte((byte) ((value >> 24) & 0xFF)); - BaseStream.WriteByte((byte) ((value >> 32) & 0xFF)); - BaseStream.WriteByte((byte) ((value >> 40) & 0xFF)); - BaseStream.WriteByte((byte) ((value >> 48) & 0xFF)); - BaseStream.WriteByte((byte) ((value >> 56) & 0xFF)); + _buffer[7] = (byte) ((value >> 56) & 0xFF); + _buffer[6] = (byte) ((value >> 48) & 0xFF); + _buffer[5] = (byte) ((value >> 40) & 0xFF); + _buffer[4] = (byte) ((value >> 32) & 0xFF); + _buffer[3] = (byte) ((value >> 24) & 0xFF); + _buffer[2] = (byte) ((value >> 16) & 0xFF); + _buffer[1] = (byte) ((value >> 8) & 0xFF); + _buffer[0] = (byte) (value & 0xFF); + BaseStream.Write(_buffer, 0, 8); } - /// + /// + /// Writes an signed byte to the stream. + /// + /// The signed byte to write. public void WriteSByte(sbyte value) { BaseStream.WriteByte(unchecked((byte) value)); } - /// + /// + /// Writes a signed 16-bit integer to the stream. + /// + /// The signed 16-bit integer to write. public void WriteInt16(short value) { - BaseStream.WriteByte((byte) (value & 0xFF)); - BaseStream.WriteByte((byte) ((value >> 8) & 0xFF)); + _buffer[1] = (byte) ((value >> 8) & 0xFF); + _buffer[0] = (byte) (value & 0xFF); + BaseStream.Write(_buffer, 0, 2); } - /// + /// + /// Writes a signed 32-bit integer to the stream. + /// + /// The signed 32-bit integer to write. public void WriteInt32(int value) { - BaseStream.WriteByte((byte) (value & 0xFF)); - BaseStream.WriteByte((byte) ((value >> 8) & 0xFF)); - BaseStream.WriteByte((byte) ((value >> 16) & 0xFF)); - BaseStream.WriteByte((byte) ((value >> 24) & 0xFF)); + _buffer[3] = (byte) ((value >> 24) & 0xFF); + _buffer[2] = (byte) ((value >> 16) & 0xFF); + _buffer[1] = (byte) ((value >> 8) & 0xFF); + _buffer[0] = (byte) (value & 0xFF); + BaseStream.Write(_buffer, 0, 4); } - /// + /// + /// Writes a signed 64-bit integer to the stream. + /// + /// The signed 64-bit integer to write. public void WriteInt64(long value) { - BaseStream.WriteByte((byte) (value & 0xFF)); - BaseStream.WriteByte((byte) ((value >> 8) & 0xFF)); - BaseStream.WriteByte((byte) ((value >> 16) & 0xFF)); - BaseStream.WriteByte((byte) ((value >> 24) & 0xFF)); - BaseStream.WriteByte((byte) ((value >> 32) & 0xFF)); - BaseStream.WriteByte((byte) ((value >> 40) & 0xFF)); - BaseStream.WriteByte((byte) ((value >> 48) & 0xFF)); - BaseStream.WriteByte((byte) ((value >> 56) & 0xFF)); + _buffer[7] = (byte) ((value >> 56) & 0xFF); + _buffer[6] = (byte) ((value >> 48) & 0xFF); + _buffer[5] = (byte) ((value >> 40) & 0xFF); + _buffer[4] = (byte) ((value >> 32) & 0xFF); + _buffer[3] = (byte) ((value >> 24) & 0xFF); + _buffer[2] = (byte) ((value >> 16) & 0xFF); + _buffer[1] = (byte) ((value >> 8) & 0xFF); + _buffer[0] = (byte) (value & 0xFF); + BaseStream.Write(_buffer, 0, 8); } - /// + /// + /// Writes a 32-bit floating point number to the stream. + /// + /// The 32-bit floating point number to write. public unsafe void WriteSingle(float value) { WriteUInt32(*(uint*) &value); } - /// + /// + /// Writes a 64-bit floating point number to the stream. + /// + /// The 64-bit floating point number to write. public unsafe void WriteDouble(double value) { WriteUInt64(*(ulong*) &value); } - /// + /// + /// Writes a 128-bit decimal value to the stream. + /// + /// The 128-bit decimal value to write. public void WriteDecimal(decimal value) { int[] bits = decimal.GetBits(value); @@ -149,5 +205,218 @@ public void WriteDecimal(decimal value) WriteInt32(bits[2]); WriteInt32(bits[3]); } + + /// + /// Writes either a 32-bit or a 64-bit number to the output stream. + /// + /// The value to write. + /// Indicates the integer to be written is 32-bit or 64-bit. + /// The read number, zero extended if necessary. + public void WriteNativeInt(ulong value, bool is32Bit) + { + if (is32Bit) + WriteUInt32((uint) value); + else + WriteUInt64(value); + } + + /// + /// Writes a buffer of data to the stream. + /// + /// The data to write. + public void WriteBytes(byte[] buffer) + { + WriteBytes(buffer, 0, buffer.Length); + } + + /// + /// Writes a specified number of zero bytes to the stream. + /// + /// The number of zeroes to write. + public void WriteZeroes(int count) + { + while (count >= ZeroBufferLength) + { + BaseStream.Write(ZeroBuffer, 0, ZeroBufferLength); + count -= ZeroBufferLength; + } + + if (count > 0) + BaseStream.Write(ZeroBuffer, 0, Math.Min(count, ZeroBufferLength)); + } + + /// + /// Writes an ASCII string to the stream. + /// + /// The string to write. + public void WriteAsciiString(string value) + { + WriteBytes(Encoding.ASCII.GetBytes(value)); + } + + /// + /// Aligns the writer to a specified boundary. + /// + /// The boundary to use. + public void Align(uint align) => AlignRelative(align, 0); + + /// + /// Aligns the writer to a specified boundary, relative to the provided start offset.. + /// + /// The boundary to use. + /// The starting offset to consider the alignment boundaries from. + public void AlignRelative(uint align, ulong startOffset) + { + ulong currentPosition = Offset - startOffset; + WriteZeroes((int) (currentPosition.Align(align) - currentPosition)); + } + + /// + /// Writes a single index to the output stream. + /// + /// The index to write. + /// + /// + public void WriteIndex(uint value, IndexSize size) + { + switch (size) + { + case IndexSize.Short: + WriteUInt16((ushort) value); + break; + case IndexSize.Long: + WriteUInt32(value); + break; + default: + throw new ArgumentOutOfRangeException(nameof(size), size, null); + } + } + + /// + /// Compresses and writes an unsigned integer to the stream. + /// + /// The value to write. + public void WriteCompressedUInt32(uint value) + { + if (value < 0x80) + { + WriteByte((byte) value); + } + else if (value < 0x4000) + { + _buffer[1] = (byte) value; + _buffer[0] = (byte) (0x80 | value >> 8); + BaseStream.Write(_buffer, 0, 2); + } + else + { + _buffer[3] = (byte) value; + _buffer[2] = (byte) (value >> 0x08); + _buffer[1] = (byte) (value >> 0x10); + _buffer[0] = (byte) (0x80 | 0x40 | value >> 0x18); + BaseStream.Write(_buffer, 0, 4); + } + } + + /// + /// Compresses and writes a signed integer to the stream. + /// + /// The value to write. + public void WriteCompressedInt32(int value) + { + uint sign = (uint) value >> 31; + if (value is >= -0x40 and < 0x40) + { + uint rotated = ((uint) (value & 0x3F) << 1) | sign; + WriteByte((byte) rotated); + } + else if (value is >= -0x2000 and < 0x2000) + { + uint rotated = ((uint) (value & 0x1FFF) << 1) | sign; + _buffer[1] = (byte) rotated; + _buffer[0] = (byte) (0x80 | rotated >> 8); + BaseStream.Write(_buffer, 0, 2); + } + else + { + uint rotated = ((uint) (value & 0x0FFF_FFFF) << 1) | sign; + _buffer[3] = (byte) rotated; + _buffer[2] = (byte) (rotated >> 0x08); + _buffer[1] = (byte) (rotated >> 0x10); + _buffer[0] = (byte)(0x80 | 0x40 | rotated >> 0x18); + BaseStream.Write(_buffer, 0, 4); + } + } + + /// + /// Writes a single 7-bit encoded 32-bit integer to the output stream. + /// + /// The value to write. + public void Write7BitEncodedInt32(int value) + { + uint x = unchecked((uint) value); + do + { + byte b = (byte) (x & 0x7F); + + if (x > 0x7F) + b |= 0x80; + + WriteByte(b); + x >>= 7; + } while (x != 0); + } + + /// + /// Writes an UTF8 string to the stream. + /// + /// The string to write. + public void WriteSerString(string? value) + { + if (value is null) + { + WriteByte(0xFF); + return; + } + + byte[] bytes = Encoding.UTF8.GetBytes(value); + WriteCompressedUInt32((uint)bytes.Length); + WriteBytes(bytes); + } + + /// + /// Writes a serialized string using the UTF-8 encoding that is prefixed by a 7-bit encoded length header. + /// + /// The string to write. + public void WriteBinaryFormatterString(string value) => WriteBinaryFormatterString(value, Encoding.UTF8); + + /// + /// Writes a serialized string that is prefixed by a 7-bit encoded length header. + /// + /// The string to write. + /// The encoding to use. + public void WriteBinaryFormatterString(string value, Encoding encoding) + { + byte[] data = encoding.GetBytes(value); + Write7BitEncodedInt32(data.Length); + WriteBytes(data); + } + + /// + /// Writes an UTF8 string to the stream. + /// + /// The string to write. + public void WriteSerString(Utf8String? value) + { + if (value is null) + { + WriteByte(0xFF); + return; + } + + byte[] bytes = value.GetBytesUnsafe(); + WriteCompressedUInt32((uint)bytes.Length); + WriteBytes(bytes); + } } } diff --git a/src/AsmResolver/IO/IBinaryStreamWriter.cs b/src/AsmResolver/IO/IBinaryStreamWriter.cs deleted file mode 100644 index c5ac930c1..000000000 --- a/src/AsmResolver/IO/IBinaryStreamWriter.cs +++ /dev/null @@ -1,342 +0,0 @@ -using System; -using System.Text; -#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP1_0_OR_GREATER -using System.Buffers; -#endif - -namespace AsmResolver.IO -{ - /// - /// Provides methods for writing data to a binary stream. - /// - public interface IBinaryStreamWriter - { - /// - /// Gets or sets the current position of the writer. - /// - ulong Offset - { - get; - set; - } - - /// - /// Gets or sets the current length of the stream. - /// - uint Length - { - get; - } - - /// - /// Writes a buffer of data to the stream. - /// - /// The buffer to write to the stream. - /// The index to start reading from the buffer. - /// The amount of bytes of the buffer to write. - void WriteBytes(byte[] buffer, int startIndex, int count); - - /// - /// Writes a single byte to the stream. - /// - /// The byte to write. - void WriteByte(byte value); - - /// - /// Writes an unsigned 16-bit integer to the stream. - /// - /// The unsigned 16-bit integer to write. - void WriteUInt16(ushort value); - - /// - /// Writes an unsigned 32-bit integer to the stream. - /// - /// The unsigned 32-bit integer to write. - void WriteUInt32(uint value); - - /// - /// Writes an unsigned 64-bit integer to the stream. - /// - /// The unsigned 64-bit integer to write. - void WriteUInt64(ulong value); - - /// - /// Writes an signed byte to the stream. - /// - /// The signed byte to write. - void WriteSByte(sbyte value); - - /// - /// Writes a signed 16-bit integer to the stream. - /// - /// The signed 16-bit integer to write. - void WriteInt16(short value); - - /// - /// Writes a signed 32-bit integer to the stream. - /// - /// The signed 32-bit integer to write. - void WriteInt32(int value); - - /// - /// Writes a signed 64-bit integer to the stream. - /// - /// The signed 64-bit integer to write. - void WriteInt64(long value); - - /// - /// Writes a 32-bit floating point number to the stream. - /// - /// The 32-bit floating point number to write. - void WriteSingle(float value); - - /// - /// Writes a 64-bit floating point number to the stream. - /// - /// The 64-bit floating point number to write. - void WriteDouble(double value); - - /// - /// Writes a 128-bit decimal value to the stream. - /// - /// The 128-bit decimal value to write. - void WriteDecimal(decimal value); - } - - /// - /// Provides extension methods to various I/O interfaces in AsmResolver. - /// - public static partial class IOExtensions - { - /// - /// Writes either a 32-bit or a 64-bit number to the output stream. - /// - /// The writer to use. - /// The value to write. - /// Indicates the integer to be written is 32-bit or 64-bit. - /// The read number, zero extended if necessary. - public static void WriteNativeInt(this IBinaryStreamWriter writer, ulong value, bool is32Bit) - { - if (is32Bit) - writer.WriteUInt32((uint) value); - else - writer.WriteUInt64(value); - } - - /// - /// Writes a buffer of data to the stream. - /// - /// The writer to use. - /// The data to write. - public static void WriteBytes(this IBinaryStreamWriter writer, byte[] buffer) - { - writer.WriteBytes(buffer, 0, buffer.Length); - } - -#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_1_OR_GREATER - /// - /// Writes a buffer of data to the stream. - /// - /// The writer to use. - /// The data to write. - public static void WriteBytes(this IBinaryStreamWriter writer, ReadOnlySpan buffer) - { - if (writer is ISpanBinaryStreamWriter spanWriter) - { - spanWriter.WriteBytes(buffer); - return; - } - - byte[] array = ArrayPool.Shared.Rent(buffer.Length); - buffer.CopyTo(array); - writer.WriteBytes(array, 0, buffer.Length); - ArrayPool.Shared.Return(array); - } -#endif - - /// - /// Writes a specified amount of zero bytes to the stream. - /// - /// The writer to use. - /// The amount of zeroes to write. - public static void WriteZeroes(this IBinaryStreamWriter writer, int count) - { - while (count >= sizeof(ulong)) - { - writer.WriteUInt64(0); - count -= sizeof(ulong); - } - - while (count >= sizeof(uint)) - { - writer.WriteUInt32(0); - count -= sizeof(uint); - } - - while (count >= sizeof(ushort)) - { - writer.WriteUInt16(0); - count -= sizeof(ushort); - } - - while (count >= sizeof(byte)) - { - writer.WriteByte(0); - count -= sizeof(byte); - } - } - - /// - /// Writes an ASCII string to the stream. - /// - /// The writer to use. - /// The string to write. - public static void WriteAsciiString(this IBinaryStreamWriter writer, string value) - { - writer.WriteBytes(Encoding.ASCII.GetBytes(value)); - } - - /// - /// Aligns the writer to a specified boundary. - /// - /// The writer to align. - /// The boundary to use. - public static void Align(this IBinaryStreamWriter writer, uint align) => writer.AlignRelative(align, 0); - - /// - /// Aligns the writer to a specified boundary, relative to the provided start offset.. - /// - /// The writer to align. - /// The boundary to use. - /// The starting offset to consider the alignment boundaries from. - public static void AlignRelative(this IBinaryStreamWriter writer, uint align, ulong startOffset) - { - ulong currentPosition = writer.Offset - startOffset; - writer.WriteZeroes((int) (currentPosition.Align(align) - currentPosition)); - } - - /// - /// Writes a single index to the output stream. - /// - /// The writer to use. - /// The index to write. - /// - /// - public static void WriteIndex(this IBinaryStreamWriter writer, uint value, IndexSize size) - { - switch (size) - { - case IndexSize.Short: - writer.WriteUInt16((ushort) value); - break; - case IndexSize.Long: - writer.WriteUInt32(value); - break; - default: - throw new ArgumentOutOfRangeException(nameof(size), size, null); - } - } - - /// - /// Compresses and writes an unsigned integer to the stream. - /// - /// - /// - public static void WriteCompressedUInt32(this IBinaryStreamWriter writer, uint value) - { - if (value < 0x80) - { - writer.WriteByte((byte) value); - } - else if (value < 0x4000) - { - writer.WriteByte((byte)(0x80 | value >> 8)); - writer.WriteByte((byte)(value & 0xFF)); - } - else - { - writer.WriteByte((byte)(0x80 | 0x40 | value >> 0x18)); - writer.WriteByte((byte)(value >> 0x10 & 0xFF)); - writer.WriteByte((byte)(value >> 0x08 & 0xFF)); - writer.WriteByte((byte)(value & 0xFF)); - } - } - - /// - /// Writes a single 7-bit encoded 32-bit integer to the output stream. - /// - /// The output stream. - /// The value to write. - public static void Write7BitEncodedInt32(this IBinaryStreamWriter writer, int value) - { - uint x = unchecked((uint) value); - do - { - byte b = (byte) (x & 0x7F); - - if (x > 0x7F) - b |= 0x80; - - writer.WriteByte(b); - x >>= 7; - } while (x != 0); - } - - /// - /// Writes an UTF8 string to the stream. - /// - /// The writer to use. - /// The string to write. - public static void WriteSerString(this IBinaryStreamWriter writer, string? value) - { - if (value is null) - { - writer.WriteByte(0xFF); - return; - } - - byte[] bytes = Encoding.UTF8.GetBytes(value); - writer.WriteCompressedUInt32((uint)bytes.Length); - writer.WriteBytes(bytes); - } - - /// - /// Writes a serialized string using the UTF-8 encoding that is prefixed by a 7-bit encoded length header. - /// - /// The output stream. - /// The string to write. - public static void WriteBinaryFormatterString(this IBinaryStreamWriter writer, string value) => - WriteBinaryFormatterString(writer, value, Encoding.UTF8); - - /// - /// Writes a serialized string that is prefixed by a 7-bit encoded length header. - /// - /// The output stream. - /// The string to write. - /// The encoding to use. - public static void WriteBinaryFormatterString(this IBinaryStreamWriter writer, string value, Encoding encoding) - { - byte[] data = encoding.GetBytes(value); - writer.Write7BitEncodedInt32(data.Length); - writer.WriteBytes(data); - } - - /// - /// Writes an UTF8 string to the stream. - /// - /// The writer to use. - /// The string to write. - public static void WriteSerString(this IBinaryStreamWriter writer, Utf8String? value) - { - if (value is null) - { - writer.WriteByte(0xFF); - return; - } - - byte[] bytes = value.GetBytesUnsafe(); - writer.WriteCompressedUInt32((uint)bytes.Length); - writer.WriteBytes(bytes); - } - } -} diff --git a/src/AsmResolver/IO/ISpanBinaryStreamWriter.cs b/src/AsmResolver/IO/ISpanBinaryStreamWriter.cs deleted file mode 100644 index 493404953..000000000 --- a/src/AsmResolver/IO/ISpanBinaryStreamWriter.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; - -namespace AsmResolver.IO -{ -#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_1_OR_GREATER - /// - /// Provides span-based methods for writing data to a binary stream. - /// - public interface ISpanBinaryStreamWriter : IBinaryStreamWriter - { - /// - /// Writes a buffer of data to the stream. - /// - /// The buffer to write to the stream. - void WriteBytes(ReadOnlySpan buffer); - } -#endif -} diff --git a/src/AsmResolver/IO/MemoryStreamWriterPool.cs b/src/AsmResolver/IO/MemoryStreamWriterPool.cs index 14a3ef691..46d0f7e78 100644 --- a/src/AsmResolver/IO/MemoryStreamWriterPool.cs +++ b/src/AsmResolver/IO/MemoryStreamWriterPool.cs @@ -5,7 +5,7 @@ namespace AsmResolver.IO { /// - /// Provides a pool of reusable instances of that are meant to be used for + /// Provides a pool of reusable instances of that are meant to be used for /// constructing byte arrays. /// /// @@ -31,7 +31,7 @@ public RentedWriter Rent() private void Return(BinaryStreamWriter writer) => _writers.Enqueue(writer); /// - /// Represents a single instance of a that is rented by a writer pool. + /// Represents a single instance of a that is rented by a writer pool. /// public ref struct RentedWriter { diff --git a/src/AsmResolver/IWritable.cs b/src/AsmResolver/IWritable.cs index 9b5b5e804..6e7743385 100644 --- a/src/AsmResolver/IWritable.cs +++ b/src/AsmResolver/IWritable.cs @@ -17,6 +17,6 @@ public interface IWritable /// Serializes the structure to an output stream. /// /// The output stream to write the data to. - void Write(IBinaryStreamWriter writer); + void Write(BinaryStreamWriter writer); } } diff --git a/src/AsmResolver/Patching/PatchContext.cs b/src/AsmResolver/Patching/PatchContext.cs index 3d8949e71..6e224e8d8 100644 --- a/src/AsmResolver/Patching/PatchContext.cs +++ b/src/AsmResolver/Patching/PatchContext.cs @@ -13,7 +13,7 @@ public readonly struct PatchContext /// The segment to be patched. /// The image base to assume while patching. /// The object responsible for writing the patches. - public PatchContext(ISegment segment, ulong imageBase, IBinaryStreamWriter writer) + public PatchContext(ISegment segment, ulong imageBase, BinaryStreamWriter writer) { Segment = segment; ImageBase = imageBase; @@ -39,7 +39,7 @@ public ulong ImageBase /// /// Gets the object responsible for writing the patches. /// - public IBinaryStreamWriter Writer + public BinaryStreamWriter Writer { get; } diff --git a/src/AsmResolver/Patching/PatchedSegment.cs b/src/AsmResolver/Patching/PatchedSegment.cs index 3e985fb54..049defdd2 100644 --- a/src/AsmResolver/Patching/PatchedSegment.cs +++ b/src/AsmResolver/Patching/PatchedSegment.cs @@ -70,13 +70,13 @@ public BinaryStreamReader CreateReader(ulong fileOffset, uint size) => Contents : throw new InvalidOperationException("Segment is not readable."); /// - public void Write(IBinaryStreamWriter writer) + public void Write(BinaryStreamWriter writer) { Contents.Write(writer); ApplyPatches(writer); } - private void ApplyPatches(IBinaryStreamWriter writer) + private void ApplyPatches(BinaryStreamWriter writer) { ulong offset = writer.Offset; diff --git a/src/AsmResolver/SegmentBase.cs b/src/AsmResolver/SegmentBase.cs index 264e1925a..abfb3db23 100644 --- a/src/AsmResolver/SegmentBase.cs +++ b/src/AsmResolver/SegmentBase.cs @@ -38,6 +38,6 @@ public virtual void UpdateOffsets(in RelocationParameters parameters) public uint GetVirtualSize() => GetPhysicalSize(); /// - public abstract void Write(IBinaryStreamWriter writer); + public abstract void Write(BinaryStreamWriter writer); } } diff --git a/src/AsmResolver/SegmentBuilder.cs b/src/AsmResolver/SegmentBuilder.cs index 5d51e23e8..5390893ab 100644 --- a/src/AsmResolver/SegmentBuilder.cs +++ b/src/AsmResolver/SegmentBuilder.cs @@ -88,7 +88,7 @@ public void UpdateOffsets(in RelocationParameters parameters) public uint GetVirtualSize() => _virtualSize; /// - public void Write(IBinaryStreamWriter writer) + public void Write(BinaryStreamWriter writer) { for (int i = 0; i < _items.Count; i++) { diff --git a/src/AsmResolver/VirtualSegment.cs b/src/AsmResolver/VirtualSegment.cs index dd2b08022..bf0e802f1 100644 --- a/src/AsmResolver/VirtualSegment.cs +++ b/src/AsmResolver/VirtualSegment.cs @@ -77,6 +77,6 @@ public BinaryStreamReader CreateReader(ulong fileOffset, uint size) } /// - public void Write(IBinaryStreamWriter writer) => PhysicalContents?.Write(writer); + public void Write(BinaryStreamWriter writer) => PhysicalContents?.Write(writer); } } diff --git a/src/AsmResolver/ZeroesSegment.cs b/src/AsmResolver/ZeroesSegment.cs index 8a3da32c1..e81af42de 100644 --- a/src/AsmResolver/ZeroesSegment.cs +++ b/src/AsmResolver/ZeroesSegment.cs @@ -32,7 +32,7 @@ public uint Size public override uint GetPhysicalSize() => Size; /// - public override void Write(IBinaryStreamWriter writer) => writer.WriteZeroes((int) Size); + public override void Write(BinaryStreamWriter writer) => writer.WriteZeroes((int) Size); /// public BinaryStreamReader CreateReader(ulong fileOffset, uint size) diff --git a/test/AsmResolver.PE.Tests/DotNet/ReadyToRun/NativeArrayTest.cs b/test/AsmResolver.PE.Tests/DotNet/ReadyToRun/NativeArrayTest.cs index e467b1fee..64f5e4ed2 100644 --- a/test/AsmResolver.PE.Tests/DotNet/ReadyToRun/NativeArrayTest.cs +++ b/test/AsmResolver.PE.Tests/DotNet/ReadyToRun/NativeArrayTest.cs @@ -15,7 +15,7 @@ public class NativeArrayTest public IntValue(int value) => Value = value; public uint GetPhysicalSize() => sizeof(uint); - public void Write(IBinaryStreamWriter writer) => writer.WriteInt32(Value); + public void Write(BinaryStreamWriter writer) => writer.WriteInt32(Value); public static implicit operator IntValue(int value) => new(value); public static implicit operator int(IntValue value) => value.Value; } diff --git a/test/AsmResolver.Tests/IO/BinaryStreamReaderTest.cs b/test/AsmResolver.Tests/IO/BinaryStreamReaderTest.cs index 2c4c201c4..5f3479898 100644 --- a/test/AsmResolver.Tests/IO/BinaryStreamReaderTest.cs +++ b/test/AsmResolver.Tests/IO/BinaryStreamReaderTest.cs @@ -80,6 +80,36 @@ public void ReadInt64() Assert.Equal(16u, reader.Offset); } + [Theory] + [InlineData(new byte[] {0x03}, 3)] + [InlineData(new byte[] {0x7f}, 0x7f)] + [InlineData(new byte[] {0x80, 0x80}, 0x80)] + [InlineData(new byte[] {0xAE, 0x57}, 0x2E57)] + [InlineData(new byte[] {0xBF, 0xFF}, 0x3FFF)] + [InlineData(new byte[] {0xC0, 0x00, 0x40, 0x00}, 0x4000)] + [InlineData(new byte[] {0xDF, 0x12, 0x34, 0x56}, 0x1F123456)] + [InlineData(new byte[] {0xDF, 0xFF, 0xFF, 0xFF}, 0x1FFFFFFF)] + public void ReadCompressedUInt32(byte[] data, uint expected) + { + var reader = new BinaryStreamReader(data); + Assert.Equal(expected, reader.ReadCompressedUInt32()); + } + + [Theory] + [InlineData(new byte[] {0x06}, 3)] + [InlineData(new byte[] {0x7B}, -3)] + [InlineData(new byte[] {0x80, 0x80}, 64)] + [InlineData(new byte[] {0x01}, -64)] + [InlineData(new byte[] {0xC0, 0x00, 0x40, 0x00}, 8192)] + [InlineData(new byte[] {0x80, 0x01}, -8192)] + [InlineData(new byte[] {0xDF, 0xFF, 0xFF, 0xFE}, 0xFFFFFFF)] + [InlineData(new byte[] {0xC0, 0x00, 0x00, 0x01}, -0x10000000)] + public void ReadCompressedInt32(byte[] data, int value) + { + var reader = new BinaryStreamReader(data); + Assert.Equal(value, reader.ReadCompressedInt32()); + } + [Theory] [InlineData("")] [InlineData("Hello, world!")] diff --git a/test/AsmResolver.Tests/IO/BinaryStreamWriterTest.cs b/test/AsmResolver.Tests/IO/BinaryStreamWriterTest.cs index 2c646ed23..0149c63c9 100644 --- a/test/AsmResolver.Tests/IO/BinaryStreamWriterTest.cs +++ b/test/AsmResolver.Tests/IO/BinaryStreamWriterTest.cs @@ -71,6 +71,65 @@ public void WriteInt64() }, stream.ToArray()); } + [Theory] + [InlineData(0)] + [InlineData(1)] + [InlineData(2)] + [InlineData(3)] + [InlineData(4)] + [InlineData(5)] + [InlineData(8)] + [InlineData(16)] + [InlineData(45)] + [InlineData(100)] + public void WriteZeroes(int count) + { + using var stream = new MemoryStream(); + var writer = new BinaryStreamWriter(stream); + + writer.WriteZeroes(count); + + Assert.Equal(new byte[count], stream.ToArray()); + } + + [Theory] + [InlineData(new byte[] {0x03}, 3)] + [InlineData(new byte[] {0x7f}, 0x7f)] + [InlineData(new byte[] {0x80, 0x80}, 0x80)] + [InlineData(new byte[] {0xAE, 0x57}, 0x2E57)] + [InlineData(new byte[] {0xBF, 0xFF}, 0x3FFF)] + [InlineData(new byte[] {0xC0, 0x00, 0x40, 0x00}, 0x4000)] + [InlineData(new byte[] {0xDF, 0x12, 0x34, 0x56}, 0x1F123456)] + [InlineData(new byte[] {0xDF, 0xFF, 0xFF, 0xFF}, 0x1FFFFFFF)] + public void WriteCompressedUInt32(byte[] expected, uint value) + { + using var stream = new MemoryStream(); + var writer = new BinaryStreamWriter(stream); + + writer.WriteCompressedUInt32(value); + + Assert.Equal(expected, stream.ToArray()); + } + + [Theory] + [InlineData(new byte[] {0x06}, 3)] + [InlineData(new byte[] {0x7B}, -3)] + [InlineData(new byte[] {0x80, 0x80}, 64)] + [InlineData(new byte[] {0x01}, -64)] + [InlineData(new byte[] {0xC0, 0x00, 0x40, 0x00}, 8192)] + [InlineData(new byte[] {0x80, 0x01}, -8192)] + [InlineData(new byte[] {0xDF, 0xFF, 0xFF, 0xFE}, 0xFFFFFFF)] + [InlineData(new byte[] {0xC0, 0x00, 0x00, 0x01}, -0x10000000)] + public void WriteCompressedInt32(byte[] expected, int value) + { + using var stream = new MemoryStream(); + var writer = new BinaryStreamWriter(stream); + + writer.WriteCompressedInt32(value); + + Assert.Equal(expected, stream.ToArray()); + } + [Theory] [InlineData(0)] [InlineData(1)]