-
Notifications
You must be signed in to change notification settings - Fork 8
/
otools.cpp
366 lines (329 loc) · 12 KB
/
otools.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
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
#include "otools.h"
#include "ui_otools.h"
#include <QFileDialog>
#include <QMessageBox>
#include <stdlib.h>
QString device("unknown");
OTools::OTools(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::OTools)
{
ui->setupUi(this);
}
OTools::~OTools()
{
delete ui;
}
// Device Selection
void OTools::on_bacon_clicked()
{
ui->modbox->setEnabled(true);
ui->recbox->setEnabled(true);
ui->filebox->setEnabled(true);
ui->backbox->setEnabled(true);
ui->UnlockB->setEnabled(true);
ui->LockB->setEnabled(true);
ui->EfsB->setEnabled(true);
ui->label->setVisible(false);
device="bacon";
setenv("adbdevice", device, true);
}
void OTools::on_find7_clicked(){
ui->modbox->setEnabled(true);
ui->recbox->setEnabled(true);
ui->filebox->setEnabled(true);
ui->backbox->setEnabled(true);
ui->label->setVisible(false);
ui->UnlockB->setEnabled(false);
ui->LockB->setEnabled(false);
ui->EfsB->setEnabled(false);
device="find7";
setenv("adbdevice", device, true);
}
void OTools::on_find5_clicked()
{
ui->modbox->setEnabled(true);
ui->recbox->setEnabled(true);
ui->filebox->setEnabled(true);
ui->backbox->setEnabled(true);
ui->label->setVisible(false);
ui->UnlockB->setEnabled(false);
ui->LockB->setEnabled(false);
ui->EfsB->setEnabled(false);
device="find5";
setenv("adbdevice", device, true);
}
void OTools::on_n1_clicked()
{
ui->modbox->setEnabled(true);
ui->recbox->setEnabled(true);
ui->filebox->setEnabled(true);
ui->backbox->setEnabled(true);
ui->label->setVisible(false);
ui->UnlockB->setEnabled(false);
ui->LockB->setEnabled(false);
ui->EfsB->setEnabled(false);
device="n1";
setenv("adbdevice", device, true);
}
// ToolBar
void OTools::on_actionDisclaimer_triggered()
{
QMessageBox::about(this,tr("Disclaimer"),"This program has enough knowledge to brick your device, destroy your computer, void warrany, eat cats and burn your flowers. The developer disclaim every damange caused from the usage of this program.", "Close");
}
void OTools::on_actionAbout_triggered()
{
QMessageBox::about(this,tr("About OTools"),"©2014 Joey Rizzoli (@linuxx)\nSources: https://github.com/linuxxxxx/OTools\nOTools is an opensource software that has the goal to provide a fast, safe and user friendly tool to manage your Oppo or OnePlus Device.");
}
void OTools::on_actionUpdate_triggered()
{
QMessageBox::information(this,tr("Update"),"Updating OTools");
}
// Buttons
//Backup
void OTools::on_BackupB_clicked()
{
/* TODO:
* File Save
* Confirm dialog
* Command
* Return Dialog
*/
}
void OTools::on_RestoreB_clicked()
{
QString backfile=QFileDialog::getOpenFileName(
this,
tr("Choose File"),
"~"
"Backups (*.ab);;All Files (*.*)"
);
QMessageBox::information(this,tr("Restore Backup"),backfile,"OK");
const char *backupf = qPrintable(backfile);
setenv("backupf", backupf, true);
system("adb restore $backupf");
//if (system? != 0) QMessageBox::information(this,tr("Done"),"Backup restored sucesfully!","OK");
//else QMessageBox::information(this,tr("Error"),"An error occured while restoring the backup","OK");
}
//Files
void OTools::on_PushB_clicked(){
QString pushfile=QFileDialog::getOpenFileName(
this,
tr("Choose File"),
"~"
"All Files (*.*)"
);
QMessageBox::information(this,tr("Push File"),pushfile,"OK");
const char *file = qPrintable(pushfile);
setenv("pushfile", file, true);
system("adb push $pushfile /sdcard/");
//if (system?!=0) QMessageBox::information(this,tr("Done"),"File pushed sucesfully!","OK");
//else QMessageBox::error(this,tr("Error"),"An error occured while pushing the file","OK");
}
void OTools::on_PullB_clicked(){
/* TODO:
* think about this
*/
}
void OTools::on_CamB_clicked(){
/* TODO:
* something similar to push, but instead of selecting a file, make user select the destination folder for the photos
*/
}
//Recovery
void OTools::on_pushButton_3_clicked()
{
/* TODO:
* if install zip is cheked enable the select button, export the path as bash var, add the flag to openrecovery script
* if wipe data is checked add a flag to openrecovery script
* if backup is checked add a flag to openrecovery script << THIS MUST BE THE FIRST
*/
}
// Advanced stuffs
//MOD
void OTools::on_UnlockB_clicked()
{
QMessageBox::information(this,tr("Unlock Bootloader"),"You want to unlock the bootloader, this operation will erase all your personal content such as photos, apps and music, a backup is recommend! This operation may brick your device if something goes wrong","Continue");
QMessageBox::about(this,tr("Unlock Bootloader"),"Plug your device in and wait until you'll see a 'done' message, if asked to allow unlock select yes.\n Press Next to start","Next");
system("adb wait-for-device");
system("adb reboot bootloader");
system("fastboot devices");
system("fastboot oem-unlock");
// Dunno how that lk manages fb commands,
QMessageBox::information(this,tr("Unlock Bootloader"),"Wait until the device completes the unlock operation, when it will say done, reboot","Done");
/* TODO:
* Dialog while executing system()
*/
}
void OTools::on_LockB_clicked()
{
QMessageBox::information(this,tr("Lock Bootloader"),"You want to lock the bootloader, you won't be able to boot or flash img files until you'll re-unlock it! You won't loose any data.\n This operation may brick your device if something goes wrong","Continue");
QMessageBox::about(this,tr("Lock Bootloader"),"Plug your device in and wait until you'll see a 'done' message, if asked to allow unlock select yes.\n Press Next to start","Next");
system("adb wait-for-device");
system("adb reboot bootloader");
system("fastboot devices");
system("fastboot oem-lock");
// Dunno how that lk manages fb commands,
QMessageBox::information(this,tr("Lock Bootloader"),"Wait until the device completes the lock operation, when it will say done, reboot","Done");
/* TODO:
* Dialog while executing system()
*/
}
void OTools::on_FBootB_clicked()
{
QString fbboot=QFileDialog::getOpenFileName(
this,
tr("Choose File"),
"~"
"IMG files (*.img);;All Files (*.*)"
);
QMessageBox::information(this,tr("Fastboot Boot"),fbboot,"OK");
const char *ffbboot = qPrintable(fbboot);
QMessageBox::about(this,tr("Fastboot Boot"),"Plug your device in and wait until device boots the file.\n Press Next to start","Next");
setenv("ffbboot", ffbboot, true);
system("adb wait-for-device");
system("adb reboot bootloader");
system("fastboot devices");
system("fastboot boot $ffbboot");
/* TODO:
* Dialog while executing system()
*/
}
void OTools::on_FlashBootB_clicked()
{
QString fboot=QFileDialog::getOpenFileName(
this,
tr("Choose File"),
"~"
"IMG files (*.img);;All Files (*.*)"
);
QMessageBox::information(this,tr("Kernel Installer"),fboot,"OK");
const char *ffboot = qPrintable(fboot);
QMessageBox::about(this,tr("Kernel Installer"),"Plug your device in and wait until kernel is flashed, the device will reboot automatically.\n Press Next to start","Next");
setenv("ffboot", ffboot, true);
system("adb wait-for-device");
system("adb reboot bootloader");
system("fastboot devices");
system("fastboot flash boot $ffboot");
system("fastboot reboot");
/* TODO:
* Dialog while executing system()
*/
}
void OTools::on_RecoveryB_clicked()
{
QString recovery=QFileDialog::getOpenFileName(
this,
tr("Choose File"),
"~"
"IMG files (*.img);;All Files (*.*)"
);
QMessageBox::information(this,tr("Kernel Installer"),fboot,"OK");
const char *ffboot = qPrintable(fboot);
QMessageBox::about(this,tr("Kernel Installer"),"Plug your device in and wait until kernel is flashed, the device will reboot automatically.\n Press Next to start","Next");
setenv("ffboot", ffboot, true);
system("adb wait-for-device");
system("adb reboot bootloader");
system("fastboot devices");
system("fastboot flash boot $ffboot");
system("fastboot reboot");
/* TODO:
* Ask user if he/she already have a recovery.img file, if not use a local twrp
* Dialog while executing system()
*/
}
void OTools::on_FBFlashB_clicked()
{
/* TODO >>LATER<<:
* ask partition name (choose from an array?)
* Filepicker
* flash
*/
}
void OTools::on_RootB_clicked()
{
//TODO: add a unlocked-checker using fastboot oem device-info | grep 'Device unlocked: '
QMessageBox::about(this,tr("Rooter"),"This operation will root your device. Your bootloader needs to be unlocked otherwhise most of the operations will fail.","Start");
const char *updatezip("res/root.zip");
setenv("updatezip", updatezip, true);
system("adb wait-for-device");
system("adb reboot bootloader");
system("fastboot device");
system("fastboot boot res/$adbdevice/recovery.img");
// TODO: find a better way to inject openrecovery commands
system("sh res/openrecovery.sh --sideload");
QMessageBox::about(this,tr("Rooter"),"Done, device will complete the installation automatically, let it reboots once it's done.","Done");
/* TODO:
* Dialog while executing system()
*/
}
void OTools::on_LogoB_clicked()
{
QString logo=QFileDialog::getOpenFileName(
this,
tr("Choose File"),
"~"
"Logo files (*.bin);;All Files (*.*)"
);
QMessageBox::information(this,tr("Logo Changer"),logo,"OK");
const char *flogo = qPrintable(logo);
QMessageBox::about(this,tr("Logo Changer"),"Plug your device in, and let it work, remember that the bootloader must be unlocked.\n Press Next to start","Next");
setenv("flogo", flogo, true);
system("adb wait-for-device");
system("adb reboot bootloader");
system("fastboot devices");
system("fastboot flash LOGO $flogo");
system("fastboot reboot");
/* TODO:
* Dialog while executing system()
*/
}
void OTools::on_EfsB_clicked()
{
/* TODO:
* check on xda files to backup
* boot into tmp recovery
* backup with dd= of=
*/
}
void OTools::on_SRECB_clicked()
{
QMessageBox::about(this,tr("Screen Recorder"),"Plug your device in, press next to start the record.\n When you want to stop it, unplug the device and plug it in again.\n Press Next to start","Next");
//freeze the program and update the suggestion text
ui->backbox->setEnabled(false);
ui->modbox->setEnabled(false);
ui->recbox->setEnabled(false);
ui->filebox->setEnabled(false);
system("adb shell screenrecord /sdcard/${date +'%F-%I-%H-%N'");
ui->modbox->setEnabled(true);
ui->recbox->setEnabled(true);
ui->filebox->setEnabled(true);
ui->backbox->setEnabled(true);
/* TODO:
* Dialog with a button to click when user wants to quit registration?? (killall -9 adb && adb start-server)
*/
}
void OTools::on_ShellB_clicked()
{
/* TODO:
* open xterm with adb shell << I don't like this
*/
}
void OTools::on_ApkB_clicked()
{
QString apk=QFileDialog::getOpenFileName(
this,
tr("Choose File"),
"~"
"Apk files (*.apk);;All Files (*.*)"
);
QMessageBox::information(this,tr("Apk Installer"),apk,"OK");
const char *fapk = qPrintable(apk);
QMessageBox::about(this,tr("Apk Installer"),"Plug your device in and wait until the apps get installed.\n Press Next to start","Next");
setenv("ffboot", ffboot, true);
system("adb wait-for-device");
system("adb install $fapk")
// check if failed or not
setenv("ffboot", ffboot, true);
QMessageBox::information(this,tr("Apk Installer"),"Done!","OK");
}