(MrgOpener): decryption moved to a static method.

This commit is contained in:
morkt 2015-11-23 14:51:56 +04:00
parent 111ffab7ac
commit ff00799d2d

View File

@ -75,16 +75,8 @@ namespace GameRes.Formats.FC01
var key = GuessKey (file, index);
if (null == key)
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;
uint next_offset = LittleEndian.ToUInt32 (index, current_offset+0x1C);
var dir = new List<Entry> (count);
@ -140,6 +132,17 @@ namespace GameRes.Formats.FC01
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)
{
uint actual_offset = (uint)file.MaxOffset;
@ -286,7 +289,7 @@ namespace GameRes.Formats.FC01
public int Unpack () // sub_10026EB0
{
uint quant = InitTable();
if (0 == quant)
if (0 == quant || quant > 0x10000)
throw new InvalidFormatException();
uint mask = GetMask (quant);
uint scale = 0x10000 / quant;