Skip to content

Commit

Permalink
Add Asar ContentLoader
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
sr229 committed Jul 20, 2023
1 parent 70eb270 commit 0b7101a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions source/Vignette/Content/AsarLoader.cs
Original file line number Diff line number Diff line change
@@ -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<AsarArchive>
{
// 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<byte> 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);
}
}
1 change: 1 addition & 0 deletions source/Vignette/Vignette.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<ItemGroup>
<PackageReference Include="Sekai" Version="0.1.0-alpha.9" />
<PackageReference Include="StbiSharp" Version="1.2.1" />
<PackageReference Include="craftersmine.Asar.Net" Version="1.0.4" />
</ItemGroup>

</Project>

0 comments on commit 0b7101a

Please sign in to comment.