-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
376 lines (366 loc) · 15.3 KB
/
Form1.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CoreFoundation;
using CFManzana;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
using System.Threading;
namespace iActivator
{
unsafe public partial class Form1 : Form
{
public iDevice Interface;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
Interface = new iDevice();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
Application.Exit();
}
}
private void button3_Click(object sender, EventArgs e)
{
if (Interface.Device == null)
{
Interface = new iDevice();
}
if (Interface.Device == null)
{
lblStatus.Text = "No device connected";
return;
}
grpCache.Enabled = false;
activate_btn.Enabled = false;
deactivate_btn.Enabled = false;
cache_btn.Enabled = false;
int result = Interface.Deactivate();
if (result == 0)
{
lblStatus.Text = "Device successfully deactivated";
}
else
{
lblStatus.Text = "Device could not be deactivated";
}
activate_btn.Enabled = true;
deactivate_btn.Enabled = true;
cache_btn.Enabled = true;
grpCache.Enabled = true;
}
private string Albert_Apple_Stuff(string cachefile)
{
string Quotation = ((char)34).ToString();
string request = "--DeviceActivation\r\nContent-Disposition: form-data; name=" + Quotation + "activation-info" + Quotation + "\r\n\r\n";
if (cachefile == "" || cachefile == null)
{
IntPtr activationinfo = Interface.CopyDictionary("ActivationInfo");
try
{
request += GrabTheDictionary(new CFPropertyList(activationinfo).ToString()) + "\r\n--DeviceActivation--";
}
catch (Exception ex)
{
lblStatus.Text = "Could not get ActivationInfo from iDevice";
return "";
}
}
else
{
try
{
CFPropertyList cache = cachefile;
request += GrabTheDictionary(cache.ToString()) + "\r\n--DeviceActivation--";
}
catch (Exception ex)
{
lblStatus.Text = "Could not read cache file";
return "";
}
}
string headers = "POST /WebObjects/ALUnbrick.woa/wa/deviceActivation HTTP/1.1\r\n";
headers += "Accept-Encoding: gzip\r\n";
headers += "Accept-Language: en-us, en;q=0.50\r\n";
headers += "Content-Type: multipart/form-data; boundary=DeviceActivation\r\n";
headers += "Content-Length: "+(request).Length.ToString() + "\r\n";
headers += "Host: albert.apple.com\r\n";
headers += "Cache-Control: no-cache\r\n";
string ret = headers + "\r\n" + request;
return ret;
}
private string GrabTheDictionary(string p_list)
{
string ret="\0";
int end = p_list.IndexOf(@"<plist version="+(char)(34)+"1.0" + (char)(34) + ">" ) + 21;
ret = p_list.Remove(0, end);
ret = ret.Remove(ret.IndexOf(@"</plist>"));
return ret;
}
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int Description, int ReservedValue);
public static bool IsConnected()
{
int Description;
return InternetGetConnectedState(out Description, 0);
}
private void activate_btn_Click(object sender, EventArgs e)
{
if (Interface.Device == null)
{
Interface = new iDevice();
}
if (Interface.Device == null)
{
lblStatus.Text = "No device connected";
return;
}
if (Interface.CopyValue("ActivationState") != "Unactivated")
{
lblStatus.Text= "Device already Activated!";
return;
}
grpCache.Enabled = false;
activate_btn.Enabled = false;
deactivate_btn.Enabled = false;
cache_btn.Enabled = false;
string response=null;
lblStatus.Text = "";
bool useCache = false;
if (activationdata.Checked == true)
{
opendialog:
Open.DefaultExt = "iData";
Open.Filter = "Activation Data|*.iData";
Open.ShowDialog();
if (Open.FileName == "")
{
MessageBox.Show("Please select a location!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
goto opendialog;
}
useCache = true;
}
#region Step 1: Get Wildcard ticket
if (IsConnected() == false)
{
lblStatus.Text = "No Internet connection available";
goto Cleanup;
}
lblStatus.Text = "Getting Wildcard ticket from Apple";
if (useCache == true)
{
ThreadStart starter = delegate
{
SslTcpClient.RunClient("albert.apple.com", Albert_Apple_Stuff(Open.FileName), ref response);
};
Thread albertThread = new Thread(starter);
albertThread.Start();
while (albertThread.IsAlive == true)
{
Application.DoEvents();
}
}
else
{
ThreadStart starter = delegate
{
SslTcpClient.RunClient("albert.apple.com", Albert_Apple_Stuff(null), ref response);
};
Thread albertThread = new Thread(starter);
albertThread.Start();
while (albertThread.IsAlive == true)
{
Application.DoEvents();
}
}
if (response.Contains("ack-received") == true)
{
lblStatus.Text = "Invalid response received from Apple";
goto Cleanup;
}
if (response == "" || response == null)
{
lblStatus.Text = "No response returned from Apple";
goto Cleanup;
}
#endregion
#region Step 2: Grab necessary information from Wildcard ticket
lblStatus.Text = "Grabbing information from the Wildcard ticket";
IntPtr[] wct = GrabTheData(response);
#endregion
#region Step 3: Send Wildcard ticket to the iDevice
string[] keys = { "AccountTokenCertificate", "AccountToken", "FairPlayKeyData", "DeviceCertificate", "AccountTokenSignature"};
lblStatus.Text = ("Sending Wildcard ticket to device");
int status = Interface.Activate(new CFDictionary(keys, wct));
lblStatus.Text = ("Wildcard ticket sent to device");
#endregion
#region Step 4: Check if activation was successful
if (status != 0)
{
lblStatus.Text = "Device could not be activated!";
}
else
{
lblStatus.Text = "Device successfully activated!";
}
#endregion
Cleanup:
activate_btn.Enabled = true;
deactivate_btn.Enabled = true;
cache_btn.Enabled = true;
grpCache.Enabled = true;
Open.FileName = "";
}
private IntPtr[] GrabTheData(string Response)
{
IntPtr[] ret = new IntPtr[5];
string temp;
temp = Response.Remove(0, Response.IndexOf("<plist version") - 1);
temp = temp.Remove((temp.IndexOf(@"</Protocol>")), temp.Length - ((temp.IndexOf(@"</Protocol>"))));
string headers = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">";
temp = headers + "\r\n" + temp;
if (File.Exists(Environment.CurrentDirectory + @"\wildcard.ticket") == true)
{
File.Delete(Environment.CurrentDirectory + @"\wildcard.ticket");
}
System.IO.File.AppendAllText(Environment.CurrentDirectory + @"\wildcard.ticket", temp);
CFPropertyList plist = new CFPropertyList(Environment.CurrentDirectory + @"\wildcard.ticket");
CFDictionary plist_to_dict = (IntPtr)plist;
CFDictionary iphone_activation = (IntPtr)plist_to_dict.GetValue("iphone-activation");
CFDictionary dict = (IntPtr)iphone_activation.GetValue("activation-record");
ret[0] = dict.GetValue("AccountTokenCertificate");
ret[1] = dict.GetValue("AccountToken");
ret[2] = dict.GetValue("FairPlayKeyData");
ret[3] = dict.GetValue("DeviceCertificate");
ret[4] = dict.GetValue("AccountTokenSignature");
if (File.Exists(Environment.CurrentDirectory + @"\wildcard.ticket") == true)
{
File.Delete(Environment.CurrentDirectory + @"\wildcard.ticket");
}
return ret;
}
private void activationdata_CheckedChanged(object sender, EventArgs e)
{
if (activationdata.Checked == true && activationticket.Checked == true)
{
activationticket.Checked = false;
}
}
private void activationticket_CheckedChanged(object sender, EventArgs e)
{
if (activationticket.Checked == true && activationdata.Checked == true)
{
activationdata.Checked = false;
}
}
private void cache_btn_Click(object sender, EventArgs e)
{
if (Interface.Device == null)
{
Interface = new iDevice();
}
if (Interface.Device == null)
{
lblStatus.Text = "No device connected";
return;
}
grpCache.Enabled = false;
activate_btn.Enabled = false;
deactivate_btn.Enabled = false;
cache_btn.Enabled = false;
MessageBox.Show("The process of creating a cache is simple: perform a legit activation, storing all the required data. That way, you can borrow (or, I guess, steal (don't do that, though)) a sim for the carrier your iPhone is locked to, and be able to reactivate without having to get that sim back.\nThis data is stored in a folder where you want it. It does not get sent to me (iSn0wra1n) or anyone else. Plus, we really have better things to do than look at your activation data.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
//This really isn't needed for iPod Touches or Wi-Fi only iPads (and I don't know if 3G iPad users need this, but be safe and do it).\n\nPress any key to continue or CONTROL-C to abort...\n\n");
if (activationticket.Checked == true && Interface.CopyValue("ActivationState") == "Unactivated")
{
#region Get Wildcard Ticket
string response = null;
if (IsConnected() == false)
{
lblStatus.Text = "No Internet connection available";
return;
}
lblStatus.Text = "Getting Wildcard ticket from Apple";
ThreadStart starter = delegate
{
SslTcpClient.RunClient("albert.apple.com", Albert_Apple_Stuff(null), ref response);
};
Thread albertThread = new Thread(starter);
albertThread.Start();
while (albertThread.IsAlive == true)
{
Application.DoEvents();
}
if (response == "")
{
lblStatus.Text = "No response returned from Apple";
return;
}
#endregion
#region Grab necessary information
lblStatus.Text = "Grabbing information from the Wildcard ticket";
string[] keys = { "AccountTokenCertificate", "AccountToken", "FairPlayKeyData", "DeviceCertificate", "AccountTokenSignature" };
IntPtr[] values = GrabTheData(response);
#endregion
activationticket:
Save.Filter = "Activation Ticket|*.iTicket";
Save.DefaultExt = "iTicket";
Save.ShowDialog();
if (Save.FileName == "")
{
MessageBox.Show("Please select a location!","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
goto activationticket;
}
File.WriteAllText(Save.FileName, new CFDictionary(keys,values).ToString());
lblStatus.Text = "Activation Ticket saved";
Save.FileName = "";
}
else if (activationdata.Checked == true)
{
activationdata:
try
{
Save.Filter = "Activation Data|*.iData";
Save.DefaultExt = "iData";
Save.ShowDialog();
if (Save.FileName == "")
{
MessageBox.Show("Please select a location!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
goto activationdata;
}
File.WriteAllText(Save.FileName, new CFDictionary(Interface.CopyDictionary("ActivationInfo")).ToString());
lblStatus.Text = "Activation Data Saved";
Save.FileName = "";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
}
}
else if (activationticket.Checked == true && Interface.CopyValue("ActivationState") != "Unactivated")
{
lblStatus.Text = "Deactivate device to cache Activation Ticket";
}
else
{
lblStatus.Text = "No cache option selected";
}
activate_btn.Enabled = true;
deactivate_btn.Enabled = true;
cache_btn.Enabled = true;
grpCache.Enabled = true;
}
}
}