mirror of
https://github.com/codestation/mhtools
synced 2024-11-10 05:44:17 +00:00
Fix savedata decryption/encryption
This commit is contained in:
parent
4f0f67cabc
commit
39d2736f9b
4 changed files with 19 additions and 13 deletions
|
@ -81,10 +81,10 @@ public abstract class DecryptUtils {
|
|||
buffer[3] = table[buffer[3] & 0xFF];
|
||||
}
|
||||
|
||||
protected void set_table_data(byte table[], int i) {
|
||||
table[i] = decrypt_table[table[i] & 0xFF];
|
||||
table[i + 1] = decrypt_table[table[i + 1] & 0xFF];
|
||||
table[i + 2] = decrypt_table[table[i + 2] & 0xFF];
|
||||
table[i + 3] = decrypt_table[table[i + 3] & 0xFF];
|
||||
protected void set_table_data(byte table[], byte base_table[], int i) {
|
||||
table[i] = base_table[table[i] & 0xFF];
|
||||
table[i + 1] = base_table[table[i + 1] & 0xFF];
|
||||
table[i + 2] = base_table[table[i + 2] & 0xFF];
|
||||
table[i + 3] = base_table[table[i + 3] & 0xFF];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -199,7 +199,7 @@ public class Decrypter extends DecryptUtils implements DataKeys {
|
|||
int read = filein.read(buffer);
|
||||
size -= read;
|
||||
for (int i = 0; i < read; i += 4) {
|
||||
set_table_data(buffer, i);
|
||||
set_table_data(buffer, decrypt_table, i);
|
||||
long alpha = get_table_value(buffer, i);
|
||||
long beta = getBeta();
|
||||
long gamma = alpha ^ beta;
|
||||
|
|
|
@ -66,6 +66,7 @@ public class KirkCypher implements GameKeys {
|
|||
fd.read(byte_bt);
|
||||
fd.seek(0);
|
||||
System.out.println("Encrypting savedata (KIRK engine): " + byte_bt.length + " bytes");
|
||||
System.out.println("Gamekey: " + getHex(gamekey));
|
||||
byte out[] = new CryptoEngine().EncryptSavedata(byte_bt, byte_bt.length, gamekey, 0);
|
||||
fd.write(out);
|
||||
fd.setLength(out.length);
|
||||
|
|
|
@ -79,13 +79,14 @@ public class SavedataCypher extends DecryptUtils implements SavedataKeys {
|
|||
long alpha = get_table_value(seed, 0);
|
||||
initSeed(alpha);
|
||||
for (int i = 0; i < len; i += 4) {
|
||||
set_table_data(buffer, i);
|
||||
set_table_data(buffer, decrypt_table, i);
|
||||
alpha = get_table_value(buffer, i);
|
||||
long beta = getBeta();
|
||||
long gamma = alpha ^ beta;
|
||||
set_table_value(buffer, i, gamma);
|
||||
set_table_data(buffer, i);
|
||||
set_table_data(buffer, decrypt_table, i);
|
||||
}
|
||||
System.arraycopy(seed, 0, buffer, len, 4);
|
||||
}
|
||||
|
||||
public void encrypt(String file) {
|
||||
|
@ -134,11 +135,15 @@ public class SavedataCypher extends DecryptUtils implements SavedataKeys {
|
|||
long alpha = get_table_value(seed, 0);
|
||||
initSeed(alpha);
|
||||
for (int i = 0; i < len; i += 4) {
|
||||
set_table_data(buffer, encrypt_table, i);
|
||||
long gamma = get_table_value(buffer, i);
|
||||
long beta = getBeta();
|
||||
alpha = beta ^ gamma;
|
||||
set_table_value(buffer, i, alpha);
|
||||
get_table_value(encrypt_table, buffer);
|
||||
}
|
||||
set_table_data(buffer, encrypt_table, i);
|
||||
}
|
||||
get_table_value(encrypt_table, seed);
|
||||
get_table_value(encrypt_table, seed);
|
||||
System.arraycopy(seed, 0, buffer, len, 4);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue