-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
210 lines (162 loc) · 6.53 KB
/
main.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
/*
* File: main.cpp
* Author: patrick
*
* Created on June 26, 2015, 6:04 PM
*/
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <regex>
#include <sstream>
using namespace std;
string convertToPlist();
/*
*
*/
int main(int argc, char** argv) {
string plistFilename = convertToPlist();
ifstream blobPlist;
blobPlist.open(plistFilename);
string line;
int dictLevel = 0, lineNumber = 0;
vector<int> startLines, endLines, iOSBuildLines;
vector<string> iOSBuildStrings;
regex keyRegex ("<key>[A-Z0-9]*</key>");
cout << "Parsing " << plistFilename << endl;
while (getline(blobPlist, line)) {
lineNumber++;
line.erase(remove(line.begin(), line.end(), ' '), line.end());
if (line == "</dict>") {
dictLevel--;
if (dictLevel == 2) {
cout << "END at line " << lineNumber << endl;
endLines.push_back(lineNumber);
}
}
else if (line == "<dict>") {
dictLevel++;
if (dictLevel == 3) {
cout << "START at line " << lineNumber << endl;
startLines.push_back(lineNumber);
}
}
else if (regex_match(line, keyRegex) && dictLevel == 1) {
//cout << "Build key at line " << lineNumber << endl;
iOSBuildLines.push_back(lineNumber);
/* check how long the build number is. <key></key> are 11 chars.
* so we need to subtract 11 to get the build number's length */
int buildLength = line.length() - 11;
//extract the build number
line = line.substr(5, buildLength);
iOSBuildStrings.push_back(line);
}
}
blobPlist.close();
cout << "Done parsing." << endl;
cout << "DEBUG INFORMATION:" << endl;
cout << "startLines.size(): " << startLines.size() << endl;
cout << "endLines.size(): " << endLines.size() << endl;
cout << "iOSBuildLines.size(): " << iOSBuildLines.size() << endl;
cout << "iOSBuildStrings.size(): " << iOSBuildStrings.size() << endl;
vector<int> buildNameAppearances;
for (int i = 0; i < iOSBuildStrings.size(); i++) {
buildNameAppearances.push_back(0);
}
for (int i = 0; i < startLines.size(); i++) {
cout << "Starting file " << i << endl;
int currentStartLine = startLines.at(i);
ifstream in;
const int filesizeInLines = endLines.at(i) - currentStartLine;
vector<string> lines;
in.open(plistFilename);
//discard lines until reaching the part we want
for (int j = 0; j < currentStartLine; j++) {
getline(in, line);
}
//now get our lines
for (int j = 0; j < filesizeInLines; j++) {
getline(in, line);
lines.push_back(line);
}
ofstream out;
string filename;
bool found = false;
for (int j = 0; !found; j++) {
if ( ( j == iOSBuildLines.size() ) || ( currentStartLine < iOSBuildLines.at(j)) ) {
filename = iOSBuildStrings.at(j-1);
if (buildNameAppearances.at(j-1) > 0) {
filename += "_";
cout << "file exists " << buildNameAppearances.at(j-1) << endl;
cout << "build number: " << iOSBuildStrings.at(j-1) << endl;
stringstream ss;
ss << buildNameAppearances.at(j - 1);
string str = ss.str();
filename += str;
}
buildNameAppearances.at(j-1) += 1;
found = true;
}
}
cout << "FILENAME: " << filename << endl;
out.open(filename += ".shsh");
out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
out << "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">" << endl;
out << "<plist version=\"1.0\">" << endl;
out << " <dict>" << endl;
for (int j = 0; j < lines.size(); j++){
out << lines.at(j) << endl;
}
out << "</plist>";
in.close();
out.close();
}
cout << "Your SHSH files have been extracted successfully." << endl <<
"For any questions, contact me on twitter.com/ppati000 :)" << endl;
return 0;
}
string convertToPlist() {
string plistFilename;
#if defined(__CYGWIN__) || defined(_WIN32)
cout << "Executing ./7za.exe e blobs.shsh -y" << endl;
int zcat = system("7za.exe e blobs.shsh -y");
plistFilename = "blobs";
#elif __APPLE__
cout << "Executing zcat < blobs.shsh > blobs.plist" << endl;
int zcat = system("zcat < blobs.shsh > blobs.plist");
plistFilename = "blobs.plist";
#else
cout << "Executing zcat blobs.shsh > blobs.plist" << endl;
int zcat = system("zcat blobs.shsh > blobs.plist");
plistFilename = "blobs.plist";
#endif
if ( zcat != 0 ) {
cerr << "Error while running zcat (code " << zcat << ")" << endl
<< "Please make sure to place your SHSH file from TinyUmbrella "
<< "in the same directory as the executable and rename it to "
<< "blobs.shsh :) Or ask for help on twitter.com/ppati000"
<< endl;
exit (EXIT_FAILURE);
}
#if defined(__linux__)
cout << "Executing perl plutil.pl blobs.plist > zcat.log" << endl;
int perl = system((string("perl plutil.pl ") + plistFilename
+ string(" > plutil.log")).c_str());
#elif defined(__CYGWIN__) || defined(_WIN32) || defined(__APPLE__)
cout << "File is good, no need for plutil." << endl;
int perl = 0;
#else
#error "Could not detect OS X or Linux. Other systems are not supported."
#endif
if ( perl != 0) {
cerr << "Error while running plutlil.pl (code " << perl << ")" << endl <<
"Please make sure perl is installed on your computer." <<
"To do this on Ubuntu, run: sudo apt-get install -y perl" <<
endl << "Or ask for help on twitter.com/ppati000";
exit (EXIT_FAILURE);
}
cout << "Done executing commands." << endl;
return plistFilename;
}