From 4f0f67cabc02fbfa81d00cf2e247b5560450fa17 Mon Sep 17 00:00:00 2001 From: codestation Date: Fri, 22 Jul 2011 23:15:04 -0430 Subject: [PATCH] KirkCypher: show gamekey --- src/crypt/KirkCypher.java | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/crypt/KirkCypher.java b/src/crypt/KirkCypher.java index 46603ee..af05a61 100644 --- a/src/crypt/KirkCypher.java +++ b/src/crypt/KirkCypher.java @@ -25,18 +25,33 @@ import jpcsp.crypto.CryptoEngine; import keys.GameKeys; public class KirkCypher implements GameKeys { - + + static final String HEXES = "0123456789ABCDEF"; + + private static String getHex(byte[] raw) { + if (raw == null) { + return null; + } + final StringBuilder hex = new StringBuilder(2 * raw.length); + for (final byte b : raw) { + hex.append(HEXES.charAt((b & 0xF0) >> 4)).append(HEXES.charAt((b & 0x0F))).append(' '); + } + return hex.toString(); + } + public void decrypt(String file) { try { RandomAccessFile fd = new RandomAccessFile(file, "rw"); byte byte_bt[] = new byte[(int)fd.length()]; fd.read(byte_bt); fd.seek(0); - System.out.print("Decrypting savedata (KIRK engine)"); - byte out[] = new CryptoEngine().DecryptSavedata(byte_bt, byte_bt.length, gamekey, 1); + System.out.println("Decrypting savedata (KIRK engine): " + byte_bt.length + " bytes"); + System.out.println("Gamekey: " + getHex(gamekey)); + byte out[] = new CryptoEngine().DecryptSavedata(byte_bt, byte_bt.length, gamekey, 0); fd.write(out); + fd.setLength(out.length); fd.close(); - System.out.println("Finished"); + System.out.println("Finished (" + out.length + " bytes)"); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { @@ -50,11 +65,12 @@ public class KirkCypher implements GameKeys { byte byte_bt[] = new byte[(int)fd.length()]; fd.read(byte_bt); fd.seek(0); - System.out.println("Encrypting savedata (KIRK engine)"); + System.out.println("Encrypting savedata (KIRK engine): " + byte_bt.length + " bytes"); byte out[] = new CryptoEngine().EncryptSavedata(byte_bt, byte_bt.length, gamekey, 0); fd.write(out); + fd.setLength(out.length); fd.close(); - System.out.println("Finished"); + System.out.println("Finished (" + out.length + " bytes)"); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) {