-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathmake_telnet_rd.php
executable file
·515 lines (482 loc) · 21.2 KB
/
make_telnet_rd.php
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
#!/usr/bin/env php
<?php
/**************************************
Automatically creates a RAMdisk for 64 bit iOS devices by bundling a bunch of other utilities. Modifies the RAMdisk to enable a remote shell over telnet and adds a bunch of utilities.
Copyright (C) 2020 Daniel Troger
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 <https://www.gnu.org/licenses/>.
**************************************/
require('log.php');
require('devices.php');
require('functions.php');
require('CFPropertyList/src/CFPropertyList/CFPropertyList.php');
$instance = sha1(time());
Log::main()->writeLog("telnet_rd instance: $instance - " . date('c'), 0, false);
$options = array(
'd' => array(
'longopt' => 'device',
'human_text' => 'device identifier',
'help' => 'Device identifier (example: iPhone10,4)'
),
'b' => array(
'longopt' => 'boardconfig',
'human_text' => 'BoardConfig',
'help' => 'Boardconfig (example: d201ap)'
),
'v' => array(
'longopt' => 'version',
'human_text' => 'iOS version',
'help' => 'iOS version to use as base for ramdisk'
),
's' => array(
'longopt' => 'shsh2',
'human_text' => 'shsh2 file',
'help' => 'shsh2 file (can be any version)'
),
'h' => array(
'longopt' => 'help',
'human_text' => null,
'help' => 'print this help text'
),
);
$shortopts = implode(':', array_keys($options));
$args = getopt($shortopts);
if(isset($args['h']))
{
print_usage();
exit(0);
}
if(empty($args['d']) || empty($args['b']))
{
Log::writeInfo("Detecting DFU device");
$detected_device = read_device();
if($detected_device)
{
define('DEVICE', $detected_device->identifier);
define('BOARDCONFIG', $detected_device->BoardConfig);
define('ECID', $detected_device->ecid);
if(empty($args['s']))
{
// try to get an shsh2 files using shsh.host API
// TODO make getSHSH2 function get a ticket for any ECID but
// with matching BNCH length.
// OR
// bundle two shsh2 in this project, eliminating the need to get an shsh2 file
$local_shsh_files = glob("{$detected_device->ecid_raw}*{$detected_device->BoardConfig}*.shsh2");
if(empty($local_shsh_files))
{
Log::writeInfo("Trying to find a usable shsh2 file on shsh.host");
$shsh_file = getSHSH2(ECID, null, BOARDCONFIG);
if($shsh_file && file_exists($shsh_file))
{
define('SHSH2', $shsh_file);
}
}
else
{
define('SHSH2', $local_shsh_files[array_rand($local_shsh_files)]);
Log::writeInfo("Choosing shsh2 from local files: ". SHSH2);
}
}
}
}
if(empty($args['v']))
{
// automatically choose versions based on success rate
// A11 - 13.5, 13.7, 14,2
// I don't have enough data on this
}
foreach($options as $opt_short => $opt)
{
if(!$opt['human_text']) continue;
$constant_name = strtoupper($opt['longopt']);
if(defined($constant_name)) continue;
if(empty($args[$opt_short]))
{
Log::writeError("[ERROR] {$opt['human_text']} not specified (use -$opt_short)\n\n");
print_usage();
exit(-1);
}
define(strtoupper($opt['longopt']), $args[$opt_short]);
}
define("WD","WD_" . DEVICE . "-" . BOARDCONFIG . "-" . VERSION . "_telnet_rd");
Log::writeVerboseInfo("Working directory set as " . WD);
if(!file_exists(SHSH2))
{
Log::writeError(".shsh2 file doesn't exist or isn't readable" . PHP_EOL);
exit(-1);
}
define("SHSH2_ABS",realpath(SHSH2)); // I shouldn't have started using constants lol (I agree - ARX8x)
Log::writeInfo("Checking for dependencies");
if(!is_installed("diskutil") || !is_installed("hdiutil") || !is_installed("unzip") || !is_installed("plutil") || !is_installed("curl")){
Log::writeError("Couldn't find diskutil, unzip, plutil, curl or hdiutil. Please use a mac." . PHP_EOL);
exit(-1);
}
$dependencies = array(
"img4" => "https://github.com/xerub/img4lib",
"img4tool" => "https://github.com/tihmstar/img4tool",
"ldid2"=>"https://github.com/xerub/ldid/releases/",
"autodecrypt" => "https://github.com/matteyeux/autodecrypt",
"kairos" => "https://github.com/dayt0n/kairos",
"iproxy" => "https://github.com/libimobiledevice/libusbmuxd",
"Kernel64Patcher" => "https://github.com/Ralph0045/Kernel64Patcher",
"irecovery" => "https://github.com/libimobiledevice/libirecovery",
"remotezip" => "https://pypi.org/project/remotezip/"
);
foreach($dependencies as $dependency_cmd => $dependency_source)
{
Log::writeInfo("Checking dependency: $dependency_cmd");
$dependency_available = is_installed($dependency_cmd);
if($dependency_cmd === 'remotezip')
{
define("HAS_REMOTEZIP", $dependency_available);
if(!HAS_REMOTEZIP)
{
Log::writeInfo("remotezip is a python library that allows you to download files from ipsw without downloading the entire ipsw. It's not necessary but it'll save time and resources\n");
// since it's an optional dependency, skip over it even if it doesn't exist
continue;
}
}
if(!$dependency_available)
{
// attempt to automatically build the dependency
$dependency_function = "add_dependency_$dependency_cmd";
if(is_callable($dependency_function))
{
Log::writeInfo("Attempting to install $dependency_cmd");
$dependency_function();
if(is_installed($dependency_cmd)) continue;
}
Log::writeError(pls_install_msg($dependency_source));
if($dependency_cmd === 'irecovery')
{
Log::writeInfo("You can also install it with brew install libimobiledevice or something if you're lazy");
}
die();
}
}
define("HAS_WGET",is_installed("wget"));
Log::writeInfo("Dependency check completed\n");
// info("Creating & entering working directory if it doesn't exist: " . WD);
if(!is_dir(WD)) {mkdir(WD);}
chdir(WD);
if(!file_exists("BuildManifest.plist"))
{
$url = get_ipsw_url(DEVICE, VERSION);
if(!$url) exit(-1);
$got_files = false;
if(HAS_REMOTEZIP)
{
Log::writeInfo("Attempting to get files with remotezip");
if(($got_files = remotezip_get_files($url, BOARDCONFIG)))
{
Log::writeInfo("remotezip seems to have downloaded all files");
}
}
if(!$got_files)
{
define("FWFILE",DEVICE . "_" . VERSION . ".ipsw");
Log::writeInfo("Downloading ipsw (it will continue/just finish if it's already (partially) there)");
if(HAS_WGET){
execute("wget -q --show-progress --progress=bar:force \"" . addslashes($url) . "\" -cO " . FWFILE . "");
} else {
execute("curl \"" . addslashes($url) . "\" -o " . FWFILE . " -C -");
}
Log::writeInfo("Extracting ipsw");
execute("unzip " . FWFILE,1);
}
} else {
Log::writeInfo("BuildManifest.plist already exists, not attempting to resume ipsw download and extraction");
}
// TODO use bom to determine files to extract and use
Log::writeInfo("Finding ramdisk and trustcache name by trying to convert and mount them");
$ramdiskexisted = false;
if(file_exists("ramdisk.dmg")){
$ramdiskexisted = true;
Log::writeVerboseInfo("ramdisk.dmg already exists, renaming it as we still need to know its original name");
if(file_exists("ramdisk.dmg.orig")){die("ramdisk.dmg.orig exists, please only run one instance of this program at once or delete ramdisk.dmg.orig" . PHP_EOL);}
rename("ramdisk.dmg","ramdisk.dmg.orig");
if(!file_exists("ramdisk.dmg.orig")){die("rename failed" . PHP_EOL);}
}
$dmgs = Array();
$sizes = Array();
foreach(glob("*.dmg") as $dmg){
$dmgs[$sizes[] = filesize($dmg)] = $dmg;
}
sort($sizes);
for($i = 0; $i<sizeof($sizes);$i++){
$maybe = $dmgs[$sizes[$i]];
Log::writeVerboseInfo("trying to convert {$maybe} to .dmg");
$try = execute("img4 -i {$maybe} -o ramdisk.dmg 2>&1",1);
if($try === "rdsk\n"){
$mount_point = mount_rd();
Log::writeVerboseInfo("Mounted potential ramdisk at \"{$mount_point}\"");
Log::writeVerboseInfo("Unmounting again because we don't need it right now");
unmount($mount_point);
if(strpos($mount_point,"CustomerRamDisk") !== false){
Log::writeInfo("Found ramdisk to be {$maybe}");
define("RAMDISK",$maybe);
break;
} else {
Log::writeVerboseInfo("{$maybe} can't be it, because it mounts wrong");
@unlink("ramdisk.dmg");
}
} else {
Log::writeVerboseInfo("{$maybe} can't be it, because img4 doesn't want to convert it");
@unlink("ramdisk.dmg");
}
}
if($ramdiskexisted){
unlink("ramdisk.dmg");
rename("ramdisk.dmg.orig","ramdisk.dmg");
}
if(!defined("RAMDISK"))
{
Log::writeError("Couldn't find ramdisk\n");
exit(-1);
}
Log::writeInfo("\nBeginning to patch and sign things");
//kernelcache
if(!file_exists("kcache.raw")){
Log::writeInfo("converting kernelcache");
execute("img4 -i kernelcache.* -o kcache.raw");
} else {
Log::writeVerboseInfo("kcache.raw already exists, not converting kernelcache");
}
if(!file_exists("kcache.patched")){
Log::writeInfo("patching signature checks on kernelcache");
execute("Kernel64Patcher kcache.raw kcache.patched -a");
} else {
Log::writeVerboseInfo("kcache.patched already exists, skipping step");
}
if(!file_exists("IM4M")){
Log::writeInfo("Converting shshs2 to IM4M");
execute("img4tool -e -s " . SHSH2_ABS . " -m IM4M");
} else {
Log::writeVerboseInfo("IM4M already exists, skipping conversion of .shsh2 into it");
}
if(!file_exists("kernelcache.im4p")){
Log::writeInfo("Compressing kernelcache back");
execute("img4tool -c kernelcache.im4p -t rkrn kcache.patched --compression complzss");
} else {
Log::writeVerboseInfo("kernelcache.im4p already exists, not compressing kernel again");
}
if(!file_exists("kernelcache.img4")){
Log::writeInfo("Stitching IM4M to kernelcache");
execute("img4tool -c kernelcache.img4 -p kernelcache.im4p -m IM4M");
} else {
Log::writeVerboseInfo("kernelcache.img4 already exists, skipping packing into .img4");
}
$ibss = glob("iBSS.*.RELEASE.bin");
if(sizeof($ibss) == 0){
Log::writeInfo("Decrypting iBSS");
execute("bash -c 'mkdir tmpdir && pushd tmpdir && autodecrypt -f iBSS -i " . VERSION . " -d " . DEVICE . " && mv -v * .. && popd && rmdir tmpdir'");
} else {
Log::writeVerboseInfo("Some file matching the pattern iBSS.*.RELEASE.bin already exists, skipping iBSS downloading and decrypting");
}
if(!file_exists("iBSS.patched")){
Log::writeInfo("Patching iBSS");
execute("kairos iBSS.*.RELEASE.bin iBSS.patched");
} else {
Log::writeVerboseInfo("iBSS.patched already exists, not patching");
}
$ibec = glob("iBEC.*.RELEASE.bin");
if(sizeof($ibec) == 0){
Log::writeInfo("Decrypting iBEC");
execute("bash -c 'mkdir tmpdir && pushd tmpdir && autodecrypt -f iBEC -i " . VERSION . " -d " . DEVICE . " && mv -v * .. && popd && rmdir tmpdir'");
} else {
Log::writeVerboseInfo("Some file matching the pattern iBEC.*.RELEASE.im4p already exists, skipping iBEC downloading and decrypting");
}
if(!file_exists("iBEC.patched")){
Log::writeInfo("Patching iBEC");
execute("kairos iBEC.*.RELEASE.bin iBEC.patched -b \"rd=md0 -v\"");
} else {
Log::writeVerboseInfo("iBEC.patched already exists, not patching");
}
if(!file_exists("iBSS.img4")){
execute("img4 -i iBSS.patched -o iBSS.img4 -M IM4M -A -T ibss");
Log::writeInfo("Stitching IM4M to iBSS");
} else {
Log::writeVerboseInfo("iBSS.patched already exists, not signing patched iBSS");
}
if(!file_exists("iBEC.img4")){
Log::writeInfo("Stitching IM4M to iBEC");
execute("img4 -i iBEC.patched -o iBEC.img4 -M IM4M -A -T ibec");
} else {
Log::writeVerboseInfo("iBEC.patched already exists, not signing patched iBEC");
}
if(!file_exists("trustcache.img4")){
Log::writeInfo("Stitching IM4M to trustcache");
execute("img4 -i Firmware/" . RAMDISK .".trustcache -o trustcache.img4 -M IM4M");
} else {
Log::writeVerboseInfo("trustcache.img4 already exists, not signing");
}
if(!file_exists("devicetree.img4")){
$orig_devicetree = "Firmware/all_flash/DeviceTree." . strtolower(BOARDCONFIG) . ".im4p";
if(!file_exists($orig_devicetree)){
Log::writeInfo("Couldn't find devicetree at {$orig_devicetree}, selecting closest other one");
foreach(glob("Firmware/all_flash/DeviceTree.*.im4p") as $devicetree){
$potential_devicetrees[$devicetree] = levenshtein($devicetree,BOARDCONFIG);
}
$orig_devicetree = array_search(min($potential_devicetrees),$potential_devicetrees);
Log::writeInfo("Selected {$orig_devicetree} instead");
}
execute("img4 -i {$orig_devicetree} -o devicetree.img4 -M IM4M -T rdtr");
} else {
Log::writeVerboseInfo("devicetree.img4 already exists, skipping singing");
}
Log::writeInfo("\nWe now have everything needed to boot the ramdisk, just need to customize the ramdisk!");
if(ask("I'm about to add utilities and modify the ramdisk.\nHave you made manual changes to ramdisk.dmg and only want me to sign it? Enter y.\nFor default just press enter ")) {
Log::writeInfo("Not adding utilities, just signing");
}
else {
Log::writeVerboseInfo("enlarging ramdisk");
execute("hdiutil resize -size 150MB ramdisk.dmg");
$mountpoint = mount_rd();
Log::writeInfo("Mounted RAMdisk at {$mountpoint} and now adding tools");
execute("xcrun -sdk iphoneos clang -arch arm64 " . dirname(__FILE__) . "/resources/restored_external.c -o restored_external");
execute(LDID2_PATH." -S restored_external");
Log::writeVerboseInfo("compiled restored_external");
if(!file_exists("{$mountpoint}/usr/local/bin/restored_external_original")){
Log::writeVerboseInfo("renaming old one");
execute("mv -v \"{$mountpoint}/usr/local/bin/restored_external\" \"{$mountpoint}/usr/local/bin/restored_external_original\"",1);
}
Log::writeVerboseInfo("adding new one");
execute("cp -v restored_external \"{$mountpoint}/usr/local/bin/restored_external\"");
Log::writeVerboseInfo("Downloading executables");
$package_dir = __DIR__."/debs/";
if(!is_dir($package_dir)){mkdir($package_dir);}
chdir($package_dir);
// apt download --print-uris inetutils ncurses ncurses5-libs readline coreutils-bin firmware-sbin system-cmds nano bash sed grep htop findutils less coreutils profile.d com.bingner.snappy
$apt_download_output = "'https://apt.bingner.com/debs/1443.00/bash_5.0.3-2_iphoneos-arm.deb' bash_5.0.3-2_iphoneos-arm.deb 480482 SHA256:078a0a6dc0619dc5db2cbb411a925ab5c08810279994714fd0343fc63f7d4072
'https://apt.bingner.com/debs/1443.00/com.bingner.snappy_1.3.0_iphoneos-arm.deb' com.bingner.snappy_1.3.0_iphoneos-arm.deb 15438 SHA256:7e9db38dd7959de4484ee686c4cf8e31c47362c43865ae2e0466af190a49d484
'https://apt.bingner.com/debs/1443.00/coreutils_8.31-1_iphoneos-arm.deb' coreutils_8.31-1_iphoneos-arm.deb 714854 SHA256:37a125683866d6afa27979f39ccad3d1e2b187c33f09a9cc291c9e9b1f14a006
'https://apt.bingner.com/debs/1443.00/coreutils-bin_8.31-1_iphoneos-arm.deb' coreutils-bin_8.31-1_iphoneos-arm.deb 679670 SHA256:b4625d37d45684317766ec4c101dc37d6a750851defeb0a175c9d9f3be7f9728
'https://apt.bingner.com/debs/1443.00/findutils_4.6.0-2_iphoneos-arm.deb' findutils_4.6.0-2_iphoneos-arm.deb 212748 SHA256:fb683abb9c0c7ca3b6bcb3aa87ce31785ad2480fd46e650c2fc757a22fa51516
'https://apt.bingner.com/debs/1443.00/firmware-sbin_0-1_iphoneos-all.deb' firmware-sbin_0-1_all.deb 2050 SHA256:ab782faee7925d2702467b7a837ea8755445589de2a3eb8e6b8bd52e6e2d2440
'https://apt.bingner.com/debs/1443.00/grep_3.1-1_iphoneos-arm.deb' grep_3.1-1_iphoneos-arm.deb 91310 SHA256:b2b9473623f867735d878ee12b76af26084bbcf7bf5788a8985a579d8b806bbe
'https://apt.bingner.com/debs/1443.00/htop_2.2.0-1_iphoneos-arm.deb' htop_2.2.0-1_iphoneos-arm.deb 47260 SHA256:56c85b1f968912ab7c85b2561923c0231b1493b6899842552a7da1889d0520f3
'https://apt.bingner.com/debs/1443.00/inetutils_1.9.4-2_iphoneos-arm.deb' inetutils_1.9.4-2_iphoneos-arm.deb 268236 SHA256:4fc0c494701bdb6fa4538788c77d63024960308cc657b72a9e8cc9c09bf9019d
'https://apt.bingner.com/debs/1443.00/less_530-2_iphoneos-arm.deb' less_530-2_iphoneos-arm.deb 73896 SHA256:71b2db9247ca5342c635d5f95bc43f56d09af2d42a6f5602144f6ec37ee6a5a0
'https://apt.bingner.com/debs/1443.00/nano_4.5-1_iphoneos-arm.deb' nano_4.5-1_iphoneos-arm.deb 174454 SHA256:a174f328475b3c926c4074880cc1535873ed5ebb1b303c4aeeba38d4108306a9
'https://apt.bingner.com/debs/1443.00/ncurses_6.1+20181013-1_iphoneos-arm.deb' ncurses_6.1+20181013-1_iphoneos-arm.deb 365394 SHA256:e55c55c9d61f3a3b0c1fd1a3df1add4083a6d3e891f87fb698c57d33d2365567
'https://apt.bingner.com/debs/1443.00/ncurses5-libs_5.9-1_iphoneos-arm.deb' ncurses5-libs_5.9-1_iphoneos-arm.deb 174740 SHA256:3001282a457fc30ea5e79b9a13fcd2f972640e2d78880d5099c4f5e2de484225
'https://apt.bingner.com/debs/1443.00/profile.d_0-1_iphoneos-arm.deb' profile.d_0-1_iphoneos-arm.deb 918 SHA256:c83306dc925b5a7844098a496b8fd3eb1c3787dea912b6f7c4611d64fc651194
'https://apt.bingner.com/debs/1443.00/readline_8.0-1_iphoneos-arm.deb' readline_8.0-1_iphoneos-arm.deb 129432 SHA256:60b71efee41f78b7c427fc575c544a6ea573e4bf07520099a579e2855a040ae4
'https://apt.bingner.com/debs/1443.00/sed_4.5-1_iphoneos-arm.deb' sed_4.5-1_iphoneos-arm.deb 76688 SHA256:8a8e92b8e611514f163ca56e6fd05cbcd9f457f07d4d87ccc9202a1c6b157422
'https://apt.bingner.com/debs/1443.00/system-cmds_790.30.1-2_iphoneos-arm.deb' system-cmds_790.30.1-2_iphoneos-arm.deb 94086 SHA256:5d657d85f7e57452b76037b78e1bd0ae64421309d7c1f43cff22a6e42d3adeaf";
foreach(explode("\n",$apt_download_output) as $line){
$url = explode("'",$line)[1];
if(HAS_WGET){
execute("wget --trust-server-names -c \"{$url}\"");
} else {
execute("curl -C - -O \"{$url}\"");
}
}
$debs = glob("*.deb");
Log::writeVerboseInfo("Extracting debs " . implode(", ",$debs));
if(!is_dir("staging")){
mkdir("staging");
}
foreach($debs as $deb){
$debdir = $deb . ".dir";
if(!is_dir($debdir)){
mkdir($debdir);
}
chdir($debdir);
execute("ar -vx ../{$deb}",1);
execute("tar -C ../staging/ -xzvkf data.*",1);
chdir("..");
}
Log::writeVerboseInfo("Downloading and installing busybox (if Sam Bingner) still hosts it");
if(HAS_WGET){
execute("wget https://www.bingner.com/busybox.gz -c -O busybox.gz");
} else {
execute("curl https://www.bingner.com/busybox.gz -C - -o busybox.gz");
}
execute("cat busybox.gz|gzip -d > busybox");
execute("chmod +xxx busybox");
execute(LDID2_PATH." -S busybox");
execute(LDID2_PATH." -S ./staging/usr/bin/htop");
execute(LDID2_PATH." -S ./staging/usr/bin/find"); // idk if this makes them not die with Killed: 9 and why they do it otherwise
execute("cp -v busybox ./staging/bin/");
Log::writeVerboseInfo("Syncing extracted debs into fs");
execute("rsync --ignore-existing -avhuK --progress ./staging/ \"{$mountpoint}/\""); // this is necessary because tar overwrites symlinks smh
chdir(__DIR__ . '/' . WD);
foreach(Array("/var/root","/var/run") as $extra_directory){
$dir = $mountpoint . $extra_directory;
if(!is_dir($dir)){
mkdir($dir);
}
}
foreach(glob(dirname(__FILE__) . "/resources/etc/*") as $etcfile){
$to = $mountpoint . "/etc/" . basename($etcfile);
Log::writeVerboseInfo("copying {$etcfile} to {$to}");
execute("cp -v \"{$etcfile}\" \"{$to}\"",1);
}
// execute("img4tool -c sep-firmware.img4 -p Firmware/all_flash/sep-firmware.d211.RELEASE.im4p -m IM4M"); // this will 99% never work, leaving it here as legacy. A missing sep-firmware.img4 can't be recovered.
// execute("cp -v sep-firmware.img4 {$mountpoint}/usr/standalone/firmware/");
unmount($mountpoint);
}
execute("img4 -i ramdisk.dmg -o ramdisk -M IM4M -A -T rdsk");
$bootrd = dirname(__FILE__) . "/bootrd_" . BOARDCONFIG . '_' . VERSION . ".sh";
Log::writeInfo("All done, writing bootscript to bootrd.sh. Execute ./bootrd_" . VERSION . ".sh to boot.");
if(!file_exists("../PyBoot/pyboot.py")){
Log::writeInfo("You have not successfully cloned pyboot, doing it for you.");
chdir("../PyBoot/");
if(HAS_WGET){
execute("wget -c https://github.com/MatthewPierson/PyBoot/archive/master.zip",1);
} else {
execute("curl -C - -o master.zip https://github.com/MatthewPierson/PyBoot/archive/master.zip",1);
}
execute("unzip master.zip",1);
execute("mv -v PyBoot-master/* .",1);
execute("rm -rvf PyBoot-master",1);
unlink("master.zip");
Log::writeInfo("Try cloning with --recursive next time.");
}
Log::writeInfo("\nPreparing boot script: $bootrd");
file_put_contents($bootrd,"#!/usr/bin/env bash
cd PyBoot
./pyboot.py -p
cd ../" . WD . "
sleep 1
irecovery -f iBSS.img4
sleep 1
irecovery -f iBSS.img4
sleep 1
irecovery -f iBEC.img4
sleep 1
irecovery -c go
sleep 1
irecovery -f ramdisk
sleep 1
irecovery -c ramdisk
sleep 1
irecovery -f devicetree.img4
sleep 1
irecovery -c devicetree
sleep 1
irecovery -f trustcache.img4
sleep 1
irecovery -c firmware
sleep 1
irecovery -f kernelcache.img4
sleep 1
irecovery -c bootx
echo Alright, now run 'iproxy 2323 23' to start the proxy, and in a new tab connect with 'telnet 127.0.0.1 2323' as soon as the screen turns white. Login with username: root, password: alpine. Screen will get black after like two minutes but you should still have connectivity.");
execute("chmod -v +xxx {$bootrd}",1);
if(ask("Cool, now pray it worked. Enter yes to boot directly (you need to be in DFU mode): ")){
chdir(dirname(__FILE__));
execute($bootrd);
}
Log::main()->writeLog("telnet_rd exit");
?>