mirror of
https://github.com/crskycode/GARbro.git
synced 2024-12-24 03:44:13 +08:00
implemented Marble scripts decryption.
This commit is contained in:
parent
8849508e41
commit
2da5ed1961
@ -216,6 +216,9 @@
|
|||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
<DependentUpon>WidgetLPK.xaml</DependentUpon>
|
<DependentUpon>WidgetLPK.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="WidgetMBL.xaml.cs">
|
||||||
|
<DependentUpon>WidgetMBL.xaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Compile Include="WidgetNOA.xaml.cs">
|
<Compile Include="WidgetNOA.xaml.cs">
|
||||||
<DependentUpon>WidgetNOA.xaml</DependentUpon>
|
<DependentUpon>WidgetNOA.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
@ -320,6 +323,10 @@
|
|||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
</Page>
|
</Page>
|
||||||
|
<Page Include="WidgetMBL.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
<Page Include="WidgetNOA.xaml">
|
<Page Include="WidgetNOA.xaml">
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
@ -28,10 +28,28 @@ using System.Collections.Generic;
|
|||||||
using System.ComponentModel.Composition;
|
using System.ComponentModel.Composition;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using GameRes.Formats.Properties;
|
||||||
|
using GameRes.Formats.Strings;
|
||||||
using GameRes.Utility;
|
using GameRes.Utility;
|
||||||
|
|
||||||
namespace GameRes.Formats.Marble
|
namespace GameRes.Formats.Marble
|
||||||
{
|
{
|
||||||
|
public class MblOptions : ResourceOptions
|
||||||
|
{
|
||||||
|
public string PassPhrase;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MblArchive : ArcFile
|
||||||
|
{
|
||||||
|
public readonly byte[] Key;
|
||||||
|
|
||||||
|
public MblArchive (ArcView arc, ArchiveFormat impl, ICollection<Entry> dir, string password)
|
||||||
|
: base (arc, impl, dir)
|
||||||
|
{
|
||||||
|
Key = Encodings.cp932.GetBytes (password);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Export(typeof(ArchiveFormat))]
|
[Export(typeof(ArchiveFormat))]
|
||||||
public class MblOpener : ArchiveFormat
|
public class MblOpener : ArchiveFormat
|
||||||
{
|
{
|
||||||
@ -64,6 +82,7 @@ namespace GameRes.Formats.Marble
|
|||||||
return null;
|
return null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
bool contains_scripts = false;
|
||||||
var dir = new List<Entry> (count);
|
var dir = new List<Entry> (count);
|
||||||
for (int i = 0; i < count; ++i)
|
for (int i = 0; i < count; ++i)
|
||||||
{
|
{
|
||||||
@ -79,13 +98,22 @@ namespace GameRes.Formats.Marble
|
|||||||
name = name.ToLowerInvariant();
|
name = name.ToLowerInvariant();
|
||||||
index_offset += (uint)filename_len;
|
index_offset += (uint)filename_len;
|
||||||
uint offset = file.View.ReadUInt32 (index_offset);
|
uint offset = file.View.ReadUInt32 (index_offset);
|
||||||
var entry = new AutoEntry (name, () => {
|
Entry entry;
|
||||||
uint signature = file.View.ReadUInt32 (offset);
|
if (name.EndsWith (".s"))
|
||||||
var res = FormatCatalog.Instance.LookupSignature (signature);
|
{
|
||||||
if (!res.Any() && 0x4259 == (0xffff & signature))
|
entry = new Entry { Name = name, Type = "script" };
|
||||||
res = FormatCatalog.Instance.ImageFormats.Where (x => x.Tag == "PRS");
|
contains_scripts = true;
|
||||||
return res.FirstOrDefault();
|
}
|
||||||
});
|
else
|
||||||
|
{
|
||||||
|
entry = new AutoEntry (name, () => {
|
||||||
|
uint signature = file.View.ReadUInt32 (offset);
|
||||||
|
var res = FormatCatalog.Instance.LookupSignature (signature);
|
||||||
|
if (!res.Any() && 0x4259 == (0xffff & signature))
|
||||||
|
res = FormatCatalog.Instance.ImageFormats.Where (x => x.Tag == "PRS");
|
||||||
|
return res.FirstOrDefault();
|
||||||
|
});
|
||||||
|
}
|
||||||
entry.Offset = offset;
|
entry.Offset = offset;
|
||||||
entry.Size = file.View.ReadUInt32 (index_offset+4);
|
entry.Size = file.View.ReadUInt32 (index_offset+4);
|
||||||
if (offset < index_size || !entry.CheckPlacement (file.MaxOffset))
|
if (offset < index_size || !entry.CheckPlacement (file.MaxOffset))
|
||||||
@ -95,6 +123,12 @@ namespace GameRes.Formats.Marble
|
|||||||
}
|
}
|
||||||
if (0 == dir.Count)
|
if (0 == dir.Count)
|
||||||
return null;
|
return null;
|
||||||
|
if (contains_scripts)
|
||||||
|
{
|
||||||
|
var options = Query<MblOptions> ("Archive contains encrypted scripts.\nChoose encryption scheme or enter a passphrase.");
|
||||||
|
if (options.PassPhrase.Length > 0)
|
||||||
|
return new MblArchive (file, this, dir, options.PassPhrase);
|
||||||
|
}
|
||||||
return new ArcFile (file, this, dir);
|
return new ArcFile (file, this, dir);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
@ -102,5 +136,44 @@ namespace GameRes.Formats.Marble
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Dictionary<string, string> KnownKeys = new Dictionary<string, string> {
|
||||||
|
{ arcStrings.ArcDefault, "" },
|
||||||
|
{ "Chikatetsu Fuusa Jiken", "naze" }
|
||||||
|
};
|
||||||
|
|
||||||
|
public override Stream OpenEntry (ArcFile arc, Entry entry)
|
||||||
|
{
|
||||||
|
if (entry.Type != "script" || !entry.Name.EndsWith (".s"))
|
||||||
|
return arc.File.CreateStream (entry.Offset, entry.Size);
|
||||||
|
var marc = arc as MblArchive;
|
||||||
|
var data = new byte[entry.Size];
|
||||||
|
arc.File.View.Read (entry.Offset, data, 0, entry.Size);
|
||||||
|
if (null == marc || null == marc.Key)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < data.Length; ++i)
|
||||||
|
{
|
||||||
|
data[i] = (byte)-data[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = 0; i < data.Length; ++i)
|
||||||
|
{
|
||||||
|
data[i] ^= marc.Key[i % marc.Key.Length];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new MemoryStream (data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override ResourceOptions GetDefaultOptions ()
|
||||||
|
{
|
||||||
|
return new MblOptions { PassPhrase = Settings.Default.MBLPassPhrase };
|
||||||
|
}
|
||||||
|
|
||||||
|
public override object GetAccessWidget ()
|
||||||
|
{
|
||||||
|
return new GUI.WidgetMBL();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
ArcFormats/Properties/Settings.Designer.cs
generated
12
ArcFormats/Properties/Settings.Designer.cs
generated
@ -357,5 +357,17 @@ namespace GameRes.Formats.Properties {
|
|||||||
this["DPKLastScheme"] = value;
|
this["DPKLastScheme"] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||||
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
|
[global::System.Configuration.DefaultSettingValueAttribute("")]
|
||||||
|
public string MBLPassPhrase {
|
||||||
|
get {
|
||||||
|
return ((string)(this["MBLPassPhrase"]));
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
this["MBLPassPhrase"] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,5 +86,8 @@
|
|||||||
<Setting Name="DPKLastScheme" Type="System.String" Scope="User">
|
<Setting Name="DPKLastScheme" Type="System.String" Scope="User">
|
||||||
<Value Profile="(Default)" />
|
<Value Profile="(Default)" />
|
||||||
</Setting>
|
</Setting>
|
||||||
|
<Setting Name="MBLPassPhrase" Type="System.String" Scope="User">
|
||||||
|
<Value Profile="(Default)" />
|
||||||
|
</Setting>
|
||||||
</Settings>
|
</Settings>
|
||||||
</SettingsFile>
|
</SettingsFile>
|
9
ArcFormats/Strings/arcStrings.Designer.cs
generated
9
ArcFormats/Strings/arcStrings.Designer.cs
generated
@ -279,6 +279,15 @@ namespace GameRes.Formats.Strings {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Archive contains encrypted scripts.Choose encryption scheme or enter a passphrase..
|
||||||
|
/// </summary>
|
||||||
|
public static string MBLNotice {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("MBLNotice", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Adding file.
|
/// Looks up a localized string similar to Adding file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -318,4 +318,8 @@ Enter archive encryption key.</value>
|
|||||||
<data name="KCAPDefault" xml:space="preserve">
|
<data name="KCAPDefault" xml:space="preserve">
|
||||||
<value>Default</value>
|
<value>Default</value>
|
||||||
</data>
|
</data>
|
||||||
</root>
|
<data name="MBLNotice" xml:space="preserve">
|
||||||
|
<value>Archive contains encrypted scripts.
|
||||||
|
Choose encryption scheme or enter a passphrase.</value>
|
||||||
|
</data>
|
||||||
|
</root>
|
||||||
|
@ -174,6 +174,10 @@
|
|||||||
<data name="LabelScheme" xml:space="preserve">
|
<data name="LabelScheme" xml:space="preserve">
|
||||||
<value>Вариант</value>
|
<value>Вариант</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="MBLNotice" xml:space="preserve">
|
||||||
|
<value>Архив содержит зашифрованные скрипты.
|
||||||
|
Выберите способ шифрования или введите текстовый пароль.</value>
|
||||||
|
</data>
|
||||||
<data name="MsgAddingFile" xml:space="preserve">
|
<data name="MsgAddingFile" xml:space="preserve">
|
||||||
<value>Добавляется файл</value>
|
<value>Добавляется файл</value>
|
||||||
</data>
|
</data>
|
||||||
|
17
ArcFormats/WidgetMBL.xaml
Normal file
17
ArcFormats/WidgetMBL.xaml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<Grid x:Class="GameRes.Formats.GUI.WidgetMBL"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:s="clr-namespace:GameRes.Formats.Strings"
|
||||||
|
xmlns:p="clr-namespace:GameRes.Formats.Properties"
|
||||||
|
xmlns:m="clr-namespace:GameRes.Formats.Marble">
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition/>
|
||||||
|
<RowDefinition/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<ComboBox Name="EncScheme" Grid.Row="0" Margin="0,3,0,0" Width="160" HorizontalAlignment="Right"
|
||||||
|
ItemsSource="{Binding Source={x:Static m:MblOpener.KnownKeys}, Mode=OneWay}"
|
||||||
|
DisplayMemberPath="Key" SelectedValuePath="Value"
|
||||||
|
SelectedValue="{Binding ElementName=PassPhrase, Path=Text, Mode=TwoWay}"/>
|
||||||
|
<TextBox Name="PassPhrase" Grid.Row="1" Margin="0,3,0,3" Width="{Binding ElementName=EncScheme, Path=ActualWidth}" HorizontalAlignment="Right"
|
||||||
|
Text="{Binding Source={x:Static p:Settings.Default}, Path=MBLPassPhrase, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
|
||||||
|
</Grid>
|
15
ArcFormats/WidgetMBL.xaml.cs
Normal file
15
ArcFormats/WidgetMBL.xaml.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System.Windows.Controls;
|
||||||
|
|
||||||
|
namespace GameRes.Formats.GUI
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for WidgetMBL.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class WidgetMBL : Grid
|
||||||
|
{
|
||||||
|
public WidgetMBL ()
|
||||||
|
{
|
||||||
|
InitializeComponent ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -88,6 +88,9 @@
|
|||||||
<setting name="DPKLastScheme" serializeAs="String">
|
<setting name="DPKLastScheme" serializeAs="String">
|
||||||
<value />
|
<value />
|
||||||
</setting>
|
</setting>
|
||||||
|
<setting name="MBLPassPhrase" serializeAs="String">
|
||||||
|
<value />
|
||||||
|
</setting>
|
||||||
</GameRes.Formats.Properties.Settings>
|
</GameRes.Formats.Properties.Settings>
|
||||||
</userSettings>
|
</userSettings>
|
||||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>
|
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user