forked from kryptonX/Codeine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
libkrypton1te.c
354 lines (298 loc) · 7.13 KB
/
libkrypton1te.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
/**
* Copyright (C) 2011 KryptonX
*
* 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 "libkrypton1te.h"
#include "../../x-irecovery/include/libirecovery.h"
#include "../../x-irecovery/include/libpois0n.h"
#include <stdlib.h>
void write(const char* msg);
BOOL JailbreakReady() {
if (DeviceInDfu() == TRUE
&& DeviceInRecovery() == FALSE
) {
return TRUE;
} else return FALSE;
}
BOOL RamdiskSent() {
if (DeviceInDfu() == TRUE
&& DeviceInRecovery() == FALSE) {
return TRUE;
} else return FALSE;
}
int iboot_command_(const char* s_cmd) {
int s_ret = 0; /*Value to be returned */
s_ret = irecv_open_attempts(&client, 10); /* Open attempts and load client */
irecv_send_command(client, s_cmd); /* Send commmand {s_cmd[2]} */
irecv_exit(); /* kill & clear client */
return s_ret; /* Return ret */
}
void RunTestDsk(int client_, unsigned char* ret, const int _cc_) {
const char* pArgs = "0";
const int cn_cli = 0;
if (client_ <= 5
&& ret != "-1"
&& _cc_ == 0)
fsck_client(cn_cli, pArgs, _cc_);
}
int fsck_client(int _client_, const char* _order_operations, unsigned int argp) {
argp = irecv_open_attempts(&client, 10); /* Open attempts and load client */
irecv_send_command(client, "fsck_hfs reset"); /* Send commmand {s_cmd[2]} */
irecv_send_command(client, _order_operations); /* Send specified order */
/* Initation payload[] */
if (argp != EOF)
argp = irecv_send_command(client, "");
do {
//_client_ = client->DfuPath;
argp = EOF;
} while (argp != EOF);
return 0;
}
void lprintf(string ch, int counter, int max, int arg, const char* suffix) {
/* printf function with an included loop */
#ifdef _STD_IO_
#ifdef _WIN32
#include <stdio.h>
#endif
#endif
#ifdef _WIN32
if (arg == 0)
EOF;
else if (arg == 1) { /* counter < max */
while (counter < max) {
printf(ch);
++counter;
if (counter == (max - 1))
printf(suffix);
}
} else if (arg == 2) {
while (counter <= max) {
printf(ch);
++counter;
if (counter == max)
printf(suffix);
}
} else if (arg == 3) {
while (counter > max) {
printf(ch);
++counter;
if (counter == (max + 1))
printf(suffix);
}
} else if (arg == 4) {
while (counter >= max) {
printf(ch);
++counter;
if (counter == (max + 1))
printf(suffix);
}
}
#endif
#ifdef _MAC_
if (arg == 0)
EOF;
else if (arg == 1) { /* counter < max */
while (counter < max) {
printf(ch);
++counter;
if (counter == (max - 1))
printf(suffix);
}
} else if (arg == 2) {
while (counter <= max) {
printf(ch);
counter++;
if (counter == max)
printf(suffix);
}
} else if (arg == 3) {
while (counter > max) {
printf(ch);
counter++;
if (counter == (max + 1))
printf(suffix);
}
} else if (arg == 4) {
while (counter >= max) {
printf(ch);
counter++;
if (counter == (max + 1))
printf(suffix);
}
}
#else
if (arg == 0)
EOF;
else if (arg == 1) { /* counter < max */
while (counter < max) {
printf(ch);
++counter;
if (counter == (max - 1))
printf(suffix);
}
} else if (arg == 2) {
while (counter <= max) {
printf(ch);
++counter;
if (counter == max)
printf(suffix);
}
} else if (arg == 3) {
while (counter > max) {
printf(ch);
++counter;
if (counter == (max + 1))
printf(suffix);
}
} else if (arg == 4) {
while (counter >= max) {
printf(ch);
++counter;
if (counter == (max + 1))
printf(suffix);
}
}
#endif
}
void load_iboot(int iboot_adress, const char* exp) {
iboot_command_("go to " + iboot_adress);
printf("loading iBoot @ %d", iboot_adress);
iboot_command_("setenv auto-boot false");
iboot_command_("sanveev");
iboot_command_("reset");
}
parameter error_if_payload_not_recieved(const char* _client, long payload) {
if (_client == NULL && payload != 0)
return (-1);
else return 0;
}
int libkrypton1te_init() {
int s_ret = 0; /*Value to be returned */
irecv_open_attempts(&client, 10); /* Open attempts and load client */
pois0n_init();
return s_ret;
}
void libkrypton1te_exit() {
irecv_exit();
pois0n_exit();
}
/* INIT */
void libkrypton1te_dsck(int vars) {
int x = 0;
for (x < vars; x != vars; x++) {
printf("%d\n", x);
}
}
void client_init() {
irecv_open_attempts(&client, 10); /* Open attempts and load client */
}
const char* reset_iboot() {
#ifdef _MAC_
load_iboot(00x0xx, "proc0x21");
#endif
libkrypton1te_init();
libkrypton1te_exit();
}
int setenv() {
libkrypton1te_init(); /* init irecovery clients */
client_init(); /* Set client */
iboot_command_("setenv");
}
void saveenv(int boolean) {
const char* var;
if (boolean == 1)
var = "true";
else if (boolean == 0)
var = "false";
iboot_command_("auto-boot");
iboot_command_(var);
iboot_command_("reboot");
libkrypton1te_exit();
}
LPSTR GrabDfuPath(LPSTR _dfuPath) {
client_init();
_dfuPath = client->DfuPath;
return _dfuPath;
}
void execPayload(const char* payload_to_be_executed, int times) {
int state = 0;
libkrypton1te_init();
pois0n_init();
do {
iboot_command_(payload_to_be_executed);
++state;
} while (state != times);
}
int python_start(const char* _app_) {
int returnval = system(_app_);
if (returnval == 0)
return 0;
else return (-1);
}
const char* connected_product() {
libkrypton1te_init();
if (device->chip_id == CPID_IPOD4G)
return "patch.pyc -ipt4";
else if (device->chip_id == CPID_IPHONE4)
return "patch.pyc -i4";
else if (device->chip_id == CPID_IPOD3G)
return "patch.pyc -ipt3";
else if (device->chip_id == CPID_IPHONE3GS)
return "patch.pyc -i3gs";
else if (device->chip_id == CPID_IPAD1G)
return "patch.pyc -ipad";
else if (device->chip_id == CPID_IPOD2G)
return "patch.pyc -i4";
}
void create_ibss(const char* _model) {
#ifdef _WIN32
system("patch.pyc");
#endif
}
int delete_ibss() {
if( remove( "kr1.iBSS" ) != 0 )
perror("Error deleting file");
else
printf("File successfully deleted");
return 0;
}
unsigned const char zero_image_location = {
0000
};
int connect_to_device() {
irecv_error_t error;
irecv_init();
printf("\nWaiting for device...\n");
error = irecv_open_attempts(&client, 10);
if(error != IRECV_E_SUCCESS)
{
fprintf(stderr, "Failed to connect to iBoot, error %d.\n", error);
return -error;
}
if (client->mode == kDfuMode) {
printf("Loaded DFU\n");
model();
}
if (client->mode == kRecoveryMode1 || client->mode == kRecoveryMode2 || client->mode == kRecoveryMode3 || client->mode == kRecoveryMode4 ) {
model();
}
}
void write(const char* msg) {
printf(msg);
}
int model() {
if (device->model == "iPod4,1")
printf("Succesfully connected to iPod4,1");
}