Skip to content

Commit 0b7101a

Browse files
committed
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 <ayane@vignetteapp.org>
1 parent 70eb270 commit 0b7101a

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) Cosyne
2+
// Licensed under GPL 3.0 with SDK Exception. See LICENSE for details.
3+
4+
using craftersmine.Asar.Net;
5+
using System;
6+
using System.IO;
7+
8+
namespace Vignette.Content;
9+
internal class AsarLoader : IContentLoader<AsarArchive>
10+
{
11+
// while the library is capable of verifying if its a valid archive, we would like to do
12+
// it in the content loader level too so we can catch masquerading malicious files as we
13+
// load them.
14+
// The first 4 bytes of an asar archive is 04 00 00 00.
15+
private static readonly byte[] signature = new byte[] { 0x04, 0x00, 0x00, 0x00 };
16+
17+
public AsarArchive Load(ReadOnlySpan<byte> bytes)
18+
{
19+
if (!MemoryExtensions.SequenceEqual(bytes[0..4], signature))
20+
throw new ArgumentException("Failed to find sequence \"04 00 00 00\" in byte sequence.", nameof(bytes));
21+
22+
// read the bytes into a stream
23+
var stream = new MemoryStream(bytes.ToArray());
24+
return new AsarArchive(stream);
25+
}
26+
}

source/Vignette/Vignette.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<ItemGroup>
99
<PackageReference Include="Sekai" Version="0.1.0-alpha.9" />
1010
<PackageReference Include="StbiSharp" Version="1.2.1" />
11+
<PackageReference Include="craftersmine.Asar.Net" Version="1.0.4" />
1112
</ItemGroup>
1213

1314
</Project>

0 commit comments

Comments
 (0)