-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.c
163 lines (141 loc) · 3.88 KB
/
main.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
/* OpenSn0w
* Open source equivalent of redsn0w
* Brought to you by rms, acfrazier & Maximus
* Special thanks to iH8sn0w & MuscleNerd
*
* 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 "sn0w.h"
bool verboseflag = false;
irecv_device_t device = NULL;
irecv_client_t client = NULL;
#define usage(x) \
printf("Usage: %s [OPTION]\n" \
"Jailbreak an iOS device (iPhones/iPod touches/iPads)\n" \
"Supported devices are: %s\n" \
"\n" \
"Options:\n" \
"\t-v Verbose mode. Useful for debugging.\n" \
"\t-h Help.\n" \
"\t-w url Get necessary files from a remote IPSW.\n" \
"\t-k kernelcache Boot using specified kernel.\n" \
"\t-i ipsw Use specified ipsw to retrieve files from\n" \
"\t-b bootlogo.img3 Use specified bootlogo img3 file during startup.\n" \
"\n", \
argv[0], \
"None." ); \
exit(-1);
bool file_exists(const char* fileName) {
struct stat buf;
return !stat(fileName, &buf);
}
int poll_device_for_dfu() {
irecv_error_t err;
static int try;
err = irecv_open(&client);
if (err != IRECV_E_SUCCESS) {
printf("\rConnect the device in DFU mode. [%d]", try);
fflush(stdout);
goto err;
}
if (client->mode != kDfuMode) {
printf("\rConnect the device in DFU mode. [%d]", try);
fflush(stdout);
irecv_close(client);
goto err;
}
return 0;
err:
try++;
return 1;
}
int main(int argc, char **argv) {
int c;
char *ipsw = NULL, *kernelcache = NULL, *bootlogo = NULL, *url = NULL;;
irecv_error_t err = IRECV_E_SUCCESS;
printf("opensn0w, an open source jailbreaking program.\n"
"Compiled on: " __DATE__ " " __TIME__ "\n\n");
opterr = 0;
while ((c = getopt (argc, argv, "vhb:w:k:i:")) != -1) {
switch (c) {
case 'v':
verboseflag = true;
break;
case 'h':
usage();
break;
case 'i':
if (!file_exists(optarg)) {
printf("Cannot open IPSW file '%s'\n", ipsw);
return -1;
}
ipsw = optarg;
break;
case 'w':
url = optarg;
break;
case 'k':
if (!file_exists(optarg)) {
printf("Cannot open kernelcache file '%s'\n", optarg);
return -1;
}
kernelcache = optarg;
break;
case 'b':
if (!file_exists(optarg)) {
printf("Cannot open bootlogo file '%s'\n", optarg);
return -1;
}
bootlogo = optarg;
break;
default:
usage();
}
}
/* to be done */
printf("Initializing libirecovery\n");
irecv_init();
#ifdef DEBUG
irecv_set_debug_level(3);
#endif
/* Poll for DFU mode */
while(poll_device_for_dfu()) {
sleep(1);
}
puts("");
/* Got the handle */
/* Check the device */
err = irecv_get_device(client, &device);
if (device == NULL || device->index == DEVICE_UNKNOWN) {
printf("Bad device. errno %d\n", err);
return -1;
}
printf("Device found: name: %s, processor s5l%dxsi\n", device->product, device->chip_id);
printf("iBoot information: %s\n", client->serial);
/* What jailbreak exploit is this thing capable of? */
if(device->chip_id == 8930 || device->chip_id == 8922 || device->chip_id == 8920) {
printf("This device is compatible with the limera1n exploit. Sending.\n");
err = limera1n();
if(err) {
printf("Error during limera1ning.\n");
exit(-1);
}
} else {
printf("Support for the S5L%dX isn't done yet.\n", device->chip_id);
}
/* We are owned now! */
printf("Bootrom is pwned now! :D\n");
printf("to be completed\n");
return 0;
}