comparison 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
comparison
equal deleted inserted replaced
34:b76a8da75ec3 35:2c574c3d50a9
82 #include "file_impl.h" 82 #include "file_impl.h"
83 83
84 using namespace std; 84 using namespace std;
85 85
86 FILESEARCH file_searcher; 86 FILESEARCH file_searcher;
87 KEYHOLDER key_holder;
87 // #define delete fprintf(stderr,"file.cc: %d.",__LINE__), delete 88 // #define delete fprintf(stderr,"file.cc: %d.",__LINE__), delete
88 89
89 /* FILESEARCH class の default の振る舞い */ 90 /* FILESEARCH class の default の振る舞い */
90 FILESEARCH::ARCTYPE FILESEARCH::default_is_archived[TYPEMAX] = { 91 FILESEARCH::ARCTYPE FILESEARCH::default_is_archived[TYPEMAX] = {
91 ATYPE_DIR, ATYPE_DIR, ATYPE_DIR, ATYPE_DIR, 92 ATYPE_DIR, ATYPE_DIR, ATYPE_DIR, ATYPE_DIR,
530 fclose(stream); 531 fclose(stream);
531 return; 532 return;
532 } 533 }
533 534
534 /******************************************************** 535 /********************************************************
536 ** KEYHOLDER
537 */
538 void KEYHOLDER::SetKey(char new_key[16])
539 {
540 unsigned short int i;
541 for (i=0; i < 16; i++)
542 key[i] = new_key[i];
543 }
544
545 void KEYHOLDER::SetKey2(char new_key[33])
546 {
547 unsigned short int i;
548 char tmp[3];
549 tmp[2] = '\0';
550 for (i=0; i < 16; i++) {
551 tmp[0] = new_key[i*2];
552 tmp[1] = new_key[i*2+1];
553 key[i] = strtoul(tmp, NULL, 16);
554 }
555 }
556
557 void KEYHOLDER::GuessKey(char *regname)
558 {
559 char key1[16] = {
560 0xa8, 0x28, 0xfd, 0x66,
561 0xa0, 0x23, 0x77, 0x69,
562 0xf9, 0x45, 0xf8, 0x2c,
563 0x7c, 0x00, 0xad, 0xf4
564 };
565
566 char key2[16] = {
567 0xAF, 0x2F, 0xFB, 0x6B,
568 0xAF, 0x30, 0x77, 0x17,
569 0x87, 0x48, 0xFE, 0x2C,
570 0x68, 0x1A, 0xB9, 0xF0
571 };
572
573
574 if (strcmp(regname, "KEY\\CLANNAD_FV") == 0) {
575 SetKey(key2);
576 }
577 else {
578 SetKey(key1);
579 }
580 }
581
582 const char * KEYHOLDER::GetKey(void)
583 {
584 return key;
585 }
586
587 /********************************************************
535 ** FILESEARCH クラスの実装 588 ** FILESEARCH クラスの実装
536 */ 589 */
537 590
538 FILESEARCH::FILESEARCH(void) { 591 FILESEARCH::FILESEARCH(void) {
539 int i; 592 int i;
595 dat_dir->Init(); 648 dat_dir->Init();
596 } 649 }
597 searcher[ALL] = dat_dir; 650 searcher[ALL] = dat_dir;
598 searcher[ROOT] = root_dir; 651 searcher[ROOT] = root_dir;
599 return 0; 652 return 0;
600 }
601
602 void FILESEARCH::SetXorKey(char *key)
603 {
604 unsigned short int i;
605 for (i=0; i < 16; i++)
606 xor_key[i] = key[i];
607 }
608
609 void FILESEARCH::GuessXorKey(char *regname)
610 {
611 char key1[16] = {
612 0xa8, 0x28, 0xfd, 0x66,
613 0xa0, 0x23, 0x77, 0x69,
614 0xf9, 0x45, 0xf8, 0x2c,
615 0x7c, 0x00, 0xad, 0xf4
616 };
617
618 char key2[16] = {
619 0xAF, 0x2F, 0xFB, 0x6B,
620 0xAF, 0x30, 0x77, 0x17,
621 0x87, 0x48, 0xFE, 0x2C,
622 0x68, 0x1A, 0xB9, 0xF0
623 };
624
625
626 if (strcmp(regname, "KEY\\CLANNAD_FV") == 0) {
627 SetXorKey(key2);
628 }
629 else {
630 SetXorKey(key1);
631 }
632 }
633
634 const char * FILESEARCH::GetXorKey(void)
635 {
636 return xor_key;
637 } 653 }
638 654
639 void FILESEARCH::SetFileInformation(FILETYPE tp, ARCTYPE is_arc, char* filename) { 655 void FILESEARCH::SetFileInformation(FILETYPE tp, ARCTYPE is_arc, char* filename) {
640 int type = tp; 656 int type = tp;
641 if (type < 0 || type >= TYPEMAX) return; 657 if (type < 0 || type >= TYPEMAX) return;
1454 d = ret_data + info.private_data; 1470 d = ret_data + info.private_data;
1455 dend = ret_data + info.filesize; 1471 dend = ret_data + info.filesize;
1456 while(lzExtract(Extract_DataType_SCN2k(), char(), s, d, send, dend)) ; 1472 while(lzExtract(Extract_DataType_SCN2k(), char(), s, d, send, dend)) ;
1457 } 1473 }
1458 if (read_little_endian_int(data+4) == 0x1adb2) { // Little Busters! 1474 if (read_little_endian_int(data+4) == 0x1adb2) { // Little Busters!
1459 const char *decode_key = file_searcher.GetXorKey(); 1475 const char *decode_key = key_holder.GetKey();
1460 int header_size = info.private_data; 1476 int header_size = info.private_data;
1461 for (i=0x100; i<=0x200 && header_size+i < info.filesize; i++) { 1477 for (i=0x100; i<=0x200 && header_size+i < info.filesize; i++) {
1462 ret_data[header_size+i] ^= decode_key[i&0x0f]; 1478 ret_data[header_size+i] ^= decode_key[i&0x0f];
1463 } 1479 }
1464 } 1480 }