forked from GiantPluto/Playstation-4-Save-Mounter
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Main.cs
676 lines (607 loc) · 25.3 KB
/
Main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
using libdebug;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
namespace PS4Saves
{
public partial class Main : Form
{
PS4DBG ps4 = new PS4DBG();
private int pid;
private ulong stub;
private ulong libSceUserServiceBase = 0x0;
private ulong libSceSaveDataBase = 0x0;
private ulong executableBase = 0x0;
private ulong libSceLibcInternalBase = 0x0;
private ulong GetSaveDirectoriesAddr = 0;
private ulong GetUsersAddr = 0;
private int user = 0x0;
private string selectedGame = null;
string mp = "";
bool log = false;
public Main()
{
InitializeComponent();
string[] args = Environment.GetCommandLineArgs();
if (args.Length == 2 && args[1] == "-log")
{
log = true;
}
if (File.Exists("ip"))
{
ipTextBox.Text = File.ReadAllText("ip");
}
}
public static string FormatSize(double size)
{
const long BytesInKilobytes = 1024;
const long BytesInMegabytes = BytesInKilobytes * 1024;
const long BytesInGigabytes = BytesInMegabytes * 1024;
double value;
string str;
if (size < BytesInGigabytes)
{
value = size / BytesInMegabytes;
str = "MB";
}
else
{
value = size /BytesInGigabytes;
str = "GB";
}
return String.Format("{0:0.##} {1}", value, str);
}
private void sizeTrackBar_Scroll(object sender, EventArgs e)
{
sizeToolTip.SetToolTip(sizeTrackBar, FormatSize((double)(sizeTrackBar.Value * 32768)));
}
private void SetStatus(string msg)
{
statusLabel.Text = $"Status: {msg}";
}
private void WriteLog(string msg)
{
if(log)
{
msg = $"|{msg}|";
var a = msg.Length / 2;
for (var i = 0; i < 48 - a; i++)
{
msg = msg.Insert(0, " ");
}
for (var i = msg.Length; i < 96; i++)
{
msg += " ";
}
var dateAndTime = DateTime.Now;
var logStr = $"|{dateAndTime:MM/dd/yyyy} {dateAndTime:hh:mm:ss tt}| |{msg}|";
if (File.Exists(@"log.txt"))
{
File.AppendAllText(@"log.txt",
$"{logStr}{Environment.NewLine}");
}
else
{
using (var sw = File.CreateText(@"log.txt"))
{
sw.WriteLine(logStr);
}
}
Console.WriteLine(logStr);
}
}
private void connectButton_Click(object sender, EventArgs e)
{
try
{
if (!checkIP(ipTextBox.Text))
{
SetStatus("Invalid IP");
return;
}
ps4 = new PS4DBG(ipTextBox.Text);
ps4.Connect();
if (!ps4.IsConnected)
{
throw new Exception();
}
SetStatus("Connected");
if (!File.Exists("ip"))
{
File.WriteAllText("ip", ipTextBox.Text);
}
else
{
using (var sw = File.CreateText(@"log.txt"))
{
sw.Write(ipTextBox.Text);
}
}
}
catch
{
SetStatus("Failed To Connect");
}
}
private void setupButton_Click(object sender, EventArgs e)
{
if (!ps4.IsConnected)
{
SetStatus("Not connected to ps4");
return;
}
var pl = ps4.GetProcessList();
var su = pl.FindProcess("SceShellUI");
if (su == null)
{
SetStatus("Couldn't find SceShellUI");
return;
}
pid = su.pid;
var pm = ps4.GetProcessMaps(pid);
var tmp = pm.FindEntry("libSceSaveData.sprx")?.start;
if (tmp == null)
{
MessageBox.Show("savedata lib not found", "Error");
return;
}
libSceSaveDataBase = (ulong)tmp;
tmp = pm.FindEntry("libSceUserService.sprx")?.start;
if (tmp == null)
{
MessageBox.Show("user service lib not found", "Error");
return;
}
libSceUserServiceBase = (ulong)tmp;
tmp = pm.FindEntry("executable")?.start;
if (tmp == null)
{
MessageBox.Show("executable not found", "Error");
return;
}
executableBase = (ulong)tmp;
tmp = pm.FindEntry("libSceLibcInternal.sprx")?.start;
if (tmp == null)
{
MessageBox.Show("libc not found", "Error");
return;
}
libSceLibcInternalBase = (ulong)tmp;
stub = pm.FindEntry("(NoName)clienthandler") == null ? ps4.InstallRPC(pid) : pm.FindEntry("(NoName)clienthandler").start;
var ret = ps4.Call(pid, stub, libSceSaveDataBase + offsets.sceSaveDataInitialize3);
WriteLog($"sceSaveDataInitialize3 ret = 0x{ret:X}");
//PATCHES
//SAVEDATA LIBRARY PATCHES (libSceSaveData)
ps4.WriteMemory(pid, libSceSaveDataBase + 0x000360E8, (byte)0x00); // 'sce_' patch
ps4.WriteMemory(pid, libSceSaveDataBase + 0x00034989, (byte)0x00); // 'sce_sdmemory' patch
ps4.WriteMemory(pid, libSceSaveDataBase + 0x00000E81, (byte)0x30); // '_' patch
var l = ps4.GetProcessList();
var s = l.FindProcess("SceShellCore");
var m = ps4.GetProcessMaps(s.pid);
var ex = m.FindEntry("executable");
//SHELLCORE PATCHES (SceShellCore)
ps4.WriteMemory(s.pid, ex.start + 0x01334060, (byte)0x00); // 'sce_sdmemory' patch
ps4.WriteMemory(s.pid, ex.start + 0x0084A300, new byte[]{0x48, 0x31, 0xC0, 0xC3}); //verify keystone patch
ps4.WriteMemory(s.pid, ex.start + 0x0006B860, new byte[] {0x31, 0xC0, 0xC3}); //transfer mount permission patch eg mount foreign saves with write permission
ps4.WriteMemory(s.pid, ex.start + 0x000C7280, new byte[] { 0x31, 0xC0, 0xC3 });//patch psn check to load saves saves foreign to current account
ps4.WriteMemory(s.pid, ex.start + 0x0006D26D, new byte[] { 0x90, 0x90 }); // ^
ps4.WriteMemory(s.pid, ex.start + 0x0006B338, new byte[] {0x90, 0x90, 0x90, 0x90, 0x90, 0x90}); // something something patches...
ps4.WriteMemory(s.pid, ex.start + 0x0006AC2D, new byte[] { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 }); // don't even remember doing this
ps4.WriteMemory(s.pid, ex.start + 0x0006A494, new byte[] { 0x90, 0x90}); //nevah jump
ps4.WriteMemory(s.pid, ex.start + 0x0006A6F0, new byte[] { 0x90, 0xE9 }); //always jump
//WRITE CUSTOM FUNCTIONS (libSceLibcInternal)
GetSaveDirectoriesAddr = ps4.AllocateMemory(pid, 0x8000);
ps4.WriteMemory(pid, GetSaveDirectoriesAddr, functions.GetSaveDirectories);
ps4.WriteMemory(pid, GetSaveDirectoriesAddr + 0x12, libSceLibcInternalBase + 0x000AFBD0); //opendir
ps4.WriteMemory(pid, GetSaveDirectoriesAddr + 0x20, libSceLibcInternalBase + 0x000B0970); //readdir
ps4.WriteMemory(pid, GetSaveDirectoriesAddr + 0x2E, libSceLibcInternalBase + 0x000AE9B0);//closedir
ps4.WriteMemory(pid, GetSaveDirectoriesAddr + 0x3C, libSceLibcInternalBase + 0x000BC220); //strcpy
GetUsersAddr = GetSaveDirectoriesAddr + (uint)functions.GetSaveDirectories.Length + 0x20;
ps4.WriteMemory(pid, GetUsersAddr, functions.GetUsers);
ps4.WriteMemory(pid, GetUsersAddr + 0x15, libSceUserServiceBase + offsets.sceUserServiceGetLoginUserIdList);
ps4.WriteMemory(pid, GetUsersAddr + 0x23, libSceUserServiceBase + offsets.sceUserServiceGetUserName);
ps4.WriteMemory(pid, GetUsersAddr + 0x31, libSceLibcInternalBase + 0x000BC220); //strcpy
var users = GetUsers();
userComboBox.DataSource = users;
SetStatus("Setup Done :)");
}
private void searchButton_Click(object sender, EventArgs e)
{
if (!ps4.IsConnected)
{
SetStatus("Not connected to ps4");
return;
}
if (pid == 0)
{
SetStatus("dont forget to click setup");
return;
}
if (selectedGame == null)
{
SetStatus("No game selected");
return;
}
var pm = ps4.GetProcessMaps(pid);
if (pm.FindEntry("(NoName)clienthandler") == null)
{
SetStatus("RPC Stub Not Found");
return;
}
var dirNameAddr = ps4.AllocateMemory(pid, Marshal.SizeOf(typeof(SceSaveDataDirName)) * 1024 + 0x10 + Marshal.SizeOf(typeof(SceSaveDataParam)) * 1024);
var titleIdAddr = dirNameAddr + (uint) Marshal.SizeOf(typeof(SceSaveDataDirName)) * 1024;
var paramAddr = titleIdAddr + 0x10;
SceSaveDataDirNameSearchCond searchCond = new SceSaveDataDirNameSearchCond
{
userId = GetUser(),
titleId = titleIdAddr
};
SceSaveDataDirNameSearchResult searchResult = new SceSaveDataDirNameSearchResult
{
dirNames = dirNameAddr,
dirNamesNum = 1024,
param = paramAddr,
};
ps4.WriteMemory(pid, titleIdAddr, selectedGame);
dirsComboBox.DataSource = Find(searchCond, searchResult);
ps4.FreeMemory(pid, dirNameAddr, Marshal.SizeOf(typeof(SceSaveDataDirName)) * 1024 + 0x10 + Marshal.SizeOf(typeof(SceSaveDataParam)) * 1024);
if (dirsComboBox.Items.Count > 0)
{
SetStatus($"Found {dirsComboBox.Items.Count} Save Directories :D");
}
else
{
SetStatus("Found 0 Save Directories :(");
}
}
private void mountButton_Click(object sender, EventArgs e)
{
if (!ps4.IsConnected)
{
SetStatus("Not connected to ps4");
return;
}
if (dirsComboBox.Items.Count == 0)
{
SetStatus("No save selected");
return;
}
if (selectedGame == null)
{
SetStatus("No game selected");
return;
}
var dirNameAddr = ps4.AllocateMemory(pid, Marshal.SizeOf(typeof(SceSaveDataDirName)) + 0x10 + 0x41);
var titleIdAddr = dirNameAddr + (uint)Marshal.SizeOf(typeof(SceSaveDataDirName));
var fingerprintAddr = titleIdAddr + 0x10;
ps4.WriteMemory(pid, titleIdAddr, selectedGame);
ps4.WriteMemory(pid, fingerprintAddr, "0000000000000000000000000000000000000000000000000000000000000000");
SceSaveDataDirName dirName = new SceSaveDataDirName
{
data = dirsComboBox.Text
};
SceSaveDataMount mount = new SceSaveDataMount
{
userId = GetUser(),
dirName = dirNameAddr,
blocks = 32768,
mountMode = 0x8 | 0x2,
titleId = titleIdAddr,
fingerprint = fingerprintAddr
};
SceSaveDataMountResult mountResult = new SceSaveDataMountResult
{
};
ps4.WriteMemory(pid, dirNameAddr, dirName);
mp = Mount(mount, mountResult);
ps4.FreeMemory(pid, dirNameAddr, Marshal.SizeOf(typeof(SceSaveDataDirName)) + 0x10 + 0x41);
if (mp != "")
{
SetStatus($"Save Mounted in {mp}");
}
else
{
SetStatus("Mounting Failed");
}
}
private void unmountButton_Click(object sender, EventArgs e)
{
if (!ps4.IsConnected)
{
SetStatus("Not connected to ps4");
return;
}
if (mp == "")
{
SetStatus("No save mounted");
return;
}
SceSaveDataMountPoint mountPoint = new SceSaveDataMountPoint
{
data = mp,
};
Unmount(mountPoint);
mp = null;
SetStatus("Save Unmounted");
}
private void createButton_Click(object sender, EventArgs e)
{
if (!ps4.IsConnected)
{
SetStatus("Not connected to ps4");
return;
}
if (pid == 0)
{
SetStatus("Don't forget to setup");
return;
}
if (nameTextBox.Text == "")
{
SetStatus("No Save Name");
return;
}
if (selectedGame == null)
{
SetStatus("No game selected");
return;
}
var pm = ps4.GetProcessMaps(pid);
if (pm.FindEntry("(NoName)clienthandler") == null)
{
SetStatus("RPC Stub Not Found");
return;
}
var dirNameAddr = ps4.AllocateMemory(pid, Marshal.SizeOf(typeof(SceSaveDataDirName)) + 0x10 + 0x41);
var titleIdAddr = dirNameAddr + (uint)Marshal.SizeOf(typeof(SceSaveDataDirName));
var fingerprintAddr = titleIdAddr + 0x10;
ps4.WriteMemory(pid, fingerprintAddr, "0000000000000000000000000000000000000000000000000000000000000000");
ps4.WriteMemory(pid, titleIdAddr, selectedGame);
SceSaveDataDirName dirName = new SceSaveDataDirName
{
data = nameTextBox.Text
};
SceSaveDataMount mount = new SceSaveDataMount
{
userId = GetUser(),
dirName = dirNameAddr,
blocks = (ulong) sizeTrackBar.Value,
mountMode = 4 | 2 | 8,
titleId = titleIdAddr,
fingerprint = fingerprintAddr
};
SceSaveDataMountResult mountResult = new SceSaveDataMountResult
{
};
ps4.WriteMemory(pid, dirNameAddr, dirName);
var mp = Mount(mount, mountResult);
ps4.FreeMemory(pid, dirNameAddr, Marshal.SizeOf(typeof(SceSaveDataDirName)) + 0x10 + 0x41);
if (mp != "")
{
SetStatus("Save Created");
SceSaveDataMountPoint mountPoint = new SceSaveDataMountPoint
{
data = mp,
};
Unmount(mountPoint);
}
else
{
SetStatus("Save Creation Failed");
}
}
private int GetUser()
{
if(user != 0)
{
return user;
}
return InitialUser();
}
private int InitialUser()
{
var bufferAddr = ps4.AllocateMemory(pid, sizeof(int));
ps4.Call(pid, stub, libSceUserServiceBase + offsets.sceUserServiceGetInitialUser, bufferAddr);
var id = ps4.ReadMemory<int>(pid, bufferAddr);
ps4.FreeMemory(pid, bufferAddr, sizeof(int));
return id;
}
private SearchEntry[] Find(SceSaveDataDirNameSearchCond searchCond, SceSaveDataDirNameSearchResult searchResult)
{
var searchCondAddr = ps4.AllocateMemory(pid, Marshal.SizeOf(typeof(SceSaveDataDirNameSearchCond)) + Marshal.SizeOf(typeof(SceSaveDataDirNameSearchResult)));
var searchResultAddr = searchCondAddr + (uint)Marshal.SizeOf(typeof(SceSaveDataDirNameSearchCond));
ps4.WriteMemory(pid, searchCondAddr, searchCond);
ps4.WriteMemory(pid, searchResultAddr, searchResult);
var ret = ps4.Call(pid, stub, libSceSaveDataBase + offsets.sceSaveDataDirNameSearch, searchCondAddr, searchResultAddr);
WriteLog($"sceSaveDataDirNameSearch ret = 0x{ret:X}");
if ( ret == 0)
{
searchResult = ps4.ReadMemory<SceSaveDataDirNameSearchResult>(pid, searchResultAddr);
SearchEntry[] sEntries = new SearchEntry[searchResult.hitNum];
var paramMemory = ps4.ReadMemory(pid, searchResult.param, (int)searchResult.hitNum * Marshal.SizeOf(typeof(SceSaveDataParam)));
var dirNamesMemory = ps4.ReadMemory(pid, searchResult.dirNames, (int)searchResult.hitNum * 32);
for (int i = 0; i < searchResult.hitNum; i++)
{
SceSaveDataParam tmp = (SceSaveDataParam)PS4DBG.GetObjectFromBytes(PS4DBG.SubArray(paramMemory, i * Marshal.SizeOf(typeof(SceSaveDataParam)), Marshal.SizeOf(typeof(SceSaveDataParam))), typeof(SceSaveDataParam));
sEntries[i] = new SearchEntry
{
dirName = System.Text.Encoding.UTF8.GetString(PS4DBG.SubArray(dirNamesMemory, i * 32, 32)),
title = System.Text.Encoding.UTF8.GetString(tmp.title),
subtitle = System.Text.Encoding.UTF8.GetString(tmp.subTitle),
detail = System.Text.Encoding.UTF8.GetString(tmp.detail),
time = new DateTime(1970, 1, 1).ToLocalTime().AddSeconds(tmp.mtime).ToString(),
};
}
ps4.FreeMemory(pid, searchCondAddr, Marshal.SizeOf(typeof(SceSaveDataDirNameSearchCond)) + Marshal.SizeOf(typeof(SceSaveDataDirNameSearchResult)));
return sEntries;
}
ps4.FreeMemory(pid, searchCondAddr, Marshal.SizeOf(typeof(SceSaveDataDirNameSearchCond)) + Marshal.SizeOf(typeof(SceSaveDataDirNameSearchResult)));
return new SearchEntry[0];
}
private void Unmount(SceSaveDataMountPoint mountPoint)
{
var mountPointAddr = ps4.AllocateMemory(pid, Marshal.SizeOf(typeof(SceSaveDataMountPoint)));
ps4.WriteMemory(pid, mountPointAddr, mountPoint);
var ret = ps4.Call(pid, stub, libSceSaveDataBase + offsets.sceSaveDataUmount, mountPointAddr);
WriteLog($"sceSaveDataUmount ret = 0x{ret:X}");
ps4.FreeMemory(pid, mountPointAddr, Marshal.SizeOf(typeof(SceSaveDataMountPoint)));
mp = null;
}
private string Mount(SceSaveDataMount mount, SceSaveDataMountResult mountResult)
{
var mountAddr = ps4.AllocateMemory(pid, Marshal.SizeOf(typeof(SceSaveDataMount)) + Marshal.SizeOf(typeof(SceSaveDataMountResult)));
var mountResultAddr = mountAddr + (uint)Marshal.SizeOf(typeof(SceSaveDataMount));
ps4.WriteMemory(pid, mountAddr, mount);
ps4.WriteMemory(pid, mountResultAddr, mountResult);
var ret = ps4.Call(pid, stub, libSceSaveDataBase + offsets.sceSaveDataMount, mountAddr, mountResultAddr);
WriteLog($"sceSaveDataMount ret = 0x{ret:X}");
if (ret == 0)
{
mountResult = ps4.ReadMemory<SceSaveDataMountResult>(pid, mountResultAddr);
ps4.FreeMemory(pid, mountAddr, Marshal.SizeOf(typeof(SceSaveDataMount)) + Marshal.SizeOf(typeof(SceSaveDataMountResult)));
return mountResult.mountPoint.data;
}
ps4.FreeMemory(pid, mountAddr, Marshal.SizeOf(typeof(SceSaveDataMount)) + Marshal.SizeOf(typeof(SceSaveDataMountResult)));
return "";
}
class SearchEntry
{
public string dirName;
public string title;
public string subtitle;
public string detail;
public string time;
public override string ToString()
{
return dirName;
}
}
private void dirsComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
titleTextBox.Text = ((SearchEntry)dirsComboBox.SelectedItem).title;
subtitleTextBox.Text = ((SearchEntry)dirsComboBox.SelectedItem).subtitle;
detailsTextBox.Text = ((SearchEntry)dirsComboBox.SelectedItem).detail;
dateTextBox.Text = ((SearchEntry)dirsComboBox.SelectedItem).time;
}
private void userComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
user = ((User)userComboBox.SelectedItem).id;
}
class User
{
public int id;
public string name;
public override string ToString()
{
return name;
}
}
private string[] GetSaveDirectories()
{
var dirs = new List<string>();
var mem = ps4.AllocateMemory(pid, 0x8000);
var path = mem;
var buffer = mem + 0x101;
ps4.WriteMemory(pid, path, $"/user/home/{GetUser():x}/savedata/");
var ret = (int)ps4.Call(pid, stub, GetSaveDirectoriesAddr, path, buffer);
if (ret != -1 && ret != 0)
{
var bDirs = ps4.ReadMemory(pid, buffer, ret * 0x10);
for (var i = 0; i < ret; i++)
{
var sDir = System.Text.Encoding.UTF8.GetString(PS4DBG.SubArray(bDirs, i * 10, 9));
dirs.Add(sDir);
}
}
ps4.FreeMemory(pid, mem, 0x8000);
return dirs.ToArray();
}
private User[] GetUsers()
{
List<User> users = new List<User>();
var mem = ps4.AllocateMemory(pid, 0x1);
var ret = (int)ps4.Call(pid, stub, GetUsersAddr, mem);
if (ret != -1 && ret != 0)
{
var buffer = ps4.ReadMemory(pid, mem, (21) * 4);
for (int i = 0; i < 4; i++)
{
var id = BitConverter.ToInt32(buffer, 21 * i);
if (id == 0)
{
continue;
}
var name = System.Text.Encoding.UTF8.GetString(PS4DBG.SubArray(buffer, i * 21 + 4, 16));
users.Add(new User { id = id, name = name });
}
}
ps4.FreeMemory(pid, mem, 0x1);
return users.ToArray();
}
public static bool checkIP(string IP)
{
return !string.IsNullOrEmpty(IP) && IPAddress.TryParse(IP, out _);
}
private void payloadButton_Click(object sender, EventArgs e)
{
try
{
if (!checkIP(ipTextBox.Text))
{
SetStatus("Invalid IP");
return;
}
var assembly = System.Reflection.Assembly.GetExecutingAssembly();
using (var stream = assembly.GetManifestResourceStream("PS4Saves.ps4debug.bin"))
{
var buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IAsyncResult result = socket.BeginConnect(new IPEndPoint(IPAddress.Parse(ipTextBox.Text), 9020), null, null);
var connected = result.AsyncWaitHandle.WaitOne(3000);
if (connected)
{
socket.Send(buffer, buffer.Length, SocketFlags.None);
}
SetStatus(connected ? "Payload sent" : "Failed to connect");
socket.Close();
}
}
catch
{
SetStatus("Sending payload failed");
}
}
private void getGamesButton_Click(object sender, EventArgs e)
{
if (!ps4.IsConnected)
{
SetStatus("Not connected to ps4");
return;
}
if (pid == 0)
{
SetStatus("Don't forget to press setup");
return;
}
var pm = ps4.GetProcessMaps(pid);
if (pm.FindEntry("(NoName)clienthandler") == null)
{
SetStatus("RPC Stub Not Found");
return;
}
var dirs = GetSaveDirectories();
gamesComboBox.DataSource = dirs;
}
private void gamesComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
selectedGame = (string)gamesComboBox.SelectedItem;
}
}
}