forked from Chronic-Dev/syringe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
libpois0n.c
915 lines (770 loc) · 20.7 KB
/
libpois0n.c
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
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
/**
* GreenPois0n Syringe - libpois0n.c
* Copyright (C) 2010 Chronic-Dev Team
* Copyright (C) 2010 Joshua Hill
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include "libpois0n.h"
#include "libpartial.h"
#include "libirecovery.h"
#include "common.h"
#include "ramdisk.h"
#include "exploits.h"
#include "payloads.h"
#define LIMERA1N
#define STEAKS4UCE
//#define PWNAGE2
static pois0n_callback progress_callback = NULL;
static void* user_object = NULL;
int recovery_callback(irecv_client_t client, const irecv_event_t* event) {
progress_callback(event->progress, user_object);
return 0;
}
void download_callback(ZipInfo* info, CDFile* file, size_t progress) {
progress_callback(progress, user_object);
}
int send_command(char* command) {
unsigned int ret = 0;
irecv_error_t error = IRECV_E_SUCCESS;
error = irecv_send_command(client, command);
if(error != IRECV_E_SUCCESS) {
printf("Unable to send command\n");
return -1;
}
error = irecv_getret(client, &ret);
if(error != IRECV_E_SUCCESS) {
printf("Unable to send command\n");
return -1;
}
return ret;
}
int fetch_image(const char* path, const char* output) {
debug("Fetching %s...\n", path);
if(download_file_from_zip(device->url, path, output, &download_callback) != 0) {
error("Unable to fetch %s\n", path);
return -1;
}
return 0;
}
int fetch_dfu_image(const char* type, const char* output) {
char name[64];
char path[255];
memset(name, '\0', 64);
memset(path, '\0', 255);
snprintf(name, 63, "%s.%s.RELEASE.dfu", type, device->model);
snprintf(path, 254, "Firmware/dfu/%s", name);
debug("Preparing to fetch DFU image from Apple's servers\n");
if(fetch_image(path, output) < 0) {
error("Unable to fetch DFU image from Apple's servers\n");
return -1;
}
return 0;
}
int fetch_firmware_image(const char* type, const char* output) {
char name[64];
char path[255];
memset(name, '\0', 64);
memset(path, '\0', 255);
snprintf(name, 63, "%s.%s.img3", type, device->model);
snprintf(path, 254, "Firmware/all_flash/all_flash.%s.production/%s", device->model, name);
debug("Preparing to fetch firmware image from Apple's servers\n");
if(fetch_image(path, output) < 0) {
error("Unable to fetch firmware image from Apple's servers\n");
}
return 0;
}
int upload_dfu_image(const char* type) {
char image[255];
struct stat buf;
irecv_error_t error = IRECV_E_SUCCESS;
memset(image, '\0', 255);
snprintf(image, 254, "%s.%s", type, device->model);
debug("Checking if %s already exists\n", image);
if(stat(image, &buf) != 0) {
if(fetch_dfu_image(type, image) < 0) {
error("Unable to upload DFU image\n");
return -1;
}
}
if(client->mode != kDfuMode) {
debug("Resetting device counters\n");
error = irecv_reset_counters(client);
if (error != IRECV_E_SUCCESS) {
debug("%s\n", irecv_strerror(error));
return -1;
}
}
debug("Uploading %s to device\n", image);
error = irecv_send_file(client, image, 1);
if(error != IRECV_E_SUCCESS) {
debug("%s\n", irecv_strerror(error));
return -1;
}
return 0;
}
int upload_firmware_image(const char* type) {
char image[255];
struct stat buf;
irecv_error_t error = IRECV_E_SUCCESS;
memset(image, '\0', 255);
snprintf(image, 254, "%s.%s", type, device->model);
debug("Checking if %s already exists\n", image);
if(stat(image, &buf) != 0) {
if(fetch_firmware_image(type, image) < 0) {
error("Unable to upload firmware image\n");
return -1;
}
}
debug("Resetting device counters\n");
error = irecv_reset_counters(client);
if (error != IRECV_E_SUCCESS) {
error("Unable to upload firmware image\n");
debug("%s\n", irecv_strerror(error));
return -1;
}
debug("Uploading %s to device\n", image);
error = irecv_send_file(client, image, 1);
if(error != IRECV_E_SUCCESS) {
error("Unable to upload firmware image\n");
debug("%s\n", irecv_strerror(error));
return -1;
}
return 0;
}
int upload_firmware_payload(const char* type) {
int size = 0;
const unsigned char* payload = NULL;
irecv_error_t error = IRECV_E_SUCCESS;
switch(device->index) {
case DEVICE_APPLETV2:
if(!strcmp(type, "iBSS")) {
payload = iBSS_k66ap;
size = sizeof(iBSS_k66ap);
debug("Loaded payload for iBSS on k66ap\n0");
}
/*
if(!strcmp(type, "iBEC")) {
payload = iBEC_k66ap;
size = sizeof(iBEC_k66ap);
debug("Loaded payload for iBEC on k66ap\n");
}
*/
if(!strcmp(type, "iBoot")) {
payload = iBoot_k66ap;
size = sizeof(iBoot_k66ap);
debug("Loaded payload for iBoot on k66ap\n");
}
break;
case DEVICE_IPAD1G:
if(!strcmp(type, "iBSS")) {
payload = iBSS_k48ap;
size = sizeof(iBSS_k48ap);
debug("Loaded payload for iBSS on k48ap\n0");
}
/*
if(!strcmp(type, "iBEC")) {
payload = iBEC_k48ap;
size = sizeof(iBEC_k48ap);
debug("Loaded payload for iBEC on k48ap\n");
}
*/
if(!strcmp(type, "iBoot")) {
payload = iBoot_k48ap;
size = sizeof(iBoot_k48ap);
debug("Loaded payload for iBoot on k48ap\n");
}
break;
case DEVICE_IPHONE3GS:
if(!strcmp(type, "iBSS")) {
payload = iBSS_n88ap;
size = sizeof(iBSS_n88ap);
debug("Loaded payload for iBSS on n88ap\n");
}
/*
if(!strcmp(type, "iBEC")) {
payload = iBEC_n88ap;
size = sizeof(iBEC_n88ap);
debug("Loaded payload for iBEC on n88ap\n");
}
*/
if(!strcmp(type, "iBoot")) {
payload = iBoot_n88ap;
size = sizeof(iBoot_n88ap);
debug("Loaded payload for iBoot on n88ap\n");
}
break;
case DEVICE_IPHONE4:
if(!strcmp(type, "iBSS")) {
payload = iBSS_n90ap;
size = sizeof(iBSS_n90ap);
debug("Loaded payload for iBSS on n90ap\n");
}
/*
if(!strcmp(type, "iBEC")) {
payload = iBEC_n90ap;
size = sizeof(iBEC_n90ap);
debug("Loaded payload for iBEC on n90ap\n");
}
*/
if(!strcmp(type, "iBoot")) {
payload = iBoot_n90ap;
size = sizeof(iBoot_n90ap);
debug("Loaded payload for iBoot on n90ap\n");
}
break;
case DEVICE_IPOD2G:
if(!strcmp(type, "iBSS")) {
payload = iBSS_n72ap;
size = sizeof(iBSS_n72ap);
debug("Loaded payload for iBSS on n72ap\n");
}
/*
if(!strcmp(type, "iBEC")) {
payload = iBEC_n72ap;
size = sizeof(iBEC_n72ap);
debug("Loaded payload for iBEC on n72ap\n");
}
*/
if(!strcmp(type, "iBoot")) {
payload = iBoot_n72ap;
size = sizeof(iBoot_n72ap);
debug("Loaded payload for iBoot on n72ap\n");
}
break;
case DEVICE_IPOD3G:
if(!strcmp(type, "iBSS")) {
payload = iBSS_n18ap;
size = sizeof(iBSS_n18ap);
debug("Loaded payload for iBSS on n18ap\n");
}
/*
if(!strcmp(type, "iBEC")) {
payload = iBEC_n18ap;
size = sizeof(iBEC_n18ap);
debug("Loaded payload for iBEC on n18ap\n");
}
*/
if(!strcmp(type, "iBoot")) {
payload = iBoot_n18ap;
size = sizeof(iBoot_n18ap);
debug("Loaded payload for iBoot on n18ap\n");
}
break;
case DEVICE_IPOD4G:
if(!strcmp(type, "iBSS")) {
payload = iBSS_n81ap;
size = sizeof(iBSS_n81ap);
debug("Loaded payload for iBSS on n81ap\n");
}
/*
if(!strcmp(type, "iBEC")) {
payload = iBEC_n81ap;
size = sizeof(iBEC_n81ap);
debug("Loaded payload for iBEC on n81ap\n");
}
*/
if(!strcmp(type, "iBoot")) {
payload = iBoot_n81ap;
size = sizeof(iBoot_n81ap);
debug("Loaded payload for iBoot on n81ap\n");
}
break;
}
if(payload == NULL) {
error("Unable to upload firmware payload\n");
return -1;
}
debug("Resetting device counters\n");
error = irecv_reset_counters(client);
if (error != IRECV_E_SUCCESS) {
error("Unable to upload firmware payload\n");
debug("%s\n", irecv_strerror(error));
return -1;
}
debug("Uploading %s payload\n", type);
error = irecv_send_buffer(client, (unsigned char*) payload, size, 1);
if(error != IRECV_E_SUCCESS) {
error("Unable to upload %s payload\n", type);
return -1;
}
return 0;
}
int upload_ibss() {
if(upload_dfu_image("iBSS") < 0) {
error("Unable upload iBSS\n");
return -1;
}
return 0;
}
int upload_iboot() {
if(upload_firmware_image("iBoot") < 0) {
error("Unable upload iBoot\n");
return -1;
}
return 0;
}
int upload_devicetree() {
if(upload_firmware_image("DeviceTree") < 0) {
error("Unable upload DeviceTree\n");
return -1;
}
return 0;
}
int upload_ramdisk() {
if(irecv_send_buffer(client, (unsigned char*) ramdisk, sizeof(ramdisk), 0) < 0) {
error("Unable upload ramdisk\n");
return -1;
}
return 0;
}
int upload_kernelcache() {
struct stat buf;
char kernelcache[255];
irecv_error_t error = IRECV_E_SUCCESS;
memset(kernelcache, '\0', 255);
memset(&buf, '\0', sizeof(buf));
snprintf(kernelcache, 254, "kernelcache.release.%c%c%c", device->model[0], device->model[1], device->model[2]);
debug("Checking if kernelcache already exists\n");
if(stat(kernelcache, &buf) != 0) {
if(fetch_image(kernelcache, kernelcache) < 0) {
error("Unable to upload kernelcache\n");
return -1;
}
}
debug("Resetting device counters\n");
error = irecv_reset_counters(client);
if (error != IRECV_E_SUCCESS) {
debug("%s\n", irecv_strerror(error));
error("Unable upload kernelcache\n");
return -1;
}
error = irecv_send_file(client, kernelcache, 1);
if(error != IRECV_E_SUCCESS) {
debug("%s\n", irecv_strerror(error));
error("Unable upload kernelcache\n");
return -1;
}
return 0;
}
int upload_ibss_payload() {
if(upload_firmware_payload("iBSS") < 0) {
error("Unable to upload iBSS payload\n");
return -1;
}
return 0;
}
int upload_ibec_payload() {
if(upload_firmware_payload("iBEC") < 0) {
error("Unable to upload iBEC payload\n");
return -1;
}
return 0;
}
int boot_ramdisk() {
irecv_error_t error = IRECV_E_SUCCESS;
// Add an exception for this since it's very different
if(device->index == DEVICE_APPLETV2) {
debug("Preparing to upload ramdisk\n");
if(upload_ramdisk() < 0) {
error("Unable to upload ramdisk\n");
return -1;
}
debug("Executing ramdisk\n");
error = irecv_send_command(client, "ramdisk");
if(error != IRECV_E_SUCCESS) {
error("Unable to execute ramdisk command\n");
return -1;
}
debug("Setting kernel bootargs\n");
error = irecv_send_command(client, "go kernel bootargs rd=md0 -v keepsyms=1");
if(error != IRECV_E_SUCCESS) {
error("Unable to set kernel bootargs\n");
return -1;
}
debug("Preparing to upload kernelcache\n");
if(upload_kernelcache() < 0) {
error("Unable to upload kernelcache\n");
return -1;
}
error = irecv_send_command(client, "bootx");
if(error != IRECV_E_SUCCESS) {
error("Unable to move iBoot into memory\n");
return -1;
}
return 0;
}
debug("Preparing to boot iBoot\n");
if(boot_iboot() < 0) {
error("Unable to boot iBoot\n");
return -1;
}
debug("Preparing to upload ramdisk\n");
if(upload_ramdisk() < 0) {
error("Unable to upload ramdisk\n");
return -1;
}
debug("Executing ramdisk\n");
error = irecv_send_command(client, "go ramdisk 1 1");
if(error != IRECV_E_SUCCESS) {
error("Unable to execute ramdisk command\n");
return -1;
}
debug("Moving ramdisk\n");
if(device->chip_id == 8720) {
error = irecv_send_command(client, "go memory move 0x9000040 0xC000000 0x100000");
} else {
error = irecv_send_command(client, "go memory move 0x41000040 0x44000000 0x100000");
}
if(error != IRECV_E_SUCCESS) {
error("Unable to move ramdisk\n");
return -1;
}
debug("Setting kernel bootargs\n");
error = irecv_send_command(client, "go kernel bootargs rd=md0 -v keepsyms=1");
if(error != IRECV_E_SUCCESS) {
error("Unable to set kernel bootargs\n");
return -1;
}
irecv_setenv(client, "boot-args", "0");
irecv_setenv(client, "auto-boot", "true");
irecv_saveenv(client);
error = irecv_send_command(client, "go fsboot");
if (error != IRECV_E_SUCCESS) {
error("Unable to fsboot\n");
return -1;
}
return 0;
}
int boot_tethered() {
irecv_error_t error = IRECV_E_SUCCESS;
debug("Initializing greenpois0n in iBoot\n");
irecv_send_command(client, "go");
// Add an exception for this since it's very different
if(device->index == DEVICE_APPLETV2) {
debug("Preparing to upload kernelcache\n");
if(upload_kernelcache() < 0) {
error("Unable to upload kernelcache\n");
return -1;
}
debug("Hooking jump_to command\n");
error = irecv_send_command(client, "go rdboot");
if(error != IRECV_E_SUCCESS) {
error("Unable to hook jump_to\n");
return -1;
}
debug("Booting kernel\n");
error = irecv_send_command(client, "bootx");
if(error != IRECV_E_SUCCESS) {
error("Unable to boot kernel\n");
return -1;
}
return 0;
}
debug("Preparing to boot iBoot\n");
if(boot_iboot() < 0) {
error("Unable to boot iBoot\n");
return -1;
}
debug("Preparing to upload ramdisk\n");
if(upload_ramdisk() < 0) {
error("Unable to upload ramdisk\n");
return -1;
}
debug("Executing ramdisk\n");
error = irecv_send_command(client, "go ramdisk 1 1");
if(error != IRECV_E_SUCCESS) {
error("Unable to execute ramdisk command\n");
return -1;
}
debug("Setting kernel bootargs\n");
error = irecv_send_command(client, "go kernel bootargs rd=disk0s1 -v keepsyms=1");
if(error != IRECV_E_SUCCESS) {
error("Unable to set kernel bootargs\n");
return -1;
}
irecv_setenv(client, "boot-args", "0");
irecv_setenv(client, "auto-boot", "true");
irecv_saveenv(client);
error = irecv_send_command(client, "go fsboot");
if (error != IRECV_E_SUCCESS) {
error("Unable to fsboot\n");
return -1;
}
return 0;
}
int boot_iboot() {
irecv_error_t error = IRECV_E_SUCCESS;
debug("Loading iBoot\n");
if(device->chip_id == 8720) {
error = irecv_send_command(client, "go image load 0x69626F74 0x9000000");
} else {
error = irecv_send_command(client, "go image load 0x69626F74 0x41000000");
}
if(error != IRECV_E_SUCCESS) {
error("Unable load iBoot to memory\n");
return -1;
}
debug("Shifting iBoot\n");
if(device->chip_id == 8720) {
error = irecv_send_command(client, "go memory move 0x9000040 0x9000000 0x48000");
} else {
error = irecv_send_command(client, "go memory move 0x41000040 0x41000000 0x48000");
}
if(error != IRECV_E_SUCCESS) {
error("Unable to move iBoot into memory\n");
return -1;
}
debug("Patching iBoot\n");
if(device->chip_id == 8720) {
error = irecv_send_command(client, "go patch 0x9000000 0x48000");
} else {
error = irecv_send_command(client, "go patch 0x41000000 0x48000");
}
if(error != IRECV_E_SUCCESS) {
error("Unable to patch iBoot\n");
return -1;
}
irecv_setenv(client, "auto-boot", "false");
irecv_saveenv(client);
debug("Jumping into iBoot\n");
if(device->chip_id == 8720) {
error = irecv_send_command(client, "go jump 0x9000000");
} else {
error = irecv_send_command(client, "go jump 0x41000000");
}
if(error != IRECV_E_SUCCESS) {
error("Unable to jump into iBoot\n");
return -1;
}
debug("Reconnecting to device\n");
client = irecv_reconnect(client, 10);
if (client == NULL) {
error("Unable to boot the device tethered\n");
return -1;
}
irecv_setenv(client, "auto-boot", "true");
irecv_saveenv(client);
if(upload_firmware_payload("iBoot") < 0) {
error("Unable to boot the device tethered\n");
return -1;
}
debug("Initializing greenpois0n in iBoot\n");
irecv_send_command(client, "go");
return 0;
}
int execute_ibss_payload() {
//int i = 0;
char* bootargs = NULL;
irecv_error_t error = IRECV_E_SUCCESS;
debug("Initializing greenpois0n in iBSS\n");
irecv_send_command(client, "go");
// Code to detect whether to boot ramdisk or filesystem
debug("Checking if device is already jailbroken\n");
error = irecv_getenv(client, "boot-args", &bootargs);
if(error != IRECV_E_SUCCESS) {
debug("%s\n", irecv_strerror(error));
error("Unable to read env var\n");
return -1;
}
// If boot-args hasn't been set then we've never been jailbroken
if(!strcmp(bootargs, "") || !strcmp(bootargs, "0")) {
debug("Booting jailbreak ramdisk\n");
if(boot_ramdisk() < 0) {
error("Unable to boot device into tethered mode\n");
return -1;
}
}
// If boot-args is 1 then boot device into tethered mode
else if(!strcmp(bootargs, "1")) {
debug("Booting tethered device\n");
if(boot_tethered() < 0) {
error("Unable to boot device into tethered mode\n");
return -1;
}
}
// If boot-args is 2, then don't boot kernel, just load iBSS payload
else if(!strcmp(bootargs, "2")) {
debug("Booting iBSS in payload mode\n");
return 0;
}
// If boot-args is 3, then don't boot kernel, just load iBoot payload
else if(!strcmp(bootargs, "3")) {
debug("Booting device in verbose mode\n");
if(boot_iboot() < 0) {
error("Unable to boot device into verbose mode\n");
return -1;
}
}
return 0;
}
void pois0n_init() {
irecv_init();
irecv_set_debug_level(libpois0n_debug);
debug("Initializing libpois0n\n");
#ifdef __APPLE__
system("killall -9 iTunesHelper");
#endif
#ifdef _WIN32
system("TASKKILL /F /IM iTunes.exe > NUL");
system("TASKKILL /F /IM iTunesHelper.exe > NUL");
#endif
}
void pois0n_set_callback(pois0n_callback callback, void* object) {
progress_callback = callback;
user_object = object;
}
int pois0n_is_ready() {
irecv_error_t error = IRECV_E_SUCCESS;
//////////////////////////////////////
// Begin
// debug("Connecting to device\n");
error = irecv_open(&client);
if (error != IRECV_E_SUCCESS) {
debug("Device must be in DFU mode to continue\n");
return -1;
}
irecv_event_subscribe(client, IRECV_PROGRESS, &recovery_callback, NULL);
//////////////////////////////////////
// Check device
// debug("Checking the device mode\n");
if (client->mode != kDfuMode) {
error("Device must be in DFU mode to continue\n");
irecv_close(client);
return -1;
}
return 0;
}
int pois0n_is_compatible() {
irecv_error_t error = IRECV_E_SUCCESS;
info("Checking if device is compatible with this jailbreak\n");
debug("Checking the device type\n");
error = irecv_get_device(client, &device);
if (device == NULL || device->index == DEVICE_UNKNOWN) {
error("Sorry device is not compatible with this jailbreak\n");
return -1;
}
info("Identified device as %s\n", device->product);
if (device->chip_id != 8930
#ifdef LIMERA1N
&& device->chip_id != 8922
&& device->chip_id != 8920
#endif
#ifdef STEAKS4UCE
&& device->chip_id != 8720
#endif
) {
error("Sorry device is not compatible with this jailbreak\n");
return -1;
}
return 0;
}
void pois0n_exit() {
debug("Exiting libpois0n\n");
irecv_close(client);
irecv_exit();
}
int pois0n_injectonly() {
//////////////////////////////////////
// Send exploit
if(device->chip_id == 8930){
#ifdef LIMERA1N
debug("Preparing to upload limera1n exploit\n");
if(limera1n_exploit() < 0) {
error("Unable to upload exploit data\n");
return -1;
}
#else
error("Sorry, this device is not currently supported\n");
return -1;
#endif
}
else if(device->chip_id == 8920 || device->chip_id == 8922) {
#ifdef LIMERA1N
debug("Preparing to upload limera1n exploit\n");
if(limera1n_exploit() < 0) {
error("Unable to upload exploit data\n");
return -1;
}
#else
error("Sorry, this device is not currently supported\n");
return -1;
#endif
}
else if(device->chip_id == 8720) {
#ifdef STEAKS4UCE
debug("Preparing to upload steaks4uce exploit\n");
if(steaks4uce_exploit() < 0) {
error("Unable to upload exploit data\n");
return -1;
}
#else
error("Sorry, this device is not currently supported\n");
return -1;
#endif
}
else if(device->chip_id == 8900) {
#ifdef PWNAGE2
debug("Preparing to upload pwnage2 exploit\n");
if(pwnage2_exploit() < 0) {
error("Unable to upload exploit data\n");
return -1;
}
#else
error("Sorry, this device is not currently supported\n");
return -1;
#endif
}
else {
error("Sorry, this device is not currently supported\n");
return -1;
}
return 0;
}
int pois0n_inject() {
int result = 0;
result = pois0n_injectonly();
if (result < 0) {
error("DFU Exploit injection failed (%u)\n", result);
return result;
}
//////////////////////////////////////
// Send iBSS
debug("Preparing to upload iBSS\n");
if(upload_ibss() < 0) {
//error("Unable to upload iBSS\n");
//return -1;
}
debug("Reconnecting to device\n");
client = irecv_reconnect(client, 10);
if (client == NULL) {
error("Unable to reconnect\n");
return -1;
}
debug("Preparing to upload iBSS payload\n");
if(upload_ibss_payload() < 0) {
error("Unable to upload iBSS payload\n");
return -1;
}
debug("Executing iBSS payload\n");
if(execute_ibss_payload() < 0) {
error("Unable to execute iBSS payload\n");
return -1;
}
return 0;
}