move SettingsHandler to Common lib

This commit is contained in:
Shawn Hoffman 2012-02-09 21:04:07 -08:00
parent c8129bc802
commit ac0883044e
9 changed files with 96 additions and 97 deletions

View File

@ -15,6 +15,7 @@ set(SRCS Src/ABI.cpp
Src/Misc.cpp Src/Misc.cpp
Src/MsgHandler.cpp Src/MsgHandler.cpp
Src/NandPaths.cpp Src/NandPaths.cpp
Src/SettingsHandler.cpp
Src/SDCardUtil.cpp Src/SDCardUtil.cpp
Src/StringUtil.cpp Src/StringUtil.cpp
Src/SymbolDB.cpp Src/SymbolDB.cpp

View File

@ -195,6 +195,7 @@
<ClCompile Include="Src\MsgHandler.cpp" /> <ClCompile Include="Src\MsgHandler.cpp" />
<ClCompile Include="Src\NandPaths.cpp" /> <ClCompile Include="Src\NandPaths.cpp" />
<ClCompile Include="Src\SDCardUtil.cpp" /> <ClCompile Include="Src\SDCardUtil.cpp" />
<ClCompile Include="Src\SettingsHandler.cpp" />
<ClCompile Include="Src\stdafx.cpp"> <ClCompile Include="Src\stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
@ -251,6 +252,7 @@
<ClInclude Include="Src\MsgHandler.h" /> <ClInclude Include="Src\MsgHandler.h" />
<ClInclude Include="Src\NandPaths.h" /> <ClInclude Include="Src\NandPaths.h" />
<ClInclude Include="Src\SDCardUtil.h" /> <ClInclude Include="Src\SDCardUtil.h" />
<ClInclude Include="Src\SettingsHandler.h" />
<ClInclude Include="Src\Setup.h" /> <ClInclude Include="Src\Setup.h" />
<ClInclude Include="Src\stdafx.h" /> <ClInclude Include="Src\stdafx.h" />
<ClInclude Include="Src\StdConditionVariable.h" /> <ClInclude Include="Src\StdConditionVariable.h" />

View File

@ -53,6 +53,7 @@
<ClCompile Include="Src\Crypto\sha1.cpp"> <ClCompile Include="Src\Crypto\sha1.cpp">
<Filter>Crypto</Filter> <Filter>Crypto</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Src\SettingsHandler.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Src\ABI.h" /> <ClInclude Include="Src\ABI.h" />
@ -121,6 +122,7 @@
</ClInclude> </ClInclude>
<ClInclude Include="Src\StdMutex.h" /> <ClInclude Include="Src\StdMutex.h" />
<ClInclude Include="Src\StdConditionVariable.h" /> <ClInclude Include="Src\StdConditionVariable.h" />
<ClInclude Include="Src\SettingsHandler.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="CMakeLists.txt" /> <None Include="CMakeLists.txt" />

View File

@ -42,22 +42,27 @@ const u8* SettingsHandler::GetData() const
return m_buffer; return m_buffer;
} }
const std::string SettingsHandler::GetValue(std::string key) const std::string SettingsHandler::GetValue(const std::string key)
{ {
std::string delim = std::string("\r\n"); std::string delim = std::string("\r\n");
std::string toFind = delim + key + "="; std::string toFind = delim + key + "=";
size_t found = decoded.find(toFind); size_t found = decoded.find(toFind);
if (found!=std::string::npos){
if (found != decoded.npos)
{
size_t delimFound = decoded.find(delim, found + toFind.length()); size_t delimFound = decoded.find(delim, found + toFind.length());
if (delimFound == std::string::npos) if (delimFound == decoded.npos)
delimFound = decoded.length() - 1; delimFound = decoded.length() - 1;
return decoded.substr(found + toFind.length(), delimFound - (found + toFind.length())); return decoded.substr(found + toFind.length(), delimFound - (found + toFind.length()));
}else{ }
else
{
toFind = key + "="; toFind = key + "=";
size_t found = decoded.find(toFind); size_t found = decoded.find(toFind);
if (found==0){ if (found == 0)
{
size_t delimFound = decoded.find(delim, found + toFind.length()); size_t delimFound = decoded.find(delim, found + toFind.length());
if (delimFound == std::string::npos) if (delimFound == decoded.npos)
delimFound = decoded.length() - 1; delimFound = decoded.length() - 1;
return decoded.substr(found + toFind.length(), delimFound - (found + toFind.length())); return decoded.substr(found + toFind.length(), delimFound - (found + toFind.length()));
} }
@ -66,18 +71,17 @@ const std::string SettingsHandler::GetValue(std::string key)
return ""; return "";
} }
void SettingsHandler::Decrypt() void SettingsHandler::Decrypt()
{ {
const u8 *str = m_buffer; const u8 *str = m_buffer;
while(*str != 0){ while (*str != 0)
{
if (m_position >= SETTINGS_SIZE) if (m_position >= SETTINGS_SIZE)
return; return;
decoded.push_back((u8)(m_buffer[m_position] ^ m_key)); decoded.push_back((u8)(m_buffer[m_position] ^ m_key));
m_position++; m_position++;
str++; str++;
m_key = ((m_key >> 31) | (m_key << 1)); m_key = (m_key >> 31) | (m_key << 1);
} }
} }
@ -116,13 +120,13 @@ void SettingsHandler::WriteByte(u8 b)
m_buffer[m_position] = b ^ m_key; m_buffer[m_position] = b ^ m_key;
m_position++; m_position++;
m_key = ((m_key >> 31) | (m_key << 1)); m_key = (m_key >> 31) | (m_key << 1);
} }
std::string SettingsHandler::generateSerialNumber() const std::string SettingsHandler::generateSerialNumber()
{ {
time_t rawtime; time_t rawtime;
struct tm * timeinfo; tm *timeinfo;
char buffer[12]; char buffer[12];
char serialNumber[12]; char serialNumber[12];

View File

@ -17,28 +17,31 @@
// Thanks to Treeki for writing the original class - 29/01/2012 // Thanks to Treeki for writing the original class - 29/01/2012
#ifndef _SETTINGS_HANDLER_H #pragma once
#define _SETTINGS_HANDLER_H
#include <string> #include <string>
#include "Common.h" #include "Common.h"
#include "../CoreParameter.h"
#define SETTINGS_SIZE 0x100
class SettingsHandler class SettingsHandler
{ {
public: public:
SettingsHandler(); SettingsHandler();
enum
{
SETTINGS_SIZE = 0x100
};
void AddSetting(const char *key, const char *value); void AddSetting(const char *key, const char *value);
const u8 *GetData() const; const u8 *GetData() const;
const std::string GetValue(std::string key); const std::string GetValue(const std::string key);
void Decrypt(); void Decrypt();
void Reset(); void Reset();
std::string generateSerialNumber(); const std::string generateSerialNumber();
private: private:
void WriteByte(u8 b); void WriteByte(u8 b);
@ -46,5 +49,3 @@ private:
u32 m_position, m_key; u32 m_position, m_key;
std::string decoded; std::string decoded;
}; };
#endif

View File

@ -203,7 +203,6 @@
<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\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 +407,6 @@
<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\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,9 +559,6 @@
<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\SettingsHandler.cpp">
<Filter>Boot</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Src\ConfigManager.h" /> <ClInclude Include="Src\ConfigManager.h" />
@ -1045,9 +1042,6 @@
<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\SettingsHandler.h">
<Filter>Boot</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="CMakeLists.txt" /> <None Include="CMakeLists.txt" />

View File

@ -177,11 +177,7 @@ bool CBoot::SetupWiiMemory(unsigned int _CountryCode)
{ {
INFO_LOG(BOOT, "Setup Wii Memory..."); INFO_LOG(BOOT, "Setup Wii Memory...");
// Write the 256 byte setting.txt to memory. This may not be needed as // Write the 256 byte setting.txt to memory.
// most or all games read the setting.txt file from
// \title\00000001\00000002\data\setting.txt directly after the read the
// SYSCONF file. The games also read it to 0x3800, what is a little strange
// however is that it only reads the first 100 bytes of it.
std::string settings_Filename(Common::GetTitleDataPath(TITLEID_SYSMENU) + WII_SETTING); std::string settings_Filename(Common::GetTitleDataPath(TITLEID_SYSMENU) + WII_SETTING);
std::string area, model, code, video, game; std::string area, model, code, video, game;
@ -217,13 +213,13 @@ 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);
SettingsHandler gen; SettingsHandler gen;
std::string serno = ""; std::string serno = "";
if (File::Exists(settings_Filename)) if (File::Exists(settings_Filename))
{ {
File::IOFile settingsFileHandle(settings_Filename, "rb"); File::IOFile settingsFileHandle(settings_Filename, "rb");
if(settingsFileHandle.ReadBytes((void*)gen.GetData(), SETTINGS_SIZE)){ if (settingsFileHandle.ReadBytes((void*)gen.GetData(), SettingsHandler::SETTINGS_SIZE))
{
gen.Decrypt(); gen.Decrypt();
serno = gen.GetValue("SERNO"); serno = gen.GetValue("SERNO");
gen.Reset(); gen.Reset();
@ -231,10 +227,13 @@ bool CBoot::SetupWiiMemory(unsigned int _CountryCode)
File::Delete(settings_Filename); File::Delete(settings_Filename);
} }
if(serno.empty() || serno == "000000000"){ if (serno.empty() || serno == "000000000")
{
serno = gen.generateSerialNumber(); serno = gen.generateSerialNumber();
INFO_LOG(BOOT, "No previous serial number found, generated one instead: %s", serno.c_str()); INFO_LOG(BOOT, "No previous serial number found, generated one instead: %s", serno.c_str());
}else{ }
else
{
INFO_LOG(BOOT, "Using serial number: %s", serno.c_str()); INFO_LOG(BOOT, "Using serial number: %s", serno.c_str());
} }
@ -253,12 +252,12 @@ bool CBoot::SetupWiiMemory(unsigned int _CountryCode)
{ {
File::IOFile settingsFileHandle(settings_Filename, "wb"); File::IOFile settingsFileHandle(settings_Filename, "wb");
if (!settingsFileHandle.WriteBytes(gen.GetData(), SETTINGS_SIZE)) if (!settingsFileHandle.WriteBytes(gen.GetData(), SettingsHandler::SETTINGS_SIZE))
{ {
PanicAlertT("SetupWiiMem: Cant create setting file"); PanicAlertT("SetupWiiMem: Cant create setting file");
return false; return false;
} }
Memory::WriteBigEData(gen.GetData(), 0x3800, SETTINGS_SIZE); Memory::WriteBigEData(gen.GetData(), 0x3800, SettingsHandler::SETTINGS_SIZE);
} }
/* /*

View File

@ -201,8 +201,6 @@ public:
// TODO Writes stuff to /shared2/nwc24/misc.bin // TODO Writes stuff to /shared2/nwc24/misc.bin
u32 update_misc = 0; u32 update_misc = 0;
static bool init = false;
switch (Parameter) switch (Parameter)
{ {
case IOCTL_NW24_GET_UNIVERSAL_TIME: case IOCTL_NW24_GET_UNIVERSAL_TIME: