diff system/file.cc @ 35:2c574c3d50a9

* Moved XOR key related things to a proper location * xclannad -v now displays the real version (as specified in configure.ac)
author thib
date Sun, 08 Mar 2009 19:16:36 +0000
parents 3fe3e5f184b5
children 01aa5ddf7dc8
line wrap: on
line diff
--- a/system/file.cc
+++ b/system/file.cc
@@ -84,6 +84,7 @@ extern "C" {
 using namespace std;
 
 FILESEARCH file_searcher;
+KEYHOLDER key_holder;
 // #define delete fprintf(stderr,"file.cc: %d.",__LINE__), delete
 
 /* FILESEARCH class の default の振る舞い */
@@ -532,6 +533,58 @@ void SCN2kFILE::ListupFiles(int fname_le
 }
 
 /********************************************************
+** KEYHOLDER
+*/
+void KEYHOLDER::SetKey(char new_key[16])
+{
+	unsigned short int i;
+	for (i=0; i < 16; i++)
+		key[i] = new_key[i];
+}
+
+void KEYHOLDER::SetKey2(char new_key[33])
+{
+	unsigned short int i;
+	char tmp[3];
+	tmp[2] = '\0';
+	for (i=0; i < 16; i++) {
+		tmp[0] = new_key[i*2];
+		tmp[1] = new_key[i*2+1];
+		key[i] = strtoul(tmp, NULL, 16);
+	}
+}
+
+void KEYHOLDER::GuessKey(char *regname)
+{
+	char key1[16] = {
+		0xa8, 0x28, 0xfd, 0x66,
+		0xa0, 0x23, 0x77, 0x69,
+		0xf9, 0x45, 0xf8, 0x2c,
+		0x7c, 0x00, 0xad, 0xf4
+	};
+
+	char key2[16] = {
+		0xAF, 0x2F, 0xFB, 0x6B,
+		0xAF, 0x30, 0x77, 0x17,
+		0x87, 0x48, 0xFE, 0x2C,
+		0x68, 0x1A, 0xB9, 0xF0
+	};
+
+
+	if (strcmp(regname, "KEY\\CLANNAD_FV") == 0) {
+		SetKey(key2);
+	}
+	else {
+		SetKey(key1);
+	}
+}
+
+const char * KEYHOLDER::GetKey(void)
+{
+	return key;
+}
+
+/********************************************************
 ** FILESEARCH クラスの実装
 */
 
@@ -599,43 +652,6 @@ int FILESEARCH::InitRoot(char* root) {
 	return 0;
 }
 
-void FILESEARCH::SetXorKey(char *key)
-{
-	unsigned short int i;
-	for (i=0; i < 16; i++)
-		xor_key[i] = key[i];
-}
-
-void FILESEARCH::GuessXorKey(char *regname)
-{
-	char key1[16] = {
-		0xa8, 0x28, 0xfd, 0x66,
-		0xa0, 0x23, 0x77, 0x69,
-		0xf9, 0x45, 0xf8, 0x2c,
-		0x7c, 0x00, 0xad, 0xf4
-	};
-
-	char key2[16] = {
-		0xAF, 0x2F, 0xFB, 0x6B,
-		0xAF, 0x30, 0x77, 0x17,
-		0x87, 0x48, 0xFE, 0x2C,
-		0x68, 0x1A, 0xB9, 0xF0
-	};
-
-
-	if (strcmp(regname, "KEY\\CLANNAD_FV") == 0) {
-		SetXorKey(key2);
-	}
-	else {
-		SetXorKey(key1);
-	}
-}
-
-const char * FILESEARCH::GetXorKey(void)
-{
-	return xor_key;
-}
-
 void FILESEARCH::SetFileInformation(FILETYPE tp, ARCTYPE is_arc, char* filename) {
 	int type = tp;
 	if (type < 0 || type >= TYPEMAX) return;
@@ -1456,7 +1472,7 @@ bool ARCINFO2k::ExecExtract(void) {
 		while(lzExtract(Extract_DataType_SCN2k(), char(), s, d, send, dend)) ;
 	}
 	if (read_little_endian_int(data+4) == 0x1adb2) { // Little Busters!
-		const char *decode_key = file_searcher.GetXorKey();
+		const char *decode_key = key_holder.GetKey();
 		int header_size = info.private_data;
 		for (i=0x100; i<=0x200 && header_size+i < info.filesize; i++) {
 			ret_data[header_size+i] ^= decode_key[i&0x0f];