-
Notifications
You must be signed in to change notification settings - Fork 15
/
adb.pas
228 lines (194 loc) · 6.29 KB
/
adb.pas
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
unit adb;
interface
uses
Winapi.Windows, System.Win.ScktComp, DosCommand, System.Classes;
const
AP_VERY_HIGH = 0;
AP_HIGH = 1;
AP_MODERATE_HIGH = 2;
AP_MEDIUM_HIGH = 3;
AP_MEDIUM = 4;
AP_LOW_MODERATE = 5;
AP_LOW = 6;
AP_MODERATE = 7;
AP_LOW_MEDIUM = 8;
AP_CRITICAL = 9;
type
TPermissions = (
androidpermissionCALL_PHONE = AP_HIGH,
androidpermissionSEND_SMS = AP_HIGH,
androidPermissionWRITE_EXTERNAL_STORAGE = AP_MEDIUM,
androidPermissionREAD_CONTACTS = 3,
androidPermissionWRITE_CONTACTS = 2,
androidPermissionREAD_CALENDAR = 4,
androidPermissionWRITE_CALENDAR = 4,
comAndroidBrowserPermissionREAD_HISTORY_BOOKMARKS = 3,
comAndroidBrowserPermissionWRITE_HISTORY_BOOKMARKS = 2,
androidPermissionREAD_LOGS = 0,
androidPermissionWRITE_SETTINGS = 4,
androidPermissionREAD_SYNC_SETGINS = 5,
androidPermissionRECEIVE_BOOT_COMPLETED = 2,
androidPermissionRESTART_PACKAGES = 1,
androidPermissionGET_TASKS = 3,
androidPermissionSYSTEM_ALERT_WINDOW = 1,
androidPermissionVIBRATE = 6,
androidPermissionCAMERA = 2,
androidPermissionACCESS_LOCATION_EXTRA_COMMANDS = 3,
androidPermissionACCESS_MOCK_LOCATION = 7,
androidPermissionBATTERY_STATUS = 6,
androidPermissionBLUETOOTH_ADMIN = 4,
androidPermissionBROADCAST_STICKY = 8,
androidPermissionCHANGE_CONFIGURATION = 3,
androidPermissionCLEAR_APP_CACHE = 6,
androidPermissionDISABLE_KEYGUARD = 3,
androidPermissionEXPAND_STATUS_BAR = 3,
androidPermissionFLASHLIGHT = 6,
androidPermissionGET_PACKAGE_SIZE = 5,
androidPermissionKILL_BACKGROUND_PROCESSES = AP_HIGH,
androidPermissionMODIFY_AUDIO_SETTINGS = AP_LOW,
androidPermissionMOUNT_FORMAT_FILESYSTEMS = AP_MEDIUM,
androidPermissionMOUNT_UNMOUNT_FILESYSTEMS = AP_MODERATE,
androidPermissionNFC = AP_MEDIUM,
androidPermissionPROCESS_OUTGOING_CALLS = AP_VERY_HIGH,
androidPermissionREAD_SYNC_STATS = AP_MODERATE,
androidPermissionRECORD_AUDIO = AP_MODERATE_HIGH,
androidPermissionSET_ALARM = AP_LOW,
androidPermissionSET_TIME_ZONE = AP_LOW,
androidPermissionSET_WALLPAPER = AP_LOW,
androidPermissionSUBSCRIBED_FEEDS_READ = AP_MEDIUM,
androidPermissionSUBSCRIBED_FEEDS_WRITE = AP_LOW_MEDIUM,
androidPermissionUSE_SIP = AP_MEDIUM_HIGH,
androidPermissionWRITE_SECURE_SETTINGS = AP_VERY_HIGH,
androidPermissionREAD_PROFILE = AP_MEDIUM_HIGH,
comAndroidLauncherPermissionINSTALL_SHORTCUT = AP_MODERATE_HIGH,
androidPermissionREAD_EXTERNAL_STORAGE = AP_LOW,
comAndroidVoicemailPermissionADD_VOICEMAIL = AP_MEDIUM_HIGH,
androidPermissionAUTHENTICATE_ACCOUNTS = AP_VERY_HIGH,
comAndroidEmailPermissionREAD_ATTACHMENT = AP_HIGH,
androidPermissionREAD_USER_DICTIONARY = AP_LOW,
androidPermissionWRITE_USER_DICTIONARY = AP_LOW,
androidPermissionINSTALL_DRM = AP_MODERATE_HIGH,
androidPermissionADD_SYSTEM_SERVICE = AP_CRITICAL,
androidPermissionACCESS_WIMAX_STATE = AP_LOW_MODERATE,
androidPermissionCHANGE_WIMAX_STATE = AP_MODERATE,
comAndroidProvidersImPermissionREAD_ONLY = AP_HIGH
);
TADB = class
private
PID: Cardinal;
FPath: string;
FClient: TClientSocket;
FPort: Integer;
FHost: string;
FCmd: TDosCommand;
procedure SetPath(const Value: string);
procedure SetHost(const Value: string);
procedure SetPort(const Value: Integer);
protected
procedure OnSocketError(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
procedure OnSocketRead(Sender: TObject; Socket: TCustomWinSocket);
procedure OnSocketDisconnect(Sender: TObject; Socket: TCustomWinSocket);
public
function StartServer(forceRestart: Boolean = False): Boolean;
function StopServer: Boolean;
function IsADBServerOn: Boolean;
function ConnectSocket(port: Integer = 5037): Boolean;
function RunScript(const command: string): string;
procedure GetADBProcessList(var PidList: TStringList);
constructor Create;
destructor Destroy; override;
property Path: string read FPath write SetPath;
property Port: Integer read FPort write SetPort;
property Host: string read FHost write SetHost;
end;
implementation
uses
Winapi.PsAPI, Winapi.TlHelp32;
{ TADB }
function TADB.ConnectSocket(port: Integer = 5037): Boolean;
begin
FClient.Address := FHost;
if port <> 5037 then
FClient.Port := port
else
FClient.Port := FPort;
FClient.Active := True; // Activates the client
Result := FClient.Socket.Connected;
end;
constructor TADB.Create;
begin
FClient := TClientSocket.Create(nil);
FPort := 5037; // default ADB socket port
FHost := '127.0.0.1'; // localhost
// FClient.OnError := OnSocketError;
FClient.OnDisconnect := OnSocketDisconnect;
FClient.OnRead := OnSocketRead;
FCmd := TDosCommand.Create(nil);
end;
destructor TADB.Destroy;
begin
FCmd.Free;
FClient.Free;
inherited;
end;
// Get a list of adb.exe processes' fullpath
procedure TADB.GetADBProcessList(var PidList: TStringList);
var
hSnap: THandle;
pe: TProcessEntry32;
begin
end;
function TADB.IsADBServerOn: Boolean;
begin
Result := False;
end;
procedure TADB.OnSocketDisconnect(Sender: TObject; Socket: TCustomWinSocket);
begin
end;
procedure TADB.OnSocketError(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
begin
ErrorCode := 0;
// FClient.Active := False;
// This can happen when no active server is started
// do something
end;
procedure TADB.OnSocketRead(Sender: TObject; Socket: TCustomWinSocket);
begin
// Reads and displays the message received from the server
// Socket.ReceiveText;
{ TODO : Handle receiving binary files }
end;
function TADB.RunScript(const command: string): string;
begin
if FClient.Socket.Connected then
begin
FClient.Socket.SendText(command);
end
else
Result := 'NOT CONNECTED!';
end;
procedure TADB.SetHost(const Value: string);
begin
FHost := Value;
end;
procedure TADB.SetPath(const Value: string);
begin
FPath := Value;
end;
procedure TADB.SetPort(const Value: Integer);
begin
FPort := Value;
end;
function TADB.StartServer(forceRestart: Boolean): Boolean;
begin
FCmd.CommandLine := 'adb.exe start-server';
FCmd.Execute;
end;
function TADB.StopServer: Boolean;
begin
FCmd.CommandLine := 'adb.exe kill-server';
FCmd.Execute;
end;
end.