-
Notifications
You must be signed in to change notification settings - Fork 38
/
adbclient.h
150 lines (129 loc) · 3.94 KB
/
adbclient.h
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
// -*- mode: c++ -*-
#ifndef ADBCLIENT_H
#define ADBCLIENT_H
#include <QString>
#include <QStringList>
#include <QTcpSocket>
extern volatile const char* __adb_serial;
#define htoll(x) (x)
#define ltohl(x) (x)
#define MKID(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24))
#define ID_STAT MKID('S','T','A','T')
#define ID_LIST MKID('L','I','S','T')
#define ID_ULNK MKID('U','L','N','K')
#define ID_SEND MKID('S','E','N','D')
#define ID_RECV MKID('R','E','C','V')
#define ID_DENT MKID('D','E','N','T')
#define ID_DONE MKID('D','O','N','E')
#define ID_DATA MKID('D','A','T','A')
#define ID_OKAY MKID('O','K','A','Y')
#define ID_FAIL MKID('F','A','I','L')
#define ID_QUIT MKID('Q','U','I','T')
typedef union {
quint32 id;
struct {
quint32 id;
quint32 namelen;
} req;
struct {
quint32 id;
quint32 mode;
quint32 size;
quint32 time;
} stat;
struct {
quint32 id;
quint32 mode;
quint32 size;
quint32 time;
quint32 namelen;
} dent;
struct {
quint32 id;
quint32 size;
} data;
struct {
quint32 id;
quint32 msglen;
} status;
} syncmsg;
#define S_IFMT 00170000
#define S_IFSOCK 0140000
#define S_IFLNK 0120000
#define S_IFREG 0100000
#define S_IFBLK 0060000
#define S_IFDIR 0040000
#define S_IFCHR 0020000
#define S_IFIFO 0010000
#define S_ISUID 0004000
#define S_ISGID 0002000
#define S_ISVTX 0001000
#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
#define S_IRWXU 00700
#define S_IRUSR 00400
#define S_IWUSR 00200
#define S_IXUSR 00100
#define S_IRWXG 00070
#define S_IRGRP 00040
#define S_IWGRP 00020
#define S_IXGRP 00010
#define S_IRWXO 00007
#define S_IROTH 00004
#define S_IWOTH 00002
#define S_IXOTH 00001
#define SYNC_DATA_MAX (64*1024)
typedef struct syncsendbuf syncsendbuf;
struct syncsendbuf {
quint32 id;
quint32 size;
char data[SYNC_DATA_MAX];
};
bool _writex(QIODevice& io, const void* data, qint64 max);
QString adb_quote_shell(const QStringList& args);
class AdbClient
{
private:
syncsendbuf send_buffer;
QTcpSocket adbSock;
bool switch_socket_transport();
bool write_data_buffer(char* file_buffer, int size, syncsendbuf *sbuf);
bool write_data_file(const QString& path, syncsendbuf *sbuf);
bool writex(const void *data, qint64 max);
bool readx(void *data, qint64 max);
void sync_quit();
QString adb_error() { return __adb_error; };
bool sync_recv(const QString& rpath, const QString& lpath);
bool do_sync_pull(const char *rpath, const char *lpath);
void adb_close();
bool adb_status();
bool do_sync_push(const char *lpath, const char *rpath);
QString __adb_error;
bool adb_connect(const char *service);
bool isOK;
bool sync_readmode(const char *path, quint32 *mode);
bool sync_send(const QString& lpath, const QString& rpath,
unsigned mtime, quint32 mode);
public:
QTcpSocket* getSock() { return &adbSock; };
AdbClient();
~AdbClient();
static QStringList doAdbShellWithStderr(const QStringList& cmdAndArgs);
static QString doAdbShell(const QStringList& cmdAndArgs);
static QString doAdbShell(const QString& cmdLine);
static AdbClient* doAdbPipe(const QStringList& cmdAndArgs);
static AdbClient* doAdbPipe(const QString& cmdLine);
static bool doAdbPull(const QString& rptah, const QString& lpath);
static bool doAdbPush(const QString& lpath, const QString& rpath);
static int doAdbKill();
static QStringList doAdbDevices();
static int doAdbForward(const QString& forwardSpec);
static void setAdbSerial(const QString& ser);
static QString getAdbSerial();
};
#endif // ADBCLIENT_H