mirror of
https://github.com/codestation/mhtools
synced 2024-11-10 05:44:17 +00:00
Make --extract-quests use the correct quest name.
Some refactoring.
This commit is contained in:
parent
966c01a9c8
commit
ca3d1b8a02
6 changed files with 41 additions and 19 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
/index.bin
|
||||
/.settings
|
||||
/bcprov-jdk16-146.jar
|
||||
|
|
|
@ -113,4 +113,17 @@ public abstract class MHUtils {
|
|||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static final String HEXES = "0123456789ABCDEF";
|
||||
|
||||
public 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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,4 +87,17 @@ public abstract class DecryptUtils {
|
|||
table[i + 2] = base_table[table[i + 2] & 0xFF];
|
||||
table[i + 3] = base_table[table[i + 3] & 0xFF];
|
||||
}
|
||||
|
||||
static final String HEXES = "0123456789ABCDEF";
|
||||
|
||||
public 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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,23 +21,12 @@ import java.io.FileNotFoundException;
|
|||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
|
||||
import base.MHUtils;
|
||||
|
||||
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 class KirkCypher extends MHUtils implements GameKeys {
|
||||
|
||||
public void decrypt(String file) {
|
||||
try {
|
||||
|
@ -47,11 +36,13 @@ public class KirkCypher implements GameKeys {
|
|||
fd.seek(0);
|
||||
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);
|
||||
byte hash[] = new byte[0x10];
|
||||
byte out[] = new CryptoEngine().DecryptSavedata(byte_bt, byte_bt.length, gamekey, 0, hash);
|
||||
fd.write(out);
|
||||
fd.setLength(out.length);
|
||||
fd.close();
|
||||
System.out.println("Finished (" + out.length + " bytes)");
|
||||
System.out.println("Hash: " + getHex(hash));
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -30,9 +30,11 @@ import java.security.MessageDigest;
|
|||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import base.MHUtils;
|
||||
|
||||
import keys.QuestKeys;
|
||||
|
||||
public class QuestCypher implements QuestKeys {
|
||||
public class QuestCypher extends MHUtils implements QuestKeys {
|
||||
|
||||
private short key_var_table[] = {0, 0, 0, 0};
|
||||
|
||||
|
@ -114,17 +116,18 @@ public class QuestCypher implements QuestKeys {
|
|||
in.read(byte_bt);
|
||||
in.close();
|
||||
for(int i = 0; i < 100; i++) {
|
||||
String mib = new String(byte_bt, (i + 1) * QUEST_SIZE - 16, 16);
|
||||
ByteBuffer bt = ByteBuffer.wrap(byte_bt,i * QUEST_SIZE, QUEST_SIZE);
|
||||
bt.order(ByteOrder.LITTLE_ENDIAN);
|
||||
ShortBuffer sb = bt.asShortBuffer();
|
||||
short short_bt[] = new short[QUEST_SIZE/2];
|
||||
sb.get(short_bt);
|
||||
System.out.println("Decrypting quest file # " + i);
|
||||
int len = decrypt_quest(short_bt);
|
||||
if(len > 0) {
|
||||
System.out.println("Decrypted quest # " + i + ": " + mib);
|
||||
sb.rewind();
|
||||
sb.put(short_bt);
|
||||
String outname = String.format("%s/%02d_quest.bin", directory, i);
|
||||
String outname = String.format("%s/%s", directory, mib);
|
||||
FileOutputStream out = new FileOutputStream(outname);
|
||||
out.write(byte_bt, i * QUEST_SIZE, len);
|
||||
out.close();
|
||||
|
|
|
@ -95,7 +95,7 @@ public class SavedataCypher extends DecryptUtils implements SavedataKeys {
|
|||
byte byte_bt[] = new byte[(int)fd.length()];
|
||||
fd.read(byte_bt);
|
||||
fd.seek(0);
|
||||
System.out.println("Updating sha1 hash");
|
||||
System.out.print("Updating ");
|
||||
update_sha1(byte_bt);
|
||||
System.out.println("Encrypting savedata");
|
||||
encrypt_buffer(byte_bt);
|
||||
|
@ -120,6 +120,7 @@ public class SavedataCypher extends DecryptUtils implements SavedataKeys {
|
|||
MessageDigest md = MessageDigest.getInstance("sha-1");
|
||||
byte digest[] = md.digest(buffer);
|
||||
System.arraycopy(replace, 0, buf, buf.length - 36, 20);
|
||||
System.out.println("SHA-1: " + getHex(digest));
|
||||
System.arraycopy(digest, 0, buf, buf.length - 24, digest.length);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
|
|
Loading…
Reference in a new issue