forked from rileytestut/AltServer-Windows
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathError.hpp
More file actions
executable file
·454 lines (353 loc) · 13 KB
/
Copy pathError.hpp
File metadata and controls
executable file
·454 lines (353 loc) · 13 KB
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
//
// Error.hpp
// AltSign-Windows
//
// Created by Riley Testut on 8/8/19.
// Copyright © 2019 Riley Testut. All rights reserved.
//
#ifndef Error_hpp
#define Error_hpp
#include <cpprest/json.h>
#include <iostream>
#include <exception>
#include <map>
#include <optional>
#include <string>
#include <any>
#include <assert.h>
#define __FILENAME__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#define SOURCE_USERINFO { {"Source File", __FILENAME__}, {"Source Line", __LINE__} }
extern std::string NSLocalizedDescriptionKey;
extern std::string NSLocalizedFailureErrorKey;
extern std::string NSLocalizedFailureReasonErrorKey;
extern std::string NSLocalizedRecoverySuggestionErrorKey;
extern std::string NSUnderlyingErrorKey;
extern std::string NSDebugDescriptionErrorKey;
extern std::string ALTLocalizedDescriptionKey;
extern std::string ALTLocalizedFailureReasonErrorKey;
extern std::string ALTLocalizedRecoverySuggestionErrorKey;
extern std::string ALTDebugDescriptionErrorKey;
extern std::string AnyStringValue(std::any& any);
enum class SignErrorCode
{
Unknown,
InvalidApp,
MissingAppBundle,
MissingInfoPlist,
MissingProvisioningProfile,
MissingAppleRootCertificate,
InvalidCertificate,
InvalidProvisioningProfile,
};
enum class APIErrorCode
{
Unknown = 3000,
InvalidParameters,
IncorrectCredentials,
AppSpecificPasswordRequired,
NoTeams,
InvalidDeviceID,
DeviceAlreadyRegistered,
InvalidCertificateRequest,
CertificateDoesNotExist,
InvalidAppIDName,
InvalidBundleIdentifier,
BundleIdentifierUnavailable,
AppIDDoesNotExist,
InvalidAppGroup,
AppGroupDoesNotExist,
InvalidProvisioningProfileIdentifier,
ProvisioningProfileDoesNotExist,
InvalidResponse,
RequiresTwoFactorAuthentication,
IncorrectVerificationCode,
AuthenticationHandshakeFailed,
InvalidAnisetteData,
};
enum class CocoaErrorCode
{
FileNoSuchFile = 4,
FileReadUnknown = 256,
FileReadCorruptFile = 259,
FileWriteUnknown = 512,
CoderReadCorrupt = 4864,
CoderValueNotFound = 4865,
};
class Error: public std::exception
{
public:
Error(int code, std::map<std::string, std::any> userInfo = {}) : _code(code), _userInfo(userInfo)
{
if (_userInfo.count(NSUnderlyingErrorKey) == 0)
{
return;
}
try
{
auto value = _userInfo[NSUnderlyingErrorKey];
std::shared_ptr<Error> underlyingError = std::any_cast<std::shared_ptr<Error>>(value);
}
catch (std::bad_any_cast)
{
// All underlying errors MUST be std::shared_ptrs in order to retrieve them from user info.
assert(false);
}
}
virtual std::string domain() const = 0;
int code() const
{
return _code;
}
std::map<std::string, std::any> userInfo() const
{
return _userInfo;
}
std::string localizedDescription() const
{
std::string localizedDescription;
if (this->_userInfo.count(NSLocalizedDescriptionKey) > 0)
{
localizedDescription = AnyStringValue(this->userInfo().at(NSLocalizedDescriptionKey));
}
else if (this->localizedFailure().has_value())
{
auto localizedFailure = *this->localizedFailure();
if (this->localizedFailureReason().has_value())
{
auto localizedFailureReason = *this->localizedFailureReason();
localizedDescription = localizedFailure + " " + localizedFailureReason;
}
else
{
localizedDescription = localizedFailure;
}
}
else if (this->localizedFailureReason().has_value())
{
localizedDescription = *this->localizedFailureReason();
}
else
{
localizedDescription = this->localizedErrorCode();
}
return localizedDescription;
}
std::optional<std::string> localizedFailure() const
{
if (this->_userInfo.count(NSLocalizedFailureErrorKey) > 0)
{
auto localizedFailure = AnyStringValue(this->userInfo().at(NSLocalizedFailureErrorKey));
return localizedFailure;
}
return std::nullopt;
}
void setLocalizedFailure(std::optional<std::string> localizedFailure)
{
this->_userInfo[NSLocalizedFailureErrorKey] = localizedFailure;
}
virtual std::optional<std::string> localizedFailureReason() const
{
if (this->_userInfo.count(NSLocalizedFailureReasonErrorKey) > 0)
{
auto localizedFailureReason = AnyStringValue(this->userInfo().at(NSLocalizedFailureReasonErrorKey));
return localizedFailureReason;
}
return std::nullopt;
}
virtual std::optional<std::string> localizedRecoverySuggestion() const
{
if (this->_userInfo.count(NSLocalizedRecoverySuggestionErrorKey) > 0)
{
auto localizedRecoverySuggestion = AnyStringValue(this->userInfo().at(NSLocalizedRecoverySuggestionErrorKey));
return localizedRecoverySuggestion;
}
return std::nullopt;
}
virtual std::optional<std::string> localizedDebugDescription() const
{
if (this->_userInfo.count(NSDebugDescriptionErrorKey) > 0)
{
auto debugDescription = AnyStringValue(this->userInfo().at(NSDebugDescriptionErrorKey));
return debugDescription;
}
return std::nullopt;
}
std::string localizedErrorCode() const
{
auto localizedErrorCode = this->domain() + " " + std::to_string(this->displayCode());
return localizedErrorCode;
}
virtual int displayCode() const
{
return this->code();
}
friend std::ostream& operator<<(std::ostream& os, const Error& error)
{
os << error.localizedErrorCode() << ". \"" << error.localizedDescription() << "\"";
return os;
}
web::json::value serialized() const;
std::string formattedDetailedDescription() const;
protected:
int _code;
std::map<std::string, std::any> _userInfo;
};
class APIError : public Error
{
public:
APIError(APIErrorCode code, std::map<std::string, std::any> userInfo = {}) : Error((int)code, userInfo)
{
}
virtual std::string domain() const
{
return "AltStore.AppleDeveloperError";
}
virtual std::optional<std::string> localizedFailureReason() const
{
switch ((APIErrorCode)this->code())
{
case APIErrorCode::Unknown:
return "An unknown error occured.";
case APIErrorCode::InvalidParameters:
return "The provided parameters are invalid.";
case APIErrorCode::IncorrectCredentials:
return "Incorrect Apple ID or password.";
case APIErrorCode::NoTeams:
return "You are not a member of any development teams.";
case APIErrorCode::AppSpecificPasswordRequired:
return "An app-specific password is required. You can create one at appleid.apple.com.";
case APIErrorCode::InvalidDeviceID:
return "This device's UDID is invalid.";
case APIErrorCode::DeviceAlreadyRegistered:
return "This device is already registered with this team.";
case APIErrorCode::InvalidCertificateRequest:
return "The certificate request is invalid.";
case APIErrorCode::CertificateDoesNotExist:
return "There is no certificate with the requested serial number for this team.";
case APIErrorCode::InvalidAppIDName:
return "The name for this app is invalid.";
case APIErrorCode::InvalidBundleIdentifier:
return "The bundle identifier for this app is invalid.";
case APIErrorCode::BundleIdentifierUnavailable:
return "The bundle identifier for this app has already been registered.";
case APIErrorCode::AppIDDoesNotExist:
return "There is no App ID with the requested identifier on this team.";
case APIErrorCode::InvalidAppGroup:
return "The provided app group is invalid.";
case APIErrorCode::AppGroupDoesNotExist:
return "App group does not exist.";
case APIErrorCode::InvalidProvisioningProfileIdentifier:
return "The identifier for the requested provisioning profile is invalid.";
case APIErrorCode::ProvisioningProfileDoesNotExist:
return "There is no provisioning profile with the requested identifier on this team.";
case APIErrorCode::InvalidResponse:
return "Server returned invalid response.";
case APIErrorCode::RequiresTwoFactorAuthentication:
return "This account requires signing in with two-factor authentication.";
case APIErrorCode::IncorrectVerificationCode:
return "Incorrect verification code.";
case APIErrorCode::AuthenticationHandshakeFailed:
return "Failed to perform authentication handshake with server.";
case APIErrorCode::InvalidAnisetteData:
return "Invalid anisette data. Please close both iTunes and iCloud, then try again.";
}
return "Unknown error.";
}
};
class SignError: public Error
{
public:
SignError(SignErrorCode code) : Error((int)code)
{
}
virtual std::string domain() const
{
return "AltSign.Error";
}
virtual std::optional<std::string> localizedFailureReason() const
{
switch ((SignErrorCode)this->code())
{
case SignErrorCode::Unknown:
return "An unknown error occured.";
case SignErrorCode::InvalidApp:
return "The app is invalid.";
case SignErrorCode::MissingAppBundle:
return "The provided .ipa does not contain an app bundle.";
case SignErrorCode::MissingInfoPlist:
return "The provided app is missing its Info.plist.";
case SignErrorCode::MissingProvisioningProfile:
return "Could not find matching provisioning profile.";
case SignErrorCode::MissingAppleRootCertificate:
return "Could not locate the root signing certificate.";
case SignErrorCode::InvalidCertificate:
return "The signing certificate is invalid.";
case SignErrorCode::InvalidProvisioningProfile:
return "The provisioning profile is invalid.";
}
return "Unknown error.";
}
};
class CocoaError: public Error
{
public:
CocoaError(CocoaErrorCode code, std::map<std::string, std::any> userInfo = {}) : Error((int)code, userInfo)
{
}
virtual std::string domain() const
{
return "NSCocoaErrorDomain";
}
virtual std::optional<std::string> localizedFailureReason() const
{
switch ((CocoaErrorCode)this->code())
{
case CocoaErrorCode::FileReadUnknown:
return "An unknown error occured while reading the file.";
case CocoaErrorCode::FileWriteUnknown:
return "An unknown error occured while writing to disk.";
case CocoaErrorCode::FileNoSuchFile:
return "The app could not be found.";
case CocoaErrorCode::FileReadCorruptFile:
return "The app isn't in the correct format.";
case CocoaErrorCode::CoderReadCorrupt:
return "The data isn't in the correct format.";
case CocoaErrorCode::CoderValueNotFound:
return "The data is missing.";
}
return "Unknown error.";
}
};
class LocalizedError : public Error
{
public:
LocalizedError(int code, std::string localizedDescription) : Error(code, { {NSLocalizedDescriptionKey, localizedDescription} })
{
}
using Error::Error;
virtual std::optional<std::string> localizedFailureReason() const
{
return std::nullopt;
}
};
class LocalizedAPIError : public LocalizedError
{
public:
virtual std::string domain() const { return "Apple.APIError"; }
using LocalizedError::LocalizedError; // Inherit constructor
};
class LocalizedInstallationError : public LocalizedError
{
public:
virtual std::string domain() const { return "Apple.InstallationError"; }
using LocalizedError::LocalizedError; // Inherit constructor
};
class ExceptionError : public LocalizedError
{
public:
virtual std::string domain() const { return "AltServer.ExceptionError"; }
ExceptionError(std::exception& exception) : LocalizedError(0, exception.what())
{
}
};
#endif /* Error_hpp */