Files
2023-02-14 22:59:51 -07:00

192 lines
4.8 KiB
C++

#include "Common.h"
#include "Utilities.h"
#include "LncUtil.h"
#include "ShellCoreUtilWrapper.h"
void klog(const char* fmt, ...)
{
char Buffer[0x200];
//Create full string from va list.
va_list args;
va_start(args, fmt);
vsprintf(Buffer, fmt, args);
va_end(args);
sceKernelDebugOutText(0, Buffer);
}
void Notify(const char* MessageFMT, ...)
{
OrbisNotificationRequest Buffer;
//Create full string from va list.
va_list args;
va_start(args, MessageFMT);
vsprintf(Buffer.message, MessageFMT, args);
va_end(args);
//Populate the notify buffer.
Buffer.type = OrbisNotificationRequestType::NotificationRequest; //this one is just a standard one and will print what ever is stored at the buffer.Message.
Buffer.unk3 = 0;
Buffer.useIconImageUri = 1; //Bool to use a custom uri.
Buffer.targetId = -1; //Not sure if name is correct but is always set to -1.
strcpy(Buffer.iconUri, "https://i.imgur.com/SJPIBGG.png"); //Copy the uri to the buffer.
//From user land we can call int64_t sceKernelSendNotificationRequest(int64_t unk1, char* Buffer, size_t size, int64_t unk2) which is a libkernel import.
sceKernelSendNotificationRequest(0, &Buffer, 3120, 0);
}
void Notify_Custom(const char* IconURI, const char* MessageFMT, ...)
{
OrbisNotificationRequest Buffer;
//Create full string from va list.
va_list args;
va_start(args, MessageFMT);
vsprintf(Buffer.message, MessageFMT, args);
va_end(args);
//Populate the notify buffer.
Buffer.type = OrbisNotificationRequestType::NotificationRequest; //this one is just a standard one and will print what ever is stored at the buffer.Message.
Buffer.unk3 = 0;
Buffer.useIconImageUri = 1; //Bool to use a custom uri.
Buffer.targetId = -1; //Not sure if name is correct but is always set to -1.
strcpy(Buffer.iconUri, IconURI); //Copy the uri to the buffer.
//From user land we can call int64_t sceKernelSendNotificationRequest(int64_t unk1, char* Buffer, size_t size, int64_t unk2) which is a libkernel import.
sceKernelSendNotificationRequest(0, &Buffer, 3120, 0);
//What sceKernelSendNotificationRequest is doing is opening the device "/dev/notification0" or "/dev/notification1"
// and writing the NotifyBuffer we created to it. Somewhere in ShellUI it is read and parsed into a json which is where
// I found some clues on how to build the buffer.
}
static void build_iovec(iovec** iov, int* iovlen, const char* name, const void* val, size_t len) {
int i;
if (*iovlen < 0)
return;
i = *iovlen;
*iov = (iovec*)realloc(*iov, sizeof * *iov * (i + 2));
if (*iov == NULL) {
*iovlen = -1;
return;
}
(*iov)[i].iov_base = strdup(name);
(*iov)[i].iov_len = strlen(name) + 1;
++i;
(*iov)[i].iov_base = (void*)val;
if (len == (size_t)-1) {
if (val != NULL)
len = strlen((const char*)val) + 1;
else
len = 0;
}
(*iov)[i].iov_len = (int)len;
*iovlen = ++i;
}
int nmount(struct iovec* iov, uint32_t niov, int flags)
{
return syscall(378, iov, niov, flags);
}
int unmount(const char* dir, int flags)
{
return syscall(22, dir, flags);
}
int mount_large_fs(const char* device, const char* mountpoint, const char* fstype, const char* mode, unsigned int flags)
{
struct iovec* iov = NULL;
int iovlen = 0;
build_iovec(&iov, &iovlen, "fstype", fstype, -1);
build_iovec(&iov, &iovlen, "fspath", mountpoint, -1);
build_iovec(&iov, &iovlen, "from", device, -1);
build_iovec(&iov, &iovlen, "large", "yes", -1);
build_iovec(&iov, &iovlen, "timezone", "static", -1);
build_iovec(&iov, &iovlen, "async", "", -1);
build_iovec(&iov, &iovlen, "ignoreacl", "", -1);
if (mode) {
build_iovec(&iov, &iovlen, "dirmask", mode, -1);
build_iovec(&iov, &iovlen, "mask", mode, -1);
}
return nmount(iov, iovlen, flags);
}
void DisableUpdates()
{
sceKernelUnlink("/update/PS4UPDATE.PUP.net.temp");
sceKernelRmdir("/update/PS4UPDATE.PUP.net.temp");
sceKernelMkdir("/update/PS4UPDATE.PUP.net.temp", 777);
sceKernelUnlink("/update/PS4UPDATE.PUP");
sceKernelRmdir("/update/PS4UPDATE.PUP");
sceKernelMkdir("/update/PS4UPDATE.PUP", 777);
}
/*
vm:
1 - Seems to be system
2 - seems to be app specific.
type:
1 - System,
2 - VRAM
System,
Video,
SharedVideoSystemAsset,
SharedVideoHighResoAsset
*/
void Get_Page_Table_Stats(int vm, int type, int* Used, int* Free, int* Total)
{
int _Total = 0, _Free = 0;
if (get_page_table_stats(vm, type, &_Total, &_Free) == -1) {
klog("get_page_table_stats() Failed.\n");
return;
}
if (Used)
*Used = (_Total - _Free);
if (Free)
*Free = _Free;
if (Total)
*Total = _Total;
}
bool SockSendInt(OrbisNetId Sock, int val)
{
return !(sceNetSend(Sock, &val, sizeof(int), 0) < 0);
}
bool SockRecvInt(OrbisNetId Sock, int* val)
{
return !(sceNetRecv(Sock, val, sizeof(int), 0) < 0);
}
int RecieveInt(OrbisNetId Sock)
{
int Int = 0;
if (sceNetRecv(Sock, &Int, sizeof(int), 0) < 0)
{
SockSendInt(Sock, 0);
return 0;
}
SockSendInt(Sock, 1);
return Int;
}