mirror of
https://github.com/crskycode/GARbro.git
synced 2026-07-08 01:30:18 +08:00
(MrgOpener): decryption moved to a static method.
This commit is contained in:
@@ -75,16 +75,8 @@ namespace GameRes.Formats.FC01
|
|||||||
var key = GuessKey (file, index);
|
var key = GuessKey (file, index);
|
||||||
if (null == key)
|
if (null == key)
|
||||||
throw new UnknownEncryptionScheme();
|
throw new UnknownEncryptionScheme();
|
||||||
byte index_key = key.Value;
|
Decrypt (index, key.Value);
|
||||||
|
|
||||||
int remaining = index.Length;
|
|
||||||
for (int i = 0; i < index.Length; ++i)
|
|
||||||
{
|
|
||||||
byte v = index[i];
|
|
||||||
v = (byte)(v << 1 | v >> 7);
|
|
||||||
index[i] = (byte)(v ^ index_key);
|
|
||||||
index_key += (byte)remaining--;
|
|
||||||
}
|
|
||||||
int current_offset = 0;
|
int current_offset = 0;
|
||||||
uint next_offset = LittleEndian.ToUInt32 (index, current_offset+0x1C);
|
uint next_offset = LittleEndian.ToUInt32 (index, current_offset+0x1C);
|
||||||
var dir = new List<Entry> (count);
|
var dir = new List<Entry> (count);
|
||||||
@@ -140,6 +132,17 @@ namespace GameRes.Formats.FC01
|
|||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public void Decrypt (byte[] data, int key)
|
||||||
|
{
|
||||||
|
int remaining = data.Length;
|
||||||
|
for (int i = 0; i < data.Length; ++i)
|
||||||
|
{
|
||||||
|
var v = data[i];
|
||||||
|
data[i] = (byte)((v << 1 | v >> 7) ^ key);
|
||||||
|
key += remaining--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private byte? GuessKey (ArcView file, byte[] index)
|
private byte? GuessKey (ArcView file, byte[] index)
|
||||||
{
|
{
|
||||||
uint actual_offset = (uint)file.MaxOffset;
|
uint actual_offset = (uint)file.MaxOffset;
|
||||||
@@ -286,7 +289,7 @@ namespace GameRes.Formats.FC01
|
|||||||
public int Unpack () // sub_10026EB0
|
public int Unpack () // sub_10026EB0
|
||||||
{
|
{
|
||||||
uint quant = InitTable();
|
uint quant = InitTable();
|
||||||
if (0 == quant)
|
if (0 == quant || quant > 0x10000)
|
||||||
throw new InvalidFormatException();
|
throw new InvalidFormatException();
|
||||||
uint mask = GetMask (quant);
|
uint mask = GetMask (quant);
|
||||||
uint scale = 0x10000 / quant;
|
uint scale = 0x10000 / quant;
|
||||||
|
|||||||
Reference in New Issue
Block a user