forked from AdrianDC/advanced_development_shell_tools
/
android_adb.rc
executable file
·506 lines (471 loc) · 16.3 KB
/
android_adb.rc
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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
#!/bin/bash
# ======================================
# Developed by Adrian DC - 2015-2016
# ======================================
# === ADB Root Mounter ===
function adbr()
{
timeout 5 adb $1 'wait-for-devices';
timeout 5 adb $1 root; sleep 2;
timeout 5 adb $1 'wait-for-devices';
timeout 5 adb $1 remount; sleep 1;
timeout 5 adb $1 'wait-for-devices';
}
# === ADB Root Checked Mounter ===
function adbro()
{
local rootaccess=$(adb shell whoami);
if [ "${rootaccess:0:4}" != 'root' ] && [ "${rootaccess:16:5}" != 'uid 0' ]; then
timeout 5 adb $1 'wait-for-devices';
timeout 5 adb $1 root; sleep 2;
timeout 5 adb $1 'wait-for-devices';
fi;
local systemmount=$(adb shell mount | grep system);
local systemacess=$(echo "$systemmount" | grep rw);
if [ ! -z "$systemmount" ] && [ -z "$systemacess" ]; then
timeout 5 adb $1 'wait-for-devices';
timeout 5 adb $1 remount; sleep 1;
timeout 5 adb $1 'wait-for-devices';
fi;
}
# === ADB Root Stock ===
function adbrstock()
{
adb shell su -c 'setprop ro.secure 0; setprop ro.debuggable 1; setprop persist.service.adb.enable 1';
adb shell getprop ro.secure;
}
# === ADB Shell Root ===
function adbsu()
{
if [ -z $(adb shell type su | grep 'no found') ]; then
adbro;
adb shell $@;
else
adb shell su -c "$@";
fi;
}
# === ADB Access Shortcuts ===
alias adbs='adb shell';
alias adbside='adb sideload';
alias adbpo='adb shell reboot -p';
alias adbre='adb reboot';
function adbrh() { adb $1 shell setprop ctl.restart zygote; }
alias adbrr='adb reboot recovery';
alias adbw='adb wait-for-device';
alias adbrb='adb reboot bootloader';
alias adbscr='mkdir -p ./screenshots; adb shell screencap /sdcard/screenshot.png; adb pull /sdcard/screenshot.png ./screenshots/screenshot-$(date +%Y%m%d-%H%M%S).png';
alias adbfotar='adb root; adb shell dd if=/dev/random of=/dev/block/platform/msm_sdcc.1/by-name/FOTAKernel';
alias adbfotaz='adb root; adb shell dd if=/dev/zero of=/dev/block/platform/msm_sdcc.1/by-name/FOTAKernel';
alias adbsgdisk='adb shell sgdisk --print /dev/block/mmcblk0';
alias adbdf='adb shell df -H';
alias adbrcbin='adb shell restorecon -R /sbin';
alias adbmountcache='adb shell mount -t ext4 /dev/block/platform/msm_sdcc.1/by-name/Cache /cache';
alias adbmountdata='adb shell mount -t ext4 /dev/block/platform/msm_sdcc.1/by-name/Userdata /data';
alias adbmountmicrosd='adb shell mkdir -p /storage/ext; adb shell mount -t ext4 /dev/block/mmcblk1p1 /storage/ext';
alias adbumountcache='adb shell umount /cache';
alias adbumountdata='adb shell umount /data';
alias adbumountmicrosd='adb shell umount /storage/ext';
alias adbmount='adbmountcache; adbmountdata; adbmountmicrosd';
alias adbumount='adbumountcache; adbumountdata; adbumountmicrosd';
# === ADB Confirmation Helper ===
alias adbconfirm='if [ ! -z "$confirm" ]; then printf " Press Enter to continue..."; read key; echo ""; fi';
# === ADB System File Listener / Installer ===
function adbif()
{
logfile=/media/adriandc/AndroidDev/Scripts/script_logs.txt;
rm -f $logfile;
$@ | tee $logfile;
InstallLog=$(grep -a "target/product/[^\/]*/system" $logfile | sort | uniq);
echo "";
adbconfirm;
for FilePath in ${InstallLog[*]}; do
if [[ "$FilePath" =~ "/system" && ! "$FilePath" =~ "/NOTICE_FILES" ]]; then
FilePath=$(printf "$FilePath" | tail -1 \
| sed "s/\x1B\[[0-9;]*[JKmsu]//g" \
| sed "s/.*\/\([^\[]*.zip\).*/\1/g");
if [ -f "$FilePath" ]; then
adbpf "$FilePath";
fi;
fi;
done;
echo "";
confirm="";
}
# === ADB Proprietary File Listener / Installer ===
function adbiv()
{
logfile=/media/adriandc/AndroidDev/Scripts/script_logs.txt;
$@ | tee $logfile;
Proprietary=$(grep -a "Binary.*proprietary/.*" $logfile \
| sed "s/.* b\/\(.*proprietary\/.*\) .*/\1/g" \
| sort | uniq);
echo "";
for FilePath in ${Proprietary[*]}; do
if [ -f "$FilePath" ]; then
FileTarget=$(echo $FilePath \
| sed "s/.*proprietary\/\(.*\)/\/system\/\1/g");
if [ -f "$FileTarget" ]; then
printf "$FileTarget: ";
adb push $FilePath $FileTarget;
fi;
fi;
done;
echo "";
confirm="";
}
# === ADB System File Listener / Lister ===
function adbil()
{
logfile=/media/adriandc/AndroidDev/Scripts/script_logs.txt;
rm -f $logfile;
$@ | tee $logfile;
InstallLog=$(grep -a "target/product/[^\/]*/system" $logfile | sort | uniq);
echo "";
for FilePath in ${InstallLog[*]}; do
if [[ "$FilePath" =~ "/system" && ! "$FilePath" =~ "/NOTICE_FILES" ]]; then
FilePath=$(printf "$FilePath" | tail -1 \
| sed "s/\x1B\[[0-9;]*[JKmsu]//g" \
| sed "s/.*\/\([^\[]*.zip\).*/\1/g");
if [ -f "$FilePath" ]; then
echo "";
echo -e " \e[1;36m${FilePath}\e[0m";
fi;
fi;
done;
echo "";
}
# === ADB File Installer Helpers ===
function adbi() { adbro; confirm=""; adbif ${@}; }
alias adbii='confirm=""; adbif';
alias adbic='adbr; confirm="true"; adbif';
# === ADB Filer Pusher ===
function adbpf()
{
if [ ! -z "${1}" ]; then
local filepath='';
local filetarget='';
for filepath in ${@}; do
local filepath=$(readlink -f "${filepath}");
if [ -d "${filepath}" ]; then
adbpf "${filepath}/"*;
else
if [[ "${filepath}" =~ 'proprietary' ]]; then
filetarget=$(printf "${filepath}" | sed "s/.*proprietary\(.*\)/\/system\1/g");
elif [[ "${filepath}" =~ 'system' ]]; then
filetarget=$(printf "${filepath}" | sed "s/.*\(system.*\)/\/\1/g");
elif [[ "${filepath}" =~ '.xml' ]] || [[ "${filepath}" =~ '.conf' ]]; then
filetarget="/system/etc/"$(basename $filepath);
elif [[ "${filepath}" =~ '.so' ]]; then
filetarget="/system/lib/"$(basename $filepath);
else
filetarget=$(printf "${filepath}" | sed "s/.*\(system.*\)/\/\1/g");
fi;
#echo '';
echo -e " \e[1;36m${filetarget} :\e[0m";
#printf ' ';
#adb shell ls -l "${filetarget}" | cut -c 30-;
#printf ' ';
adb push "${filepath}" "${filetarget}";
fi;
done;
echo "";
fi;
}
# === ADB Resursive File Pusher ===
function adbpfa()
{
adbro;
for file in $@; do
adbpf "$(readlink -f $file)";
done;
}
# === ADB IP Connector ===
function adbco()
{
echo "";
if [ ! -z "$1" ]; then export ADB_IP_ADDRESS="$1"; fi;
if [ -z "${ADB_IP_ADDRESS}" ]; then
echo " Usage: adbco [ipaddressonlyonce]";
echo "";
return;
fi;
export ADB_IP_PORT="5555";
echo -e "\e[1;36mConnecting to ${ADB_IP_ADDRESS}:${ADB_IP_PORT}...\e[0m";
timeout 5 adb connect ${ADB_IP_ADDRESS}:${ADB_IP_PORT};
echo -e "\e[1;36mConnected...\e[0m";
timeout 5 adb 'wait-for-devices';
echo -e "\e[1;36mGetting root access...\e[0m";
timeout 5 adb root;
sleep 2;
echo -e "\e[1;36mReconnecting...\e[0m";
timeout 5 adb connect ${ADB_IP_ADDRESS}:${ADB_IP_PORT};
echo -e "\e[1;36mConnected...\e[0m";
timeout 5 adb 'wait-for-devices';
echo -e "\e[1;36mMounting as root...\e[0m";
timeout 5 adb remount;
sleep 1;
timeout 5 adb 'wait-for-devices';
echo -e "\e[1;36mReady...\e[0m";
echo "";
}
# === ADB Bootimage Worker ===
function adbbootdump()
{
local kernel=/dev/block/platform/msm_sdcc.1/by-name/Kernel;
local cmdaddr=$(adb shell od -j 152 -N 4 -tx4 -An $kernel \
| cut -c 2-9);
local cmdsize=$(adb shell od -j 164 -N 4 -tx4 -An $kernel \
| cut -c 2-9);
if [ ! -z "$cmdaddr" ] && [ $(echo "$cmdaddr" | wc -l) -eq 1 ] && \
[ ! -z "$cmdsize" ] && [ $(echo "$cmdsize" | wc -l) -eq 1 ]; then
local bootsize=$((16#$cmdaddr+16#$cmdsize));
adbsu "dd if=$kernel of=/sdcard/boot.img skip=0 bs=$bootsize count=1";
adb pull /sdcard/boot.img;
else
adbsu "dd if=$kernel of=/sdcard/boot.dump";
adb pull /sdcard/boot.dump;
adbbootcut boot.dump;
fi;
}
# === ADB Bootimage Resizer ===
function adbbootcut()
{
local cmdaddr=$(od -j 152 -N 4 -tx4 -An $1 \
| cut -c 2-9);
local cmdsize=$(od -j 164 -N 4 -tx4 -An $1 \
| cut -c 2-9);
local bootsize=$((16#$cmdaddr+16#$cmdsize));
dd if=$1 of=boot.img skip=0 bs=$bootsize count=1;
}
# === ADB Bootimage Writer ===
function adbbootpush()
{
local kernel=/dev/block/platform/msm_sdcc.1/by-name/Kernel;
adb push $1 /sdcard/boot.img;
adbsu "dd if=/dev/zero of=$kernel";
adbsu "dd if=/sdcard/boot.img of=$kernel";
}
# === ADB FOTA Installer ===
function adbfotapush()
{
local fota=/dev/block/platform/msm_sdcc.1/by-name/FOTAKernel;
adb push $1 /sdcard/fota.img;
adbsu "dd if=/dev/zero of=$fota";
adbsu "dd if=/sdcard/fota.img of=$fota";
}
# === ADB FOTA Installer ===
function adbfotarecovery()
{
local fota=/dev/block/bootdevice/by-name/FOTAKernel;
adb push $1 /tmp/fota.img;
adbsu "dd if=/dev/zero of=$fota";
adbsu "dd if=/tmp/fota.img of=$fota";
adb reboot recovery;
}
# === ADB TWRP Installer ===
function adbrecoveryinstall()
{
if [ -z "$1" ] || [ ! -f "$1" ]; then
echo "";
echo " Usage: adbrecoveryinstall file_path";
echo "";
return;
fi;
local filename=$(basename $1);
adbro;
adb shell mkdir -p /sdcard/;
adb push "$1" /sdcard/${filename};
adb shell "mkdir -p /cache/recovery";
adb shell "echo 'install /sdcard/${filename}' > /cache/recovery/command";
adb shell 'echo /cache/recovery/command: $(/cache/recovery/command)';
adb reboot recovery;
}
# === ADB File Editor ===
function adbedit()
{
adbro;
path="$1";
if [ -z "$path" ]; then
path="/system/build.prop";
fi;
name=$(basename "$path");
adb pull "$path";
gedit "$name";
printf " Ok ? [ENTER] ";
read key;
adb push "$name" "$path";
rm "$name";
}
# === ADB Binaries Updater ===
function adbupdate()
{
adb version;
sudo rm -f adb;
wget -O - https://skia.googlesource.com/skia/+archive/cd048d18e0b81338c1a04b9749a00444597df394/platform_tools/android/bin/linux.tar.gz | tar -zxvf - adb;
sudo rm -f /usr/bin/adb;
sudo mv adb /usr/bin/adb;
sudo chmod +x /usr/bin/adb;
adb version;
}
# === ADB Inputs Reader ===
function adbinputs()
{
#grep . /sys/class/input/event*/device/name
#adbs hexdump -C /dev/input/event7
command="cat /proc/bus/input/devices";
echo "";
echo "adb shell $command";
echo "";
adb shell "$command";
}
# === ADB Events Reader ===
function adbreadevents()
{
if [ -z "$1" ]; then
echo "usage: adbreadevents eventNUM";
return;
fi;
adb shell od -x /dev/input/$1 \
| awk -Wposix '{ if ($7) printf(" Key %4d - State %4d\n", "0x" $7, "0x" $8) }';
}
# === ADB Huashan Events Reader ===
alias adbgpio='adbreadevents event11';
alias adbkeypad='adbreadevents event1';
alias adbtouchpad='adbreadevents event7';
# === ADB Alsa Reader ===
function adbalsa()
{
printf "" | tee alsalog;
adb shell "cat /proc/asound/card0/id" | tee -a alsalog;
for line in $(adb shell find /proc/asound/card0 -name info); do
path=$(printf $line | tr -dc 'a-zA-Z0-9/');
echo "" | tee -a alsalog;
echo "=== $path ===" | tee -a alsalog;
adb shell "cat $path" | tee -a alsalog;
if [[ "$path" =~ "sub" ]]; then
folder=$(dirname "$path");
adb shell "cat $folder/hw_params" | tee -a alsalog;
adb shell "cat $folder/status" | tee -a alsalog;
adb shell "cat $folder/sw_params" | tee -a alsalog;
fi;
done;
adb shell "cat /proc/asound/devices" | tee -a alsalog;
adb shell "cat /proc/asound/pcm" | tee -a alsalog;
adb shell "cat /proc/asound/timers" | tee -a alsalog;
}
# === ADB Init Bootchart ===
function adbbootchart()
{
rm -rf /tmp/android-bootchart/;
rm -f ./bootchart.png;
printf " Timeout in seconds ? [Enter] ";
read timeinput;
if [ -z "$timeinput" ]; then timeinput=120; fi;
adb shell "echo $timeinput > /data/bootchart/start";
printf " Reboot Android ? [Enter] ";
adb reboot;
read;
echo " Waiting for the device to boot...";
adb 'wait-for-device';
printf " Export Logs now ? [Enter] ";
read -t $timeinput;
adb shell 'echo 1 > /data/bootchart/stop'
adb shell 'rm /data/bootchart/start';
sleep 1;
/media/adriandc/AndroidDev/CM-13.0/system/core/init/grab-bootchart.sh;
}
# === Sepolicies Extractor ===
function sepaud()
{
cat $1 | grep -a avc.*denied;
cat $1 | grep -a 'does not have a SELinux domain defined';
cat $1 | grep -a avc.*denied | audit2allow -p sepolicy;
}
# === ADB Loggers ===
function adbl() { while [ 1 ]; do cls; printf "" >adb.log; adb $1 logcat -v threadtime *:V | tee -a adb.log;
echo ""; if [ -z "$2" ]; then printf "Press Enter to continue... "; read key; else sleep 10; fi; done; }
alias adblb='while [ 1 ]; do cls; printf "" >adb.log; adb logcat -v audit2allow *:V | tee -a adb.log;
echo ""; printf "Press Enter to continue... "; read key; done';
alias adblc='adb logcat -c; adbl';
alias adbk='adbro; printf "" >kmsg; adb shell cat /proc/kmsg | tee -a kmsg';
alias adbdm='adbro; printf "" >dmesg; adb shell dmesg | tee -a dmesg';
alias adbkd='printf "" >kmsg; adb shell cat /proc/kmsg | tee -a kmsg';
alias adbkl='cls; adbro; printf "" >last_kmsg; adb shell cat /proc/last_kmsg | tee -a last_kmsg';
alias adbkld='cls; printf "" >last_kmsg; adb shell cat /proc/last_kmsg | tee -a last_kmsg';
alias adbpl='cls; adbro; printf "" >last_kmsg; adb shell cat /sys/fs/pstore/console-ramoops | tee -a last_kmsg';
alias adbpld='cls; printf "" >last_kmsg; adb shell cat /sys/fs/pstore/console-ramoops | tee -a last_kmsg';
alias adbse='adbro; printf "" >kmsg; adb shell cat /proc/kmsg | tee -a kmsg; sepaud kmsg';
alias adbdumpsensors='adb shell dumpsys sensorservice';
alias adbsel='adbkl; sepaud kmsg';
alias adblf='adb logcat -v audit2allow';
alias adblh='adb logcat -b events -b main -b radio | highlight';
alias adbtrampoline='adb shell "dmesg | grep -i trampoline"';
function adblcln() { cat $1 | cut -c 32- | tee $1.clean; }
function adbkcln() { cat $1 | cut -c 15- | tee $1.clean; }
function adbcl() { filename=$(getine $1 adb.log);
cat "$filename" | cut -c 32- | sed -E "s/[0-9]{8}/00000000/g" > "$filename.cut.log"; }
# === ADB Intents ===
alias adbintents='adb shell dumpsys package r > intents.txt';
alias adbcamera='adb shell pm enable com.android.camera2/com.android.camera.CameraLauncher; \
adb shell pm enable com.google.android.GoogleCamera/com.android.camera.CameraLauncher; \
adb shell "am start -a android.media.action.IMAGE_CAPTURE"';
alias adblkl='adb root; adb wait-for-device; adb shell killall zigote; adbl';
# === ADB Crash Debuggers ===
function adbpk() { pid=$(adb shell ps | grep mediaserver | awk '{ print $2 }');
adb root; adb 'wait-for-device';
adb logcat -c;
adb shell kill $pid;
adb shell ps | grep mediaserver;
sleep 2; adbl; }
function adbms() { pid=$(adb shell ps | grep mediaserver | awk '{ print $2 }');
adb root; adb 'wait-for-device';
adb logcat -c;
adb shell kill $pid;
pid=$(adb shell ps | grep mediaserver | awk '{ print $2 }');
adb shell strace -p $pid; }
function adbst()
{
if [ -z "$2" ]; then adb 'wait-for-device'; adb root; adb 'wait-for-device'; fi;
adb shell ps | grep $1;
pid=$(adb shell ps | grep $1 | awk '{ print $2 }');
adb shell strace -p ${pid};
}
function adbkp()
{
adb 'wait-for-device'; adb root; adb 'wait-for-device';
adb shell ps | grep $1;
pid=$(adb shell ps | grep $1 | awk '{ print $2 }');
adb shell kill ${pid};
}
function adblibs() { adb shell grep -air "$1" $(getine $2 /system/lib/); }
alias ndkstack='ndk-stack -sym /media/adriandc/AndroidDev/CM-13.0/out/target/product/huashan/symbols -dump';
function adbwtch() { adbr; while [ 1 ]; do adb shell cat "$1"; done; }
alias adbservices='adb shell service list';
alias adbsl='adb shell ls -l';
alias adbslz='adb shell ls -lZ';
alias adbsc='adb shell cat';
alias adbsg='adb shell getprop';
function adbsw() { adbro; adb shell "echo $1 > $2"; }
alias isdone='notify-send "Process execution finished !"';
function adbgitpf()
{
adbro;
local tmpfile=$(mktemp);
git diff-tree --no-commit-id --name-status -r $1 >"$tmpfile";
while read line; do
local status=$(echo "$line" | awk '{ print $1 }');
local file_path=$(echo "$line" | awk '{ print $2 }');
if [[ "$status" =~ "D" || "$file_path" =~ ".mk" ]]; then
continue;
fi;
adbpf "$file_path";
done <$tmpfile;
rm -f $tmpfile;
}
function adbdu()
{
tmp=$(mktemp);
adbro;
adbsu 'du /data/ | sort -hr' > $tmp;
gedit $tmp;
}