Skip to content

Commit d473064

Browse files
author
LawnMeower
committed
added de/encryption support for the jpn file. also fixed a minor error
1 parent 4d60e75 commit d473064

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

Line__Crypt.exe

512 Bytes
Binary file not shown.

Line__Crypt.h

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,21 @@ namespace Line__Crypt
6262
return size;
6363
}
6464

65-
static void Decrypt(void* file, uint32_t fileSize)
65+
static void Decrypt(void* file, uint32_t fileSize, bool isJPN)
6666
{
6767
//prepare key values and parameters
68-
int key0 = 0x000cd8f3;
69-
int key1 = 0x9b36bb94;
70-
int key2 = 0xaf8910be;
68+
int saltUSA = 0x180a;
69+
int saltJPN = 0x0ce0;
7170
int salt = 0;
71+
int key0USA = 0x000cd8f3;
72+
int key0JPN = 0x0004f107;
73+
int key0 = isJPN ? key0JPN : key0USA;
74+
int key1USA = 0x9b36bb94;
75+
int key1JPN = 0xb5fb6483;
76+
int key1 = isJPN ? key1JPN : key1USA;
77+
int key2USA = 0xaf8910be;
78+
int key2JPN = 0xdeaddead;
79+
int key2 = isJPN ? key2JPN : key2USA;
7280
int fileSizeExtended = (fileSize + 0x1f) & ~0; //filesize next multiple of 0x20
7381
int fileLocation = reinterpret_cast<int>(file);
7482
int r8 = rlwinm(fileSizeExtended, 30, 2, 31);
@@ -83,7 +91,7 @@ namespace Line__Crypt
8391
{
8492
//decrypting 1st 4 bytes of 0x20 bytes block
8593
int keyProd = key2 * key1;
86-
salt = 0x180a;
94+
salt = isJPN ? saltJPN : saltUSA;
8795
r3 = lwz(0, rwLocation);
8896
int r29 = keyProd + key0;
8997
r3 ^= r29;
@@ -176,14 +184,14 @@ namespace Line__Crypt
176184
return;
177185

178186
//set parameters for last block processing
179-
r3 = 0x9b370000;
187+
r3 = isJPN ? 0xb5fb0000 : 0x9b370000;
180188
int r4 = rlwinm(cryptedWords, 2, 0, 29);
181-
r11 = r3, (short)0xbb94;
189+
r11 = r3 + isJPN ? (short)0x6483 : (short)0xbb94;
182190
r3 = 0x000d0000;
183191
int r0 = r8 - cryptedWords;
184192
rwLocation = fileLocation + r4;
185-
r3 += (short)0xd8f3;
186-
salt = 0x180a;
193+
r3 += isJPN ? (short)0xf107 : (short)0xd8f3;
194+
salt = isJPN ? saltJPN : saltUSA;
187195

188196
//crypt last block
189197
for (int i = r0; i > 0; --i)

main.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#include"Line__Crypt.h"
2+
#include <algorithm>
23

34
int wmain(int argc, wchar_t** argv)
45
{
5-
if (argc <= 1)
6+
if (argc <= 2)
67
{
78
std::cout << "empty argument";
89
return 3;
@@ -19,9 +20,12 @@ int wmain(int argc, wchar_t** argv)
1920
return 1;
2021
}
2122

22-
Line__Crypt::Decrypt(file, size);
23+
std::wstring region(argv[2]);
24+
std::transform(region.begin(), region.end(), region.begin(), towupper);
25+
bool isJPN = !(bool)region.compare(L"JPN");
26+
27+
Line__Crypt::Decrypt(file, size, isJPN);
2328

24-
std::wcout << "bleh " << path.substr(0, path.length() - 3);
2529
if (!path.substr(path.length() - 3).compare(L"bin"))
2630
{
2731
path = path.substr(0, path.length() - 3).append(L"rel.lz");

0 commit comments

Comments
 (0)