-
Notifications
You must be signed in to change notification settings - Fork 18
/
restored_external.c
136 lines (115 loc) · 3.78 KB
/
restored_external.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
/*
* ramdisk ssh server
*
* Copyright (c) 2015 xerub
*
* 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 2 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 <unistd.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <net/if.h>
#include <assert.h>
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/IOTypes.h>
#include "IOUSBDeviceControllerLib.h"
IOUSBDeviceDescriptionRef IOUSBDeviceDescriptionCreateWithType(CFAllocatorRef, CFStringRef);
io_service_t
get_service(const char *name, unsigned int retry)
{
io_service_t service;
CFDictionaryRef match = IOServiceMatching(name);
while (1) {
CFRetain(match);
service = IOServiceGetMatchingService(kIOMasterPortDefault, match);
if (service || !retry--) {
break;
}
printf("Didn't find %s, trying again\n", name);
sleep(1);
}
CFRelease(match);
return service;
}
/* reversed from restored_external */
int
init_usb(void)
{
int i;
CFNumberRef n;
io_service_t service;
CFMutableDictionaryRef dict;
IOUSBDeviceDescriptionRef desc;
IOUSBDeviceControllerRef controller;
desc = IOUSBDeviceDescriptionCreateWithType(kCFAllocatorDefault, CFSTR("standardMuxOnly")); /* standardRestore */
if (!desc) {
return -1;
}
IOUSBDeviceDescriptionSetSerialString(desc, CFSTR("ramdisk tool " __DATE__ " " __TIME__ ));
controller = 0;
while (IOUSBDeviceControllerCreate(kCFAllocatorDefault, &controller)) {
printf("Unable to get USB device controller\n");
sleep(3);
}
IOUSBDeviceControllerSetDescription(controller, desc);
CFRelease(desc);
CFRelease(controller);
service = get_service("AppleUSBDeviceMux", 10);
if (!service) {
return -1;
}
dict = CFDictionaryCreateMutable(NULL, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
i = 7;
n = CFNumberCreate(NULL, kCFNumberIntType, &i);
CFDictionarySetValue(dict, CFSTR("DebugLevel"), n);
CFRelease(n);
i = IORegistryEntrySetCFProperties(service, dict);
CFRelease(dict);
IOObjectRelease(service);
return i;
}
#include "micro_inetd.c" /* I know, I am a bad person for doing this */
char *execve_params[] = { "micro_inetd", "22", "/usr/local/sbin/dropbear", "-i", NULL };
/* chopped from https://code.google.com/p/iphone-dataprotection/ */
int
main(int argc, char *argv[])
{
printf("Starting ramdisk tool\n");
printf("Compiled " __DATE__ " " __TIME__ "\n");
io_service_t service = get_service("IOWatchDogTimer", 0);
if (service) {
int zero = 0;
CFNumberRef n = CFNumberCreate(NULL, kCFNumberSInt32Type, &zero);
IORegistryEntrySetCFProperties(service, n);
CFRelease(n);
IOObjectRelease(service);
}
if (init_usb()) {
printf("USB init FAIL\n");
} else {
printf("USB init done\n");
}
printf(" ####### ## ##\n");
printf("## ## ## ## \n");
printf("## ## ## ## \n");
printf("## ## ##### \n");
printf("## ## ## ## \n");
printf("## ## ## ## \n");
printf(" ####### ## ##\n");
printf("Running server\n");
return main2(4, execve_params);
}