int (*sceKernelGetIdPs)(void* ret);
int (*sceKernelGetOpenPsIdForSystem)(void* ret);
int kernel_lib = sceKernelLoadStartModule("libkernel.sprx", 0, NULL, 0, NULL, NULL);
sceKernelDlsym(kernel_lib, "sceKernelGetIdPs", &sceKernelGetIdPs);
sceKernelDlsym(kernel_lib, "sceKernelGetOpenPsIdForSystem", &sceKernelGetOpenPsIdForSystem);
void* idps = malloc(64);
void* psid = malloc(16);
sceKernelGetIdPs(idps); // Missing some byte at end
sceKernelGetOpenPsIdForSystem(psid);

public static Socket _psocket;
public static bool pDConnected;
public static string IP = "192.168.0.8";//Temporary.
public static void Connect2PS4(string ip)
{
try
{
_psocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_psocket.ReceiveTimeout = 3000;
_psocket.SendTimeout = 3000;
_psocket.Connect(new IPEndPoint(IPAddress.Parse(IP), 9023));
pDConnected = true;
return true;
}
catch
{
pDConnected = false;
return false;
}
}
public static bool SendPayload(string filename)
{
_psocket.SendFile(filename);
return true;
}
public static bool DisconnectPayload()
{
pDConnected = false;
_psocket.Close();
return true;
}
//Below is a simple example using the above to send the payload to ps4.
Connect2PS4(IP);
if(_pConnected)
{
OpenFileDialog FileO = new OpenFileDialog();
FileO.FileName = "payload.bin";
FileO.InitialDirectory = "C:\\";
FileO.Filter = "bin files|*.bin|All Files|*.*";
DialogResult result = FileO.ShowDialog();
if(result == DialogResult.OK)
SendPayload(FileO.FileName);
DisconnectPayload();
}