2012-01-21 21:57:41 +01:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2010
|
|
|
|
* by r-win
|
|
|
|
*
|
|
|
|
* This software is provided 'as-is', without any express or implied
|
|
|
|
* warranty. In no event will the authors be held liable for any
|
|
|
|
* damages arising from the use of this software.
|
|
|
|
*
|
|
|
|
* Permission is granted to anyone to use this software for any
|
|
|
|
* purpose, including commercial applications, and to alter it and
|
|
|
|
* redistribute it freely, subject to the following restrictions:
|
|
|
|
*
|
|
|
|
* 1. The origin of this software must not be misrepresented; you
|
|
|
|
* must not claim that you wrote the original software. If you use
|
|
|
|
* this software in a product, an acknowledgment in the product
|
|
|
|
* documentation would be appreciated but is not required.
|
|
|
|
*
|
|
|
|
* 2. Altered source versions must be plainly marked as such, and
|
|
|
|
* must not be misrepresented as being the original software.
|
|
|
|
*
|
|
|
|
* 3. This notice may not be removed or altered from any source
|
|
|
|
* distribution.
|
|
|
|
*
|
|
|
|
* Banner Handling Class
|
|
|
|
*
|
|
|
|
* for wiiflow 2010
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include <ogcsys.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ogc/conf.h>
|
|
|
|
#include <ogc/isfs.h>
|
2012-11-03 20:16:03 +01:00
|
|
|
#include <malloc.h>
|
2014-03-01 00:11:02 +01:00
|
|
|
#include "memory/mem2.hpp"
|
2012-01-21 21:57:41 +01:00
|
|
|
#include "banner.h"
|
|
|
|
#include "MD5.h"
|
2012-12-22 17:47:02 +01:00
|
|
|
#include "nand.hpp"
|
2012-12-08 17:17:35 +01:00
|
|
|
#include "gecko/gecko.hpp"
|
2012-01-21 21:57:41 +01:00
|
|
|
#include "loader/fs.h"
|
2012-12-22 19:57:19 +01:00
|
|
|
#include "loader/sys.h"
|
2012-08-05 15:48:15 +02:00
|
|
|
#include "unzip/U8Archive.h"
|
2012-01-21 21:57:41 +01:00
|
|
|
|
|
|
|
#define IMET_OFFSET 0x40
|
|
|
|
#define IMET_SIGNATURE 0x494d4554
|
|
|
|
|
2012-10-15 21:16:14 +02:00
|
|
|
Banner CurrentBanner;
|
|
|
|
|
|
|
|
Banner::Banner()
|
|
|
|
{
|
|
|
|
opening = NULL;
|
|
|
|
opening_size = 0;
|
2013-10-19 20:59:17 +02:00
|
|
|
allocated = false;
|
2012-10-15 21:16:14 +02:00
|
|
|
imet = NULL;
|
|
|
|
}
|
|
|
|
|
2013-10-19 20:59:17 +02:00
|
|
|
void Banner::SetBanner(u8 *bnr, u32 bnr_size, bool custom, bool alloc)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-10-15 21:16:14 +02:00
|
|
|
ClearBanner();
|
|
|
|
if(bnr == NULL || bnr_size == 0)
|
|
|
|
return;
|
|
|
|
|
2012-01-21 21:57:41 +01:00
|
|
|
opening = bnr;
|
2012-07-04 20:58:31 +02:00
|
|
|
opening_size = bnr_size;
|
2013-10-19 20:59:17 +02:00
|
|
|
allocated = alloc;
|
2012-10-15 21:16:14 +02:00
|
|
|
imet = (IMET *)opening;
|
2012-07-27 19:26:49 +02:00
|
|
|
if(imet->sig != IMET_SIGNATURE)
|
2012-01-21 21:57:41 +01:00
|
|
|
imet = (IMET *) (opening + IMET_OFFSET);
|
2012-07-05 01:31:38 +02:00
|
|
|
|
|
|
|
if(imet->sig == IMET_SIGNATURE)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-10-15 21:16:14 +02:00
|
|
|
DCFlushRange(opening, opening_size);
|
2012-01-21 21:57:41 +01:00
|
|
|
unsigned char md5[16];
|
|
|
|
unsigned char imetmd5[16];
|
|
|
|
|
|
|
|
memcpy(imetmd5, imet->md5, 16);
|
|
|
|
memset(imet->md5, 0, 16);
|
|
|
|
MD5(md5, (unsigned char*)(imet), sizeof(IMET));
|
2012-07-05 18:18:23 +02:00
|
|
|
memcpy(imet->md5, imetmd5, 16);
|
|
|
|
|
2012-07-05 01:31:38 +02:00
|
|
|
if(memcmp(imetmd5, md5, 16) == 0 || custom)
|
2012-01-21 21:57:41 +01:00
|
|
|
this->imet = imet;
|
|
|
|
else
|
2021-10-02 00:55:38 +02:00
|
|
|
{
|
|
|
|
imet = NULL;
|
2013-10-19 20:59:17 +02:00
|
|
|
gprintf("Invalid md5, banner not valid\n");
|
2021-10-02 00:55:38 +02:00
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
2021-10-02 00:55:38 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
imet = NULL;
|
2013-10-19 20:59:17 +02:00
|
|
|
gprintf("Invalid signature found, banner not valid\n");
|
2021-10-02 00:55:38 +02:00
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-10-15 21:16:14 +02:00
|
|
|
void Banner::ClearBanner()
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2013-10-19 20:59:17 +02:00
|
|
|
if(allocated == true && opening != NULL)
|
2020-08-13 23:21:29 +02:00
|
|
|
free(opening);
|
2012-10-15 21:16:14 +02:00
|
|
|
opening = NULL;
|
|
|
|
opening_size = 0;
|
2013-10-19 20:59:17 +02:00
|
|
|
allocated = false;
|
2012-10-20 00:01:30 +02:00
|
|
|
imet = NULL;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Banner::IsValid()
|
|
|
|
{
|
|
|
|
return imet != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
u16 *Banner::GetName(int language)
|
|
|
|
{
|
|
|
|
if (imet == NULL) return NULL;
|
|
|
|
|
|
|
|
if (imet->name_japanese[language*IMET_MAX_NAME_LEN] == 0) // Requested language is not found
|
|
|
|
{
|
|
|
|
if (imet->name_english[0] == 0) // And the channel name is not available in english
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
language = CONF_LANG_ENGLISH;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (language >= 0)
|
|
|
|
{
|
|
|
|
return &imet->name_japanese[language * IMET_MAX_NAME_LEN]; // Return a pointer to the start of the channel name
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Banner::GetName(u8 *name, int language)
|
|
|
|
{
|
|
|
|
if (imet == NULL) return false;
|
|
|
|
|
|
|
|
u16 *channelname = GetName(language);
|
|
|
|
if (channelname)
|
|
|
|
{
|
|
|
|
memcpy(name, channelname, IMET_MAX_NAME_LEN * sizeof(u16));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Banner::GetName(wchar_t *name, int language)
|
|
|
|
{
|
|
|
|
if (imet == NULL) return false;
|
|
|
|
|
|
|
|
u16 *channelname = GetName(language);
|
2012-07-27 19:26:49 +02:00
|
|
|
if(channelname)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-07-27 19:26:49 +02:00
|
|
|
for(int i = 0; i < IMET_MAX_NAME_LEN; i++)
|
2012-01-21 21:57:41 +01:00
|
|
|
name[i] = channelname[i];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-12-27 18:01:04 +01:00
|
|
|
u8 *Banner::GetFile(const char *name, u32 *size)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
|
|
|
const u8 *bnrArc = (const u8 *)(((u8 *) imet) + sizeof(IMET));
|
2012-07-27 19:26:49 +02:00
|
|
|
const u8* curfile = u8_get_file(bnrArc, name, size);
|
|
|
|
if(curfile == NULL || *size == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
//I like to have stuff in a separate memory region
|
2014-03-01 00:11:02 +01:00
|
|
|
u8 *file = (u8*)MEM2_lo_alloc(*size);
|
2012-07-27 19:26:49 +02:00
|
|
|
if(file == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
memcpy(file, curfile, (*size));
|
|
|
|
return file;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2013-10-19 20:59:17 +02:00
|
|
|
void Banner::GetBanner(char *appname, bool imetOnly)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-12-22 17:47:02 +01:00
|
|
|
u8 *buf = NULL;
|
2012-07-04 20:58:31 +02:00
|
|
|
u32 size = 0;
|
2012-12-22 17:47:02 +01:00
|
|
|
s32 len = imetOnly ? sizeof(IMET) + IMET_OFFSET : -1;
|
2012-12-22 19:57:19 +01:00
|
|
|
if(NANDemuView)
|
2012-12-22 17:47:02 +01:00
|
|
|
buf = NandHandle.GetEmuFile(appname, &size, len);
|
2012-01-21 21:57:41 +01:00
|
|
|
else
|
2012-12-22 17:47:02 +01:00
|
|
|
buf = ISFS_GetFile(appname, &size, len);
|
|
|
|
if(size == 0)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-12-22 17:47:02 +01:00
|
|
|
if(buf != NULL)
|
2020-06-26 01:11:58 +02:00
|
|
|
MEM2_free(buf);
|
2012-12-22 17:47:02 +01:00
|
|
|
return;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
2013-10-19 20:59:17 +02:00
|
|
|
SetBanner(buf, size, false, true);
|
2012-05-13 19:25:26 +02:00
|
|
|
}
|