Added generation of serial number for dolphin, we found problems with games like Fifa 11 who tie their user accounts to certain serial numbers.

This commit is contained in:
Matthew Parlane 2012-01-29 21:41:35 +13:00
parent 42e8c6c17f
commit 289cb5db95
5 changed files with 629 additions and 427 deletions

View File

@ -203,7 +203,7 @@
<ClCompile Include="Src\Boot\Boot_ELF.cpp" /> <ClCompile Include="Src\Boot\Boot_ELF.cpp" />
<ClCompile Include="Src\Boot\Boot_WiiWAD.cpp" /> <ClCompile Include="Src\Boot\Boot_WiiWAD.cpp" />
<ClCompile Include="Src\Boot\ElfReader.cpp" /> <ClCompile Include="Src\Boot\ElfReader.cpp" />
<ClCompile Include="Src\Boot\SettingsGenerator.cpp" /> <ClCompile Include="Src\Boot\SettingsHandler.cpp" />
<ClCompile Include="Src\ConfigManager.cpp" /> <ClCompile Include="Src\ConfigManager.cpp" />
<ClCompile Include="Src\Console.cpp" /> <ClCompile Include="Src\Console.cpp" />
<ClCompile Include="Src\Core.cpp" /> <ClCompile Include="Src\Core.cpp" />
@ -408,7 +408,7 @@
<ClInclude Include="Src\Boot\Boot_ELF.h" /> <ClInclude Include="Src\Boot\Boot_ELF.h" />
<ClInclude Include="Src\Boot\ElfReader.h" /> <ClInclude Include="Src\Boot\ElfReader.h" />
<ClInclude Include="Src\Boot\ElfTypes.h" /> <ClInclude Include="Src\Boot\ElfTypes.h" />
<ClInclude Include="Src\Boot\SettingsGenerator.h" /> <ClInclude Include="Src\Boot\SettingsHandler.h" />
<ClInclude Include="Src\ConfigManager.h" /> <ClInclude Include="Src\ConfigManager.h" />
<ClInclude Include="Src\Console.h" /> <ClInclude Include="Src\Console.h" />
<ClInclude Include="Src\Core.h" /> <ClInclude Include="Src\Core.h" />

View File

@ -559,7 +559,7 @@
<ClCompile Include="Src\HW\GCMemcard.cpp"> <ClCompile Include="Src\HW\GCMemcard.cpp">
<Filter>HW %28Flipper/Hollywood%29\GCMemcard</Filter> <Filter>HW %28Flipper/Hollywood%29\GCMemcard</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Src\Boot\SettingsGenerator.cpp"> <ClCompile Include="Src\Boot\SettingsHandler.cpp">
<Filter>Boot</Filter> <Filter>Boot</Filter>
</ClCompile> </ClCompile>
</ItemGroup> </ItemGroup>
@ -1045,7 +1045,7 @@
<ClInclude Include="Src\IPC_HLE\fakepoll.h"> <ClInclude Include="Src\IPC_HLE\fakepoll.h">
<Filter>IPC HLE %28IOS/Starlet%29\Net</Filter> <Filter>IPC HLE %28IOS/Starlet%29\Net</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Src\Boot\SettingsGenerator.h"> <ClInclude Include="Src\Boot\SettingsHandler.h">
<Filter>Boot</Filter> <Filter>Boot</Filter>
</ClInclude> </ClInclude>
</ItemGroup> </ItemGroup>

View File

@ -36,7 +36,7 @@
#include "VolumeCreator.h" #include "VolumeCreator.h"
#include "Boot.h" #include "Boot.h"
#include "HLE/HLE.h" #include "HLE/HLE.h"
#include "SettingsGenerator.h" #include "SettingsHandler.h"
void CBoot::RunFunction(u32 _iAddr) void CBoot::RunFunction(u32 _iAddr)
{ {
@ -217,21 +217,37 @@ bool CBoot::SetupWiiMemory(unsigned int _CountryCode)
code = "L" + area.substr(0,1); code = "L" + area.substr(0,1);
game = area.substr(0,2); game = area.substr(0,2);
SettingsGenerator gen;
SettingsHandler gen;
std::string serno = "";
if (File::Exists(settings_Filename))
{
File::IOFile settingsFileHandle(settings_Filename, "rb");
if(settingsFileHandle.ReadBytes((void*)gen.GetData(), SETTINGS_SIZE)){
gen.Decrypt();
serno = gen.GetValue("SERNO");
gen.Reset();
}
File::Delete(settings_Filename);
}
if(serno.empty() || serno == "000000000"){
serno = gen.generateSerialNumber();
INFO_LOG(BOOT, "No previous serial number found, generated one instead: %s", serno.c_str());
}else{
INFO_LOG(BOOT, "Using serial number: %s", serno.c_str());
}
gen.AddSetting("AREA", area.c_str()); gen.AddSetting("AREA", area.c_str());
gen.AddSetting("MODEL", model.c_str()); gen.AddSetting("MODEL", model.c_str());
gen.AddSetting("DVD", "0"); gen.AddSetting("DVD", "0");
gen.AddSetting("MPCH", "0x7FFE"); gen.AddSetting("MPCH", "0x7FFE");
gen.AddSetting("CODE", code.c_str()); gen.AddSetting("CODE", code.c_str());
gen.AddSetting("SERNO", "000000000"); gen.AddSetting("SERNO", serno.c_str());
gen.AddSetting("VIDEO", video.c_str()); gen.AddSetting("VIDEO", video.c_str());
gen.AddSetting("GAME", game.c_str()); gen.AddSetting("GAME", game.c_str());
if (File::Exists(settings_Filename))
{
File::Delete(settings_Filename);
}
File::CreateFullPath(settings_Filename); File::CreateFullPath(settings_Filename);
{ {

View File

@ -0,0 +1,136 @@
// Copyright (C) 2003 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
// Thanks to Treeki for writing the original class - 29/01/2012
#include "Common.h"
#include "CommonPaths.h"
#include "Timer.h"
#include "SettingsHandler.h"
#include <time.h>
#ifdef _WIN32
#include <Windows.h>
#include <mmsystem.h>
#include <sys/timeb.h>
#else
#include <sys/time.h>
#endif
SettingsHandler::SettingsHandler()
{
Reset();
}
const u8* SettingsHandler::GetData() const
{
return m_buffer;
}
const std::string SettingsHandler::GetValue(std::string key)
{
std::string delim = std::string("\r\n");
std::string toFind = delim + key + "=";
size_t found = decoded.find(toFind);
if (found!=std::string::npos){
size_t delimFound = decoded.find(delim, found+toFind.length());
if (delimFound == std::string::npos)
delimFound = decoded.length()-1;
return decoded.substr(found+toFind.length(), delimFound - (found+toFind.length()));
}else{
toFind = key + "=";
size_t found = decoded.find(toFind);
if (found==0){
size_t delimFound = decoded.find(delim, found+toFind.length());
if (delimFound == std::string::npos)
delimFound = decoded.length()-1;
return decoded.substr(found+toFind.length(), delimFound - (found+toFind.length()));
}
}
return "";
}
void SettingsHandler::Decrypt()
{
const u8 *str = m_buffer;
while(*str != 0){
if (m_position >= SETTINGS_SIZE)
return;
decoded.push_back((u8)(m_buffer[m_position] ^ m_key));
m_position++;
str++;
m_key = ((m_key >> 31) | (m_key << 1));
}
}
void SettingsHandler::Reset()
{
decoded = "";
m_position = 0;
m_key = 0x73B5DBFA;
memset(m_buffer, 0, SETTINGS_SIZE);
}
void SettingsHandler::AddSetting(const char *key, const char *value)
{
while (*key != 0)
{
WriteByte(*key);
key++;
}
WriteByte('=');
while (*value != 0)
{
WriteByte(*value);
value++;
}
WriteByte(13);
WriteByte(10);
}
void SettingsHandler::WriteByte(u8 b)
{
if (m_position >= SETTINGS_SIZE)
return;
m_buffer[m_position] = b ^ m_key;
m_position++;
m_key = ((m_key >> 31) | (m_key << 1));
}
std::string SettingsHandler::generateSerialNumber()
{
time_t rawtime;
struct tm * timeinfo;
char buffer [12];
char serialNumber [12];
time ( &rawtime );
timeinfo = localtime ( &rawtime );
strftime (buffer,11,"%j%H%M%S",timeinfo);
snprintf(serialNumber,11, "%s%i", buffer, (Common::Timer::GetTimeMs()>>1)&0xF);
serialNumber[10] = 0;
return std::string(serialNumber);
}

View File

@ -0,0 +1,50 @@
// Copyright (C) 2003 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
// Thanks to Treeki for writing the original class - 29/01/2012
#ifndef _SETTINGS_HANDLER_H
#define _SETTINGS_HANDLER_H
#include <string>
#include "Common.h"
#include "../CoreParameter.h"
#define SETTINGS_SIZE 0x100
class SettingsHandler
{
public:
SettingsHandler();
void AddSetting(const char *key, const char *value);
const u8 *GetData() const;
const std::string GetValue(std::string key);
void Decrypt();
void Reset();
std::string generateSerialNumber();
private:
void WriteByte(u8 b);
u8 m_buffer[SETTINGS_SIZE];
u32 m_position, m_key;
std::string decoded;
};
#endif