2012-01-21 21:57:41 +01:00
|
|
|
/***************************************************************************
|
2012-04-05 13:00:05 +02:00
|
|
|
* Copyright (C) 2011 by Miigotu
|
|
|
|
* (C) 2012 by OverjoY
|
2012-03-13 00:57:59 +01:00
|
|
|
*
|
2012-01-21 21:57:41 +01:00
|
|
|
* Rewritten code from Mighty Channels and Triiforce
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2012-04-05 13:00:05 +02:00
|
|
|
* Nand/Emulation Handling Class for Wiiflow
|
2012-01-21 21:57:41 +01:00
|
|
|
*
|
|
|
|
***************************************************************************/
|
2012-08-21 18:33:44 +02:00
|
|
|
#include <ogc/machine/processor.h>
|
2012-01-21 21:57:41 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <ogcsys.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <cstdlib>
|
2012-03-14 22:09:29 +01:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <dirent.h>
|
2012-07-27 19:26:49 +02:00
|
|
|
#include <malloc.h>
|
2012-01-21 21:57:41 +01:00
|
|
|
|
|
|
|
#include "nand.hpp"
|
2012-12-08 01:25:07 +01:00
|
|
|
#include "identify.h"
|
2012-08-05 15:48:15 +02:00
|
|
|
#include "fileOps/fileOps.h"
|
2012-12-08 17:17:35 +01:00
|
|
|
#include "gecko/gecko.hpp"
|
2012-12-22 17:47:02 +01:00
|
|
|
#include "gui/text.hpp"
|
2012-08-24 00:29:15 +02:00
|
|
|
#include "loader/alt_ios.h"
|
|
|
|
#include "loader/cios.h"
|
2012-11-12 21:12:00 +01:00
|
|
|
#include "loader/fs.h"
|
2012-08-24 00:29:15 +02:00
|
|
|
#include "loader/sys.h"
|
2012-08-05 15:48:15 +02:00
|
|
|
#include "loader/wbfs.h"
|
2012-08-21 18:33:44 +02:00
|
|
|
#include "memory/memory.h"
|
2012-08-26 14:05:04 +02:00
|
|
|
#include "wiiuse/wpad.h"
|
2012-03-14 22:09:29 +01:00
|
|
|
|
|
|
|
u8 *confbuffer ATTRIBUTE_ALIGN(32);
|
2012-03-13 00:57:59 +01:00
|
|
|
u8 CCode[0x1008];
|
|
|
|
char SCode[4];
|
2012-03-14 22:09:29 +01:00
|
|
|
char *txtbuffer ATTRIBUTE_ALIGN(32);
|
2012-03-13 00:57:59 +01:00
|
|
|
|
|
|
|
config_header *cfg_hdr;
|
|
|
|
|
|
|
|
bool tbdec = false;
|
|
|
|
bool configloaded = false;
|
2012-06-21 16:53:20 +02:00
|
|
|
bool emu_enabled = false;
|
2012-03-13 00:57:59 +01:00
|
|
|
|
2012-10-15 21:16:14 +02:00
|
|
|
Nand NandHandle;
|
|
|
|
|
2012-04-05 13:00:05 +02:00
|
|
|
static NandDevice NandDeviceList[] =
|
|
|
|
{
|
2012-01-21 21:57:41 +01:00
|
|
|
{ "Disable", 0, 0x00, 0x00 },
|
|
|
|
{ "SD/SDHC Card", 1, 0xF0, 0xF1 },
|
|
|
|
{ "USB 2.0 Mass Storage Device", 2, 0xF2, 0xF3 },
|
|
|
|
};
|
|
|
|
|
2012-10-15 21:16:14 +02:00
|
|
|
void Nand::Init()
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-10-15 21:16:14 +02:00
|
|
|
MountedDevice = 0;
|
|
|
|
EmuDevice = REAL_NAND;
|
|
|
|
Partition = 0;
|
|
|
|
FullMode = 0x100;
|
2012-12-25 14:42:53 +01:00
|
|
|
memset(NandPath, 0, sizeof(NandPath));
|
2013-01-27 13:12:44 +01:00
|
|
|
isfs_inited = false;
|
2012-12-25 14:42:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Nand::LoadDefaultIOS(void)
|
|
|
|
{
|
|
|
|
Patch_AHB();
|
2013-01-27 14:42:54 +01:00
|
|
|
s32 ret = IOS_ReloadIOS(IOS_GetPreferredVersion());
|
2012-12-25 14:42:53 +01:00
|
|
|
loadIOS(IOS_GetVersion(), false);
|
|
|
|
Init_ISFS();
|
|
|
|
return (ret == 0);
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-12-22 17:47:02 +01:00
|
|
|
void Nand::SetNANDEmu(u32 partition)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-12-22 17:47:02 +01:00
|
|
|
EmuDevice = partition == 0 ? EMU_SD : EMU_USB;
|
|
|
|
Partition = partition > 0 ? partition - 1 : partition;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
s32 Nand::Nand_Mount(NandDevice *Device)
|
|
|
|
{
|
2012-05-20 14:34:48 +02:00
|
|
|
gprintf("Device: %s\n", Device->Name);
|
|
|
|
|
2012-01-21 21:57:41 +01:00
|
|
|
s32 fd = IOS_Open("fat", 0);
|
2012-05-20 14:34:48 +02:00
|
|
|
if(fd < 0)
|
|
|
|
return fd;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
|
|
|
static ioctlv vector[1] ATTRIBUTE_ALIGN(32);
|
2012-09-01 11:34:18 +02:00
|
|
|
|
2012-01-21 21:57:41 +01:00
|
|
|
vector[0].data = &Partition;
|
|
|
|
vector[0].len = sizeof(u32);
|
|
|
|
|
|
|
|
s32 ret = IOS_Ioctlv(fd, Device->Mount, 1, 0, vector);
|
|
|
|
IOS_Close(fd);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 Nand::Nand_Unmount(NandDevice *Device)
|
|
|
|
{
|
|
|
|
s32 fd = IOS_Open("fat", 0);
|
2012-09-01 11:34:18 +02:00
|
|
|
if(fd < 0)
|
|
|
|
return fd;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
|
|
|
s32 ret = IOS_Ioctlv(fd, Device->Unmount, 0, 0, NULL);
|
|
|
|
IOS_Close(fd);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 Nand::Nand_Enable(NandDevice *Device)
|
|
|
|
{
|
2012-09-10 00:38:42 +02:00
|
|
|
gprintf("Enabling NAND Emulator...");
|
2012-01-21 21:57:41 +01:00
|
|
|
s32 fd = IOS_Open("/dev/fs", 0);
|
2012-09-01 11:34:18 +02:00
|
|
|
if(fd < 0)
|
2012-09-10 00:38:42 +02:00
|
|
|
{
|
|
|
|
gprintf(" failed!\n");
|
2012-05-24 00:09:11 +02:00
|
|
|
return fd;
|
2012-09-10 00:38:42 +02:00
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
|
|
|
|
int NandPathlen = strlen(NandPath) + 1;
|
|
|
|
|
|
|
|
static ioctlv vector[2] ATTRIBUTE_ALIGN(32);
|
|
|
|
|
|
|
|
static u32 mode ATTRIBUTE_ALIGN(32) = Device->Mode | FullMode;
|
|
|
|
|
|
|
|
vector[0].data = &mode;
|
|
|
|
vector[0].len = sizeof(u32);
|
|
|
|
vector[1].data = NandPath;
|
|
|
|
vector[1].len = NandPathlen;
|
|
|
|
|
|
|
|
s32 ret = IOS_Ioctlv(fd, 100, 2, 0, vector);
|
|
|
|
IOS_Close(fd);
|
2012-09-10 00:38:42 +02:00
|
|
|
|
|
|
|
gprintf(" %s!\n", ret < 0 ? "failed" : "OK");
|
2012-01-21 21:57:41 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 Nand::Nand_Disable(void)
|
|
|
|
{
|
2012-03-11 20:47:24 +01:00
|
|
|
gprintf("Disabling NAND Emulator\n");
|
2012-01-21 21:57:41 +01:00
|
|
|
s32 fd = IOS_Open("/dev/fs", 0);
|
2012-06-21 16:53:20 +02:00
|
|
|
if(fd < 0)
|
|
|
|
return fd;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-03-13 00:57:59 +01:00
|
|
|
u32 inbuf ATTRIBUTE_ALIGN(32) = 0;
|
2012-01-21 21:57:41 +01:00
|
|
|
s32 ret = IOS_Ioctl(fd, 100, &inbuf, sizeof(inbuf), NULL, 0);
|
|
|
|
IOS_Close(fd);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 Nand::Enable_Emu()
|
|
|
|
{
|
2012-06-21 16:53:20 +02:00
|
|
|
if(emu_enabled)
|
|
|
|
return 0;
|
2012-01-21 21:57:41 +01:00
|
|
|
NandDevice *Device = &NandDeviceList[EmuDevice];
|
|
|
|
|
|
|
|
s32 ret = Nand_Mount(Device);
|
2012-05-20 14:34:48 +02:00
|
|
|
if(ret < 0)
|
|
|
|
return ret;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
|
|
|
ret = Nand_Enable(Device);
|
2012-05-20 14:34:48 +02:00
|
|
|
if(ret < 0)
|
|
|
|
return ret;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
|
|
|
MountedDevice = EmuDevice;
|
|
|
|
|
2012-06-21 16:53:20 +02:00
|
|
|
emu_enabled = true;
|
2012-01-21 21:57:41 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 Nand::Disable_Emu()
|
|
|
|
{
|
2012-06-21 16:53:20 +02:00
|
|
|
if(MountedDevice == 0 || !emu_enabled)
|
2012-12-22 17:47:02 +01:00
|
|
|
{
|
|
|
|
emu_enabled = false;
|
2012-01-21 21:57:41 +01:00
|
|
|
return 0;
|
2012-12-22 17:47:02 +01:00
|
|
|
}
|
|
|
|
emu_enabled = false;
|
|
|
|
NandDevice *Device = &NandDeviceList[MountedDevice];
|
2012-01-21 21:57:41 +01:00
|
|
|
|
|
|
|
Nand_Disable();
|
|
|
|
Nand_Unmount(Device);
|
|
|
|
|
|
|
|
MountedDevice = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-10 00:38:42 +02:00
|
|
|
bool Nand::EmulationEnabled(void)
|
|
|
|
{
|
|
|
|
return emu_enabled;
|
|
|
|
}
|
|
|
|
|
2012-03-13 00:57:59 +01:00
|
|
|
void Nand::__Dec_Enc_TB(void)
|
|
|
|
{
|
|
|
|
u32 key = 0x73B5DBFA;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for( i=0; i < 0x100; ++i )
|
|
|
|
{
|
|
|
|
txtbuffer[i] ^= key&0xFF;
|
|
|
|
key = (key<<1) | (key>>31);
|
|
|
|
}
|
|
|
|
|
2012-03-17 23:30:16 +01:00
|
|
|
tbdec = tbdec ? false : true;
|
2012-03-13 00:57:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Nand::__configshifttxt(char *str)
|
|
|
|
{
|
|
|
|
const char *ptr = str;
|
|
|
|
char *ctr = str;
|
|
|
|
int i;
|
|
|
|
int j = strlen(str);
|
|
|
|
|
|
|
|
for( i=0; i<j; ++i )
|
|
|
|
{
|
|
|
|
if( strncmp( str+(i-3), "PALC", 4 ) == 0 )
|
|
|
|
*ctr = 0x0d;
|
|
|
|
else if( strncmp( str+(i-2), "LUH", 3 ) == 0 )
|
|
|
|
*ctr = 0x0d;
|
|
|
|
else if( strncmp( str+(i-2), "LUM", 3 ) == 0 )
|
|
|
|
*ctr = 0x0d;
|
|
|
|
else
|
|
|
|
*ctr = str[i];
|
|
|
|
|
|
|
|
ctr++;
|
|
|
|
}
|
|
|
|
*ctr = *ptr;
|
|
|
|
*ctr = '\0';
|
|
|
|
}
|
|
|
|
|
2012-04-05 13:00:05 +02:00
|
|
|
void Nand::__GetNameList(const char *source, namelist **entries, int *count)
|
|
|
|
{
|
|
|
|
u32 i, j, k, l;
|
|
|
|
u32 numentries = 0;
|
2012-05-13 19:25:26 +02:00
|
|
|
char *names = NULL;
|
2012-04-05 13:00:05 +02:00
|
|
|
char curentry[ISFS_MAXPATH];
|
|
|
|
char entrypath[ISFS_MAXPATH];
|
|
|
|
|
|
|
|
s32 ret = ISFS_ReadDir(source, NULL, &numentries);
|
2012-07-27 19:26:49 +02:00
|
|
|
names = (char *)memalign(32, ALIGN32((ISFS_MAXPATH) * numentries));
|
2012-05-13 19:25:26 +02:00
|
|
|
if(names == NULL)
|
|
|
|
return;
|
|
|
|
|
2012-04-05 13:00:05 +02:00
|
|
|
ret = ISFS_ReadDir(source, names, &numentries);
|
|
|
|
*count = numentries;
|
|
|
|
|
2012-05-13 19:25:26 +02:00
|
|
|
if(*entries != NULL)
|
|
|
|
{
|
2012-07-27 19:26:49 +02:00
|
|
|
free(*entries);
|
2012-05-13 19:25:26 +02:00
|
|
|
*entries = NULL;
|
|
|
|
}
|
2012-04-05 13:00:05 +02:00
|
|
|
|
2012-07-27 19:26:49 +02:00
|
|
|
*entries = (namelist *)malloc(sizeof(namelist) * numentries);
|
2012-05-13 19:25:26 +02:00
|
|
|
if(*entries == NULL)
|
2012-07-27 19:26:49 +02:00
|
|
|
{
|
|
|
|
free(names);
|
2012-05-13 19:25:26 +02:00
|
|
|
return;
|
2012-07-27 19:26:49 +02:00
|
|
|
}
|
2012-04-05 13:00:05 +02:00
|
|
|
|
|
|
|
for(i = 0, k = 0; i < numentries; i++)
|
|
|
|
{
|
|
|
|
for(j = 0; names[k] != 0; j++, k++)
|
|
|
|
curentry[j] = names[k];
|
2012-07-27 19:26:49 +02:00
|
|
|
|
2012-04-05 13:00:05 +02:00
|
|
|
curentry[j] = 0;
|
|
|
|
k++;
|
|
|
|
|
|
|
|
strcpy((*entries)[i].name, curentry);
|
|
|
|
|
|
|
|
if(source[strlen(source)-1] == '/')
|
|
|
|
snprintf(entrypath, sizeof(entrypath), "%s%s", source, curentry);
|
|
|
|
else
|
|
|
|
snprintf(entrypath, sizeof(entrypath), "%s/%s", source, curentry);
|
2012-07-27 19:26:49 +02:00
|
|
|
|
2012-04-05 13:00:05 +02:00
|
|
|
ret = ISFS_ReadDir(entrypath, NULL, &l);
|
|
|
|
(*entries)[i].type = ret < 0 ? 0 : 1;
|
|
|
|
}
|
2012-07-27 19:26:49 +02:00
|
|
|
free(names);
|
2012-04-05 13:00:05 +02:00
|
|
|
}
|
|
|
|
|
2012-03-13 00:57:59 +01:00
|
|
|
s32 Nand::__configread(void)
|
2012-03-17 23:30:16 +01:00
|
|
|
{
|
2012-07-27 19:26:49 +02:00
|
|
|
confbuffer = (u8 *)malloc(0x4000);
|
|
|
|
txtbuffer = (char *)malloc(0x100);
|
2012-05-13 19:25:26 +02:00
|
|
|
if(confbuffer == NULL || txtbuffer == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2012-03-13 00:57:59 +01:00
|
|
|
cfg_hdr = (config_header *)NULL;
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-03-17 23:30:16 +01:00
|
|
|
FILE *f = fopen(cfgpath, "rb");
|
|
|
|
if(f)
|
|
|
|
{
|
|
|
|
fread(confbuffer, 1, 0x4000, f);
|
2012-05-13 17:13:33 +02:00
|
|
|
fclose(f);
|
2012-03-17 23:30:16 +01:00
|
|
|
}
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-03-17 23:30:16 +01:00
|
|
|
f = fopen(settxtpath, "rb");
|
|
|
|
if(f)
|
|
|
|
{
|
|
|
|
fread(txtbuffer, 1, 0x100, f);
|
2012-05-13 17:13:33 +02:00
|
|
|
fclose(f);
|
2012-03-17 23:30:16 +01:00
|
|
|
}
|
2012-03-13 00:57:59 +01:00
|
|
|
cfg_hdr = (config_header *)confbuffer;
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-03-13 00:57:59 +01:00
|
|
|
__Dec_Enc_TB();
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-03-13 00:57:59 +01:00
|
|
|
configloaded = configloaded ? false : true;
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-03-13 00:57:59 +01:00
|
|
|
if(tbdec && configloaded)
|
2012-07-26 00:12:17 +02:00
|
|
|
return 1;
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-03-17 23:30:16 +01:00
|
|
|
return 0;
|
2012-03-13 00:57:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
s32 Nand::__configwrite(void)
|
|
|
|
{
|
|
|
|
if(configloaded)
|
|
|
|
{
|
2012-03-17 23:30:16 +01:00
|
|
|
__Dec_Enc_TB();
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-03-13 00:57:59 +01:00
|
|
|
if(!tbdec)
|
|
|
|
{
|
|
|
|
FILE *f = fopen(cfgpath, "wb");
|
|
|
|
if(f)
|
|
|
|
{
|
|
|
|
fwrite(confbuffer, 1, 0x4000, f);
|
2012-03-14 22:09:29 +01:00
|
|
|
gprintf("SYSCONF written to:\"%s\"\n", cfgpath);
|
2012-05-13 17:13:33 +02:00
|
|
|
fclose(f);
|
2012-03-13 00:57:59 +01:00
|
|
|
}
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-03-13 00:57:59 +01:00
|
|
|
f = fopen(settxtpath, "wb");
|
|
|
|
if(f)
|
|
|
|
{
|
|
|
|
fwrite(txtbuffer, 1, 0x100, f);
|
2012-03-14 22:09:29 +01:00
|
|
|
gprintf("setting.txt written to: \"%s\"\n", settxtpath);
|
2012-05-13 17:13:33 +02:00
|
|
|
fclose(f);
|
2012-05-13 19:25:26 +02:00
|
|
|
}
|
2012-03-13 00:57:59 +01:00
|
|
|
configloaded = configloaded ? false : true;
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-03-13 00:57:59 +01:00
|
|
|
if(!tbdec && !configloaded)
|
2012-05-13 19:25:26 +02:00
|
|
|
return 1;
|
2012-03-13 00:57:59 +01:00
|
|
|
}
|
|
|
|
}
|
2012-07-27 19:26:49 +02:00
|
|
|
free(confbuffer);
|
|
|
|
free(txtbuffer);
|
2012-05-13 19:25:26 +02:00
|
|
|
return 0;
|
2012-05-13 17:13:33 +02:00
|
|
|
}
|
2012-03-13 00:57:59 +01:00
|
|
|
|
|
|
|
u32 Nand::__configsetbyte(const char *item, u8 val)
|
|
|
|
{
|
|
|
|
u32 i;
|
|
|
|
for(i=0; i<cfg_hdr->ncnt; ++i)
|
|
|
|
{
|
|
|
|
if(memcmp(confbuffer+(cfg_hdr->noff[i] + 1), item, strlen(item)) == 0)
|
|
|
|
{
|
|
|
|
*(u8*)(confbuffer+cfg_hdr->noff[i] + 1 + strlen(item)) = val;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 Nand::__configsetbigarray(const char *item, void *val, u32 size)
|
|
|
|
{
|
|
|
|
u32 i;
|
|
|
|
for(i=0; i<cfg_hdr->ncnt; ++i)
|
|
|
|
{
|
|
|
|
if(memcmp(confbuffer+(cfg_hdr->noff[i] + 1), item, strlen(item)) == 0)
|
|
|
|
{
|
|
|
|
memcpy(confbuffer+cfg_hdr->noff[i] + 3 + strlen(item), val, size);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 Nand::__configsetsetting(const char *item, const char *val)
|
|
|
|
{
|
|
|
|
char *curitem = strstr(txtbuffer, item);
|
|
|
|
char *curstrt, *curend;
|
|
|
|
|
|
|
|
if(curitem == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
curstrt = strchr(curitem, '=');
|
|
|
|
curend = strchr(curitem, 0x0d);
|
|
|
|
|
2012-03-14 22:09:29 +01:00
|
|
|
if(curstrt && curend)
|
2012-03-13 00:57:59 +01:00
|
|
|
{
|
|
|
|
curstrt += 1;
|
|
|
|
u32 len = curend - curstrt;
|
2012-03-14 22:09:29 +01:00
|
|
|
if(strlen(val) > len)
|
2012-03-13 00:57:59 +01:00
|
|
|
{
|
|
|
|
static char buffer[0x100];
|
|
|
|
u32 nlen;
|
|
|
|
nlen = txtbuffer-(curstrt+strlen(val));
|
|
|
|
strcpy( buffer, txtbuffer+nlen );
|
|
|
|
strncpy( curstrt, val, strlen(val));
|
|
|
|
curstrt += strlen(val);
|
|
|
|
strncpy(curstrt, buffer, strlen(buffer));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strncpy(curstrt, val, strlen(val));
|
|
|
|
}
|
|
|
|
|
|
|
|
__configshifttxt(txtbuffer);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-03 01:08:11 +02:00
|
|
|
void Nand::__FATify(char *ptr, const char *str)
|
2012-04-05 13:00:05 +02:00
|
|
|
{
|
2012-05-03 01:08:11 +02:00
|
|
|
char ctr;
|
2012-07-26 00:12:17 +02:00
|
|
|
while((ctr = *(str++)) != '\0')
|
2012-04-05 13:00:05 +02:00
|
|
|
{
|
2012-05-03 01:08:11 +02:00
|
|
|
const char *esc;
|
2012-07-26 00:12:17 +02:00
|
|
|
switch(ctr)
|
2012-05-03 01:08:11 +02:00
|
|
|
{
|
|
|
|
case '"':
|
|
|
|
esc = "&qt;";
|
|
|
|
break;
|
|
|
|
case '*':
|
|
|
|
esc = "&st;";
|
|
|
|
break;
|
|
|
|
case ':':
|
|
|
|
esc = "&cl;";
|
|
|
|
break;
|
|
|
|
case '<':
|
|
|
|
esc = "<";
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
esc = ">";
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
esc = "&qm;";
|
|
|
|
break;
|
|
|
|
case '|':
|
|
|
|
esc = "&vb;";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*(ptr++) = ctr;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
strcpy(ptr, esc);
|
|
|
|
ptr += 4;
|
2012-04-05 13:00:05 +02:00
|
|
|
}
|
2012-05-03 01:08:11 +02:00
|
|
|
*ptr = '\0';
|
2012-04-05 13:00:05 +02:00
|
|
|
}
|
|
|
|
|
2012-05-11 02:07:44 +02:00
|
|
|
void Nand::__NANDify(char *str)
|
|
|
|
{
|
|
|
|
char *src = str;
|
|
|
|
char *dst = str;
|
|
|
|
char c;
|
|
|
|
|
|
|
|
while((c = *(src++)) != '\0')
|
|
|
|
{
|
|
|
|
if(c == '&')
|
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
if(!strncmp(src, "qt;", 3))
|
|
|
|
c = '"';
|
|
|
|
else if(!strncmp(src, "st;", 3))
|
|
|
|
c = '*';
|
|
|
|
else if(!strncmp(src, "cl;", 3))
|
|
|
|
c = ':';
|
|
|
|
else if(!strncmp(src, "lt;", 3))
|
|
|
|
c = '<';
|
|
|
|
else if(!strncmp(src, "gt;", 3))
|
|
|
|
c = '>';
|
|
|
|
else if(!strncmp(src, "qm;", 3))
|
|
|
|
c = '?';
|
|
|
|
else if(!strncmp(src, "vb;", 3))
|
|
|
|
c = '|';
|
2012-05-11 02:07:44 +02:00
|
|
|
|
|
|
|
if (c != '&')
|
|
|
|
src += 3;
|
|
|
|
}
|
|
|
|
*(dst++) = c;
|
|
|
|
}
|
|
|
|
*dst = '\0';
|
|
|
|
}
|
|
|
|
|
2012-03-17 23:30:16 +01:00
|
|
|
s32 Nand::__FlashNandFile(const char *source, const char *dest)
|
|
|
|
{
|
|
|
|
s32 ret;
|
|
|
|
FILE *file = fopen(source, "rb");
|
|
|
|
if(!file)
|
|
|
|
{
|
|
|
|
gprintf("Error opening source: \"%s\"\n", source);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-03-17 23:30:16 +01:00
|
|
|
fseek(file, 0, SEEK_END);
|
|
|
|
u32 fsize = ftell(file);
|
|
|
|
fseek(file, 0, SEEK_SET);
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-05-11 01:38:34 +02:00
|
|
|
if(fake)
|
|
|
|
{
|
|
|
|
NandSize += fsize;
|
|
|
|
if(showprogress)
|
2012-12-27 21:22:40 +01:00
|
|
|
dumper(NandSize, 0x1f400000, 0x1f400000, NandSize, FilesDone, FoldersDone, "", data);
|
2012-05-13 17:13:33 +02:00
|
|
|
fclose(file);
|
2012-05-11 01:38:34 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-05-11 01:38:34 +02:00
|
|
|
gprintf("Flashing: %s (%uKB) to nand...", dest, (fsize / 0x400)+1);
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-03-17 23:30:16 +01:00
|
|
|
ISFS_Delete(dest);
|
|
|
|
ISFS_CreateFile(dest, 0, 3, 3, 3);
|
|
|
|
s32 fd = ISFS_Open(dest, ISFS_OPEN_RW);
|
|
|
|
if(fd < 0)
|
|
|
|
{
|
|
|
|
gprintf(" failed\nError: ISFS_OPEN(%s, %d) %d\n", dest, ISFS_OPEN_RW, fd);
|
2012-05-13 17:13:33 +02:00
|
|
|
fclose(file);
|
2012-03-17 23:30:16 +01:00
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2012-07-27 19:26:49 +02:00
|
|
|
u8 *buffer = (u8 *)memalign(32, ALIGN32(BLOCK));
|
2012-05-13 19:25:26 +02:00
|
|
|
if(buffer == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2012-03-17 23:30:16 +01:00
|
|
|
u32 toread = fsize;
|
|
|
|
while(toread > 0)
|
|
|
|
{
|
|
|
|
u32 size = BLOCK;
|
|
|
|
if(toread < BLOCK)
|
|
|
|
size = toread;
|
|
|
|
|
|
|
|
ret = fread(buffer, 1, size, file);
|
|
|
|
if(ret <= 0)
|
|
|
|
{
|
|
|
|
gprintf(" failed\nError: fread(%p, 1, %d, %s) %d\n", buffer, size, source, ret);
|
|
|
|
ISFS_Close(fd);
|
2012-05-13 17:13:33 +02:00
|
|
|
fclose(file);
|
2012-07-27 19:26:49 +02:00
|
|
|
free(buffer);
|
2012-03-17 23:30:16 +01:00
|
|
|
return ret;
|
|
|
|
}
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-03-17 23:30:16 +01:00
|
|
|
ret = ISFS_Write(fd, buffer, size);
|
|
|
|
if(ret <= 0)
|
|
|
|
{
|
|
|
|
gprintf(" failed\nError: ISFS_Write(%d, %p, %d) %d\n", fd, buffer, size, ret);
|
|
|
|
ISFS_Close(fd);
|
2012-05-13 17:13:33 +02:00
|
|
|
fclose(file);
|
2012-07-27 19:26:49 +02:00
|
|
|
free(buffer);
|
2012-03-17 23:30:16 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
toread -= size;
|
2012-05-11 01:38:34 +02:00
|
|
|
NandDone += size;
|
|
|
|
FileDone += size;
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-05-11 01:38:34 +02:00
|
|
|
if(showprogress)
|
|
|
|
{
|
|
|
|
const char *file = strrchr(dest, '/')+1;
|
2012-12-27 21:22:40 +01:00
|
|
|
dumper(NandDone, NandSize, fsize, FileDone, FilesDone, FoldersDone, file, data);
|
2012-05-11 01:38:34 +02:00
|
|
|
}
|
2012-07-26 00:12:17 +02:00
|
|
|
}
|
2012-05-11 01:38:34 +02:00
|
|
|
gprintf(" done!\n");
|
|
|
|
FilesDone++;
|
|
|
|
if(showprogress)
|
|
|
|
{
|
|
|
|
const char *file = strrchr(dest, '/')+1;
|
2012-12-27 21:22:40 +01:00
|
|
|
dumper(NandDone, NandSize, fsize, FileDone, FilesDone, FoldersDone, file, data);
|
2012-03-17 23:30:16 +01:00
|
|
|
}
|
|
|
|
ISFS_Close(fd);
|
2012-07-27 19:26:49 +02:00
|
|
|
free(buffer);
|
2012-07-26 00:12:17 +02:00
|
|
|
fclose(file);
|
2012-03-17 23:30:16 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 Nand::__DumpNandFile(const char *source, const char *dest)
|
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
FileDone = 0;
|
2012-03-17 23:30:16 +01:00
|
|
|
s32 fd = ISFS_Open(source, ISFS_OPEN_READ);
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
|
|
|
gprintf("Error: IOS_OPEN(%s, %d) %d\n", source, ISFS_OPEN_READ, fd);
|
|
|
|
return fd;
|
|
|
|
}
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-07-27 19:26:49 +02:00
|
|
|
fstats *status = (fstats *)memalign(32, ALIGN32(sizeof(fstats)));
|
2012-05-13 19:25:26 +02:00
|
|
|
if(status == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2012-03-17 23:30:16 +01:00
|
|
|
s32 ret = ISFS_GetFileStats(fd, status);
|
2012-07-27 19:26:49 +02:00
|
|
|
if(ret < 0)
|
2012-03-17 23:30:16 +01:00
|
|
|
{
|
|
|
|
gprintf("Error: ISFS_GetFileStats(%d) %d\n", fd, ret);
|
|
|
|
ISFS_Close(fd);
|
2012-07-27 19:26:49 +02:00
|
|
|
free(status);
|
2012-03-17 23:30:16 +01:00
|
|
|
return ret;
|
|
|
|
}
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-05-03 01:08:11 +02:00
|
|
|
if(fake)
|
|
|
|
{
|
|
|
|
NandSize += status->file_length;
|
|
|
|
if(showprogress)
|
2012-12-27 21:22:40 +01:00
|
|
|
dumper(NandSize, 0x1f400000, 0x1f400000, NandSize, FilesDone, FoldersDone, "", data);
|
2012-05-03 01:08:11 +02:00
|
|
|
ISFS_Close(fd);
|
2012-07-27 19:26:49 +02:00
|
|
|
free(status);
|
2012-05-03 01:08:11 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-06-07 07:14:51 +02:00
|
|
|
if(fsop_FileExist(dest))
|
2012-07-22 21:18:00 +02:00
|
|
|
fsop_deleteFile(dest);
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-05-03 01:08:11 +02:00
|
|
|
FILE *file = fopen(dest, "wb");
|
2012-07-27 19:26:49 +02:00
|
|
|
if(!file)
|
2012-05-03 01:08:11 +02:00
|
|
|
{
|
|
|
|
gprintf("Error opening destination: \"%s\"\n", dest);
|
|
|
|
ISFS_Close(fd);
|
2012-07-27 19:26:49 +02:00
|
|
|
free(status);
|
2012-05-03 01:08:11 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-05-03 01:08:11 +02:00
|
|
|
gprintf("Dumping: %s (%ukb)...", source, (status->file_length / 0x400)+1);
|
2012-03-17 23:30:16 +01:00
|
|
|
|
2012-07-27 19:26:49 +02:00
|
|
|
u8 *buffer = (u8 *)memalign(32, ALIGN32(BLOCK));
|
2012-05-13 19:25:26 +02:00
|
|
|
if(buffer == NULL)
|
2012-07-27 19:26:49 +02:00
|
|
|
{
|
|
|
|
free(status);
|
2012-05-13 19:25:26 +02:00
|
|
|
return -1;
|
2012-07-27 19:26:49 +02:00
|
|
|
}
|
2012-05-13 19:25:26 +02:00
|
|
|
|
2012-03-17 23:30:16 +01:00
|
|
|
u32 toread = status->file_length;
|
|
|
|
while(toread > 0)
|
|
|
|
{
|
|
|
|
u32 size = BLOCK;
|
|
|
|
if (toread < BLOCK)
|
|
|
|
size = toread;
|
|
|
|
|
|
|
|
ret = ISFS_Read(fd, buffer, size);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
gprintf(" failed\nError: ISFS_Read(%d, %p, %d) %d\n", fd, buffer, size, ret);
|
|
|
|
ISFS_Close(fd);
|
2012-05-13 17:13:33 +02:00
|
|
|
fclose(file);
|
2012-07-27 19:26:49 +02:00
|
|
|
free(status);
|
|
|
|
free(buffer);
|
2012-03-17 23:30:16 +01:00
|
|
|
return ret;
|
|
|
|
}
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-03-17 23:30:16 +01:00
|
|
|
ret = fwrite(buffer, 1, size, file);
|
|
|
|
if(ret < 0)
|
|
|
|
{
|
|
|
|
gprintf(" failed\nError writing to destination: \"%s\" (%d)\n", dest, ret);
|
|
|
|
ISFS_Close(fd);
|
2012-05-13 17:13:33 +02:00
|
|
|
fclose(file);
|
2012-07-27 19:26:49 +02:00
|
|
|
free(status);
|
|
|
|
free(buffer);
|
2012-03-17 23:30:16 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
toread -= size;
|
2012-05-03 01:08:11 +02:00
|
|
|
NandDone += size;
|
|
|
|
FileDone += size;
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-05-03 01:08:11 +02:00
|
|
|
if(showprogress)
|
|
|
|
{
|
|
|
|
const char *file = strrchr(source, '/')+1;
|
2012-12-27 21:22:40 +01:00
|
|
|
dumper(NandDone, NandSize, status->file_length, FileDone, FilesDone, FoldersDone, file, data);
|
2012-05-03 01:08:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
FilesDone++;
|
|
|
|
if(showprogress)
|
|
|
|
{
|
|
|
|
const char *file = strrchr(source, '/')+1;
|
2012-12-27 21:22:40 +01:00
|
|
|
dumper(NandDone, NandSize, status->file_length, FileDone, FilesDone, FoldersDone, file, data);
|
2012-03-17 23:30:16 +01:00
|
|
|
}
|
|
|
|
gprintf(" done!\n");
|
2012-07-26 00:12:17 +02:00
|
|
|
fclose(file);
|
|
|
|
ISFS_Close(fd);
|
2012-07-27 19:26:49 +02:00
|
|
|
free(status);
|
|
|
|
free(buffer);
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-05-03 01:08:11 +02:00
|
|
|
return 0;
|
2012-03-17 23:30:16 +01:00
|
|
|
}
|
|
|
|
|
2012-05-11 01:38:34 +02:00
|
|
|
|
|
|
|
s32 Nand::__FlashNandFolder(const char *source, const char *dest)
|
|
|
|
{
|
|
|
|
char nsource[MAX_FAT_PATH];
|
|
|
|
char ndest[ISFS_MAXPATH];
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-05-11 01:38:34 +02:00
|
|
|
DIR *dir_iter;
|
|
|
|
struct dirent *ent;
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-05-11 01:38:34 +02:00
|
|
|
dir_iter = opendir(source);
|
|
|
|
if (!dir_iter)
|
|
|
|
return 1;
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-05-11 01:38:34 +02:00
|
|
|
while((ent = readdir(dir_iter)) != NULL)
|
|
|
|
{
|
|
|
|
if(ent->d_name[0] == '.')
|
|
|
|
continue;
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-05-11 01:38:34 +02:00
|
|
|
if(dest[strlen(dest)-1] == '/')
|
|
|
|
snprintf(ndest, sizeof(ndest), "%s%s", dest, ent->d_name);
|
|
|
|
else
|
|
|
|
snprintf(ndest, sizeof(ndest), "%s/%s", dest, ent->d_name);
|
|
|
|
|
|
|
|
if(source[strlen(source)-1] == '/')
|
|
|
|
snprintf(nsource, sizeof(nsource), "%s%s", source, ent->d_name);
|
|
|
|
else
|
|
|
|
snprintf(nsource, sizeof(nsource), "%s/%s", source, ent->d_name);
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-05-11 01:38:34 +02:00
|
|
|
if(ent->d_type == DT_DIR)
|
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
__NANDify(ndest);
|
2012-05-11 01:38:34 +02:00
|
|
|
if(!fake)
|
|
|
|
{
|
|
|
|
ISFS_CreateDir(ndest, 0, 3, 3, 3);
|
|
|
|
FoldersDone++;
|
|
|
|
}
|
2012-07-26 00:12:17 +02:00
|
|
|
__FlashNandFolder(nsource, ndest);
|
2012-05-11 01:38:34 +02:00
|
|
|
}
|
|
|
|
else
|
2012-07-26 00:12:17 +02:00
|
|
|
{
|
2012-05-11 02:07:44 +02:00
|
|
|
__NANDify(ndest);
|
2012-05-11 01:38:34 +02:00
|
|
|
__FlashNandFile(nsource, ndest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-05 13:00:05 +02:00
|
|
|
s32 Nand::__DumpNandFolder(const char *source, const char *dest)
|
2012-03-14 22:09:29 +01:00
|
|
|
{
|
2012-04-05 13:00:05 +02:00
|
|
|
namelist *names = NULL;
|
|
|
|
int cnt, i;
|
|
|
|
char nsource[ISFS_MAXPATH];
|
2012-05-03 01:08:11 +02:00
|
|
|
char ndest[MAX_FAT_PATH];
|
|
|
|
char tdest[MAX_FAT_PATH];
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
__GetNameList(source, &names, &cnt);
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-04-05 13:00:05 +02:00
|
|
|
for(i = 0; i < cnt; i++)
|
|
|
|
{
|
|
|
|
if(source[strlen(source)-1] == '/')
|
|
|
|
snprintf(nsource, sizeof(nsource), "%s%s", source, names[i].name);
|
|
|
|
else
|
2012-07-26 00:12:17 +02:00
|
|
|
snprintf(nsource, sizeof(nsource), "%s/%s", source, names[i].name);
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-04-05 13:00:05 +02:00
|
|
|
if(!names[i].type)
|
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
__FATify(tdest, nsource);
|
2012-05-03 01:08:11 +02:00
|
|
|
snprintf(ndest, sizeof(ndest), "%s%s", dest, tdest);
|
2012-04-05 13:00:05 +02:00
|
|
|
__DumpNandFile(nsource, ndest);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-05-03 01:08:11 +02:00
|
|
|
if(!fake)
|
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
__FATify(tdest, nsource);
|
2012-05-03 01:08:11 +02:00
|
|
|
CreatePath("%s%s", dest, tdest);
|
|
|
|
FoldersDone++;
|
2012-04-05 13:00:05 +02:00
|
|
|
}
|
2012-05-03 01:08:11 +02:00
|
|
|
|
|
|
|
__DumpNandFolder(nsource, dest);
|
2012-04-05 13:00:05 +02:00
|
|
|
}
|
|
|
|
}
|
2012-07-27 19:26:49 +02:00
|
|
|
free(names);
|
2012-05-03 01:08:11 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2012-04-05 13:00:05 +02:00
|
|
|
|
|
|
|
void Nand::CreatePath(const char *path, ...)
|
2012-05-03 01:08:11 +02:00
|
|
|
{
|
2012-03-14 22:09:29 +01:00
|
|
|
char *folder = NULL;
|
|
|
|
va_list args;
|
|
|
|
va_start(args, path);
|
|
|
|
if((vasprintf(&folder, path, args) >= 0) && folder)
|
|
|
|
{
|
2012-04-05 13:00:05 +02:00
|
|
|
if(folder[strlen(folder)-1] == '/')
|
2012-07-26 00:12:17 +02:00
|
|
|
folder[strlen(folder)-1] = 0;
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-05-12 19:14:25 +02:00
|
|
|
char *check = folder;
|
2012-08-26 14:40:34 +02:00
|
|
|
while(true)
|
2012-05-12 19:14:25 +02:00
|
|
|
{
|
|
|
|
check = strstr(folder, "//");
|
|
|
|
if (check != NULL)
|
|
|
|
strcpy(check, check + 1);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2012-08-26 14:40:34 +02:00
|
|
|
__makedir(folder);
|
2012-05-13 19:25:26 +02:00
|
|
|
free(folder);
|
2012-03-14 22:09:29 +01:00
|
|
|
}
|
|
|
|
va_end(args);
|
|
|
|
}
|
2012-04-05 13:00:05 +02:00
|
|
|
|
2012-12-22 17:47:02 +01:00
|
|
|
void Nand::CreateTitleTMD(dir_discHdr *hdr)
|
2012-05-11 01:38:34 +02:00
|
|
|
{
|
2012-06-16 19:03:23 +02:00
|
|
|
wbfs_disc_t *disc = WBFS_OpenDisc((u8 *)&hdr->id, (char *)hdr->path);
|
2012-05-11 01:38:34 +02:00
|
|
|
if(!disc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
u8 *titleTMD = NULL;
|
2012-12-27 21:22:40 +01:00
|
|
|
u32 tmd_size = wbfs_extract_file(disc, (char*)"TMD", (void**)&titleTMD);
|
2012-05-11 01:38:34 +02:00
|
|
|
WBFS_CloseDisc(disc);
|
|
|
|
|
2012-05-13 19:25:26 +02:00
|
|
|
if(titleTMD == NULL)
|
2012-05-11 01:38:34 +02:00
|
|
|
return;
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-05-11 01:38:34 +02:00
|
|
|
u32 highTID = *(u32*)(titleTMD+0x18c);
|
|
|
|
u32 lowTID = *(u32*)(titleTMD+0x190);
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-12-22 17:47:02 +01:00
|
|
|
CreatePath("%s/title/%08x/%08x/data", FullNANDPath, highTID, lowTID);
|
|
|
|
CreatePath("%s/title/%08x/%08x/content", FullNANDPath, highTID, lowTID);
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-05-11 01:38:34 +02:00
|
|
|
char nandpath[MAX_FAT_PATH];
|
2012-12-22 17:47:02 +01:00
|
|
|
snprintf(nandpath, sizeof(nandpath), "%s/title/%08x/%08x/content/title.tmd", FullNANDPath, highTID, lowTID);
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-05-11 01:38:34 +02:00
|
|
|
struct stat filestat;
|
2012-12-22 17:47:02 +01:00
|
|
|
if(stat(nandpath, &filestat) == 0)
|
2012-05-11 01:38:34 +02:00
|
|
|
{
|
2012-07-27 19:26:49 +02:00
|
|
|
free(titleTMD);
|
2012-05-11 01:38:34 +02:00
|
|
|
gprintf("%s Exists!\n", nandpath);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gprintf("Creating title TMD: %s\n", nandpath);
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-05-11 01:38:34 +02:00
|
|
|
FILE *file = fopen(nandpath, "wb");
|
|
|
|
if(file)
|
|
|
|
{
|
|
|
|
fwrite(titleTMD, 1, tmd_size, file);
|
|
|
|
gprintf("Title TMD written to: %s\n", nandpath);
|
|
|
|
fclose(file);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gprintf("Creating title TMD: %s failed (%i)\n", nandpath, file);
|
|
|
|
|
2012-07-27 19:26:49 +02:00
|
|
|
free(titleTMD);
|
2012-05-11 01:38:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
s32 Nand::FlashToNAND(const char *source, const char *dest, dump_callback_t i_dumper, void *i_data)
|
|
|
|
{
|
|
|
|
ISFS_CreateDir(dest, 0, 3, 3, 3);
|
|
|
|
data = i_data;
|
|
|
|
dumper = i_dumper;
|
|
|
|
fake = false;
|
2012-07-26 00:12:17 +02:00
|
|
|
showprogress = true;
|
2012-05-11 01:38:34 +02:00
|
|
|
__FlashNandFolder(source, dest);
|
2012-07-26 00:12:17 +02:00
|
|
|
return 0;
|
2012-05-11 01:38:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
s32 Nand::DoNandDump(const char *source, const char *dest, dump_callback_t i_dumper, void *i_data)
|
2012-05-03 01:08:11 +02:00
|
|
|
{
|
|
|
|
data = i_data;
|
|
|
|
dumper = i_dumper;
|
|
|
|
fake = false;
|
|
|
|
showprogress = true;
|
2012-07-26 00:12:17 +02:00
|
|
|
u32 temp = 0;
|
2012-04-05 13:00:05 +02:00
|
|
|
s32 ret = ISFS_ReadDir(source, NULL, &temp);
|
|
|
|
if(ret < 0)
|
|
|
|
{
|
|
|
|
char ndest[MAX_FAT_PATH];
|
|
|
|
snprintf(ndest, sizeof(ndest), "%s%s", dest, source);
|
|
|
|
CreatePath(dest);
|
|
|
|
|
|
|
|
__DumpNandFile(source, ndest);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
__DumpNandFolder(source, dest);
|
2012-07-26 00:12:17 +02:00
|
|
|
return 0;
|
2012-04-05 13:00:05 +02:00
|
|
|
}
|
2012-05-03 01:08:11 +02:00
|
|
|
|
2012-05-11 01:38:34 +02:00
|
|
|
s32 Nand::CalcFlashSize(const char *source, dump_callback_t i_dumper, void *i_data)
|
|
|
|
{
|
|
|
|
data = i_data;
|
|
|
|
dumper = i_dumper;
|
|
|
|
fake = true;
|
|
|
|
showprogress = true;
|
2012-07-26 00:12:17 +02:00
|
|
|
__FlashNandFolder(source, "");
|
|
|
|
return NandSize;
|
2012-05-11 01:38:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
s32 Nand::CalcDumpSpace(const char *source, dump_callback_t i_dumper, void *i_data)
|
2012-05-03 01:08:11 +02:00
|
|
|
{
|
|
|
|
data = i_data;
|
|
|
|
dumper = i_dumper;
|
|
|
|
fake = true;
|
2012-07-26 00:12:17 +02:00
|
|
|
showprogress = true;
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
u32 temp = 0;
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-05-03 01:08:11 +02:00
|
|
|
s32 ret = ISFS_ReadDir(source, NULL, &temp);
|
2012-07-26 00:12:17 +02:00
|
|
|
if(ret < 0)
|
2012-05-03 01:08:11 +02:00
|
|
|
__DumpNandFile(source, "");
|
|
|
|
else
|
|
|
|
__DumpNandFolder(source, "");
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
return NandSize;
|
2012-05-03 01:08:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Nand::ResetCounters(void)
|
|
|
|
{
|
|
|
|
NandSize = 0;
|
|
|
|
FilesDone = 0;
|
|
|
|
FoldersDone = 0;
|
|
|
|
NandDone = 0;
|
|
|
|
}
|
2012-03-14 22:09:29 +01:00
|
|
|
|
2012-12-22 17:47:02 +01:00
|
|
|
s32 Nand::CreateConfig()
|
2012-03-14 22:09:29 +01:00
|
|
|
{
|
2012-12-22 17:47:02 +01:00
|
|
|
CreatePath(FullNANDPath);
|
|
|
|
CreatePath("%s/shared2", FullNANDPath);
|
|
|
|
CreatePath("%s/shared2/sys", FullNANDPath);
|
|
|
|
CreatePath("%s/title", FullNANDPath);
|
|
|
|
CreatePath("%s/title/00000001", FullNANDPath);
|
|
|
|
CreatePath("%s/title/00000001/00000002", FullNANDPath);
|
|
|
|
CreatePath("%s/title/00000001/00000002/data", FullNANDPath);
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-05-03 01:08:11 +02:00
|
|
|
fake = false;
|
|
|
|
showprogress = false;
|
2012-05-13 17:13:33 +02:00
|
|
|
|
2012-07-22 21:18:00 +02:00
|
|
|
memset(cfgpath, 0, sizeof(cfgpath));
|
2012-12-22 17:47:02 +01:00
|
|
|
snprintf(cfgpath, sizeof(cfgpath), "%s%s", FullNANDPath, SYSCONFPATH);
|
2012-03-17 23:30:16 +01:00
|
|
|
__DumpNandFile(SYSCONFPATH, cfgpath);
|
2012-07-22 21:18:00 +02:00
|
|
|
|
|
|
|
memset(settxtpath, 0, sizeof(settxtpath));
|
2012-12-22 17:47:02 +01:00
|
|
|
snprintf(settxtpath, sizeof(settxtpath), "%s%s", FullNANDPath, TXTPATH);
|
2012-03-17 23:30:16 +01:00
|
|
|
__DumpNandFile(TXTPATH, settxtpath);
|
2012-07-22 21:18:00 +02:00
|
|
|
|
|
|
|
return 0;
|
2012-03-17 23:30:16 +01:00
|
|
|
}
|
|
|
|
|
2012-12-22 17:47:02 +01:00
|
|
|
s32 Nand::PreNandCfg(bool miis, bool realconfig)
|
2012-06-07 02:34:47 +02:00
|
|
|
{
|
2012-12-22 17:47:02 +01:00
|
|
|
CreatePath(FullNANDPath);
|
|
|
|
CreatePath("%s/shared2", FullNANDPath);
|
|
|
|
CreatePath("%s/shared2/sys", FullNANDPath);
|
|
|
|
CreatePath("%s/shared2/menu", FullNANDPath);
|
|
|
|
CreatePath("%s/shared2/menu/FaceLib", FullNANDPath);
|
|
|
|
CreatePath("%s/title", FullNANDPath);
|
|
|
|
CreatePath("%s/title/00000001", FullNANDPath);
|
|
|
|
CreatePath("%s/title/00000001/00000002", FullNANDPath);
|
|
|
|
CreatePath("%s/title/00000001/00000002/data", FullNANDPath);
|
2012-06-07 02:34:47 +02:00
|
|
|
|
|
|
|
char dest[MAX_FAT_PATH];
|
|
|
|
|
|
|
|
fake = false;
|
|
|
|
showprogress = false;
|
|
|
|
|
2012-07-22 21:18:00 +02:00
|
|
|
if(realconfig)
|
|
|
|
{
|
2012-12-22 17:47:02 +01:00
|
|
|
snprintf(dest, sizeof(dest), "%s%s", FullNANDPath, SYSCONFPATH);
|
2012-07-22 21:18:00 +02:00
|
|
|
__DumpNandFile(SYSCONFPATH, dest);
|
|
|
|
|
2012-12-22 17:47:02 +01:00
|
|
|
snprintf(dest, sizeof(dest), "%s%s", FullNANDPath, TXTPATH);
|
2012-07-22 21:18:00 +02:00
|
|
|
__DumpNandFile(TXTPATH, dest);
|
|
|
|
}
|
2012-06-07 02:34:47 +02:00
|
|
|
if(miis)
|
|
|
|
{
|
2012-12-22 17:47:02 +01:00
|
|
|
snprintf(dest, sizeof(dest), "%s%s", FullNANDPath, MIIPATH);
|
2012-06-07 02:34:47 +02:00
|
|
|
__DumpNandFile(MIIPATH, dest);
|
|
|
|
}
|
2012-07-22 21:18:00 +02:00
|
|
|
return 0;
|
2012-06-07 02:34:47 +02:00
|
|
|
}
|
|
|
|
|
2012-03-17 23:30:16 +01:00
|
|
|
s32 Nand::Do_Region_Change(string id)
|
|
|
|
{
|
2012-03-13 00:57:59 +01:00
|
|
|
if(__configread())
|
|
|
|
{
|
|
|
|
switch(id[3])
|
|
|
|
{
|
|
|
|
case 'J':
|
2012-05-13 17:13:33 +02:00
|
|
|
gprintf("Switching region to NTSC-J \n");
|
2012-03-13 00:57:59 +01:00
|
|
|
CCode[0] = 1;
|
2012-05-13 17:13:33 +02:00
|
|
|
__configsetbyte( "IPL.LNG", 0 );
|
2012-03-13 00:57:59 +01:00
|
|
|
__configsetbigarray( "SADR.LNG", CCode, 0x1007 );
|
|
|
|
__configsetsetting( "AREA", "JPN" );
|
|
|
|
__configsetsetting( "MODEL", "RVL-001(JPN)" );
|
|
|
|
__configsetsetting( "CODE", "LJM" );
|
|
|
|
__configsetsetting( "VIDEO", "NTSC" );
|
2012-05-13 17:13:33 +02:00
|
|
|
__configsetsetting( "GAME", "JP" );
|
|
|
|
break;
|
2012-03-13 00:57:59 +01:00
|
|
|
case 'E':
|
2012-05-13 17:13:33 +02:00
|
|
|
gprintf("Switching region to NTSC-U \n");
|
2012-03-13 00:57:59 +01:00
|
|
|
CCode[0] = 31;
|
2012-05-13 17:13:33 +02:00
|
|
|
__configsetbyte( "IPL.LNG", 1 );
|
2012-03-13 00:57:59 +01:00
|
|
|
__configsetbigarray( "IPL.SADR", CCode, 0x1007 );
|
|
|
|
__configsetsetting( "AREA", "USA" );
|
|
|
|
__configsetsetting( "MODEL", "RVL-001(USA)" );
|
|
|
|
__configsetsetting( "CODE", "LU" );
|
|
|
|
__configsetsetting( "VIDEO", "NTSC" );
|
2012-05-13 17:13:33 +02:00
|
|
|
__configsetsetting( "GAME", "US" );
|
|
|
|
break;
|
2012-03-13 00:57:59 +01:00
|
|
|
case 'D':
|
|
|
|
case 'F':
|
|
|
|
case 'I':
|
|
|
|
case 'M':
|
|
|
|
case 'P':
|
|
|
|
case 'S':
|
2012-05-13 17:13:33 +02:00
|
|
|
case 'U':
|
2012-03-13 00:57:59 +01:00
|
|
|
gprintf("Switching region to PAL \n");
|
|
|
|
CCode[0] = 110;
|
2012-05-13 17:13:33 +02:00
|
|
|
__configsetbyte( "IPL.LNG", 1 );
|
2012-03-13 00:57:59 +01:00
|
|
|
__configsetbigarray( "IPL.SADR", CCode, 0x1007 );
|
|
|
|
__configsetsetting( "AREA", "EUR" );
|
|
|
|
__configsetsetting( "MODEL", "RVL-001(EUR)" );
|
|
|
|
__configsetsetting( "CODE", "LEH" );
|
|
|
|
__configsetsetting( "VIDEO", "PAL" );
|
2012-05-13 17:13:33 +02:00
|
|
|
__configsetsetting( "GAME", "EU" );
|
|
|
|
break;
|
|
|
|
case 'K':
|
|
|
|
gprintf("Switching region to NTSC-K \n");
|
2012-03-13 00:57:59 +01:00
|
|
|
CCode[0] = 137;
|
2012-05-13 17:13:33 +02:00
|
|
|
__configsetbyte( "IPL.LNG", 9 );
|
2012-03-13 00:57:59 +01:00
|
|
|
__configsetbigarray( "IPL.SADR", CCode, 0x1007 );
|
|
|
|
__configsetsetting( "AREA", "KOR" );
|
|
|
|
__configsetsetting( "MODEL", "RVL-001(KOR)" );
|
|
|
|
__configsetsetting( "CODE", "LKM" );
|
|
|
|
__configsetsetting( "VIDEO", "NTSC" );
|
|
|
|
__configsetsetting( "GAME", "KR" );
|
2012-05-13 17:13:33 +02:00
|
|
|
break;
|
2012-03-13 00:57:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
__configwrite();
|
2012-07-26 00:12:17 +02:00
|
|
|
return 1;
|
2012-05-13 17:13:33 +02:00
|
|
|
}
|
2012-08-21 18:33:44 +02:00
|
|
|
|
2012-10-14 19:18:13 +02:00
|
|
|
void Nand::Init_ISFS()
|
|
|
|
{
|
2013-01-27 13:12:44 +01:00
|
|
|
if(isfs_inited)
|
|
|
|
return;
|
2012-12-22 19:57:19 +01:00
|
|
|
if(IOS_GetVersion() < 222)
|
2013-01-27 13:12:44 +01:00
|
|
|
PatchIOS();
|
2012-12-25 14:42:53 +01:00
|
|
|
usleep(1000);
|
2012-12-22 19:57:19 +01:00
|
|
|
gprintf("Init ISFS\n");
|
|
|
|
ISFS_Initialize();
|
2013-01-27 13:12:44 +01:00
|
|
|
isfs_inited = true;
|
2012-10-14 19:18:13 +02:00
|
|
|
}
|
|
|
|
|
2013-01-27 13:12:44 +01:00
|
|
|
void Nand::DeInit_ISFS()
|
2012-10-14 19:18:13 +02:00
|
|
|
{
|
2012-10-15 07:12:18 +02:00
|
|
|
gprintf("Deinit ISFS\n");
|
2012-08-22 17:29:42 +02:00
|
|
|
ISFS_Deinitialize();
|
2013-01-27 13:12:44 +01:00
|
|
|
isfs_inited = false;
|
2012-12-25 14:42:53 +01:00
|
|
|
usleep(1000);
|
2012-08-21 18:33:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Thanks to postloader for that patch */
|
|
|
|
#define ES_MODULE_START (u16*)0x939F0000
|
|
|
|
|
|
|
|
static const u16 ticket_check[] = {
|
|
|
|
0x685B, // ldr r3,[r3,#4] ; get TMD pointer
|
|
|
|
0x22EC, 0x0052, // movls r2, 0x1D8
|
|
|
|
0x189B, // adds r3, r3, r2; add offset of access rights field in TMD
|
|
|
|
0x681B, // ldr r3, [r3] ; load access rights (haxxme!)
|
|
|
|
0x4698, // mov r8, r3 ; store it for the DVD video bitcheck later
|
|
|
|
0x07DB // lsls r3, r3, #31; check AHBPROT bit
|
|
|
|
};
|
|
|
|
|
|
|
|
void Nand::PatchAHB()
|
|
|
|
{
|
|
|
|
for(u16 *patchme = ES_MODULE_START; patchme < ES_MODULE_START + 0x4000; patchme++)
|
|
|
|
{
|
|
|
|
if(!memcmp(patchme, ticket_check, sizeof(ticket_check)))
|
|
|
|
{
|
|
|
|
// write16/uncached poke doesn't work for this. Go figure.
|
|
|
|
patchme[4] = 0x23FF; // li r3, 0xFF
|
|
|
|
DCFlushRange(patchme + 4, 2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-26 14:40:34 +02:00
|
|
|
|
2012-10-14 19:18:13 +02:00
|
|
|
void Nand::Patch_AHB()
|
|
|
|
{
|
|
|
|
if(AHBRPOT_Patched())
|
|
|
|
{
|
|
|
|
// Disable memory protection
|
|
|
|
write16(MEM_PROT, 0);
|
|
|
|
// Do patches
|
|
|
|
PatchAHB();
|
|
|
|
// Enable memory protection
|
|
|
|
write16(MEM_PROT, 1);
|
|
|
|
}
|
|
|
|
}
|
2012-08-26 14:40:34 +02:00
|
|
|
|
2012-12-22 17:47:02 +01:00
|
|
|
u8 *Nand::GetEmuFile(const char *path, u32 *size, s32 len)
|
|
|
|
{
|
|
|
|
u32 filesize = 0;
|
|
|
|
const char *tmp_path = fmt("%s%s", FullNANDPath, path);
|
|
|
|
bool ret = fsop_GetFileSizeBytes(tmp_path, &filesize);
|
|
|
|
if(ret == false || filesize == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if(len > 0)
|
|
|
|
filesize = min(filesize, (u32)len);
|
|
|
|
u8 *tmp_buf = (u8*)MEM2_alloc(filesize);
|
|
|
|
FILE *f = fopen(tmp_path, "rb");
|
|
|
|
fread(tmp_buf, filesize, 1, f);
|
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
DCFlushRange(tmp_buf, filesize);
|
|
|
|
*size = filesize;
|
|
|
|
return tmp_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 *Nand::GetChannels(u32 *count)
|
|
|
|
{
|
|
|
|
u32 size = 0;
|
|
|
|
u8 *uid_buf = GetEmuFile("/sys/uid.sys", &size);
|
|
|
|
if(uid_buf == NULL || size == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
uid *uid_file = (uid*)uid_buf;
|
|
|
|
u32 chans = size/sizeof(uid);
|
|
|
|
u64 *title_buf = (u64*)MEM2_alloc(chans*sizeof(u64));
|
|
|
|
for(u32 i = 0; i < chans; ++i)
|
|
|
|
title_buf[i] = uid_file[i].TitleID;
|
|
|
|
MEM2_free(uid_buf);
|
|
|
|
|
|
|
|
DCFlushRange(title_buf, chans);
|
|
|
|
*count = chans;
|
|
|
|
return title_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 *Nand::GetTMD(u64 title, u32 *size)
|
|
|
|
{
|
|
|
|
u32 tmd_size = 0;
|
|
|
|
const char *tmd_path = fmt("/title/%08x/%08x/content/title.tmd",
|
|
|
|
TITLE_UPPER(title), TITLE_LOWER(title));
|
|
|
|
u8 *tmd_buf = GetEmuFile(tmd_path, &tmd_size);
|
|
|
|
|
|
|
|
*size = tmd_size;
|
|
|
|
return tmd_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Nand::SetPaths(const char *emuPath, const char *currentPart)
|
|
|
|
{
|
2012-12-22 23:28:58 +01:00
|
|
|
memset(&NandPath, 0, sizeof(NandPath));
|
2012-12-22 17:47:02 +01:00
|
|
|
if(emuPath[0] == '\0' || emuPath[0] == ' ')
|
|
|
|
return;
|
|
|
|
else if(emuPath[0] != '/' && emuPath[1] != '\0') //missing / before path
|
2012-12-22 23:28:58 +01:00
|
|
|
strcat(NandPath, "/");
|
2012-12-22 17:47:02 +01:00
|
|
|
for(u32 i = 0; emuPath[i] != '\0'; i++)
|
|
|
|
{
|
|
|
|
if(emuPath[i] == '/' && emuPath[i+1] == '\0')
|
|
|
|
break;
|
2012-12-22 23:28:58 +01:00
|
|
|
strncat(NandPath, &emuPath[i], 1);
|
2012-12-22 17:47:02 +01:00
|
|
|
}
|
2012-12-24 13:19:30 +01:00
|
|
|
/* Our WiiFlow handle Path */
|
2012-12-22 23:28:58 +01:00
|
|
|
memset(&FullNANDPath, 0, sizeof(FullNANDPath));
|
|
|
|
strcat(FullNANDPath, fmt("%s:%s", currentPart, NandPath));
|
|
|
|
gprintf("Emu NAND Full Path = %s\n", FullNANDPath);
|
2012-12-24 13:19:30 +01:00
|
|
|
/* For d2x IOS Path */
|
|
|
|
if(strlen(NandPath) == 0) strcat(NandPath, "/");
|
|
|
|
gprintf("IOS Compatible NAND Path = %s\n", NandPath);
|
2012-12-22 17:47:02 +01:00
|
|
|
}
|
|
|
|
|
2012-08-26 14:40:34 +02:00
|
|
|
/*
|
|
|
|
part of miniunz.c
|
|
|
|
Version 1.01e, February 12th, 2005
|
|
|
|
|
|
|
|
Copyright (C) 1998-2005 Gilles Vollant
|
|
|
|
*/
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <utime.h>
|
|
|
|
|
|
|
|
struct stat exists;
|
|
|
|
static int mymkdir(const char* dirname)
|
|
|
|
{
|
|
|
|
if(stat(dirname, &exists) == 0)
|
|
|
|
return 0;
|
|
|
|
return mkdir(dirname, S_IREAD | S_IWRITE);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Nand::__makedir(char *newdir)
|
|
|
|
{
|
|
|
|
if(stat(newdir, &exists) == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
int len = (int)strlen(newdir);
|
|
|
|
if(len <= 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
char *buffer = (char*)MEM2_alloc(len + 1);
|
|
|
|
strcpy(buffer, newdir);
|
|
|
|
|
|
|
|
if(buffer[len-1] == '/')
|
|
|
|
buffer[len-1] = '\0';
|
|
|
|
if(mymkdir(buffer) == 0)
|
|
|
|
{
|
|
|
|
MEM2_free(buffer);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *p = buffer + 1;
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
char hold;
|
|
|
|
while(*p && *p != '\\' && *p != '/')
|
|
|
|
p++;
|
|
|
|
hold = *p;
|
|
|
|
*p = 0;
|
|
|
|
if((mymkdir(buffer) == -1) && (errno == ENOENT))
|
|
|
|
{
|
|
|
|
gprintf("couldn't create directory %s\n",buffer);
|
|
|
|
MEM2_free(buffer);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(hold == 0)
|
|
|
|
break;
|
|
|
|
*p++ = hold;
|
|
|
|
}
|
|
|
|
MEM2_free(buffer);
|
|
|
|
return 1;
|
|
|
|
}
|