280 lines
7.5 KiB
C
280 lines
7.5 KiB
C
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <psp2/ctrl.h>
|
|
#include <psp2/kernel/threadmgr.h>
|
|
#include <sys/time.h>
|
|
#include <taihen.h>
|
|
#include <vitasdk.h>
|
|
|
|
#include "graphics.h"
|
|
#include "rtcUserBridge.h"
|
|
|
|
#define printf psvDebugScreenPrintf
|
|
|
|
int ret;
|
|
SceUID fd;
|
|
|
|
int get_key(void) {
|
|
static unsigned buttons[] = {
|
|
SCE_CTRL_SELECT,
|
|
SCE_CTRL_START,
|
|
SCE_CTRL_UP,
|
|
SCE_CTRL_RIGHT,
|
|
SCE_CTRL_DOWN,
|
|
SCE_CTRL_LEFT,
|
|
SCE_CTRL_LTRIGGER,
|
|
SCE_CTRL_RTRIGGER,
|
|
SCE_CTRL_TRIANGLE,
|
|
SCE_CTRL_CIRCLE,
|
|
SCE_CTRL_CROSS,
|
|
SCE_CTRL_SQUARE,
|
|
};
|
|
|
|
static unsigned prev = 0;
|
|
SceCtrlData pad;
|
|
while (1) {
|
|
memset(&pad, 0, sizeof(pad));
|
|
sceCtrlPeekBufferPositive(0, &pad, 1);
|
|
unsigned newb = prev ^ (pad.buttons & prev);
|
|
prev = pad.buttons;
|
|
for (int i = 0; i < sizeof(buttons)/sizeof(*buttons); ++i)
|
|
if (newb & buttons[i])
|
|
return buttons[i];
|
|
|
|
sceKernelDelayThread(1000); // 1ms
|
|
}
|
|
}
|
|
|
|
int WriteFile(char *file, void *buf, int size) {
|
|
SceUID fd = sceIoOpen(file, SCE_O_WRONLY | SCE_O_CREAT | SCE_O_TRUNC, 0777);
|
|
if (fd < 0)
|
|
return fd;
|
|
|
|
int written = sceIoWrite(fd, buf, size);
|
|
|
|
sceIoClose(fd);
|
|
return written;
|
|
}
|
|
|
|
int ReadFile(char *file, void *buf, int size) {
|
|
SceUID fd = sceIoOpen(file,SCE_O_RDONLY, 0777);
|
|
if (fd < 0)
|
|
return fd;
|
|
|
|
int read = sceIoRead(fd, buf, size);
|
|
|
|
sceIoClose(fd);
|
|
return read;
|
|
}
|
|
|
|
int getFileSize(const char *file) {
|
|
SceUID fd = sceIoOpen(file, SCE_O_RDONLY, 0);
|
|
if (fd < 0)
|
|
return fd;
|
|
int fileSize = sceIoLseek(fd, 0, SCE_SEEK_END);
|
|
sceIoClose(fd);
|
|
return fileSize;
|
|
}
|
|
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
psvDebugScreenInit();
|
|
if(vshSblAimgrIsDEX() == 0)
|
|
{
|
|
printf("This is not a testing kit . . . \n");
|
|
get_key();
|
|
sceKernelExitProcess(0);
|
|
}
|
|
|
|
char kplugin_path[0x200];
|
|
memset(kplugin_path,0x00,0x200);
|
|
|
|
char uplugin_path[0x200];
|
|
memset(uplugin_path,0x00,0x200);
|
|
|
|
char titleid[12];
|
|
sceAppMgrUmount("app0:");
|
|
|
|
printf("Loading kmodule...");
|
|
|
|
sceAppMgrAppParamGetString(0, 12, titleid , 256);
|
|
sprintf(kplugin_path, "ux0:app/%s/kern_clockset.skprx", titleid);
|
|
int kernel_modid = 0;
|
|
kernel_modid = taiLoadStartKernelModule(kplugin_path, 0, NULL, 0);
|
|
|
|
|
|
if(kernel_modid <= 0 && kernel_modid != 0x8002d013 && kernel_modid != 0x8002d004)
|
|
{
|
|
printf("Error cannot load kern_clockset.skprx error 0x%x\n",kernel_modid);
|
|
get_key();
|
|
sceKernelExitProcess(0);
|
|
}
|
|
|
|
printf("OK\n");
|
|
|
|
printf("Loading umodule...");
|
|
|
|
sceAppMgrAppParamGetString(0, 12, titleid , 256);
|
|
sprintf(uplugin_path, "ux0:app/%s/user_clockset.suprx", titleid);
|
|
int user_modid = 0;
|
|
user_modid = sceKernelLoadStartModule(uplugin_path, 0, NULL, 0, NULL, NULL);
|
|
|
|
|
|
if(user_modid <= 0)
|
|
{
|
|
printf("Error cannot load user_clockset.suprx error 0x%x\n",user_modid);
|
|
get_key();
|
|
sceKernelExitProcess(0);
|
|
}
|
|
|
|
printf("OK\n");
|
|
|
|
|
|
|
|
|
|
printf("Finding expiration start date...");
|
|
|
|
unsigned char startDate[0x4];
|
|
fd = sceIoOpen("tm0:/activate/act.dat",SCE_O_RDONLY, 0444);
|
|
if(fd <= -1)
|
|
{
|
|
printf("\ntm0:/activate/act.dat not found, cannot proceed :'( 0x%x\n",ret);
|
|
get_key();
|
|
sceKernelExitProcess(0);
|
|
}
|
|
|
|
sceIoLseek(fd,0xC,SCE_SEEK_SET);
|
|
sceIoRead(fd,&startDate,0x04);
|
|
sceIoClose(fd);
|
|
|
|
fd = sceIoOpen("tm0:/activate/actsig.dat",SCE_O_RDONLY, 0444);
|
|
if(fd <= -1)
|
|
{
|
|
printf("\ntm0:/activate/actsig.dat not found, cannot proceed :'( 0x%x\n",ret);
|
|
get_key();
|
|
sceKernelExitProcess(0);
|
|
}
|
|
sceIoClose(fd);
|
|
|
|
printf(" found: 0x%02X%02X%02X%02X\n",startDate[0],startDate[1],startDate[2],startDate[3]);
|
|
|
|
|
|
printf("Backing up activation files... ");
|
|
|
|
uint32_t buf[3];
|
|
buf[0] = 0x00;
|
|
buf[1] = 0x00;
|
|
buf[2] = 0x00;
|
|
|
|
vshIoUmount(0xC00, 0, 0, 0);
|
|
vshIoUmount(0xC00, 1, 0, 0);
|
|
_vshIoMount(0xC00, 0, 2, buf);
|
|
|
|
//backup actdat
|
|
int size = getFileSize("tm0:/activate/act.dat");
|
|
if (size <= -1){
|
|
printf("getFileSize Failed, ret: 0x%x\n",size);
|
|
}
|
|
else
|
|
{
|
|
char *actdat = malloc(size);
|
|
ret = ReadFile("tm0:/activate/act.dat",actdat,size);
|
|
if (ret <= -1)
|
|
{
|
|
printf("ReadFile act failed 0x%x\n",ret);
|
|
}
|
|
|
|
ret = WriteFile("pd0:/data/act.dat",actdat,size);
|
|
if (ret <= -1){
|
|
printf("WriteFile actsig failed 0x%x\n",ret);
|
|
}
|
|
ret = WriteFile("ux0:/data/act.dat",actdat,size);
|
|
if (ret <= -1){
|
|
printf("WriteFile act failed 0x%x\n",ret);
|
|
}
|
|
}
|
|
|
|
//backup actsig
|
|
size = getFileSize("tm0:/activate/actsig.dat");
|
|
if (size <= -1){
|
|
printf("getFileSize failed ret: 0x%x\n",size);
|
|
}
|
|
else
|
|
{
|
|
char *actsig = malloc(size);
|
|
|
|
ret = ReadFile("tm0:/activate/actsig.dat",actsig,size);
|
|
if (ret <= -1){
|
|
printf("ReadFile actsig failed 0x%x\n",ret);
|
|
}
|
|
|
|
ret = WriteFile("pd0:/data/actsig.dat",actsig,size);
|
|
if (ret <= -1){
|
|
printf("WriteFile actsig failed 0x%x\n",ret);
|
|
}
|
|
|
|
ret = WriteFile("ux0:/data/actsig.dat",actsig,size);
|
|
if (ret <= -1){
|
|
printf("WriteFile actsig failed 0x%x\n",ret);
|
|
}
|
|
}
|
|
|
|
vshIoUmount(0xC00, 0, 0, 0);
|
|
vshIoUmount(0xC00, 1, 0, 0);
|
|
_vshIoMount(0xC00, 0, 1, buf);
|
|
|
|
printf("Done, backup at pd0:/data and ux0:/data\n");
|
|
|
|
printf("Calculating PSTime: ");
|
|
|
|
unsigned long long int timestamp;
|
|
memset(×tamp,0,sizeof(unsigned long long int));
|
|
timestamp = *((unsigned int*)&startDate);
|
|
timestamp = ((timestamp * 1000) + 62135596800000) * 1000;
|
|
|
|
|
|
printf("%llx\n",timestamp);
|
|
|
|
printf("Creating splits..\n");
|
|
char hexint[15];
|
|
memset(hexint,0,15);
|
|
|
|
sprintf(hexint,"%llx",timestamp);
|
|
|
|
char ts1[7] = {hexint[0],hexint[1],hexint[2],hexint[3],hexint[4],hexint[5],0x00};
|
|
unsigned long long int split1 = (unsigned int)strtoul(ts1, NULL, 16);
|
|
printf("Split1: %llx\n",split1);
|
|
|
|
|
|
char ts2[10] = {hexint[6],hexint[7],hexint[8],hexint[9],hexint[10],hexint[11],hexint[12],hexint[13],hexint[14],0x00};
|
|
unsigned long long int split2 = (unsigned int)strtoul(ts2, NULL, 16);
|
|
printf("Split2: %llx\n",split2);
|
|
|
|
printf("Updating SecureTick.. ");
|
|
|
|
ret = silRtcSetCurrentSecureTick(split2,split1);
|
|
sceRegMgrSetKeyInt("/CONFIG/DATE", "set_automatically", 0);
|
|
|
|
printf("has ret 0x%x\n",ret);
|
|
|
|
if(ret == 0)
|
|
{
|
|
printf("\n\nYour PSVITA Testing Kit has been activated!\n");
|
|
printf("\n");
|
|
printf("Deactivate by holding START + SELECT + PS + POWER\n\n");
|
|
printf("Press any key to reboot console");
|
|
get_key();
|
|
scePowerRequestColdReset();
|
|
}
|
|
else
|
|
{
|
|
printf("Error: 0x%x\n",ret);
|
|
}
|
|
|
|
get_key();
|
|
}
|