2013-04-18 03:43:35 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2014-02-10 18:54:46 +00:00
|
|
|
#pragma once
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2013-10-27 18:27:07 +00:00
|
|
|
#include <polarssl/aes.h>
|
2014-02-17 10:18:15 +00:00
|
|
|
|
2014-02-22 22:36:30 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2010-06-09 01:37:08 +00:00
|
|
|
|
|
|
|
// --- this is used for encrypted Wii save files
|
|
|
|
|
|
|
|
|
|
|
|
class CWiiSaveCrypted
|
|
|
|
{
|
|
|
|
public:
|
2013-08-18 21:58:23 +00:00
|
|
|
bool static ImportWiiSave(const char* FileName);
|
|
|
|
bool static ExportWiiSave(u64 TitleID);
|
2013-08-18 21:59:05 +00:00
|
|
|
void static ExportAllSaves();
|
2013-08-18 21:58:23 +00:00
|
|
|
|
|
|
|
private:
|
2011-06-27 06:19:23 +00:00
|
|
|
CWiiSaveCrypted(const char* FileName, u64 TitleID = 0);
|
2010-06-09 01:37:08 +00:00
|
|
|
~CWiiSaveCrypted();
|
|
|
|
void ReadHDR();
|
|
|
|
void ReadBKHDR();
|
|
|
|
void WriteHDR();
|
|
|
|
void WriteBKHDR();
|
|
|
|
void Extract(){;}
|
|
|
|
void ImportWiiSaveFiles();
|
|
|
|
void ExportWiiSaveFiles(); // To data.bin
|
|
|
|
void do_sig();
|
2013-04-08 05:16:50 +00:00
|
|
|
void make_ec_cert(u8 *cert, u8 *sig, char *signer, char *name, u8 *priv, u32 key_id);
|
2010-12-15 21:23:42 +00:00
|
|
|
bool getPaths(bool forExport = false);
|
2010-06-09 01:37:08 +00:00
|
|
|
void ScanForFiles(std::string savDir, std::vector<std::string>&FilesList, u32 *_numFiles, u32 *_sizeFiles);
|
|
|
|
|
2013-10-27 18:27:07 +00:00
|
|
|
aes_context m_AES_ctx;
|
2010-06-09 01:37:08 +00:00
|
|
|
u8 SD_IV[0x10];
|
2011-03-11 10:21:46 +00:00
|
|
|
std::vector<std::string> FilesList;
|
2013-04-08 05:16:50 +00:00
|
|
|
|
2013-08-18 21:58:23 +00:00
|
|
|
std::string encryptedSavePath;
|
2011-06-27 06:19:23 +00:00
|
|
|
|
2013-09-02 03:25:57 +00:00
|
|
|
std::string WiiTitlePath;
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2013-08-18 21:58:23 +00:00
|
|
|
u8 IV[0x10];
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-08-18 21:58:23 +00:00
|
|
|
u32 //_bannerSize,
|
2010-06-09 01:37:08 +00:00
|
|
|
_numberOfFiles,
|
|
|
|
_sizeOfFiles,
|
2013-08-18 21:58:23 +00:00
|
|
|
_totalSize;
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2011-06-27 06:19:23 +00:00
|
|
|
u64 m_TitleID;
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2013-08-18 21:58:23 +00:00
|
|
|
bool b_valid;
|
2010-06-09 01:37:08 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2014-02-09 21:03:16 +00:00
|
|
|
BLOCK_SZ = 0x40,
|
|
|
|
HDR_SZ = 0x20,
|
|
|
|
ICON_SZ = 0x1200,
|
|
|
|
BNR_SZ = 0x60a0,
|
|
|
|
FULL_BNR_MIN = 0x72a0, // BNR_SZ + 1*ICON_SZ
|
|
|
|
FULL_BNR_MAX = 0xF0A0, // BNR_SZ + 8*ICON_SZ
|
|
|
|
HEADER_SZ = 0xF0C0, // HDR_SZ + FULL_BNR_MAX
|
|
|
|
BK_LISTED_SZ = 0x70, // Size before rounding to nearest block
|
|
|
|
BK_SZ = 0x80,
|
|
|
|
FILE_HDR_SZ = 0x80,
|
2013-04-08 05:16:50 +00:00
|
|
|
|
2014-02-09 21:03:16 +00:00
|
|
|
SIG_SZ = 0x40,
|
|
|
|
NG_CERT_SZ = 0x180,
|
|
|
|
AP_CERT_SZ = 0x180,
|
|
|
|
FULL_CERT_SZ = 0x3C0, // SIG_SZ + NG_CERT_SZ + AP_CERT_SZ + 0x80?
|
2013-04-08 05:16:50 +00:00
|
|
|
|
2010-06-09 01:37:08 +00:00
|
|
|
BK_HDR_MAGIC = 0x426B0001,
|
|
|
|
FILE_HDR_MAGIC = 0x03adf17e
|
|
|
|
};
|
|
|
|
|
|
|
|
#pragma pack(push,1)
|
|
|
|
|
|
|
|
struct Data_Bin_HDR // encrypted
|
|
|
|
{
|
|
|
|
u64 SaveGameTitle;
|
|
|
|
u32 BannerSize; // (0x72A0 or 0xF0A0, also seen 0xBAA0)
|
|
|
|
u8 Permissions;
|
|
|
|
u8 unk1; // maybe permissions is a be16
|
|
|
|
u8 Md5[0x10]; // md5 of plaintext header with md5 blanker applied
|
|
|
|
u16 unk2;
|
|
|
|
};
|
2013-04-08 05:16:50 +00:00
|
|
|
|
2010-06-09 01:37:08 +00:00
|
|
|
struct HEADER
|
|
|
|
{
|
|
|
|
Data_Bin_HDR hdr;
|
|
|
|
u8 BNR[FULL_BNR_MAX];
|
|
|
|
}_header, _encryptedHeader;
|
|
|
|
|
|
|
|
struct BK_Header // Not encrypted
|
|
|
|
{
|
|
|
|
u32 size; // 0x00000070
|
2014-02-17 04:51:41 +00:00
|
|
|
// u16 magic; // 'Bk'
|
|
|
|
// u16 magic2; // or version (0x0001)
|
2010-06-09 01:37:08 +00:00
|
|
|
u32 magic; // 0x426B0001
|
|
|
|
u32 NGid;
|
|
|
|
u32 numberOfFiles;
|
|
|
|
u32 sizeOfFiles;
|
|
|
|
u32 unk1;
|
|
|
|
u32 unk2;
|
|
|
|
u32 totalSize;
|
|
|
|
u8 unk3[64];
|
|
|
|
u64 SaveGameTitle;
|
|
|
|
u8 MACaddress[6];
|
|
|
|
u8 padding[0x12];
|
|
|
|
}bkhdr;
|
|
|
|
|
|
|
|
struct FileHDR // encrypted
|
|
|
|
{
|
|
|
|
u32 magic; //0x03adf17e
|
|
|
|
u32 size;
|
|
|
|
u8 Permissions;
|
|
|
|
u8 attrib;
|
|
|
|
u8 type; // (1=file, 2=directory)
|
|
|
|
u8 name[0x45];
|
|
|
|
u8 IV[0x10];
|
|
|
|
u8 unk[0x20];
|
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
};
|