Skip to content

Commit ca3d1b8

Browse files
author
codestation
committedJul 24, 2011
Make --extract-quests use the correct quest name.
Some refactoring.
1 parent 966c01a commit ca3d1b8

6 files changed

+41
-19
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/index.bin
22
/.settings
3+
/bcprov-jdk16-146.jar

‎src/base/MHUtils.java

+13
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,17 @@ public static int getOffset(int value) throws EOFException,
113113
}
114114
return res;
115115
}
116+
117+
static final String HEXES = "0123456789ABCDEF";
118+
119+
public static String getHex(byte[] raw) {
120+
if (raw == null) {
121+
return null;
122+
}
123+
final StringBuilder hex = new StringBuilder(2 * raw.length);
124+
for (final byte b : raw) {
125+
hex.append(HEXES.charAt((b & 0xF0) >> 4)).append(HEXES.charAt((b & 0x0F))).append(' ');
126+
}
127+
return hex.toString();
128+
}
116129
}

‎src/crypt/DecryptUtils.java

+13
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,17 @@ protected void set_table_data(byte table[], byte base_table[], int i) {
8787
table[i + 2] = base_table[table[i + 2] & 0xFF];
8888
table[i + 3] = base_table[table[i + 3] & 0xFF];
8989
}
90+
91+
static final String HEXES = "0123456789ABCDEF";
92+
93+
public static String getHex(byte[] raw) {
94+
if (raw == null) {
95+
return null;
96+
}
97+
final StringBuilder hex = new StringBuilder(2 * raw.length);
98+
for (final byte b : raw) {
99+
hex.append(HEXES.charAt((b & 0xF0) >> 4)).append(HEXES.charAt((b & 0x0F))).append(' ');
100+
}
101+
return hex.toString();
102+
}
90103
}

‎src/crypt/KirkCypher.java

+6-15
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,12 @@
2121
import java.io.IOException;
2222
import java.io.RandomAccessFile;
2323

24+
import base.MHUtils;
25+
2426
import jpcsp.crypto.CryptoEngine;
2527
import keys.GameKeys;
2628

27-
public class KirkCypher implements GameKeys {
28-
29-
static final String HEXES = "0123456789ABCDEF";
30-
31-
private static String getHex(byte[] raw) {
32-
if (raw == null) {
33-
return null;
34-
}
35-
final StringBuilder hex = new StringBuilder(2 * raw.length);
36-
for (final byte b : raw) {
37-
hex.append(HEXES.charAt((b & 0xF0) >> 4)).append(HEXES.charAt((b & 0x0F))).append(' ');
38-
}
39-
return hex.toString();
40-
}
29+
public class KirkCypher extends MHUtils implements GameKeys {
4130

4231
public void decrypt(String file) {
4332
try {
@@ -47,11 +36,13 @@ public void decrypt(String file) {
4736
fd.seek(0);
4837
System.out.println("Decrypting savedata (KIRK engine): " + byte_bt.length + " bytes");
4938
System.out.println("Gamekey: " + getHex(gamekey));
50-
byte out[] = new CryptoEngine().DecryptSavedata(byte_bt, byte_bt.length, gamekey, 0);
39+
byte hash[] = new byte[0x10];
40+
byte out[] = new CryptoEngine().DecryptSavedata(byte_bt, byte_bt.length, gamekey, 0, hash);
5141
fd.write(out);
5242
fd.setLength(out.length);
5343
fd.close();
5444
System.out.println("Finished (" + out.length + " bytes)");
45+
System.out.println("Hash: " + getHex(hash));
5546
} catch (FileNotFoundException e) {
5647
e.printStackTrace();
5748
} catch (IOException e) {

‎src/crypt/QuestCypher.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@
3030
import java.security.NoSuchAlgorithmException;
3131
import java.util.Arrays;
3232

33+
import base.MHUtils;
34+
3335
import keys.QuestKeys;
3436

35-
public class QuestCypher implements QuestKeys {
37+
public class QuestCypher extends MHUtils implements QuestKeys {
3638

3739
private short key_var_table[] = {0, 0, 0, 0};
3840

@@ -114,17 +116,18 @@ public boolean extract(String filein) {
114116
in.read(byte_bt);
115117
in.close();
116118
for(int i = 0; i < 100; i++) {
119+
String mib = new String(byte_bt, (i + 1) * QUEST_SIZE - 16, 16);
117120
ByteBuffer bt = ByteBuffer.wrap(byte_bt,i * QUEST_SIZE, QUEST_SIZE);
118121
bt.order(ByteOrder.LITTLE_ENDIAN);
119122
ShortBuffer sb = bt.asShortBuffer();
120123
short short_bt[] = new short[QUEST_SIZE/2];
121124
sb.get(short_bt);
122-
System.out.println("Decrypting quest file # " + i);
123125
int len = decrypt_quest(short_bt);
124126
if(len > 0) {
127+
System.out.println("Decrypted quest # " + i + ": " + mib);
125128
sb.rewind();
126129
sb.put(short_bt);
127-
String outname = String.format("%s/%02d_quest.bin", directory, i);
130+
String outname = String.format("%s/%s", directory, mib);
128131
FileOutputStream out = new FileOutputStream(outname);
129132
out.write(byte_bt, i * QUEST_SIZE, len);
130133
out.close();

‎src/crypt/SavedataCypher.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void encrypt(String file) {
9595
byte byte_bt[] = new byte[(int)fd.length()];
9696
fd.read(byte_bt);
9797
fd.seek(0);
98-
System.out.println("Updating sha1 hash");
98+
System.out.print("Updating ");
9999
update_sha1(byte_bt);
100100
System.out.println("Encrypting savedata");
101101
encrypt_buffer(byte_bt);
@@ -120,6 +120,7 @@ private void update_sha1(byte buf[]) {
120120
MessageDigest md = MessageDigest.getInstance("sha-1");
121121
byte digest[] = md.digest(buffer);
122122
System.arraycopy(replace, 0, buf, buf.length - 36, 20);
123+
System.out.println("SHA-1: " + getHex(digest));
123124
System.arraycopy(digest, 0, buf, buf.length - 24, digest.length);
124125
} catch (NoSuchAlgorithmException e) {
125126
e.printStackTrace();

0 commit comments

Comments
 (0)
Please sign in to comment.