/
RestoreInterface.cpp
301 lines (234 loc) · 10.7 KB
/
RestoreInterface.cpp
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
#include "RestoreInterface.h"
int restore_mount(string *args, struct shell_state *sh)
{
mach_error_t retval;
if( args[1] == "" || args[2] == "")
{
ifNotQuiet cout << "mount: please provide both arguments." << endl;
set_rfr(1);
return SHELL_CONTINUE;
}
D("allocating CFMutableDictionary");
CFMutableDictionaryRef req = CFDictionaryCreateMutable( kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
D("setting values");
CFDictionarySetValue(req, CFSTR("Operation"), CFSTR("Mount"));
CFDictionarySetValue(req, CFSTR("DeviceName"),
CFStringCreateWithCString(NULL, args[1].c_str(), kCFStringEncodingASCII));
CFDictionarySetValue(req, CFSTR("MountPoint"),
CFStringCreateWithCString(NULL, args[2].c_str(), kCFStringEncodingASCII));
D("sending dictionary");
retval = performOperation(sh->restore_dev, req);
ifVerbose cout << "mount: mounting '" << args[1] << "' at '" << args[2] << endl;
// build a list of known error codes
ifNotQuiet
{
switch (retval)
{
case 0:
ifVerbose cout << "mount: Successful." << endl;
break;
case 6:
cout << "mount: iPhone returned '6' - invalid argument." << endl;
break;
default:
cout << "mount: iPhone returned '" << retval << "' - unknown error code." << endl;
break;
}
}
// set return function retval so we can break a script if this doesn't work for some reason
set_rfr(retval);
return SHELL_CONTINUE;
}
int restore_partition(string *args, struct shell_state *sh)
{
mach_error_t retval;
D("allocating CFMutableDictionary");
CFMutableDictionaryRef req = CFDictionaryCreateMutable( kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
D("setting values");
CFDictionarySetValue(req, CFSTR("Operation"), CFSTR("Partition"));
D("sending dictionary");
retval = performOperation(sh->restore_dev, req);
ifVerbose cout << "partition: returned error code: "
<< retval << endl;
// set return function retval so we can break a script if this doesn't work for some reason
set_rfr(retval);
return SHELL_CONTINUE;
}
int restore_erase(string *args, struct shell_state *sh)
{
mach_error_t retval;
if( args[1] == "" || args[2] == "")
{
ifNotQuiet cout << "mount: please provide both arguments." << endl;
set_rfr(1);
return SHELL_CONTINUE;
}
D("allocating CFMutableDictionary");
CFMutableDictionaryRef req = CFDictionaryCreateMutable( kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
D("setting values");
CFDictionarySetValue(req, CFSTR("Operation"), CFSTR("Erase"));
CFDictionarySetValue(req, CFSTR("DeviceName"),
CFStringCreateWithCString(NULL, args[1].c_str(), kCFStringEncodingASCII) );
CFDictionarySetValue(req, CFSTR("VolumeName"),
CFStringCreateWithCString(NULL, args[2].c_str(), kCFStringEncodingASCII) );
D("sending dictionary");
retval = performOperation(sh->restore_dev, req);
ifVerbose cout << "erase: erasing device '" << args[1] << "' at volume '" << args[2] << "': " << retval << endl;
// set return function retval so we can break a script if this doesn't work for some reason
set_rfr(retval);
return SHELL_CONTINUE;
}
int restore_ditto(string *args, struct shell_state *sh)
{
mach_error_t retval;
if( args[1] == "" || args[2] == "")
{
ifNotQuiet cout << "ditto: please provide both arguments." << endl;
set_rfr(1);
return SHELL_CONTINUE;
}
D("allocating CFMutableDictionary");
CFMutableDictionaryRef req = CFDictionaryCreateMutable( kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
D("setting values");
CFDictionarySetValue(req, CFSTR("Operation"), CFSTR("Ditto"));
CFDictionarySetValue(req, CFSTR("SourcePath"),
CFStringCreateWithCString(NULL, args[1].c_str(), kCFStringEncodingASCII) );
CFDictionarySetValue(req, CFSTR("DestinationPath"),
CFStringCreateWithCString(NULL, args[2].c_str(), kCFStringEncodingASCII) );
D("sending dictionary");
retval = performOperation(sh->restore_dev, req);
ifVerbose cout << "ditto: copying file '" << args[1] << "' to '" << args[2] << "': " << retval << endl;
// set return function retval so we can break a script if this doesn't work for some reason
set_rfr(retval);
return SHELL_CONTINUE;
}
int restore_umount(string *args, struct shell_state *sh)
{
mach_error_t retval;
if( args[1] == "" )
{
ifNotQuiet cout << "umount: please provide an argument." << endl;
set_rfr(1);
return SHELL_CONTINUE;
}
D("allocating CFMutableDictionary");
CFMutableDictionaryRef req = CFDictionaryCreateMutable( kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
D("setting values");
CFDictionarySetValue(req, CFSTR("Operation"), CFSTR("Unmount"));
CFDictionarySetValue(req, CFSTR("MountPoint"),
CFStringCreateWithCString(NULL, args[1].c_str(), kCFStringEncodingASCII) );
D("sending dictionary");
retval = performOperation(sh->restore_dev, req);
ifVerbose cout << "umount: Unmounting '" << args[1] << "': " << retval << endl;
// set return function retval so we can break a script if this doesn't work for some reason
set_rfr(retval);
return SHELL_CONTINUE;
}
int restore_filesystemcheck(string *args, struct shell_state *sh)
{
mach_error_t retval;
if( args[1] == "" )
{
ifNotQuiet cout << "filesystemcheck: please provide a path to a disk to check." << endl;
set_rfr(1);
return SHELL_CONTINUE;
}
D("allocating CFMutableDictionary");
CFMutableDictionaryRef req = CFDictionaryCreateMutable( kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
D("setting values");
CFDictionarySetValue(req, CFSTR("Operation"), CFSTR("FilesystemCheck"));
CFDictionarySetValue(req, CFSTR("DeviceName"),
CFStringCreateWithCString(NULL, args[1].c_str(), kCFStringEncodingASCII) );
D("sending dictionary");
retval = performOperation(sh->restore_dev, req);
ifVerbose cout << "FileSystemCheck: checking device '" << args[1] << "': " << retval << endl;
//Here we should check for 'unknown device' error code to assume that anything else means
//that fsck could not repair the disk, which we should alert the user to.
// set return function retval so we can break a script if this doesn't work for some reason
set_rfr(retval);
return SHELL_CONTINUE;
}
int restore_mkdir(string *args, struct shell_state *sh)
{
mach_error_t retval;
if( args[1] == "" || args[2] == "")
{
ifNotQuiet cout << "mkdir: please provide both arguments." << endl;
set_rfr(1);
return SHELL_CONTINUE;
}
D("allocating CFMutableDictionary");
CFMutableDictionaryRef req = CFDictionaryCreateMutable( kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
D("setting values");
CFDictionarySetValue(req, CFSTR("Operation"), CFSTR("MakeDirectory"));
CFDictionarySetValue(req, CFSTR("Mode"),
CFStringCreateWithCString(NULL, args[1].c_str(), kCFStringEncodingASCII) );
CFDictionarySetValue(req, CFSTR("Path"),
CFStringCreateWithCString(NULL, args[2].c_str(), kCFStringEncodingASCII) );
D("sending dictionary");
retval = performOperation(sh->restore_dev, req);
ifVerbose cout << "mkdir: creating directory with modes '"
<< args[1] << "' at location '" << args[2] << "': " << retval << endl;
// set return function retval so we can break a script if this doesn't work for some reason
set_rfr(retval);
return SHELL_CONTINUE;
}
int restore_force(string *args, struct shell_state *sh)
{
mach_error_t retval;
if( args[1] == "" )
{
ifNotQuiet cout << "force: please provide a command." << endl;
set_rfr(1);
return SHELL_CONTINUE;
}
D("allocating CFMutableDictionary");
CFMutableDictionaryRef req = CFDictionaryCreateMutable( kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
D("setting values");
CFDictionarySetValue(req, CFSTR("Operation"),
CFStringCreateWithCString(NULL, args[1].c_str(), kCFStringEncodingASCII) );
D("sending dictionary");
retval = performOperation(sh->restore_dev, req);
ifVerbose cout << "force: sending operation: '" << args[1] << "'" << endl;
ifNotQuiet
{
switch(retval)
{
case 0:
ifVerbose cout << "force: Successful." << endl;
break;
case 8:
cout << "force: Unknown command." << endl;
break;
default:
cout << "force: Unknown error code '" << retval << "'. Please report." << endl;
break;
}
}
// set return function retval so we can break a script if this doesn't work for some reason
set_rfr(retval);
return SHELL_CONTINUE;
}
int restore_exit(string *args, struct shell_state *sh)
{
ifNotQuiet cout << "shell: exiting restore mode." << endl;
ifVerbose cout << "shell: If connected, the phone may restart itself. Otherwise use button combo." << endl;
set_rfr(0);
return SHELL_WAIT;
}