-
Notifications
You must be signed in to change notification settings - Fork 74
/
AnisetteDataManager.cpp
260 lines (211 loc) · 6.38 KB
/
AnisetteDataManager.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
#include "AnisetteDataManager.h"
#include <sstream>
#include <filesystem>
#include "Error.hpp"
#include "ServerError.hpp"
#include <set>
#include <ctime>
#include <cstdlib>
#include "AnisetteData.h"
#include "AltServerApp.h"
AnisetteDataManager* AnisetteDataManager::_instance = nullptr;
AnisetteDataManager* AnisetteDataManager::instance()
{
if (_instance == 0)
{
_instance = new AnisetteDataManager();
}
return _instance;
}
AnisetteDataManager::AnisetteDataManager() : loadedDependencies(false)
{
}
AnisetteDataManager::~AnisetteDataManager()
{
}
bool AnisetteDataManager::LoadiCloudDependencies()
{
return true;
}
bool AnisetteDataManager::LoadDependencies()
{
return true;
}
#include <cpprest/json.h>
using namespace web; // Common features like URIs.
using namespace web::http; // Common HTTP functionality
using namespace web::http::client; // HTTP client features
std::shared_ptr<AnisetteData> AnisetteDataManager::FetchAnisetteData()
{
std::string wideURI = ("/anisette/irGb3Quww8zrhgqnzmrx");
auto encodedURI = web::uri::encode_uri(wideURI);
uri_builder builder(encodedURI);
http_request request(methods::GET);
request.set_request_uri(builder.to_string());
std::map<utility::string_t, utility::string_t> headers = {
{"User-Agent", "Xcode"},
};
for (auto& pair : headers)
{
if (request.headers().has(pair.first))
{
request.headers().remove(pair.first);
}
request.headers().add(pair.first, pair.second);
}
std::shared_ptr<AnisetteData> anisetteData = NULL;
auto client = web::http::client::http_client(U("https://armconverter.com"));
auto task = client.request(request)
.then([=](http_response response)
{
return response.content_ready();
})
.then([=](http_response response)
{
odslog("Received response status code: " << response.status_code());
return response.extract_json();
})
.then([&anisetteData](pplx::task<json::value> previousTask)
{
odslog("parse anisette data ret");
json::value jsonVal = previousTask.get();
odslog("Got anisetteData json: " << jsonVal);
std::vector<std::string> keys = {
"X-Apple-I-MD-M",
"X-Apple-I-MD",
"X-Apple-I-MD-LU",
"X-Apple-I-MD-RINFO",
"X-Mme-Device-Id",
"X-Apple-I-SRL-NO",
"X-MMe-Client-Info",
"X-Apple-I-Client-Time",
"X-Apple-Locale",
"X-Apple-I-TimeZone"
};
for (auto &key : keys) {
odslog(key << ": " << jsonVal.at(key).as_string().c_str());
}
struct tm tm = { 0 };
strptime(jsonVal.at("X-Apple-I-Client-Time").as_string().c_str(), "%FT%T%z", &tm);
time_t ts = mktime(&tm);
struct timeval tv = {0};
tv.tv_sec = ts;
odslog("Building anisetteData obj...");
anisetteData = std::make_shared<AnisetteData>(
jsonVal.at("X-Apple-I-MD-M").as_string(),
jsonVal.at("X-Apple-I-MD").as_string(),
jsonVal.at("X-Apple-I-MD-LU").as_string(),
std::atoi(jsonVal.at("X-Apple-I-MD-RINFO").as_string().c_str()),
jsonVal.at("X-Mme-Device-Id").as_string(),
jsonVal.at("X-Apple-I-SRL-NO").as_string(),
jsonVal.at("X-MMe-Client-Info").as_string(),
tv,
jsonVal.at("X-Apple-Locale").as_string(),
jsonVal.at("X-Apple-I-TimeZone").as_string());
//IterateJSONValue();
});
task.wait();
odslog(*anisetteData);
return anisetteData;
}
bool AnisetteDataManager::ReprovisionDevice(std::function<void(void)> provisionCallback)
{
#if !SPOOF_MAC
provisionCallback();
return true;
#else
std::string adiDirectoryPath = "C:\\ProgramData\\Apple Computer\\iTunes\\adi";
/* Start Provisioning */
// Move iCloud's ADI files (so we don't mess with them).
for (const auto& entry : fs::directory_iterator(adiDirectoryPath))
{
if (entry.path().extension() == ".pb")
{
fs::path backupPath = entry.path();
backupPath += ".icloud";
fs::rename(entry.path(), backupPath);
}
}
// Copy existing AltServer .pb files into original location to reuse the MID.
for (const auto& entry : fs::directory_iterator(adiDirectoryPath))
{
if (entry.path().extension() == ".altserver")
{
fs::path path = entry.path();
path.replace_extension();
fs::rename(entry.path(), path);
}
}
auto cleanUp = [adiDirectoryPath]() {
/* Finish Provisioning */
// Backup AltServer ADI files.
for (const auto& entry : fs::directory_iterator(adiDirectoryPath))
{
// Backup AltStore file
if (entry.path().extension() == ".pb")
{
fs::path backupPath = entry.path();
backupPath += ".altserver";
fs::rename(entry.path(), backupPath);
}
}
// Copy iCloud ADI files back to original location.
for (const auto& entry : fs::directory_iterator(adiDirectoryPath))
{
if (entry.path().extension() == ".icloud")
{
// Move backup file to original location
fs::path path = entry.path();
path.replace_extension();
fs::rename(entry.path(), path);
odslog("Copying iCloud file from: " << entry.path().string() << " to: " << path.string());
}
}
};
// Calling CopyAnisetteData implicitly generates new anisette data,
// using the new client info string we injected.
ObjcObject* error = NULL;
ObjcObject* anisetteDictionary = (ObjcObject*)CopyAnisetteData(NULL, 0x1, &error);
try
{
if (anisetteDictionary == NULL)
{
odslog("Reprovision Error:" << ((ObjcObject*)error)->description());
ObjcObject* localizedDescription = (ObjcObject*)((id(*)(id, SEL))objc_msgSend)(error, sel_registerName("localizedDescription"));
if (localizedDescription)
{
int errorCode = ((int(*)(id, SEL))objc_msgSend)(error, sel_registerName("code"));
throw LocalizedError(errorCode, localizedDescription->description());
}
else
{
throw ServerError(ServerErrorCode::InvalidAnisetteData);
}
}
odslog("Reprovisioned Anisette:" << anisetteDictionary->description());
AltServerApp::instance()->setReprovisionedDevice(true);
// Call callback while machine is provisioned for AltServer.
provisionCallback();
}
catch (std::exception &exception)
{
cleanUp();
throw;
}
cleanUp();
return true;
#endif
}
bool AnisetteDataManager::ResetProvisioning()
{
std::string adiDirectoryPath = "C:\\ProgramData\\Apple Computer\\iTunes\\adi";
// Remove existing AltServer .pb files so we can create new ones next time we provision this device.
for (const auto& entry : fs::directory_iterator(adiDirectoryPath))
{
if (entry.path().extension() == ".altserver")
{
fs::remove(entry.path());
}
}
return true;
}