forked from charlyzard/PS4OfflineAccountActivator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainForm.cs
411 lines (329 loc) · 16.1 KB
/
MainForm.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
using libdebug;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace PS4OfflineAccountActivator
{
public partial class MainForm : Form
{
public PS4DBG ps4 = null;
public ulong executable = 0;
public ulong sceRegMgrGetInt_addr = 0;
public ulong sceRegMgrGetStr_addr = 0;
public ulong sceRegMgrGetBin_addr = 0;
public ulong sceRegMgrSetInt_addr = 0;
public ulong sceRegMgrSetStr_addr = 0;
public ulong sceRegMgrSetBin_addr = 0;
public Process p = null;
public ulong stub = 0;
public Registry r = new Registry();
public MainForm()
{
InitializeComponent();
}
public ulong GetIntNative(uint regId, out int intVal)
{
ulong errorCode = 0;
var bufferAddr = ps4.AllocateMemory(p.pid, sizeof(int));
ps4.WriteMemory<int>(p.pid, bufferAddr, 0);
errorCode = ps4.Call(p.pid, stub, sceRegMgrGetInt_addr, regId, bufferAddr);
int valueReturned = ps4.ReadMemory<int>(p.pid, bufferAddr);
ps4.FreeMemory(p.pid, bufferAddr, sizeof(int));
intVal = valueReturned;
return errorCode;
}
public ulong SetIntNative(uint regId, int intVal)
{
return ps4.Call(p.pid, stub, sceRegMgrSetInt_addr, regId, intVal);
}
public ulong GetStrNative(uint regId, out string strVal, uint strSize)
{
ulong errorCode = 0;
var blankArray = new byte[strSize];
var bufferAddr = ps4.AllocateMemory(p.pid, (int)strSize);
ps4.WriteMemory(p.pid, bufferAddr, blankArray);
errorCode = ps4.Call(p.pid, stub, sceRegMgrGetStr_addr, regId, bufferAddr, strSize);
var valueReturned = ps4.ReadMemory(p.pid, bufferAddr, (int)strSize);
ps4.FreeMemory(p.pid, bufferAddr, (int)strSize);
int len = Array.IndexOf(valueReturned, (byte)0);
strVal = Encoding.UTF8.GetString(valueReturned, 0, len);
return errorCode;
}
public byte[] Combine(byte[] first, byte[] second)
{
byte[] ret = new byte[first.Length + second.Length];
Buffer.BlockCopy(first, 0, ret, 0, first.Length);
Buffer.BlockCopy(second, 0, ret, first.Length, second.Length);
return ret;
}
public ulong SetStrNative(uint regId, string strVal, uint strSize)
{
ulong errorCode = 0;
byte[] temp_bytes = Encoding.ASCII.GetBytes(strVal);
byte[] bytes = Combine(temp_bytes, new byte[] { 0x0 });
var bufferAddr = ps4.AllocateMemory(p.pid, bytes.Length);
ps4.WriteMemory(p.pid, bufferAddr, bytes);
errorCode = ps4.Call(p.pid, stub, sceRegMgrSetStr_addr, regId, bufferAddr, bytes.Length);
ps4.FreeMemory(p.pid, bufferAddr, bytes.Length);
return errorCode;
}
public ulong GetBinNative(uint regId, out byte[] binVal, uint binSize)
{
ulong errorCode = 0;
var blankArray = new byte[binSize];
var bufferAddr = ps4.AllocateMemory(p.pid, (int)binSize);
ps4.WriteMemory(p.pid, bufferAddr, blankArray);
errorCode = ps4.Call(p.pid, stub, sceRegMgrGetBin_addr, regId, bufferAddr, binSize);
binVal = ps4.ReadMemory(p.pid, bufferAddr, (int)binSize);
ps4.FreeMemory(p.pid, bufferAddr, (int)binSize);
return errorCode;
}
public ulong SetBinNative(uint regId, byte[] binVal, uint binSize)
{
ulong errorCode = 0;
var bufferAddr = ps4.AllocateMemory(p.pid, (int)binSize);
ps4.WriteMemory(p.pid, bufferAddr, binVal);
errorCode = ps4.Call(p.pid, stub, sceRegMgrSetBin_addr, regId, bufferAddr, binSize);
ps4.FreeMemory(p.pid, bufferAddr, (int)binSize);
return errorCode;
}
public byte[] GetAccountId(int userNumber)
{
ulong errorCode = 0;
byte[] psnAccountId = null;
errorCode = GetBinNative((uint)r.KEY_account_id(userNumber), out psnAccountId, Registry.SIZE_account_id);
return psnAccountId;
}
public ulong SetAccountId(int userNumber, byte[] psnAccountId)
{
ulong errorCode = 0;
errorCode = SetBinNative((uint)r.KEY_account_id(userNumber), psnAccountId, Registry.SIZE_account_id);
//errorCode = GetBinNative((uint)r.KEY_account_id(userNumber), out psnAccountId, Registry.SIZE_account_id);
string text = "np";
errorCode = SetStrNative((uint)r.KEY_NP_env(userNumber), text, (uint)text.Length);
errorCode = SetIntNative((uint)r.KEY_login_flag(userNumber), 6);
return errorCode;
}
private void btConnect_Click(object sender, EventArgs e)
{
try
{
ps4 = new PS4DBG(tbIPAddress.Text);
ps4.Connect();
ProcessList pl = ps4.GetProcessList();
p = pl.FindProcess("eboot.bin");
ProcessMap pi = ps4.GetProcessMaps(p.pid);
stub = ps4.InstallRPC(p.pid);
if (ps4.IsConnected)
{
toolStripStatusLabel1.Text = "Connected to " + tbIPAddress.Text + ". Click Get Users";
//btGetUsers.Enabled = true;
string folderPath = "";
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
{
folderPath = fbd.SelectedPath;
}
if (string.IsNullOrEmpty(folderPath))
return;
ulong ptr = 0x100F720260; // 1.30 campaign
byte[] pointerBuffer = ps4.ReadMemory(p.pid, ptr, 0x20000); // reading as block is faster than individual read calls
for (int i = 0; i < pointerBuffer.Length; i += 0x18) // interate over the lua pool, each asset header is 0x18 bytes
{
byte[] hash = new byte[8];
Buffer.BlockCopy(pointerBuffer, i, hash, 0, 8); // hash is at offset 0x00
if (BitConverter.ToUInt64(hash, 0) < 0xFFFFFFFFFFFF)
break;
int size = BitConverter.ToInt32(pointerBuffer, i + 0x08); // file size is at offset 0x08 (for compressed files this is the compressed size)
ulong filePtr = BitConverter.ToUInt64(pointerBuffer, i + 0x10); // pointer to the file buffer is at offset 0x10
byte[] fileDump = ps4.ReadMemory(p.pid, filePtr, size);
File.WriteAllBytes($@"{folderPath}\{BitConverter.ToString(hash).Replace("-", ""):X16}.lua", fileDump);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "Something went wrong and it's probably your fault ;-P");
}
}
private void btGetUsers_Click(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = "Getting Users... ";
string userName = "";
for (int i = 1; i <= 16; i++)
{
userName = GetUserName(i);
if (userName.Length > 0)
{
(this.Controls.Find("lbUsername" + i.ToString(), true)[0] as Label).Text = userName;
(this.Controls.Find("tbPSNId" + i.ToString(), true)[0] as TextBox).Text = GetAccountIdText(i);
(this.Controls.Find("btSetAccountId" + i.ToString(), true)[0] as Button).Enabled = true;
}
}
toolStripStatusLabel1.Text = "Got Users. Type in the account id and click the Set Id && Activate button of the specific user";
}
public static byte[] StringToByteArray(string hex)
{
return Enumerable.Range(0, hex.Length)
.Where(x => x % 2 == 0)
.Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
.ToArray();
}
public static string ByteArrayToString(byte[] ba)
{
return BitConverter.ToString(ba).Replace("-", "");
}
private string GetAccountIdText(int userNumber)
{
byte[] temp = GetAccountId(userNumber);
Array.Reverse(temp);
return ByteArrayToString(temp);
}
private string GetUserName(int userNumber)
{
string outString = "";
ulong errorCode = 0;
errorCode = GetStrNative((uint)r.KEY_user_name(userNumber), out outString, Registry.SIZE_user_name);
return outString;
}
private void btSetAccountId1_Click(object sender, EventArgs e)
{
SetAccountIdText(1, tbPSNId1.Text);
string text = "np";
SetStrNative((uint)r.KEY_NP_env(1), text, (uint)text.Length);
SetIntNative((uint)r.KEY_login_flag(1), 6);
toolStripStatusLabel1.Text = "Account id set && activated. Click Get Users to verify it was written properly";
}
private void SetAccountIdText(int userNumber, string accountId)
{
byte[] temp = StringToByteArray(accountId);
Array.Reverse(temp);
SetAccountId(userNumber, temp);
}
private void btSetAccountId2_Click(object sender, EventArgs e)
{
SetAccountIdText(2, tbPSNId2.Text);
string text = "np";
SetStrNative((uint)r.KEY_NP_env(2), text, (uint)text.Length);
SetIntNative((uint)r.KEY_login_flag(2), 6);
toolStripStatusLabel1.Text = "Account id set && activated. Click Get Users to verify it was written properly";
}
private void btSetAccountId3_Click(object sender, EventArgs e)
{
SetAccountIdText(3, tbPSNId3.Text);
string text = "np";
SetStrNative((uint)r.KEY_NP_env(3), text, (uint)text.Length);
SetIntNative((uint)r.KEY_login_flag(3), 6);
toolStripStatusLabel1.Text = "Account id set && activated. Click Get Users to verify it was written properly";
}
private void btSetAccountId4_Click(object sender, EventArgs e)
{
SetAccountIdText(4, tbPSNId4.Text);
string text = "np";
SetStrNative((uint)r.KEY_NP_env(4), text, (uint)text.Length);
SetIntNative((uint)r.KEY_login_flag(4), 6);
toolStripStatusLabel1.Text = "Account id set && activated. Click Get Users to verify it was written properly";
}
private void btSetAccountId5_Click(object sender, EventArgs e)
{
SetAccountIdText(5, tbPSNId5.Text);
string text = "np";
SetStrNative((uint)r.KEY_NP_env(5), text, (uint)text.Length);
SetIntNative((uint)r.KEY_login_flag(5), 6);
toolStripStatusLabel1.Text = "Account id set && activated. Click Get Users to verify it was written properly";
}
private void btSetAccountId6_Click(object sender, EventArgs e)
{
SetAccountIdText(6, tbPSNId6.Text);
string text = "np";
SetStrNative((uint)r.KEY_NP_env(6), text, (uint)text.Length);
SetIntNative((uint)r.KEY_login_flag(6), 6);
toolStripStatusLabel1.Text = "Account id set && activated. Click Get Users to verify it was written properly";
}
private void btSetAccountId7_Click(object sender, EventArgs e)
{
SetAccountIdText(7, tbPSNId7.Text);
string text = "np";
SetStrNative((uint)r.KEY_NP_env(7), text, (uint)text.Length);
SetIntNative((uint)r.KEY_login_flag(7), 6);
toolStripStatusLabel1.Text = "Account id set && activated. Click Get Users to verify it was written properly";
}
private void btSetAccountId8_Click(object sender, EventArgs e)
{
SetAccountIdText(8, tbPSNId8.Text);
string text = "np";
SetStrNative((uint)r.KEY_NP_env(8), text, (uint)text.Length);
SetIntNative((uint)r.KEY_login_flag(8), 6);
toolStripStatusLabel1.Text = "Account id set && activated. Click Get Users to verify it was written properly";
}
private void btSetAccountId9_Click(object sender, EventArgs e)
{
SetAccountIdText(9, tbPSNId9.Text);
string text = "np";
SetStrNative((uint)r.KEY_NP_env(9), text, (uint)text.Length);
SetIntNative((uint)r.KEY_login_flag(9), 6);
toolStripStatusLabel1.Text = "Account id set && activated. Click Get Users to verify it was written properly";
}
private void btSetAccountId10_Click(object sender, EventArgs e)
{
SetAccountIdText(10, tbPSNId10.Text);
string text = "np";
SetStrNative((uint)r.KEY_NP_env(10), text, (uint)text.Length);
SetIntNative((uint)r.KEY_login_flag(10), 6);
toolStripStatusLabel1.Text = "Account id set && activated. Click Get Users to verify it was written properly";
}
private void btSetAccountId11_Click(object sender, EventArgs e)
{
SetAccountIdText(11, tbPSNId11.Text);
string text = "np";
SetStrNative((uint)r.KEY_NP_env(11), text, (uint)text.Length);
SetIntNative((uint)r.KEY_login_flag(11), 6);
toolStripStatusLabel1.Text = "Account id set && activated. Click Get Users to verify it was written properly";
}
private void btSetAccountId12_Click(object sender, EventArgs e)
{
SetAccountIdText(12, tbPSNId12.Text);
string text = "np";
SetStrNative((uint)r.KEY_NP_env(12), text, (uint)text.Length);
SetIntNative((uint)r.KEY_login_flag(12), 6);
toolStripStatusLabel1.Text = "Account id set && activated. Click Get Users to verify it was written properly";
}
private void btSetAccountId13_Click(object sender, EventArgs e)
{
SetAccountIdText(13, tbPSNId13.Text);
string text = "np";
SetStrNative((uint)r.KEY_NP_env(13), text, (uint)text.Length);
SetIntNative((uint)r.KEY_login_flag(13), 6);
toolStripStatusLabel1.Text = "Account id set && activated. Click Get Users to verify it was written properly";
}
private void btSetAccountId14_Click(object sender, EventArgs e)
{
SetAccountIdText(14, tbPSNId14.Text);
string text = "np";
SetStrNative((uint)r.KEY_NP_env(14), text, (uint)text.Length);
SetIntNative((uint)r.KEY_login_flag(14), 6);
toolStripStatusLabel1.Text = "Account id set && activated. Click Get Users to verify it was written properly";
}
private void btSetAccountId15_Click(object sender, EventArgs e)
{
SetAccountIdText(15, tbPSNId15.Text);
string text = "np";
SetStrNative((uint)r.KEY_NP_env(15), text, (uint)text.Length);
SetIntNative((uint)r.KEY_login_flag(15), 6);
toolStripStatusLabel1.Text = "Account id set && activated. Click Get Users to verify it was written properly";
}
private void btSetAccountId16_Click(object sender, EventArgs e)
{
SetAccountIdText(16, tbPSNId16.Text);
string text = "np";
SetStrNative((uint)r.KEY_NP_env(16), text, (uint)text.Length);
SetIntNative((uint)r.KEY_login_flag(16), 6);
toolStripStatusLabel1.Text = "Account id set && activated. Click Get Users to verify it was written properly";
}
}
}