From 0b7101aac58f6a51f05856e9dd2359e7bb8df72b Mon Sep 17 00:00:00 2001 From: Ayane Date: Thu, 20 Jul 2023 12:42:17 +0800 Subject: [PATCH 1/2] Add Asar ContentLoader Right now all it does it load and verifies in the content level if our Asar Archive is valid supported by the craftersmine.Asar.Net library, but in the future we might use the content-level verification for hash checking too Signed-off-by: Ayane --- source/Vignette/Content/AsarLoader.cs | 26 ++++++++++++++++++++++++++ source/Vignette/Vignette.csproj | 1 + 2 files changed, 27 insertions(+) create mode 100644 source/Vignette/Content/AsarLoader.cs diff --git a/source/Vignette/Content/AsarLoader.cs b/source/Vignette/Content/AsarLoader.cs new file mode 100644 index 0000000..66c0998 --- /dev/null +++ b/source/Vignette/Content/AsarLoader.cs @@ -0,0 +1,26 @@ +// Copyright (c) Cosyne +// Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. + +using craftersmine.Asar.Net; +using System; +using System.IO; + +namespace Vignette.Content; +internal class AsarLoader : IContentLoader +{ + // while the library is capable of verifying if its a valid archive, we would like to do + // it in the content loader level too so we can catch masquerading malicious files as we + // load them. + // The first 4 bytes of an asar archive is 04 00 00 00. + private static readonly byte[] signature = new byte[] { 0x04, 0x00, 0x00, 0x00 }; + + public AsarArchive Load(ReadOnlySpan bytes) + { + if (!MemoryExtensions.SequenceEqual(bytes[0..4], signature)) + throw new ArgumentException("Failed to find sequence \"04 00 00 00\" in byte sequence.", nameof(bytes)); + + // read the bytes into a stream + var stream = new MemoryStream(bytes.ToArray()); + return new AsarArchive(stream); + } +} diff --git a/source/Vignette/Vignette.csproj b/source/Vignette/Vignette.csproj index 0bd80f1..acb8829 100644 --- a/source/Vignette/Vignette.csproj +++ b/source/Vignette/Vignette.csproj @@ -8,6 +8,7 @@ + From 94ca5504db912d511881e18c7edf76bed29c200c Mon Sep 17 00:00:00 2001 From: Ayase Minori Date: Thu, 20 Jul 2023 07:41:53 +0000 Subject: [PATCH 2/2] Indent Signed-off-by: GitHub --- source/Vignette/Audio/AudioManager.cs | 2 +- source/Vignette/Content/AsarLoader.cs | 4 ++-- source/Vignette/Graphics/IProjector.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/Vignette/Audio/AudioManager.cs b/source/Vignette/Audio/AudioManager.cs index e461756..47ab475 100644 --- a/source/Vignette/Audio/AudioManager.cs +++ b/source/Vignette/Audio/AudioManager.cs @@ -166,7 +166,7 @@ public void Dispose() source.Stop(); - while(source.TryDequeue(out var buffer)) + while (source.TryDequeue(out var buffer)) { bufferPool.Return(buffer); } diff --git a/source/Vignette/Content/AsarLoader.cs b/source/Vignette/Content/AsarLoader.cs index 66c0998..08cc7ee 100644 --- a/source/Vignette/Content/AsarLoader.cs +++ b/source/Vignette/Content/AsarLoader.cs @@ -1,9 +1,9 @@ -// Copyright (c) Cosyne +// Copyright (c) Cosyne // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. -using craftersmine.Asar.Net; using System; using System.IO; +using craftersmine.Asar.Net; namespace Vignette.Content; internal class AsarLoader : IContentLoader diff --git a/source/Vignette/Graphics/IProjector.cs b/source/Vignette/Graphics/IProjector.cs index 17601b1..2590b55 100644 --- a/source/Vignette/Graphics/IProjector.cs +++ b/source/Vignette/Graphics/IProjector.cs @@ -19,7 +19,7 @@ public interface IProjector /// /// The projector's rotation. /// - Vector3 Rotation { get; } + Vector3 Rotation { get; } /// /// The projector's view matrix.