mirror of
https://github.com/crskycode/GARbro.git
synced 2026-06-06 05:38:48 +08:00
feat: add ASAR format
This commit is contained in:
92
ArcFormats/ArcASAR.cs
Normal file
92
ArcFormats/ArcASAR.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
//! \file ArcASAR.cs
|
||||
//! \date 2025-12-23
|
||||
//! \brief Electron/Atom Shell resource archive format.
|
||||
//
|
||||
// Copyright (C) 2025 by morkt
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace GameRes.Formats.Chromium
|
||||
{
|
||||
class AsarNode
|
||||
{
|
||||
[JsonProperty("files")]
|
||||
public Dictionary<string, AsarNode> Files { get; set; }
|
||||
|
||||
[JsonProperty("size")]
|
||||
public uint Size { get; set; }
|
||||
|
||||
[JsonProperty("offset")]
|
||||
public string Offset { get; set; }
|
||||
}
|
||||
|
||||
[Export(typeof(ArchiveFormat))]
|
||||
public class AsarOpener : ArchiveFormat
|
||||
{
|
||||
public override string Tag { get { return "ASAR"; } }
|
||||
public override string Description { get { return "Electron/Atom Shell archive format"; } }
|
||||
public override uint Signature { get { return 0; } }
|
||||
public override bool IsHierarchic { get { return true; } }
|
||||
public override bool CanWrite { get { return false; } }
|
||||
|
||||
public AsarOpener ()
|
||||
{
|
||||
Extensions = new string[] { "asar" };
|
||||
}
|
||||
|
||||
public override ArcFile TryOpen (ArcView file)
|
||||
{
|
||||
uint index_size = file.View.ReadUInt32 (0x0C);
|
||||
string json = file.View.ReadString (0x10, index_size, Encoding.UTF8);
|
||||
var dict = JsonConvert.DeserializeObject<AsarNode> (json);
|
||||
var dir = new List<Entry> ();
|
||||
ParseIndex (dir, dict, (uint)((index_size + 0x10 + 3) & ~3));
|
||||
return new ArcFile (file, this, dir);
|
||||
}
|
||||
|
||||
internal void ParseIndex (List<Entry> dir, AsarNode dict, uint pad, string cur = "") {
|
||||
if (dict.Files != null)
|
||||
{
|
||||
foreach (var kv in dict.Files)
|
||||
{
|
||||
string k = kv.Key;
|
||||
AsarNode v = kv.Value;
|
||||
ParseIndex (dir, v, pad, cur != "" ? $"{cur}/{k}" : k);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var entry = new Entry {
|
||||
Name = cur,
|
||||
Size = dict.Size,
|
||||
Offset = uint.Parse (dict.Offset) + pad,
|
||||
Type = FormatCatalog.Instance.GetTypeFromName (cur)
|
||||
};
|
||||
dir.Add (entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,6 +63,9 @@
|
||||
<Reference Include="NVorbis, Version=0.10.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NVorbis.0.10.4\lib\net45\NVorbis.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="Snappy.NET, Version=1.1.1.8, Culture=neutral, processorArchitecture=MSIL">
|
||||
@@ -194,6 +197,7 @@
|
||||
<Compile Include="Aoi\ImageAGF.cs" />
|
||||
<Compile Include="Apricot\ArcDAT.cs" />
|
||||
<Compile Include="ArcARCX.cs" />
|
||||
<Compile Include="ArcASAR.cs" />
|
||||
<Compile Include="Artemis\ArcMJA.cs" />
|
||||
<Compile Include="Macintosh\ImagePICT.cs" />
|
||||
<Compile Include="Macromedia\ArcDXR.cs" />
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Crc32C.NET" version="1.0.5.0" targetFramework="net461" />
|
||||
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net461" />
|
||||
<package id="NVorbis" version="0.10.4" targetFramework="net461" />
|
||||
<package id="SharpZipLib" version="1.3.3" targetFramework="net461" />
|
||||
<package id="Snappy.NET" version="1.1.1.8" targetFramework="net461" />
|
||||
|
||||
Reference in New Issue
Block a user