mirror of
https://github.com/crskycode/GARbro.git
synced 2024-12-24 03:44:13 +08:00
implemented encrypted Anime Game System archives.
This commit is contained in:
parent
b3d2f6b999
commit
fda4f26845
@ -2,7 +2,7 @@
|
||||
//! \date Thu Nov 05 04:40:35 2015
|
||||
//! \brief AnimeGameSystem resource archive.
|
||||
//
|
||||
// Copyright (C) 2015 by morkt
|
||||
// Copyright (C) 2015-2016 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
|
||||
@ -27,6 +27,8 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using GameRes.Formats.Properties;
|
||||
using GameRes.Formats.Strings;
|
||||
using GameRes.Utility;
|
||||
|
||||
namespace GameRes.Formats.Ags
|
||||
@ -67,7 +69,102 @@ namespace GameRes.Formats.Ags
|
||||
dir.Add (entry);
|
||||
index_offset += 0x18;
|
||||
}
|
||||
var arc_name = Path.GetFileName (file.Name);
|
||||
if (EncryptedArchives.Contains (arc_name))
|
||||
{
|
||||
var options = Query<AgsOptions> (arcStrings.AGSMightBeEncrypted);
|
||||
EncryptionKey key;
|
||||
if (options.Scheme.FileMap.TryGetValue (arc_name, out key))
|
||||
return new DatArchive (file, this, dir, key);
|
||||
}
|
||||
return new ArcFile (file, this, dir);
|
||||
}
|
||||
|
||||
public override Stream OpenEntry (ArcFile arc, Entry entry)
|
||||
{
|
||||
var earc = arc as DatArchive;
|
||||
if (null == earc)
|
||||
return base.OpenEntry (arc, entry);
|
||||
var data = arc.File.View.ReadBytes (entry.Offset, entry.Size);
|
||||
byte key = earc.Key.Initial;
|
||||
for (int i = 0; i < data.Length; ++i)
|
||||
{
|
||||
data[i] ^= key;
|
||||
key += earc.Key.Increment;
|
||||
}
|
||||
return new MemoryStream (data);
|
||||
}
|
||||
|
||||
public static readonly EncryptionScheme DefaultScheme = new EncryptionScheme {
|
||||
FileMap = new Dictionary<string, EncryptionKey>()
|
||||
};
|
||||
|
||||
public override ResourceOptions GetDefaultOptions ()
|
||||
{
|
||||
return new AgsOptions { Scheme = GetScheme (Settings.Default.AGSTitle) };
|
||||
}
|
||||
|
||||
public override object GetAccessWidget ()
|
||||
{
|
||||
return new GUI.WidgetAGS();
|
||||
}
|
||||
|
||||
public static EncryptionScheme GetScheme (string title)
|
||||
{
|
||||
EncryptionScheme scheme;
|
||||
if (string.IsNullOrEmpty (title) || !KnownSchemes.TryGetValue (title, out scheme))
|
||||
scheme = DefaultScheme;
|
||||
return scheme;
|
||||
}
|
||||
|
||||
public static Dictionary<string, EncryptionScheme> KnownSchemes = new Dictionary<string, EncryptionScheme>();
|
||||
static HashSet<string> EncryptedArchives = new HashSet<string>();
|
||||
|
||||
public override ResourceScheme Scheme
|
||||
{
|
||||
get { return new AgsScheme { KnownSchemes = KnownSchemes, EncryptedArchives = EncryptedArchives }; }
|
||||
set
|
||||
{
|
||||
var ags = (AgsScheme)value;
|
||||
KnownSchemes = ags.KnownSchemes;
|
||||
EncryptedArchives = ags.EncryptedArchives;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class DatArchive : ArcFile
|
||||
{
|
||||
public EncryptionKey Key;
|
||||
|
||||
public DatArchive (ArcView arc, ArchiveFormat impl, ICollection<Entry> dir, EncryptionKey key)
|
||||
: base (arc, impl, dir)
|
||||
{
|
||||
Key = key;
|
||||
}
|
||||
}
|
||||
|
||||
internal class AgsOptions : ResourceOptions
|
||||
{
|
||||
public EncryptionScheme Scheme;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct EncryptionKey
|
||||
{
|
||||
public byte Initial;
|
||||
public byte Increment;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class EncryptionScheme
|
||||
{
|
||||
public Dictionary<string, EncryptionKey> FileMap;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class AgsScheme : ResourceScheme
|
||||
{
|
||||
public Dictionary<string, EncryptionScheme> KnownSchemes;
|
||||
public HashSet<string> EncryptedArchives;
|
||||
}
|
||||
}
|
||||
|
7
ArcFormats/AnimeGameSystem/WidgetAGS.xaml
Normal file
7
ArcFormats/AnimeGameSystem/WidgetAGS.xaml
Normal file
@ -0,0 +1,7 @@
|
||||
<StackPanel x:Class="GameRes.Formats.GUI.WidgetAGS"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:p="clr-namespace:GameRes.Formats.Properties">
|
||||
<ComboBox Name="Scheme" Width="180" ItemsSource="{Binding}"
|
||||
SelectedValue="{Binding Source={x:Static p:Settings.Default}, Path=AGSTitle, Mode=TwoWay}"/>
|
||||
</StackPanel>
|
22
ArcFormats/AnimeGameSystem/WidgetAGS.xaml.cs
Normal file
22
ArcFormats/AnimeGameSystem/WidgetAGS.xaml.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System.Linq;
|
||||
using System.Windows.Controls;
|
||||
using GameRes.Formats.Ags;
|
||||
using GameRes.Formats.Strings;
|
||||
|
||||
namespace GameRes.Formats.GUI
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for WidgetAGS.xaml
|
||||
/// </summary>
|
||||
public partial class WidgetAGS : StackPanel
|
||||
{
|
||||
public WidgetAGS()
|
||||
{
|
||||
InitializeComponent();
|
||||
var keys = new string[] { arcStrings.ArcNoEncryption };
|
||||
Scheme.ItemsSource = keys.Concat (DatOpener.KnownSchemes.Keys.OrderBy (x => x));
|
||||
if (-1 == Scheme.SelectedIndex)
|
||||
Scheme.SelectedIndex = 0;
|
||||
}
|
||||
}
|
||||
}
|
@ -67,6 +67,9 @@
|
||||
<Compile Include="Actgs\ArcDAT.cs" />
|
||||
<Compile Include="AliceSoft\ArcAFA.cs" />
|
||||
<Compile Include="AliceSoft\ArcALK.cs" />
|
||||
<Compile Include="AnimeGameSystem\WidgetAGS.xaml.cs">
|
||||
<DependentUpon>WidgetAGS.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Ankh\ArcGRP.cs" />
|
||||
<Compile Include="ArcCG.cs" />
|
||||
<Compile Include="ArcZIP.cs" />
|
||||
@ -495,6 +498,10 @@
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="AnimeGameSystem\WidgetAGS.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="AZSys\WidgetAZ.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
|
12
ArcFormats/Properties/Settings.Designer.cs
generated
12
ArcFormats/Properties/Settings.Designer.cs
generated
@ -513,5 +513,17 @@ namespace GameRes.Formats.Properties {
|
||||
this["AZScriptScheme"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("")]
|
||||
public string AGSTitle {
|
||||
get {
|
||||
return ((string)(this["AGSTitle"]));
|
||||
}
|
||||
set {
|
||||
this["AGSTitle"] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -125,5 +125,8 @@
|
||||
<Setting Name="AZScriptScheme" Type="System.String" Scope="User">
|
||||
<Value Profile="(Default)" />
|
||||
</Setting>
|
||||
<Setting Name="AGSTitle" Type="System.String" Scope="User">
|
||||
<Value Profile="(Default)" />
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
12
ArcFormats/Strings/arcStrings.Designer.cs
generated
12
ArcFormats/Strings/arcStrings.Designer.cs
generated
@ -1,7 +1,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.34209
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
@ -60,6 +60,16 @@ namespace GameRes.Formats.Strings {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Archive contents might be encrypted,
|
||||
///choose appropriate encryption scheme..
|
||||
/// </summary>
|
||||
public static string AGSMightBeEncrypted {
|
||||
get {
|
||||
return ResourceManager.GetString("AGSMightBeEncrypted", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Base archive.
|
||||
/// </summary>
|
||||
|
@ -372,4 +372,9 @@
|
||||
<value>Try to guess</value>
|
||||
<comment>translation pending</comment>
|
||||
</data>
|
||||
<data name="AGSMightBeEncrypted" xml:space="preserve">
|
||||
<value>Archive contents might be encrypted,
|
||||
choose appropriate encryption scheme.</value>
|
||||
<comment>translation pending</comment>
|
||||
</data>
|
||||
</root>
|
@ -367,4 +367,8 @@ Choose appropriate encryption scheme.</value>
|
||||
<data name="YPFTryGuess" xml:space="preserve">
|
||||
<value>Try to guess</value>
|
||||
</data>
|
||||
<data name="AGSMightBeEncrypted" xml:space="preserve">
|
||||
<value>Archive contents might be encrypted,
|
||||
choose appropriate encryption scheme.</value>
|
||||
</data>
|
||||
</root>
|
@ -117,6 +117,10 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="AGSMightBeEncrypted" xml:space="preserve">
|
||||
<value>Содержимое архива может быть зашифровано,
|
||||
выберите подходящий способ шифрования.</value>
|
||||
</data>
|
||||
<data name="AMIBaseArchive" xml:space="preserve">
|
||||
<value>Базовый архив</value>
|
||||
</data>
|
||||
|
@ -367,4 +367,9 @@
|
||||
<data name="YPFTryGuess" xml:space="preserve">
|
||||
<value>尝试猜测</value>
|
||||
</data>
|
||||
<data name="AGSMightBeEncrypted" xml:space="preserve">
|
||||
<value>Archive contents might be encrypted,
|
||||
choose appropriate encryption scheme.</value>
|
||||
<comment>translation pending</comment>
|
||||
</data>
|
||||
</root>
|
@ -127,6 +127,9 @@
|
||||
<setting name="AZScriptScheme" serializeAs="String">
|
||||
<value />
|
||||
</setting>
|
||||
<setting name="AGSTitle" serializeAs="String">
|
||||
<value />
|
||||
</setting>
|
||||
</GameRes.Formats.Properties.Settings>
|
||||
</userSettings>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>
|
||||
|
Loading…
x
Reference in New Issue
Block a user