2017-09-15 16:16:13 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2018-07-31 18:59:17 +00:00
|
|
|
#include "fs.h"
|
2017-06-25 16:58:31 +00:00
|
|
|
#include "kernel.h"
|
2017-07-17 06:57:18 +00:00
|
|
|
#include "system.h"
|
2018-07-31 18:59:17 +00:00
|
|
|
#include "utils.h"
|
2017-06-25 16:58:31 +00:00
|
|
|
|
2018-07-31 18:59:17 +00:00
|
|
|
char *Kernel_GetInitalVersion(void)
|
|
|
|
{
|
|
|
|
static char initialVer[0xB];
|
|
|
|
|
|
|
|
FS_OpenArchive(&archive, ARCHIVE_NAND_TWL_FS);
|
|
|
|
|
|
|
|
Handle handle;
|
|
|
|
|
|
|
|
if (R_FAILED(FSUSER_OpenFileDirectly(&handle, ARCHIVE_NAND_TWL_FS, fsMakePath(PATH_EMPTY, ""), fsMakePath(PATH_ASCII, "/sys/log/product.log"), FS_OPEN_READ, 0)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
u64 size64 = 0;
|
|
|
|
u32 size = 0;
|
|
|
|
|
|
|
|
if (R_FAILED(FSFILE_GetSize(handle, &size64)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
size = (u32)size64;
|
|
|
|
|
|
|
|
char *buf = (char *)malloc(size + 1);
|
|
|
|
u32 bytesread = 0;
|
|
|
|
|
|
|
|
if (R_FAILED(FSFILE_Read(handle, &bytesread, 0, (u32 *)buf, size)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
buf[size] = '\0';
|
|
|
|
|
|
|
|
// New 3DS/2DS only
|
|
|
|
strcpy(initialVer, Utils_ExtractBetween(buf, "cup:", " preInstall:"));
|
|
|
|
|
|
|
|
if (strlen(initialVer) == 0)
|
|
|
|
strcpy(initialVer, Utils_ExtractBetween(buf, "cup:", ","));
|
|
|
|
|
|
|
|
strcat(initialVer, "-");
|
|
|
|
strcat(initialVer, Utils_ExtractBetween(buf, "nup:", " cup:"));
|
|
|
|
|
|
|
|
if (R_FAILED(FSFILE_Close(handle)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
free(buf);
|
|
|
|
|
|
|
|
FS_CloseArchive(archive);
|
|
|
|
|
|
|
|
return initialVer;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *Kernel_GetVersion(int version)
|
2017-06-25 16:58:31 +00:00
|
|
|
{
|
|
|
|
char *str_kernel = (char *)malloc(sizeof(char) * 255), *str_ver = (char *)malloc(sizeof(char) * 255), *str_sysver = (char *)malloc(sizeof(char) * 255);
|
|
|
|
u32 os_ver = osGetKernelVersion(), firm_ver = osGetKernelVersion();
|
|
|
|
OS_VersionBin *nver = (OS_VersionBin *)malloc(sizeof(OS_VersionBin)), *cver = (OS_VersionBin *)malloc(sizeof(OS_VersionBin));
|
|
|
|
s32 ret;
|
|
|
|
|
|
|
|
snprintf(str_kernel, 255, "%lu.%lu-%lu",
|
|
|
|
GET_VERSION_MAJOR(os_ver),
|
|
|
|
GET_VERSION_MINOR(os_ver),
|
|
|
|
GET_VERSION_REVISION(os_ver)
|
|
|
|
);
|
|
|
|
|
2017-07-17 06:57:18 +00:00
|
|
|
snprintf(str_ver, 255, "%lu.%lu-%lu",
|
2017-06-25 16:58:31 +00:00
|
|
|
GET_VERSION_MAJOR(firm_ver),
|
|
|
|
GET_VERSION_MINOR(firm_ver),
|
|
|
|
GET_VERSION_REVISION(firm_ver)
|
|
|
|
);
|
|
|
|
|
|
|
|
memset(nver, 0, sizeof(OS_VersionBin));
|
|
|
|
memset(cver, 0, sizeof(OS_VersionBin));
|
|
|
|
|
2017-09-17 06:16:14 +00:00
|
|
|
if (R_FAILED(ret = osGetSystemVersionData(nver, cver)))
|
2017-06-25 16:58:31 +00:00
|
|
|
snprintf(str_sysver, 100, "0x%08liX", ret);
|
|
|
|
else
|
2017-07-17 06:57:18 +00:00
|
|
|
snprintf(str_sysver, 100, "%d.%d.%d-%d%c",
|
2017-06-25 16:58:31 +00:00
|
|
|
cver->mainver,
|
|
|
|
cver->minor,
|
|
|
|
cver->build,
|
2017-07-17 06:57:18 +00:00
|
|
|
nver->mainver,
|
2018-07-31 18:59:17 +00:00
|
|
|
System_GetFirmRegion()
|
2017-07-17 06:57:18 +00:00
|
|
|
);
|
2017-06-25 16:58:31 +00:00
|
|
|
|
|
|
|
if (version == 0)
|
|
|
|
return str_kernel;
|
2017-09-17 16:45:30 +00:00
|
|
|
else if (version == 1)
|
2017-06-25 16:58:31 +00:00
|
|
|
return str_ver;
|
2018-07-31 18:59:17 +00:00
|
|
|
else if (version == 2)
|
|
|
|
return Kernel_GetInitalVersion();
|
2017-06-25 16:58:31 +00:00
|
|
|
else
|
|
|
|
return str_sysver;
|
|
|
|
}
|
|
|
|
|
2018-07-31 18:59:17 +00:00
|
|
|
char *Kernel_GetSDMCCID(void)
|
2017-06-25 16:58:31 +00:00
|
|
|
{
|
|
|
|
u8 buf[16];
|
2017-07-17 06:57:18 +00:00
|
|
|
static char cid[33];
|
2017-09-15 16:16:13 +00:00
|
|
|
|
|
|
|
if (R_SUCCEEDED(FSUSER_GetSdmcCid(buf, 0x10)))
|
|
|
|
{
|
|
|
|
snprintf(cid, 33, "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
|
|
|
|
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5],
|
|
|
|
buf[6], buf[7], buf[8], buf[9], buf[10], buf[11],
|
|
|
|
buf[12], buf[13], buf[14], buf[15]);
|
2018-07-31 18:59:17 +00:00
|
|
|
|
|
|
|
return cid;
|
2017-09-15 16:16:13 +00:00
|
|
|
}
|
2018-07-31 18:59:17 +00:00
|
|
|
|
|
|
|
return NULL;
|
2017-09-15 16:16:13 +00:00
|
|
|
}
|
|
|
|
|
2018-07-31 18:59:17 +00:00
|
|
|
char *Kernel_GetNANDCID(void)
|
2017-09-15 16:16:13 +00:00
|
|
|
{
|
|
|
|
u8 buf[16];
|
|
|
|
static char cid[33];
|
2017-06-25 16:58:31 +00:00
|
|
|
|
2017-09-15 16:16:13 +00:00
|
|
|
if (R_SUCCEEDED(FSUSER_GetNandCid(buf, 0x10)))
|
|
|
|
{
|
|
|
|
snprintf(cid, 33, "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
|
2017-06-25 16:58:31 +00:00
|
|
|
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5],
|
|
|
|
buf[6], buf[7], buf[8], buf[9], buf[10], buf[11],
|
|
|
|
buf[12], buf[13], buf[14], buf[15]);
|
2018-07-31 18:59:17 +00:00
|
|
|
|
|
|
|
return cid;
|
2017-09-15 16:16:13 +00:00
|
|
|
}
|
2018-07-31 18:59:17 +00:00
|
|
|
|
|
|
|
return NULL;
|
2017-09-15 16:16:13 +00:00
|
|
|
}
|
|
|
|
|
2018-07-31 18:59:17 +00:00
|
|
|
u32 Kernel_GetDeviceId(void) // Same as PS_GetDeviceId
|
2017-09-15 16:16:13 +00:00
|
|
|
{
|
2017-09-17 16:45:30 +00:00
|
|
|
u32 id = 0;
|
2017-09-15 16:16:13 +00:00
|
|
|
|
2017-09-17 16:45:30 +00:00
|
|
|
if (R_SUCCEEDED(AM_GetDeviceId(&id)))
|
2017-09-15 16:16:13 +00:00
|
|
|
return id;
|
|
|
|
|
|
|
|
return 0;
|
2018-07-31 18:59:17 +00:00
|
|
|
}
|