mirror of
https://github.com/crskycode/GARbro.git
synced 2024-12-24 03:44:13 +08:00
(KiriKiri): parametrized SmxCrypt.
This commit is contained in:
parent
f787e608c9
commit
f5c39003a1
@ -1247,20 +1247,30 @@ namespace GameRes.Formats.KiriKiri
|
||||
[Serializable]
|
||||
public class SmxCrypt : ICrypt
|
||||
{
|
||||
byte[] KeySeq;
|
||||
|
||||
public SmxCrypt (params byte[] key_seq)
|
||||
{
|
||||
if (key_seq.Length < 7)
|
||||
throw new ArgumentException ("Not enough arguments for SmxCrypt.");
|
||||
KeySeq = key_seq;
|
||||
}
|
||||
|
||||
public override void Decrypt (Xp3Entry entry, long offset, byte[] buffer, int pos, int count)
|
||||
{
|
||||
var key = new byte[6] {
|
||||
(byte)(entry.Hash >> 5),
|
||||
(byte)(entry.Hash >> 4),
|
||||
(byte)(entry.Hash >> 3),
|
||||
(byte)(entry.Hash >> 2),
|
||||
(byte)(entry.Hash >> 2),
|
||||
(byte)(entry.Hash >> 3),
|
||||
byte start_key = (byte)(entry.Hash >> KeySeq[0]);
|
||||
var key = new byte[] {
|
||||
(byte)(entry.Hash >> KeySeq[1]),
|
||||
(byte)(entry.Hash >> KeySeq[2]),
|
||||
(byte)(entry.Hash >> KeySeq[3]),
|
||||
(byte)(entry.Hash >> KeySeq[4]),
|
||||
(byte)(entry.Hash >> KeySeq[5]),
|
||||
(byte)(entry.Hash >> KeySeq[6]),
|
||||
};
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
if ((offset + i) <= 100)
|
||||
buffer[pos+i] ^= key[3];
|
||||
buffer[pos+i] ^= start_key;
|
||||
else
|
||||
buffer[pos+i] ^= key[(int)(offset + i) & 5];
|
||||
}
|
||||
@ -1270,6 +1280,12 @@ namespace GameRes.Formats.KiriKiri
|
||||
{
|
||||
Decrypt (entry, offset, buffer, pos, count);
|
||||
}
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
var key_seq = KeySeq != null ? string.Join (",", KeySeq.Select (x => x.ToString ("D"))) : "null";
|
||||
return string.Format ("{0}({1})", base.ToString(), key_seq);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
|
Loading…
x
Reference in New Issue
Block a user