Added PatchBuilder class

This commit is contained in:
codestation 2010-12-20 12:41:53 +00:00
parent 7aba2b96f3
commit 322cf28838
3 changed files with 87 additions and 13 deletions

3
README
View file

@ -35,3 +35,6 @@ java -jar mhtrans.jar --dec-ext 0017.bin.enc 1
To only generate a index.bin (necessary to decrypt/encrypt), e.g.:
java -jar mhtrans.jar --gen-index /home/user/data.bin
To create a patchfile, e.g.:
java -jar mhtrans.jar --create-patch 0017.bin.enc 2813.bin.enc 2814.bin.enc

View file

@ -86,6 +86,10 @@ public class Mhtrans {
}
enc.compile(filename);
}
public static void createPatch(String[] args) {
}
public static void main(String[] args) {
System.out.println("mhtrans v2.0 - MHP2G/MHFU/MHP3 xxxx.bin language table extractor/rebuilder");
@ -99,8 +103,7 @@ public class Mhtrans {
System.err.println(" java -jar mhtrans.jar --reb-enc <path to project folder> <encoder number>");
System.err.println(" java -jar mhtrans.jar --gen-index <data.bin>");
System.err.println(" java -jar mhtrans.jar --dec-all <data.bin> <path to output folder>");
// System.err.println(" java MHP2GTRANS --dec-single <data.bin> <path of xxxx.bin>");
// System.err.println(" java MHP2GTRANS --insert <path of xxxx.bin> <data.bin>");
System.err.println(" java -jar mhtrans.jar --create-patch <xxxx.bin.enc> [ ... <xxxx.bin.enc>]");
System.exit(1);
} else {
if (args[0].equals("--extract")) {
@ -150,17 +153,8 @@ public class Mhtrans {
System.exit(1);
}
new Decrypter().decrypt_whole(args[1], args[2]);
// } else if(args[0].equals("--dec-single")) {
// if(args.length < 3) {
// System.err.println("Output xxxx.bin missing. Aborting");
// System.exit(1);
// }
//
// } else if(args[0].equals("--insert")) {
// if(args.length < 3) {
// System.err.println("Path of data.bin missing. Aborting");
// System.exit(1);
// }
} else if(args[0].equals("--create-patch")) {
new PatchBuilder().create(args);
} else {
System.err.println("Unknown parameter: " + args[0]);
System.exit(1);

View file

@ -0,0 +1,77 @@
package base;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import crypt.DecryptTable;
public class PatchBuilder extends DecryptTable {
public void create(String[] args) {
List<String> list = new ArrayList<String>(Arrays.asList(args));
list.remove(0);
try {
RandomAccessFile out = new RandomAccessFile("MHP3RD_DATA.BIN", "rw");
int table_size = (list.size() + 1) * 4 * 2;
System.out.println("Table size: " + table_size + " bytes");
if(table_size % 16 > 0) {
table_size += 16 - (table_size % 16);
System.out.println("Table size (padded): " + table_size + " bytes");
}
out.setLength(table_size);
out.seek(0);
long current = 0;
writeInt(out, list.size());
for (String file : list) {
int offset = getOffset(extractNumber(file)) << 11;
writeInt(out, offset);
InputStream in = new FileInputStream(file);
int len = (int)new File(file).length();
writeInt(out, (int)len);
System.out.println(file + ", offset: " + offset + ", size: " + len);
current = out.getFilePointer();
byte buffer[] = new byte[1024];
out.seek(out.length());
while((len = in.read(buffer)) > 0)
out.write(buffer, 0, len);
in.close();
out.seek(current);
}
writeInt(out, 0);
out.close();
}catch(FileNotFoundException e) {
e.printStackTrace();
} catch (EOFException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* The "writeInt" function of java writes in BigEndian mode but we need
* LittleEndian so i made a custom function for that
*
* @param file
* @throws IOException
* if any error occur while writing
*/
private void writeInt(RandomAccessFile file, int value)
throws IOException {
int ch1 = (byte) (value >>> 24);
int ch2 = (byte) (value >>> 16);
int ch3 = (byte) (value >>> 8);
int ch4 = (byte) value;
file.write(ch4);
file.write(ch3);
file.write(ch2);
file.write(ch1);
}
}