-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzip2IMG.cpp
More file actions
112 lines (100 loc) · 3.3 KB
/
Copy pathzip2IMG.cpp
File metadata and controls
112 lines (100 loc) · 3.3 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
#include "zip2IMG.h"
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
// Code by Nix Panqueca -w-
std::string prefix = "--";
std::string file;
void extract() {
std::cout << "\033[H\033[2J" << std::flush;
printf("Decompressing system.new.dat.br ...\n");
system("brotli --decompress image/system.new.dat.br -o image/system.new.dat");
#ifdef _WIN32
system("del /f image\\system.new.dat.br");
#elif
system("rm -rf image/system.new.dat.br");
#endif
std::cout << "DONE!";
printf("Converting to system.img ...\n");
#ifdef _WIN32
system("python sdat2img.py image/system.transfer.list image/system.new.dat image/system.img");
#elif __linux__
system("python sdat2img.py image/system.transfer.list image/system.new.dat image/system.raw.img");
system("img2simg image/system.raw.img image/system.img")
#endif
printf("Cleaning ...\n");
#ifdef _WIN32
system("del /f image\\system.new.dat image\\system.patch.dat image\\system.transfer.list");
#elif __linux__
system("rm -rf image/system.new.dat image/system.patch.dat image/system.transfer.list image/system.raw.img META-INF/ install/");
#endif
std::cout << "Process completed!" << endl;
exit(0);
}
int main(int argc, char* argv[]) {
for (int i = 1; i < argc; i++) {
std::string arg = argv[i];
if (arg == (prefix + "help") || arg == "-h") {
printf("Avaiable arguments: \n");
std::cout << "install -i"; std::cout << " : installs every zip2img dependency" << endl;
std::cout << "zip -z"; std::cout << " : specifies the .zip file to be extracted" << endl;
return 0;
}
else if (arg == (prefix + "install") || arg == "-i") {
#ifdef _WIN32
system("winget install -e --id Google.Brotli");
system("winget install -e --id 7zip.7zip");
system("winget install -e --id Google.PlatformTools");
#elif __linux__
system("sudo apt update && sudo apt install brotli 7zip android-platform-tools -y");
#endif
}
else if (arg == (prefix + "zip") || arg == "-z") {
if (i + 1 < argc) {
file = argv[i + 1];
#ifdef _WIN32
std::string cmd = "\"C:\\Program Files\\7-zip\\7z.exe\" >nul 2>&1";
int result = system(cmd.c_str());
#elif __linux__
std::string cmd = "7z t \"" + file + "\" >nul 2>&1";
int result = system(cmd.c_str());
#endif
if (result == 0){printf("zip file is:\033[3m valid\033[0m\n");}
else if (result != 0){
printf("zip file is:\033[3m invalid\033[0m\n");
return 1;
}
printf("Make sure you have all the dependencies installed.\n if you dont have, run zip2img --install\n");
#ifdef _WIN32
system("\"C:\\Program Files\\7-zip\\7z.exe\" > version.txt");
std::cout << "\"C:\\Program Files\\7-zip\\7z.exe\" > version.txt" << endl;
std::ifstream text("version.txt");
if (!text.is_open()) {
std::cerr << "CANT GET version.txt\n";
}
std::string line;
if (std::getline(text, line)) {
std::cout << line << std::endl;
}
text.close();
system("del /f version.txt");
#endif
if (result == 0) {
#ifdef _WIN32
cmd = "7-zip\\7z.exe x \"" + file + "\" -o\"image\\\"";
system(cmd.c_str());
#elif __linux__
cmd = "7z x \"" + file + "\"";
system(cmd.c_str());
#endif
extract();
}
}
else {
printf("Please select a zip file");
return 1;
}
}
}
}