| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#pragma once |
| 19 |
|
| 20 |
#include <QtNetwork> |
| 21 |
#include <QDataStream> |
| 22 |
#include <QQmlListProperty> |
| 23 |
#include <QCryptographicHash> |
| 24 |
#include <QSettings> |
| 25 |
#include <QFileDialog> |
| 26 |
#include <QThread> |
| 27 |
#include <openssl/rsa.h> |
| 28 |
#include <openssl/bn.h> |
| 29 |
#include <openssl/rand.h> |
| 30 |
#include <openssl/evp.h> |
| 31 |
#include <openssl/pem.h> |
| 32 |
#ifndef _WIN32 |
| 33 |
#include <sys/types.h> |
| 34 |
#include <sys/socket.h> |
| 35 |
#include <netinet/in.h> |
| 36 |
#include <arpa/inet.h> |
| 37 |
#endif |
| 38 |
#include <quazip/quazip.h> |
| 39 |
#include <quazip/quazipfile.h> |
| 40 |
#include "apps.h" |
| 41 |
#include "backupinfo.h" |
| 42 |
#include "deviceinfo.h" |
| 43 |
#include "blitzinfo.h" |
| 44 |
|
| 45 |
struct BarInfo { |
| 46 |
QString name; |
| 47 |
QString version; |
| 48 |
QString packageid; |
| 49 |
BarType type; |
| 50 |
}; |
| 51 |
|
| 52 |
class SslNetworkAccessManager : public QNetworkAccessManager |
| 53 |
{ |
| 54 |
Q_OBJECT |
| 55 |
public: |
| 56 |
SslNetworkAccessManager() {} |
| 57 |
|
| 58 |
protected: |
| 59 |
QNetworkReply* createRequest(Operation op, const QNetworkRequest & req, QIODevice * outgoingData = 0); |
| 60 |
}; |
| 61 |
|
| 62 |
class InstallNet : public QObject { |
| 63 |
Q_OBJECT |
| 64 |
Q_PROPERTY(QString password MEMBER _password WRITE setPassword NOTIFY passwordChanged) |
| 65 |
Q_PROPERTY(bool wrongPass MEMBER _wrongPass WRITE setWrongPass NOTIFY wrongPassChanged) |
| 66 |
Q_PROPERTY(bool loginBlock MEMBER _loginBlock WRITE setLoginBlock NOTIFY loginBlockChanged) |
| 67 |
Q_PROPERTY(int possibleDevices MEMBER _possibleDevices WRITE setPossibleDevices NOTIFY possibleDevicesChanged) |
| 68 |
Q_PROPERTY(QString ip MEMBER _ip WRITE setIp NOTIFY ipChanged) |
| 69 |
Q_PROPERTY(QString newLine MEMBER _newLine WRITE setNewLine NOTIFY newLineChanged) |
| 70 |
Q_PROPERTY(int state MEMBER _state WRITE setState NOTIFY stateChanged) |
| 71 |
Q_PROPERTY(int dgPos MEMBER _downgradePos NOTIFY dgPosChanged) |
| 72 |
Q_PROPERTY(int dgMaxPos READ dgMaxPos NOTIFY dgMaxPosChanged) |
| 73 |
Q_PROPERTY(int dgProgress MEMBER _dgProgress NOTIFY curDGProgressChanged) |
| 74 |
Q_PROPERTY(int curDGProgress MEMBER _curDGProgress WRITE setCurDGProgress NOTIFY curDGProgressChanged) |
| 75 |
Q_PROPERTY(QString curInstallName MEMBER _curInstallName WRITE setCurInstallName NOTIFY curInstallNameChanged) |
| 76 |
Q_PROPERTY(bool completed MEMBER _completed NOTIFY completedChanged) |
| 77 |
Q_PROPERTY(bool installing MEMBER _installing WRITE setInstalling NOTIFY installingChanged) |
| 78 |
Q_PROPERTY(bool restoring MEMBER _restoring WRITE setRestoring NOTIFY restoringChanged) |
| 79 |
Q_PROPERTY(bool backing MEMBER _backing WRITE setBacking NOTIFY backingChanged) |
| 80 |
Q_PROPERTY(bool firmwareUpdate MEMBER _firmwareUpdate WRITE setFirmwareUpdate NOTIFY firmwareUpdateChanged) |
| 81 |
Q_PROPERTY(bool extractInstallZip MEMBER _extractInstallZip NOTIFY extractInstallZipChanged) |
| 82 |
Q_PROPERTY(bool allowDowngrades MEMBER _allowDowngrades WRITE setAllowDowngrades NOTIFY allowDowngradesChanged) |
| 83 |
Q_PROPERTY(QStringList firmwareNames MEMBER _firmwareNames NOTIFY firmwareNamesChanged) |
| 84 |
Q_PROPERTY(QStringList firmwarePaths MEMBER _firmwarePaths NOTIFY firmwarePathsChanged) |
| 85 |
Q_PROPERTY(int knownHWFamily MEMBER _knownHWFamily NOTIFY appListChanged) |
| 86 |
Q_PROPERTY(DeviceInfo* device MEMBER device NOTIFY deviceChanged) |
| 87 |
Q_PROPERTY(QQmlListProperty<Apps> appList READ appList NOTIFY appListChanged) |
| 88 |
Q_PROPERTY(int appCount READ appCount NOTIFY appListChanged) |
| 89 |
Q_PROPERTY(bool hasLog READ hasLog NOTIFY hasLogChanged) |
| 90 |
|
| 91 |
Q_PROPERTY(QString backStatus READ backStatus NOTIFY backStatusChanged) |
| 92 |
Q_PROPERTY(int backProgress READ backProgress NOTIFY backCurProgressChanged) |
| 93 |
Q_PROPERTY(int backCurProgress READ backCurProgress NOTIFY backCurProgressChanged) |
| 94 |
|
| 95 |
Q_PROPERTY(int backMethods READ backMethods NOTIFY backMethodsChanged) |
| 96 |
Q_PROPERTY(QStringList backNames READ backNames NOTIFY backMethodsChanged) |
| 97 |
|
| 98 |
Q_PROPERTY(QList<double> backSizes READ backSizes NOTIFY backMethodsChanged) |
| 99 |
Q_PROPERTY(QQmlListProperty<Apps> backAppList READ backAppList NOTIFY backMethodsChanged) |
| 100 |
public: |
| 101 |
InstallNet(QObject* parent = 0); |
| 102 |
~InstallNet(); |
| 103 |
Q_INVOKABLE void keepAlive(); |
| 104 |
Q_INVOKABLE void scanProps(); |
| 105 |
Q_INVOKABLE void install(QList<QUrl> files); |
| 106 |
Q_INVOKABLE void uninstall(QStringList packageids, bool firmwareUpdate); |
| 107 |
Q_INVOKABLE bool uninstallMarked(); |
| 108 |
Q_INVOKABLE void restore(QUrl url, int options); |
| 109 |
Q_INVOKABLE void backup(QUrl url, int options); |
| 110 |
Q_INVOKABLE void wipe(); |
| 111 |
Q_INVOKABLE void startRTAS(); |
| 112 |
Q_INVOKABLE void newPin(QString pin); |
| 113 |
Q_INVOKABLE void resignNVRAM(); |
| 114 |
Q_INVOKABLE void factorywipe(); |
| 115 |
Q_INVOKABLE void reboot(); |
| 116 |
Q_INVOKABLE void getPIN(); |
| 117 |
Q_INVOKABLE void setActionProperty(QString name, QString value); |
| 118 |
Q_INVOKABLE void backupQuery(); |
| 119 |
Q_INVOKABLE qint64 changeBackAppMode(QString type); |
| 120 |
Q_INVOKABLE void exportInstalled(); |
| 121 |
Q_INVOKABLE void openLog(); |
| 122 |
Q_INVOKABLE bool hasLog(); |
| 123 |
Q_INVOKABLE QString appDeltaMsg(); |
| 124 |
void requestConfigure(); |
| 125 |
void requestChallenge(); |
| 126 |
void replyChallenge(); |
| 127 |
void requestAuthenticate(); |
| 128 |
void authorise(); |
| 129 |
QByteArray HashPass(QByteArray challenge, QByteArray salt, int iterations); |
| 130 |
void logadd(QString logtxt); |
| 131 |
void AESEncryptSend(QByteArray &plain, int code); |
| 132 |
QString password() const; |
| 133 |
int dgMaxPos() const; |
| 134 |
QQmlListProperty<Apps> appList(); |
| 135 |
QQmlListProperty<Apps> backAppList(); |
| 136 |
QList<Apps*> appQList() { return _appList; } |
| 137 |
int appCount() const { return _appList.count(); } |
| 138 |
BackupInfo* back(); |
| 139 |
QString backStatus() const; |
| 140 |
int backProgress() const; |
| 141 |
int backCurProgress() const; |
| 142 |
int backMethods() const; |
| 143 |
QStringList backNames() const; |
| 144 |
QList<double> backSizes() const; |
| 145 |
QPair<QString,QString> getConnected(int downloadDevice, bool specialQ30); |
| 146 |
DeviceInfo* device; |
| 147 |
|
| 148 |
void setIp(const QString &ip); |
| 149 |
void setPassword(const QString &password); |
| 150 |
void setWrongPass(const bool &wrong); |
| 151 |
void setLoginBlock(const bool &wrong); |
| 152 |
void setPossibleDevices(const int &devices); |
| 153 |
void setNewLine(const QString &newLine); |
| 154 |
void setState(const int &state); |
| 155 |
void setCurDGProgress(const int &progress); |
| 156 |
void setCurInstallName(const QString &name); |
| 157 |
void setCompleted(const bool &exists); |
| 158 |
void setInstalling(const bool &installing); |
| 159 |
void setRestoring(const bool &restoring); |
| 160 |
void setBacking(const bool &backing); |
| 161 |
void setFirmwareUpdate(const bool &firmwareUpdate); |
| 162 |
void setAllowDowngrades(const bool &allowDowngrades); |
| 163 |
signals: |
| 164 |
void passwordChanged(); |
| 165 |
void newPassword(QString newPass); |
| 166 |
void wrongPassChanged(); |
| 167 |
void loginBlockChanged(); |
| 168 |
void possibleDevicesChanged(); |
| 169 |
void ipChanged(); |
| 170 |
void newLineChanged(); |
| 171 |
void stateChanged(); |
| 172 |
void completedChanged(); |
| 173 |
void dgPosChanged(); |
| 174 |
void dgMaxPosChanged(); |
| 175 |
void curDGProgressChanged(); |
| 176 |
void curInstallNameChanged(); |
| 177 |
void installingChanged(); |
| 178 |
void restoringChanged(); |
| 179 |
void backingChanged(); |
| 180 |
|
| 181 |
void backStatusChanged(); |
| 182 |
void backCurProgressChanged(); |
| 183 |
void backMethodsChanged(); |
| 184 |
|
| 185 |
void firmwareUpdateChanged(); |
| 186 |
void firmwareNamesChanged(); |
| 187 |
void firmwarePathsChanged(); |
| 188 |
void extractInstallZipChanged(); |
| 189 |
void allowDowngradesChanged(); |
| 190 |
void appListChanged(); |
| 191 |
void backAppListChanged(); |
| 192 |
void deviceChanged(); |
| 193 |
void hasLogChanged(); |
| 194 |
private slots: |
| 195 |
bool checkLogin(); |
| 196 |
void login(); |
| 197 |
void connected(); |
| 198 |
void disconnected(); |
| 199 |
|
| 200 |
void restoreSendFile(); |
| 201 |
void restoreReply(); |
| 202 |
void discoveryReply(); |
| 203 |
void resetVars(); |
| 204 |
void restoreError(QNetworkReply::NetworkError error); |
| 205 |
void installProgress(qint64 pread, qint64); |
| 206 |
void backupProgress(qint64 pread, qint64 psize); |
| 207 |
void restoreProgress(qint64 pwrite, qint64 psize); |
| 208 |
void backupFileFinish(); |
| 209 |
void dumpLogs(); |
| 210 |
private: |
| 211 |
QNetworkRequest setData(QString page, QString contentType); |
| 212 |
QNetworkReply* postQuery(QString page, QString contentType, const QUrlQuery& query); |
| 213 |
QNetworkReply* getQuery(QString page, QString contentType); |
| 214 |
BarInfo checkInstallableInfo(QString name, bool blitz); |
| 215 |
BarInfo blitzCheck(QString name); |
| 216 |
void install(); |
| 217 |
void restore(); |
| 218 |
void backup(); |
| 219 |
void determineDeviceFamily(); |
| 220 |
QTcpSocket* sock; |
| 221 |
unsigned char* serverChallenge; |
| 222 |
RSA* privkey; |
| 223 |
QByteArray sessionKey; |
| 224 |
QByteArray hashedPassword; |
| 225 |
QTimer* connectTimer; |
| 226 |
QProcess proc; |
| 227 |
#ifdef _MSC_VER |
| 228 |
WSADATA wsadata; |
| 229 |
#endif |
| 230 |
QNetworkAccessManager* dlmanager; |
| 231 |
SslNetworkAccessManager* manager; |
| 232 |
QNetworkReply *reply; |
| 233 |
QNetworkCookieJar* cookieJar; |
| 234 |
QTemporaryFile* logFile; |
| 235 |
QFile* compressedFile; |
| 236 |
QStringList _firmwareNames; |
| 237 |
QStringList _firmwarePaths; |
| 238 |
int _knownHWFamily; |
| 239 |
QString _knownConnectedOSType; |
| 240 |
QString _knownConnectedRadioType; |
| 241 |
|
| 242 |
QStringList _firmwareInfo; |
| 243 |
QStringList _downgradeInfo; |
| 244 |
int _downgradePos; |
| 245 |
int _firmwarePos; |
| 246 |
|
| 247 |
QString _ip; |
| 248 |
QString _password; |
| 249 |
bool _wrongPass; |
| 250 |
bool _loginBlock; |
| 251 |
int _possibleDevices; |
| 252 |
QString _newLine; |
| 253 |
QFile _firmware; |
| 254 |
int _state; |
| 255 |
|
| 256 |
quint64 _dlBytes; |
| 257 |
quint64 _dlTotal; |
| 258 |
quint64 _dlDoneBytes; |
| 259 |
quint64 _dlOverallTotal; |
| 260 |
int _dgProgress; |
| 261 |
int _curDGProgress; |
| 262 |
QString _curInstallName; |
| 263 |
BackupInfo _back; |
| 264 |
bool _completed; |
| 265 |
bool _firmwareUpdate; |
| 266 |
bool _extractInstallZip; |
| 267 |
bool _allowDowngrades; |
| 268 |
QList<BarInfo> _installInfo; |
| 269 |
QString _backupFileName; |
| 270 |
QStringList _currentApps; |
| 271 |
bool _installing; |
| 272 |
bool _restoring; |
| 273 |
bool _backing; |
| 274 |
bool _hadPassword; |
| 275 |
QuaZip* currentBackupZip; |
| 276 |
QuaZipFile* _zipFile; |
| 277 |
QList<Apps*> _appList; |
| 278 |
QList<Apps*> _appRemList; |
| 279 |
}; |