| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#pragma once |
| 19 |
|
| 20 |
#include <QObject> |
| 21 |
#include <QFile> |
| 22 |
#include <QTimer> |
| 23 |
#include <QThread> |
| 24 |
#include <QStringList> |
| 25 |
#include <libusb-1.0/libusb.h> |
| 26 |
|
| 27 |
#define BLACKBERRY_VENDOR_ID 0x0FCA |
| 28 |
|
| 29 |
#define BUFFER_SIZE 2048 |
| 30 |
|
| 31 |
#ifdef _WIN32 |
| 32 |
#pragma pack(push,1) |
| 33 |
#endif |
| 34 |
|
| 35 |
typedef struct ControlMessageHeader { |
| 36 |
unsigned short type; |
| 37 |
unsigned short packetSize; |
| 38 |
unsigned char command; |
| 39 |
unsigned char mode; |
| 40 |
unsigned short packetId; |
| 41 |
|
| 42 |
} |
| 43 |
#ifndef _WIN32 |
| 44 |
__attribute__((packed)) ControlMessageHeader; |
| 45 |
#else |
| 46 |
ControlMessageHeader; |
| 47 |
#pragma pack(pop) |
| 48 |
#endif |
| 49 |
|
| 50 |
enum SachesiCommand { |
| 51 |
commandInfo = 0x01, |
| 52 |
commandBootloader = 0x02, |
| 53 |
commandNuke = 0x03, |
| 54 |
commandDebug = 0x04 |
| 55 |
}; |
| 56 |
|
| 57 |
enum ControlMessageCommand { |
| 58 |
kCommandPing = 0x01, |
| 59 |
kCommandPingResponse = 0x02, |
| 60 |
kCommandReboot = 0x03, |
| 61 |
kCommandRebootResponse = 0x04, |
| 62 |
kCommandGetVariable = 0x05, |
| 63 |
kCommandGetVariableResponse = 0x06, |
| 64 |
kCommandSetMode = 0x07, |
| 65 |
kCommandSetModeSuccess = 0x08, |
| 66 |
kCommandSetModeFailure = 0x09, |
| 67 |
kCommandGetPasswordInfo = 0x0A, |
| 68 |
kCommandLoadTransferredData = 0x0B, |
| 69 |
kCommandLoadTransferredDataSuccess = 0x0C, |
| 70 |
kCommandLoadTransferredDataFailure = 0x0D, |
| 71 |
kCommandGetPasswordInfoResponse = 0x0E, |
| 72 |
kCommandSendPassword = 0x0F, |
| 73 |
kCommandSendPasswordCorrect = 0x10, |
| 74 |
kCommandUnkn1 = 0x11, |
| 75 |
kCommandUnkn1Response = 0x12, |
| 76 |
kCommandReadyForDataTransfer = 0x13 |
| 77 |
}; |
| 78 |
|
| 79 |
typedef enum BootloaderMode { |
| 80 |
|
| 81 |
kBootloaderRimReinit = 0x0, |
| 82 |
kBootloaderRimBoot = 0x1, |
| 83 |
kBootloaderRamBoot = 0x2, |
| 84 |
kBootloaderUPL = 0x3, |
| 85 |
|
| 86 |
|
| 87 |
kBootloaderRimBootNuke = 0x4 |
| 88 |
} BootloaderMode; |
| 89 |
|
| 90 |
class Boot : public QThread |
| 91 |
{ |
| 92 |
Q_OBJECT |
| 93 |
Q_PROPERTY(bool connecting READ connecting WRITE setConnecting NOTIFY connectingChanged) |
| 94 |
Q_PROPERTY(int command READ command WRITE setCommand NOTIFY commandChanged) |
| 95 |
Q_PROPERTY(QStringList devices MEMBER _devices NOTIFY devicesChanged) |
| 96 |
public: |
| 97 |
Boot(); |
| 98 |
~Boot(); |
| 99 |
libusb_device_handle* openDevice(libusb_device* dev); |
| 100 |
int closeDevice(libusb_device_handle* handle); |
| 101 |
int sendControlMessage(libusb_device_handle* aHandle, uint8_t aCommand, QByteArray* aData, int aDataSize); |
| 102 |
int receiveControlMessage(libusb_device_handle* aHandle, ControlMessageHeader* aHeader, QByteArray* aData); |
| 103 |
void commandReboot(libusb_device_handle* aHandle); |
| 104 |
void commandPing(libusb_device_handle* aHandle); |
| 105 |
bool commandSendPass(libusb_device_handle* aHandle); |
| 106 |
void commandSendLoader(libusb_device_handle* aHandle); |
| 107 |
int commandGetVariable(libusb_device_handle* aHandle, int variable, QByteArray* buffer, int bufferSize); |
| 108 |
void commandSetMode(libusb_device_handle* aHandle, BootloaderMode mode); |
| 109 |
void commandLoadBootloader(libusb_device_handle* aHandle); |
| 110 |
void commandTransferData(libusb_device_handle* aHandle); |
| 111 |
|
| 112 |
bool connecting() const; |
| 113 |
int command() const; |
| 114 |
void setCommand(const int &command); |
| 115 |
void setConnecting(const bool &connecting); |
| 116 |
signals: |
| 117 |
void connectingChanged(); |
| 118 |
void commandChanged(); |
| 119 |
void devicesChanged(); |
| 120 |
public slots: |
| 121 |
Q_INVOKABLE void search(); |
| 122 |
Q_INVOKABLE void connect(); |
| 123 |
Q_INVOKABLE void disconnect(); |
| 124 |
Q_INVOKABLE void setCommandMode(int mode, bool rebootAfter); |
| 125 |
void newPassword(QString newPass); |
| 126 |
void exit() { |
| 127 |
_kill = true; |
| 128 |
} |
| 129 |
private: |
| 130 |
int _bootloaderMode; |
| 131 |
bool _connecting; |
| 132 |
int _command; |
| 133 |
bool _rebootAfter; |
| 134 |
short _packetNum; |
| 135 |
int _found; |
| 136 |
QString _password; |
| 137 |
QStringList _devices; |
| 138 |
QList<QByteArray*> bootloaderModeData; |
| 139 |
bool _kill; |
| 140 |
}; |