Preliminary support for having MasterKey for U/P/J and MasterKey for Korean wii games. Needs testing by someone who has a Korean wii game

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2272 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
LPFaint99 2009-02-16 06:17:21 +00:00
parent daf11ee708
commit 7d3e84c182
4 changed files with 54 additions and 37 deletions

View File

@ -67,6 +67,8 @@
#define WII_MASTERKEY "masterkey.bin" #define WII_MASTERKEY "masterkey.bin"
#define WII_MASTERKEY_HEX "masterkey.txt" #define WII_MASTERKEY_HEX "masterkey.txt"
#define WII_MASTERKEY1 "masterkey1.bin"
#define WII_MASTERKEY1_HEX "masterkey1.txt"
#define WII_EUR_SETTING "setting-eur.txt" #define WII_EUR_SETTING "setting-eur.txt"
#define WII_USA_SETTING "setting-usa.txt" #define WII_USA_SETTING "setting-usa.txt"
#define WII_JAP_SETTING "setting-jpn.txt" #define WII_JAP_SETTING "setting-jpn.txt"
@ -123,6 +125,8 @@
#define WII_MASTERKEY_FILE FULL_WII_SYS_DIR WII_MASTERKEY #define WII_MASTERKEY_FILE FULL_WII_SYS_DIR WII_MASTERKEY
#define WII_MASTERKEY_FILE_HEX FULL_WII_SYS_DIR WII_MASTERKEY_HEX #define WII_MASTERKEY_FILE_HEX FULL_WII_SYS_DIR WII_MASTERKEY_HEX
#define WII_MASTERKEY1_FILE FULL_WII_SYS_DIR WII_MASTERKEY1
#define WII_MASTERKEY1_FILE_HEX FULL_WII_SYS_DIR WII_MASTERKEY1_HEX
#define WII_EUR_SETTING_FILE FULL_WII_SYS_DIR WII_EUR_SETTING #define WII_EUR_SETTING_FILE FULL_WII_SYS_DIR WII_EUR_SETTING
#define WII_USA_SETTING_FILE FULL_WII_SYS_DIR WII_USA_SETTING #define WII_USA_SETTING_FILE FULL_WII_SYS_DIR WII_USA_SETTING
#define WII_JAP_SETTING_FILE FULL_WII_SYS_DIR WII_JAP_SETTING #define WII_JAP_SETTING_FILE FULL_WII_SYS_DIR WII_JAP_SETTING

View File

@ -51,6 +51,7 @@ class IVolume
COUNTRY_FRANCE = 1, COUNTRY_FRANCE = 1,
COUNTRY_USA = 2, COUNTRY_USA = 2,
COUNTRY_JAP, COUNTRY_JAP,
COUNTRY_KOR,
COUNTRY_UNKNOWN, COUNTRY_UNKNOWN,
NUMBER_OF_COUNTRIES NUMBER_OF_COUNTRIES
}; };

View File

@ -63,9 +63,10 @@ private:
}; };
unsigned char g_MasterKey[16]; unsigned char g_MasterKey[16];
bool g_MasterKeyInit = false; unsigned char g_MasterKeyK[16];
bool g_MasterKeyInit[] = {false, false};
IVolume* CreateVolumeFromCryptedWiiImage(IBlobReader& _rReader, u32 _VolumeType); IVolume* CreateVolumeFromCryptedWiiImage(IBlobReader& _rReader, u32 _VolumeType, bool Korean);
EDiscType GetDiscType(IBlobReader& _rReader); EDiscType GetDiscType(IBlobReader& _rReader);
IVolume* CreateVolumeFromFilename(const std::string& _rFilename) IVolume* CreateVolumeFromFilename(const std::string& _rFilename)
@ -77,27 +78,30 @@ IVolume* CreateVolumeFromFilename(const std::string& _rFilename)
switch (GetDiscType(*pReader)) switch (GetDiscType(*pReader))
{ {
case DISC_TYPE_WII: case DISC_TYPE_WII:
case DISC_TYPE_GC: case DISC_TYPE_GC:
return new CVolumeGC(pReader); return new CVolumeGC(pReader);
case DISC_TYPE_WII_CONTAINER: case DISC_TYPE_WII_CONTAINER:
{ {
IVolume* pVolume = CreateVolumeFromCryptedWiiImage(*pReader, 0); u8 region;
pReader->Read(0x3,1,&region);
if (pVolume == NULL) IVolume* pVolume = CreateVolumeFromCryptedWiiImage(*pReader, 0, region == 'K');
{
delete pReader;
}
return(pVolume); if (pVolume == NULL)
} {
break; delete pReader;
}
case DISC_TYPE_UNK: return(pVolume);
default: }
delete pReader; break;
return NULL;
case DISC_TYPE_UNK:
default:
delete pReader;
return NULL;
} }
// unreachable code // unreachable code
@ -120,26 +124,29 @@ bool IsVolumeWiiDisc(const IVolume *_rVolume)
return (Common::swap32(MagicWord) == 0x5D1C9EA3); return (Common::swap32(MagicWord) == 0x5D1C9EA3);
} }
IVolume* CreateVolumeFromCryptedWiiImage(IBlobReader& _rReader, u32 _VolumeType) IVolume* CreateVolumeFromCryptedWiiImage(IBlobReader& _rReader, u32 _VolumeType, bool Korean)
{ {
if (!g_MasterKeyInit) if (!g_MasterKeyInit[Korean ? 1 : 0])
{ {
FILE* pT = fopen(WII_MASTERKEY_FILE, "rb"); const char * MasterKeyFile = Korean ? WII_MASTERKEY1_FILE : WII_MASTERKEY_FILE;
const char * MasterKeyFileHex = Korean ? WII_MASTERKEY1_FILE_HEX : WII_MASTERKEY_FILE_HEX;
FILE* pT = fopen(MasterKeyFile, "rb");
if (pT == NULL) if (pT == NULL)
{ {
if(PanicYesNo("Can't open '" WII_MASTERKEY_FILE "'.\n If you know the key, now it's the time to paste it into '" if(PanicYesNo("Can't open '%s'.\n If you know the key, now it's the time to paste it into "
WII_MASTERKEY_FILE_HEX "' before pressing [YES].")) "'%s' before pressing [YES].", MasterKeyFile, MasterKeyFileHex))
{ {
pT = fopen(WII_MASTERKEY_FILE_HEX, "r"); pT = fopen(MasterKeyFileHex, "r");
if(pT==NULL){ if(pT==NULL){
PanicAlert("could not open " WII_MASTERKEY_FILE_HEX ); PanicAlert("could not open %s", MasterKeyFileHex);
return NULL; return NULL;
} }
static char hexkey[32]; static char hexkey[32];
if(fread(hexkey,1,32,pT)<32) if(fread(hexkey,1,32,pT)<32)
{ {
PanicAlert(WII_MASTERKEY_FILE_HEX " is not the right size" ); PanicAlert("%s is not the right size", MasterKeyFileHex);
fclose(pT); fclose(pT);
return NULL; return NULL;
} }
@ -153,18 +160,18 @@ IVolume* CreateVolumeFromCryptedWiiImage(IBlobReader& _rReader, u32 _VolumeType)
binkey[i] = (char) strtol(h,NULL,16); binkey[i] = (char) strtol(h,NULL,16);
} }
pT = fopen(WII_MASTERKEY_FILE, "wb"); pT = fopen(MasterKeyFile, "wb");
if(pT==NULL){ if(pT==NULL){
PanicAlert("could not open/make '" WII_MASTERKEY_FILE "' for writing!"); PanicAlert("could not open/make '%s' for writing!", MasterKeyFile);
return NULL; return NULL;
} }
fwrite(binkey,16,1,pT); fwrite(binkey,16,1,pT);
fclose(pT); fclose(pT);
pT = fopen(WII_MASTERKEY_FILE, "rb"); pT = fopen(MasterKeyFileHex, "rb");
if(pT==NULL){ if(pT==NULL){
PanicAlert("could not open '" WII_MASTERKEY_FILE "' for reading!\n did the file get deleted or locked after converting?"); PanicAlert("could not open '%s' for reading!\n did the file get deleted or locked after converting?", MasterKeyFileHex);
return NULL; return NULL;
} }
} }
@ -172,14 +179,15 @@ IVolume* CreateVolumeFromCryptedWiiImage(IBlobReader& _rReader, u32 _VolumeType)
return NULL; return NULL;
} }
fread(g_MasterKey, 16, 1, pT); fread(Korean ? g_MasterKeyK : g_MasterKey, 16, 1, pT);
fclose(pT); fclose(pT);
const u32 keyhash = 0x4bc30936; const u32 keyhash = 0x4bc30936;
u32 hash = HashAdler32(g_MasterKey, 16); const u32 keyhashK = 0x485c08e9;
if (hash != keyhash) u32 hash = HashAdler32(Korean ? g_MasterKeyK : g_MasterKey, 16);
PanicAlert("Your Wii disc decryption key is bad.", keyhash, hash); if (hash != (Korean ? keyhashK : keyhash))
PanicAlert("Your Wii %sdisc decryption key is bad.", Korean ? "Korean " : "",keyhash, hash);
else else
g_MasterKeyInit = true; g_MasterKeyInit[Korean ? 1 : 0] = true;
} }
CBlobBigEndianReader Reader(_rReader); CBlobBigEndianReader Reader(_rReader);
@ -219,7 +227,7 @@ IVolume* CreateVolumeFromCryptedWiiImage(IBlobReader& _rReader, u32 _VolumeType)
_rReader.Read(rPartition.Offset + 0x44c, 8, IV); _rReader.Read(rPartition.Offset + 0x44c, 8, IV);
AES_KEY AES_KEY; AES_KEY AES_KEY;
AES_set_decrypt_key(g_MasterKey, 128, &AES_KEY); AES_set_decrypt_key((Korean ? g_MasterKeyK : g_MasterKey), 128, &AES_KEY);
u8 VolumeKey[16]; u8 VolumeKey[16];
AES_cbc_encrypt(SubKey, VolumeKey, 16, &AES_KEY, IV, AES_DECRYPT); AES_cbc_encrypt(SubKey, VolumeKey, 16, &AES_KEY, IV, AES_DECRYPT);

View File

@ -150,6 +150,10 @@ CVolumeWiiCrypted::GetCountry() const
country = COUNTRY_JAP; country = COUNTRY_JAP;
break; // JAP break; // JAP
case 'K':
country = COUNTRY_KOR;
break; // KOR
case 'O': case 'O':
country = COUNTRY_UNKNOWN; country = COUNTRY_UNKNOWN;
break; // SDK break; // SDK