diff options
Diffstat (limited to 'utils/zenutils/source')
-rw-r--r-- | utils/zenutils/source/shared/updater.cpp | 16 | ||||
-rw-r--r-- | utils/zenutils/source/zen_crypt/CMakeLists.txt | 2 | ||||
-rw-r--r-- | utils/zenutils/source/zen_crypt/main.cpp | 60 |
3 files changed, 52 insertions, 26 deletions
diff --git a/utils/zenutils/source/shared/updater.cpp b/utils/zenutils/source/shared/updater.cpp index 7efac3d373..6f200e3da4 100644 --- a/utils/zenutils/source/shared/updater.cpp +++ b/utils/zenutils/source/shared/updater.cpp | |||
@@ -115,18 +115,18 @@ bool zen::crypt_firmware(const char* key, byte* buffer, size_t len) | |||
115 | 115 | ||
116 | return true; | 116 | return true; |
117 | #else | 117 | #else |
118 | // Determine if the key length is dword aligned. | 118 | /* Determine if the key length is dword aligned. */ |
119 | int keylen = strlen(key); | 119 | int keylen = strlen(key); |
120 | int keylen_rem = keylen % sizeof(dword); | 120 | int keylen_rem = keylen % sizeof(dword); |
121 | 121 | ||
122 | // Determine how many times the key must be repeated to be dword aligned. | 122 | /* Determine how many times the key must be repeated to be dword aligned. */ |
123 | int keycycle = keylen_rem ? (sizeof(dword) / keylen_rem) : 1; | 123 | int keycycle = keylen_rem ? (sizeof(dword) / keylen_rem) : 1; |
124 | int keyscount = (keylen * keycycle) / sizeof(dword); | 124 | int keyscount = (keylen * keycycle) / sizeof(dword); |
125 | 125 | ||
126 | // Allocate a buffer to hold the key as an array of dwords. | 126 | /* Allocate a buffer to hold the key as an array of dwords. */ |
127 | dword* keys = new dword[keyscount]; | 127 | dword* keys = new dword[keyscount]; |
128 | 128 | ||
129 | // Copy the key into the key array, whilst mutating it. | 129 | /* Copy the key into the key array, whilst mutating it. */ |
130 | for (int i = 0; i < keyscount; i++) | 130 | for (int i = 0; i < keyscount; i++) |
131 | { | 131 | { |
132 | dword val; | 132 | dword val; |
@@ -145,19 +145,19 @@ bool zen::crypt_firmware(const char* key, byte* buffer, size_t len) | |||
145 | keys[i] = (val - 0x01010101) | 0x80808080; | 145 | keys[i] = (val - 0x01010101) | 0x80808080; |
146 | } | 146 | } |
147 | 147 | ||
148 | // Determine the number of dwords in the buffer. | 148 | /* Determine the number of dwords in the buffer. */ |
149 | int len_div = len / sizeof(dword); | 149 | int len_div = len / sizeof(dword); |
150 | 150 | ||
151 | // Decrypt all dwords of the buffer. | 151 | /* Decrypt all dwords of the buffer. */ |
152 | for (int i = 0; i < len_div; i++) | 152 | for (int i = 0; i < len_div; i++) |
153 | { | 153 | { |
154 | ((dword*)buffer)[i] ^= keys[i % keyscount]; | 154 | ((dword*)buffer)[i] ^= keys[i % keyscount]; |
155 | } | 155 | } |
156 | 156 | ||
157 | // Determine the remaining number of bytes in the buffer. | 157 | /* Determine the remaining number of bytes in the buffer. */ |
158 | int len_rem = len % sizeof(dword); | 158 | int len_rem = len % sizeof(dword); |
159 | 159 | ||
160 | // Decrypt the remaining number of bytes in the buffer. | 160 | /* Decrypt the remaining number of bytes in the buffer. */ |
161 | for (int i = len_div * sizeof(dword); i < len; i++) | 161 | for (int i = len_div * sizeof(dword); i < len; i++) |
162 | { | 162 | { |
163 | buffer[i] ^= ((key[i % keylen] - 0x01) | 0x80); | 163 | buffer[i] ^= ((key[i % keylen] - 0x01) | 0x80); |
diff --git a/utils/zenutils/source/zen_crypt/CMakeLists.txt b/utils/zenutils/source/zen_crypt/CMakeLists.txt index 5721bbfa06..c0e9d3ee12 100644 --- a/utils/zenutils/source/zen_crypt/CMakeLists.txt +++ b/utils/zenutils/source/zen_crypt/CMakeLists.txt | |||
@@ -1,4 +1,6 @@ | |||
1 | ADD_EXECUTABLE(zen_crypt main.cpp) | 1 | ADD_EXECUTABLE(zen_crypt main.cpp) |
2 | 2 | ||
3 | SET_SOURCE_FILES_PROPERTIES(main.cpp PROPERTIES COMPILE_FLAGS -Wno-multichar) | ||
4 | |||
3 | TARGET_LINK_LIBRARIES(zen_crypt shared) | 5 | TARGET_LINK_LIBRARIES(zen_crypt shared) |
4 | TARGET_LINK_LIBRARIES(zen_crypt beecrypt) | 6 | TARGET_LINK_LIBRARIES(zen_crypt beecrypt) |
diff --git a/utils/zenutils/source/zen_crypt/main.cpp b/utils/zenutils/source/zen_crypt/main.cpp index 532de25078..3442baf738 100644 --- a/utils/zenutils/source/zen_crypt/main.cpp +++ b/utils/zenutils/source/zen_crypt/main.cpp | |||
@@ -46,12 +46,12 @@ enum mode_t | |||
46 | struct player_info_t | 46 | struct player_info_t |
47 | { | 47 | { |
48 | const char* name; | 48 | const char* name; |
49 | const char* null_key; // HMAC-SHA1 key | 49 | const char* null_key; /* HMAC-SHA1 key */ |
50 | const char* fresc_key; // BlowFish key | 50 | const char* fresc_key; /* BlowFish key */ |
51 | const char* tl_key; // BlowFish key | 51 | const char* tl_key; /* BlowFish key */ |
52 | bool big_endian; | 52 | bool big_endian; |
53 | }; | 53 | }; |
54 | }; //namespace | 54 | }; /* namespace */ |
55 | 55 | ||
56 | 56 | ||
57 | static const char VERSION[] = "0.2"; | 57 | static const char VERSION[] = "0.2"; |
@@ -210,7 +210,7 @@ bool sign(shared::bytes& data, player_info_t* pi, const std::string& file, | |||
210 | if (index) | 210 | if (index) |
211 | { | 211 | { |
212 | if (verbose) | 212 | if (verbose) |
213 | std::cout << "[*] Found NULL signature at: " | 213 | std::cout << "[*] Found NULL signature at: 0x" |
214 | << std::hex << index << std::endl; | 214 | << std::hex << index << std::endl; |
215 | 215 | ||
216 | if (verbose) | 216 | if (verbose) |
@@ -317,7 +317,7 @@ bool verify(shared::bytes& data, player_info_t* pi, bool verbose) | |||
317 | return false; | 317 | return false; |
318 | } | 318 | } |
319 | if (verbose) | 319 | if (verbose) |
320 | std::cout << "[*] Found NULL signature at: " | 320 | std::cout << "[*] Found NULL signature at: 0x" |
321 | << std::hex << index << std::endl; | 321 | << std::hex << index << std::endl; |
322 | 322 | ||
323 | if (verbose) | 323 | if (verbose) |
@@ -382,8 +382,26 @@ bool encrypt(shared::bytes& data, int mode, player_info_t* pi, | |||
382 | } | 382 | } |
383 | else if (mode == mode_fresc) | 383 | else if (mode == mode_fresc) |
384 | { | 384 | { |
385 | std::cerr << "FRESC mode is not supported." << std::endl; | 385 | if (verbose) |
386 | return false; | 386 | std::cout << "[*] Encrypting input file..." << std::endl; |
387 | |||
388 | dword iv[2] = {shared::swap(data.size()), 0}; | ||
389 | if (!zen::bf_cbc_encrypt((const byte*)pi->fresc_key, | ||
390 | strlen(pi->fresc_key)+1, &data[0], | ||
391 | data.size(), (const byte*)iv)) | ||
392 | { | ||
393 | std::cerr << "Failed to encrypt the input file." << std::endl; | ||
394 | return false; | ||
395 | } | ||
396 | |||
397 | if (verbose) | ||
398 | std::cout << "[*] Writing file data..." << std::endl; | ||
399 | |||
400 | if (!shared::write_file(file, data, true)) | ||
401 | { | ||
402 | std::cerr << "Failed to save the output file." << std::endl; | ||
403 | return false; | ||
404 | } | ||
387 | } | 405 | } |
388 | else if (mode == mode_tl) | 406 | else if (mode == mode_tl) |
389 | { | 407 | { |
@@ -413,7 +431,7 @@ bool encrypt(shared::bytes& data, int mode, player_info_t* pi, | |||
413 | if (!zen::bf_cbc_encrypt((const byte*)pi->tl_key, strlen(pi->tl_key)+1, | 431 | if (!zen::bf_cbc_encrypt((const byte*)pi->tl_key, strlen(pi->tl_key)+1, |
414 | &outbuf[0], len, (const byte*)iv)) | 432 | &outbuf[0], len, (const byte*)iv)) |
415 | { | 433 | { |
416 | std::cerr << "Failed to decrypt the input file." << std::endl; | 434 | std::cerr << "Failed to encrypt the input file." << std::endl; |
417 | return false; | 435 | return false; |
418 | } | 436 | } |
419 | 437 | ||
@@ -540,9 +558,11 @@ bool decrypt(shared::bytes& data, int mode, player_info_t* pi, | |||
540 | 558 | ||
541 | int process_arguments(int argc, char*argv[]) | 559 | int process_arguments(int argc, char*argv[]) |
542 | { | 560 | { |
543 | //-------------------------------------------------------------------- | 561 | /* |
544 | // Parse input variables. | 562 | -------------------------------------------------------------------- |
545 | //-------------------------------------------------------------------- | 563 | Parse input variables. |
564 | -------------------------------------------------------------------- | ||
565 | */ | ||
546 | 566 | ||
547 | GetPot cl(argc, argv); | 567 | GetPot cl(argc, argv); |
548 | if (cl.size() == 1 || cl.search(2, "-h", "--help")) | 568 | if (cl.size() == 1 || cl.search(2, "-h", "--help")) |
@@ -636,9 +656,11 @@ int process_arguments(int argc, char*argv[]) | |||
636 | pi->big_endian = big_endian; | 656 | pi->big_endian = big_endian; |
637 | 657 | ||
638 | 658 | ||
639 | //-------------------------------------------------------------------- | 659 | /* |
640 | // Read the input file. | 660 | -------------------------------------------------------------------- |
641 | //-------------------------------------------------------------------- | 661 | Read the input file. |
662 | -------------------------------------------------------------------- | ||
663 | */ | ||
642 | 664 | ||
643 | if (verbose) | 665 | if (verbose) |
644 | std::cout << "[*] Reading input file..." << std::endl; | 666 | std::cout << "[*] Reading input file..." << std::endl; |
@@ -651,9 +673,11 @@ int process_arguments(int argc, char*argv[]) | |||
651 | } | 673 | } |
652 | 674 | ||
653 | 675 | ||
654 | //-------------------------------------------------------------------- | 676 | /* |
655 | // Process the input file. | 677 | -------------------------------------------------------------------- |
656 | //-------------------------------------------------------------------- | 678 | Process the input file. |
679 | -------------------------------------------------------------------- | ||
680 | */ | ||
657 | 681 | ||
658 | switch (command) | 682 | switch (command) |
659 | { | 683 | { |