-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
2 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters