Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #3152 from ShadowsFriend/ipl_checksum
Use CRC32 for IPL checks and update hashes
  • Loading branch information
Parlane committed Nov 20, 2015
2 parents f571bdd + 5fbf8f5 commit 0e258d4
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions Source/Core/Core/Boot/Boot.cpp
Expand Up @@ -4,10 +4,11 @@

#include <vector>

#include <zlib.h>

#include "Common/CommonPaths.h"
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
#include "Common/Hash.h"
#include "Common/MathUtil.h"
#include "Common/StringUtil.h"

Expand Down Expand Up @@ -161,30 +162,37 @@ bool CBoot::LoadMapFromFilename()
// It does not initialize the hardware or anything else like BS1 does.
bool CBoot::Load_BS2(const std::string& _rBootROMFilename)
{
const u32 USA = 0x1FCE3FD6;
const u32 USA_v1_1 = 0x4D5935D1;
const u32 JAP = 0x87424396;
const u32 PAL = 0xA0EA7341;
//const u32 PanasonicQJ = 0xAEA8265C;
//const u32 PanasonicQU = 0x94015753;
// CRC32
const u32 USA_v1_0 = 0x6D740AE7; // https://forums.dolphin-emu.org/Thread-unknown-hash-on-ipl-bin?pid=385344#pid385344
const u32 USA_v1_1 = 0xD5E6FEEA; // https://forums.dolphin-emu.org/Thread-unknown-hash-on-ipl-bin?pid=385334#pid385334
const u32 USA_v1_2 = 0x86573808; // https://forums.dolphin-emu.org/Thread-unknown-hash-on-ipl-bin?pid=385399#pid385399
const u32 JAP_v1_0 = 0x6DAC1F2A; // Redump
const u32 JAP_v1_1 = 0xD235E3F9; // https://bugs.dolphin-emu.org/issues/8936
const u32 PAL_v1_0 = 0x4F319F43; // Redump
const u32 PAL_v1_2 = 0xAD1B7F16; // Redump

// Load the whole ROM dump
std::string data;
if (!File::ReadFileToString(_rBootROMFilename, data))
return false;

u32 ipl_hash = HashAdler32((const u8*)data.data(), data.size());
// Use zlibs crc32 implementation to compute the hash
u32 ipl_hash = crc32(0L, Z_NULL, 0);
ipl_hash = crc32(ipl_hash, (const Bytef*)data.data(), (u32)data.size());
std::string ipl_region;
switch (ipl_hash)
{
case USA:
case USA_v1_0:
case USA_v1_1:
case USA_v1_2:
ipl_region = USA_DIR;
break;
case JAP:
case JAP_v1_0:
case JAP_v1_1:
ipl_region = JAP_DIR;
break;
case PAL:
case PAL_v1_0:
case PAL_v1_2:
ipl_region = EUR_DIR;
break;
default:
Expand Down

0 comments on commit 0e258d4

Please sign in to comment.