Shell Android

Mise à jour : Android 9 - LineageOS 16

Sommaire

1 - Accès au shell

1.1 - Mode local et mode distant

Lorsque le périphérique Android est démarré en mode Système, l'accès au shell peut s'effectuer

1.2 - Accès au mode local

a5y17lte:/ $

a5y17lte est le nom de code de l'appareil (Samsung Galaxy A5 2017), $ est le symbole indiquant une connexion en tant que simple-utilisateur

2 - Droits

2.1 - Shell utilisateur

a5y17lte:/ $ pwd
/

a5y17lte:/ $ id
uid=2000(shell) gid=2000(shell) groups=2000(shell),1004(input),1007(log),1011(adb),1015(sdcard_rw),1028(sdcard_r),3001(net_bt_admin),3002(net_bt),3003(inet),3006(net_bw_stats),3009(readproc),3011(uhid) context=u:r:shell:s0
~ $ pwd
/data/data/com.termux/files/home

~ $ id
uid=10130(u0_a130) gid=10130(u0_a130) groups=10130(u0_a130),3003(inet),9997(everybody),20130(u0_a130_cache),50130(all_a130)

2.2 - Passage d'une commande avec les droits root

gts210velte:/ $ su -h | grep command
-c, --command COMMAND pass COMMAND to the invoked shell
gts210velte:/ $ su -c id
uid=0(root) gid=0(root) groups=0(root) context=u:r:magisk:s0
gts210velte:/ $ su -c 'cd /storage/57*; touch test; ls -l ./ |grep test'
-rw-rw---- 1 root sdcard_rw 0 2018-10-28 19:00 test

2.2 - Shell root

gts210velte:/ $ su
gts210velte:/ #
gts210velte:/ # id
uid=0(root) gid=0(root) groups=0(root) context=u:r:magisk:s0
gts210velte:/ # mount -o remount,rw /system

gts210velte:/ # mount |grep /dev/block |grep /system /dev/block/mmcblk0p36 on /system type ext4 (rw,seclabel,relatime,discard)
gts210velte:/ # exit
gts210velte:/ $

3 - Commandes du système

/system/bin  # en particulier les commandes toybox
/system/vendor
/system/xbin # les commandes busybox (si installée)
/vendor/bin

3.1 - Commandes de base du shell

a5y17lte:/ $ toybox
acpi base64 basename blkid blockdev cal cat chattr chcon chgrp chmod
chown chroot chrt cksum clear cmp comm cp cpio cut date dd df diff
.....
a5y17lte:/ $ busybox --list
[
[
[[
acpid
adjtimex
ar
arch
......
a5y17lte:/ $ date --help
usage: date [-u] [-r FILE] [-d DATE] [+DISPLAY_FORMAT] [-D SET_FORMAT] [SET]

Set/get the current date/time. With no SET shows the current date.
.........

3.2 - Gestion des services - cmd

$ adb shell cmd -l |head
Currently running services:
DockObserver
Exynos.HWCService
SurfaceFlinger
accessibility
account
activity
activity_task
adb
adbroot_service
a5y17lte:/ $ cmd vibrator
Vibrator commands:
help
Prints this help text.

vibrate duration [description]
Vibrates for duration milliseconds; ignored when device is on DND
(Do Not Disturb) mode.
.......
|a5y17lte:/ $ su -c cmd wifi get-country-code                               
Wifi Country Code = FR

a5y17lte:/ $ cmd settings list system
accelerometer_rotation=0
alarm_alert=content://media/internal/audio/media/55?title=Hassium&canonical=1
alarm_alert_set=1
dim_screen=1
....
volume_ring=5
volume_system=7
volume_voice=4

3.3 - Gestion des paquets - pm

$ pm |head
Package manager (package) commands:
help
Print this help text.

path [--user USER_ID] PACKAGE
Print the path to the .apk of the given PACKAGE.

dump PACKAGE
Print various system state associated with the given PACKAGE.
......

3.4 - Commandes diverses

# Lancer une application
?????
screencap /sdcard/copie_écran.png

screenrecord --time-limit 10 /sdcard/video_écran.mp4
# Réduire la luminosité
input keyevent 220

# Augmenter la luminosité
input keyevent 221

4 - Commandes supplémentaires

Annexe - Liste de keyevents

0 -->  "KEYCODE_0" 
1 -->  "KEYCODE_SOFT_LEFT" 
2 -->  "KEYCODE_SOFT_RIGHT" 
3 -->  "KEYCODE_HOME" 
4 -->  "KEYCODE_BACK" 
5 -->  "KEYCODE_CALL" 
6 -->  "KEYCODE_ENDCALL" 
7 -->  "KEYCODE_0" 
8 -->  "KEYCODE_1" 
9 -->  "KEYCODE_2" 
10 -->  "KEYCODE_3" 
11 -->  "KEYCODE_4" 
12 -->  "KEYCODE_5" 
13 -->  "KEYCODE_6" 
14 -->  "KEYCODE_7" 
15 -->  "KEYCODE_8" 
16 -->  "KEYCODE_9" 
17 -->  "KEYCODE_STAR" 
18 -->  "KEYCODE_POUND" 
19 -->  "KEYCODE_DPAD_UP" 
20 -->  "KEYCODE_DPAD_DOWN" 
21 -->  "KEYCODE_DPAD_LEFT" 
22 -->  "KEYCODE_DPAD_RIGHT" 
23 -->  "KEYCODE_DPAD_CENTER" 
24 -->  "KEYCODE_VOLUME_UP" 
25 -->  "KEYCODE_VOLUME_DOWN" 
26 -->  "KEYCODE_POWER" 
27 -->  "KEYCODE_CAMERA" 
28 -->  "KEYCODE_CLEAR" 
29 -->  "KEYCODE_A" 
30 -->  "KEYCODE_B" 
31 -->  "KEYCODE_C" 
32 -->  "KEYCODE_D" 
33 -->  "KEYCODE_E" 
34 -->  "KEYCODE_F" 
35 -->  "KEYCODE_G" 
36 -->  "KEYCODE_H" 
37 -->  "KEYCODE_I" 
38 -->  "KEYCODE_J" 
39 -->  "KEYCODE_K" 
40 -->  "KEYCODE_L" 
41 -->  "KEYCODE_M" 
42 -->  "KEYCODE_N" 
43 -->  "KEYCODE_O" 
44 -->  "KEYCODE_P" 
45 -->  "KEYCODE_Q" 
46 -->  "KEYCODE_R" 
47 -->  "KEYCODE_S" 
48 -->  "KEYCODE_T" 
49 -->  "KEYCODE_U" 
50 -->  "KEYCODE_V" 
51 -->  "KEYCODE_W" 
52 -->  "KEYCODE_X" 
53 -->  "KEYCODE_Y" 
54 -->  "KEYCODE_Z" 
55 -->  "KEYCODE_COMMA" 
56 -->  "KEYCODE_PERIOD" 
57 -->  "KEYCODE_ALT_LEFT" 
58 -->  "KEYCODE_ALT_RIGHT" 
59 -->  "KEYCODE_SHIFT_LEFT" 
60 -->  "KEYCODE_SHIFT_RIGHT" 
61 -->  "KEYCODE_TAB" 
62 -->  "KEYCODE_SPACE" 
63 -->  "KEYCODE_SYM" 
64 -->  "KEYCODE_EXPLORER" 
65 -->  "KEYCODE_ENVELOPE" 
66 -->  "KEYCODE_ENTER" 
67 -->  "KEYCODE_DEL" 
68 -->  "KEYCODE_GRAVE" 
69 -->  "KEYCODE_MINUS" 
70 -->  "KEYCODE_EQUALS" 
71 -->  "KEYCODE_LEFT_BRACKET" 
72 -->  "KEYCODE_RIGHT_BRACKET" 
73 -->  "KEYCODE_BACKSLASH" 
74 -->  "KEYCODE_SEMICOLON" 
75 -->  "KEYCODE_APOSTROPHE" 
76 -->  "KEYCODE_SLASH" 
77 -->  "KEYCODE_AT" 
78 -->  "KEYCODE_NUM" 
79 -->  "KEYCODE_HEADSETHOOK" 
80 -->  "KEYCODE_FOCUS" 
81 -->  "KEYCODE_PLUS" 
82 -->  "KEYCODE_MENU" 
83 -->  "KEYCODE_NOTIFICATION" 
84 -->  "KEYCODE_SEARCH" 
85 -->  "KEYCODE_MEDIA_PLAY_PAUSE"
86 -->  "KEYCODE_MEDIA_STOP"
87 -->  "KEYCODE_MEDIA_NEXT"
88 -->  "KEYCODE_MEDIA_PREVIOUS"
89 -->  "KEYCODE_MEDIA_REWIND"
90 -->  "KEYCODE_MEDIA_FAST_FORWARD"
91 -->  "KEYCODE_MUTE"
92 -->  "KEYCODE_PAGE_UP"
93 -->  "KEYCODE_PAGE_DOWN"
94 -->  "KEYCODE_PICTSYMBOLS"
...
122 -->  "KEYCODE_MOVE_HOME"
123 -->  "KEYCODE_MOVE_END"

220 --> "Augmenter la luminosité"
221 --> "Réduire la luminosité"
222 --> ???
223 --> "Lock screen"
224 --> "Wakes up the device"
{
"key_events": {
"key_unknown": "adb shell input keyevent 0",
"key_soft_left": "adb shell input keyevent 1",
"key_soft_right": "adb shell input keyevent 2",
"key_home": "adb shell input keyevent 3",
"key_back": "adb shell input keyevent 4",
"key_call": "adb shell input keyevent 5",
"key_endcall": "adb shell input keyevent 6",
"key_0": "adb shell input keyevent 7",
"key_1": "adb shell input keyevent 8",
"key_2": "adb shell input keyevent 9",
"key_3": "adb shell input keyevent 10",
"key_4": "adb shell input keyevent 11",
"key_5": "adb shell input keyevent 12",
"key_6": "adb shell input keyevent 13",
"key_7": "adb shell input keyevent 14",
"key_8": "adb shell input keyevent 15",
"key_9": "adb shell input keyevent 16",
"key_star": "adb shell input keyevent 17",
"key_pound": "adb shell input keyevent 18",
"key_dpad_up": "adb shell input keyevent 19",
"key_dpad_down": "adb shell input keyevent 20",
"key_dpad_left": "adb shell input keyevent 21",
"key_dpad_right": "adb shell input keyevent 22",
"key_dpad_center": "adb shell input keyevent 23",
"key_volume_up": "adb shell input keyevent 24",
"key_volume_down": "adb shell input keyevent 25",
"key_power": "adb shell input keyevent 26",
"key_camera": "adb shell input keyevent 27",
"key_clear": "adb shell input keyevent 28",
"key_a": "adb shell input keyevent 29",
"key_b": "adb shell input keyevent 30",
"key_c": "adb shell input keyevent 31",
"key_d": "adb shell input keyevent 32",
"key_e": "adb shell input keyevent 33",
"key_f": "adb shell input keyevent 34",
"key_g": "adb shell input keyevent 35",
"key_h": "adb shell input keyevent 36",
"key_i": "adb shell input keyevent 37",
"key_j": "adb shell input keyevent 38",
"key_k": "adb shell input keyevent 39",
"key_l": "adb shell input keyevent 40",
"key_m": "adb shell input keyevent 41",
"key_n": "adb shell input keyevent 42",
"key_o": "adb shell input keyevent 43",
"key_p": "adb shell input keyevent 44",
"key_q": "adb shell input keyevent 45",
"key_r": "adb shell input keyevent 46",
"key_s": "adb shell input keyevent 47",
"key_t": "adb shell input keyevent 48",
"key_u": "adb shell input keyevent 49",
"key_v": "adb shell input keyevent 50",
"key_w": "adb shell input keyevent 51",
"key_x": "adb shell input keyevent 52",
"key_y": "adb shell input keyevent 53",
"key_z": "adb shell input keyevent 54",
"key_comma": "adb shell input keyevent 55",
"key_period": "adb shell input keyevent 56",
"key_alt_left": "adb shell input keyevent 57",
"key_alt_right": "adb shell input keyevent 58",
"key_shift_left": "adb shell input keyevent 59",
"key_shift_right": "adb shell input keyevent 60",
"key_tab": "adb shell input keyevent 61",
"key_space": "adb shell input keyevent 62",
"key_sym": "adb shell input keyevent 63",
"key_explorer": "adb shell input keyevent 64",
"key_envelope": "adb shell input keyevent 65",
"key_enter": "adb shell input keyevent 66",
"key_del": "adb shell input keyevent 67",
"key_grave": "adb shell input keyevent 68",
"key_minus": "adb shell input keyevent 69",
"key_equals": "adb shell input keyevent 70",
"key_left_bracket": "adb shell input keyevent 71",
"key_right_bracket": "adb shell input keyevent 72",
"key_backslash": "adb shell input keyevent 73",
"key_semicolon": "adb shell input keyevent 74",
"key_apostrophe": "adb shell input keyevent 75",
"key_slash": "adb shell input keyevent 76",
"key_at": "adb shell input keyevent 77",
"key_num": "adb shell input keyevent 78",
"key_headsethook": "adb shell input keyevent 79",
"key_focus": "adb shell input keyevent 80",
"key_plus": "adb shell input keyevent 81",
"key_menu": "adb shell input keyevent 82",
"key_notification": "adb shell input keyevent 83",
"key_search": "adb shell input keyevent 84",
"key_media_play_pause": "adb shell input keyevent 85",
"key_media_stop": "adb shell input keyevent 86",
"key_media_next": "adb shell input keyevent 87",
"key_media_previous": "adb shell input keyevent 88",
"key_media_rewind": "adb shell input keyevent 89",
"key_media_fast_forward": "adb shell input keyevent 90",
"key_mute": "adb shell input keyevent 91",
"key_page_up": "adb shell input keyevent 92",
"key_page_down": "adb shell input keyevent 93",
"key_pictsymbols": "adb shell input keyevent 94",
"key_switch_charset": "adb shell input keyevent 95",
"key_button_a": "adb shell input keyevent 96",
"key_button_b": "adb shell input keyevent 97",
"key_button_c": "adb shell input keyevent 98",
"key_button_x": "adb shell input keyevent 99",
"key_button_y": "adb shell input keyevent 100",
"key_button_z": "adb shell input keyevent 101",
"key_button_l1": "adb shell input keyevent 102",
"key_button_r1": "adb shell input keyevent 103",
"key_button_l2": "adb shell input keyevent 104",
"key_button_r2": "adb shell input keyevent 105",
"key_button_thumbl": "adb shell input keyevent 106",
"key_button_thumbr": "adb shell input keyevent 107",
"key_button_start": "adb shell input keyevent 108",
"key_button_select": "adb shell input keyevent 109",
"key_button_mode": "adb shell input keyevent 110",
"key_escape": "adb shell input keyevent 111",
"key_forward_del": "adb shell input keyevent 112",
"key_ctrl_left": "adb shell input keyevent 113",
"key_ctrl_right": "adb shell input keyevent 114",
"key_caps_lock": "adb shell input keyevent 115",
"key_scroll_lock": "adb shell input keyevent 116",
"key_meta_left": "adb shell input keyevent 117",
"key_meta_right": "adb shell input keyevent 118",
"key_function": "adb shell input keyevent 119",
"key_sysrq": "adb shell input keyevent 120",
"key_break": "adb shell input keyevent 121",
"key_move_home": "adb shell input keyevent 122",
"key_move_end": "adb shell input keyevent 123",
"key_insert": "adb shell input keyevent 124",
"key_forward": "adb shell input keyevent 125",
"key_media_play": "adb shell input keyevent 126",
"key_media_pause": "adb shell input keyevent 127",
"key_media_close": "adb shell input keyevent 128",
"key_media_eject": "adb shell input keyevent 129",
"key_media_record": "adb shell input keyevent 130",
"key_f1": "adb shell input keyevent 131",
"key_f2": "adb shell input keyevent 132",
"key_f3": "adb shell input keyevent 133",
"key_f4": "adb shell input keyevent 134",
"key_f5": "adb shell input keyevent 135",
"key_f6": "adb shell input keyevent 136",
"key_f7": "adb shell input keyevent 137",
"key_f8": "adb shell input keyevent 138",
"key_f9": "adb shell input keyevent 139",
"key_f10": "adb shell input keyevent 140",
"key_f11": "adb shell input keyevent 141",
"key_f12": "adb shell input keyevent 142",
"key_num_lock": "adb shell input keyevent 143",
"key_numpad_0": "adb shell input keyevent 144",
"key_numpad_1": "adb shell input keyevent 145",
"key_numpad_2": "adb shell input keyevent 146",
"key_numpad_3": "adb shell input keyevent 147",
"key_numpad_4": "adb shell input keyevent 148",
"key_numpad_5": "adb shell input keyevent 149",
"key_numpad_6": "adb shell input keyevent 150",
"key_numpad_7": "adb shell input keyevent 151",
"key_numpad_8": "adb shell input keyevent 152",
"key_numpad_9": "adb shell input keyevent 153",
"key_numpad_divide": "adb shell input keyevent 154",
"key_numpad_multiply": "adb shell input keyevent 155",
"key_numpad_subtract": "adb shell input keyevent 156",
"key_numpad_add": "adb shell input keyevent 157",
"key_numpad_dot": "adb shell input keyevent 158",
"key_numpad_comma": "adb shell input keyevent 159",
"key_numpad_enter": "adb shell input keyevent 160",
"key_numpad_equals": "adb shell input keyevent 161",
"key_numpad_left_paren": "adb shell input keyevent 162",
"key_numpad_right_paren": "adb shell input keyevent 163",
"key_volume_mute": "adb shell input keyevent 164",
"key_info": "adb shell input keyevent 165",
"key_channel_up": "adb shell input keyevent 166",
"key_channel_down": "adb shell input keyevent 167",
"key_zoom_in": "adb shell input keyevent 168",
"key_zoom_out": "adb shell input keyevent 169",
"key_tv": "adb shell input keyevent 170",
"key_window": "adb shell input keyevent 171",
"key_guide": "adb shell input keyevent 172",
"key_dvr": "adb shell input keyevent 173",
"key_bookmark": "adb shell input keyevent 174",
"key_captions": "adb shell input keyevent 175",
"key_settings": "adb shell input keyevent 176",
"key_tv_power": "adb shell input keyevent 177",
"key_tv_input": "adb shell input keyevent 178",
"key_stb_power": "adb shell input keyevent 179",
"key_stb_input": "adb shell input keyevent 180",
"key_avr_power": "adb shell input keyevent 181",
"key_avr_input": "adb shell input keyevent 182",
"key_prog_red": "adb shell input keyevent 183",
"key_prog_green": "adb shell input keyevent 184",
"key_prog_yellow": "adb shell input keyevent 185",
"key_prog_blue": "adb shell input keyevent 186",
"key_app_switch": "adb shell input keyevent 187",
"key_button_1": "adb shell input keyevent 188",
"key_button_2": "adb shell input keyevent 189",
"key_button_3": "adb shell input keyevent 190",
"key_button_4": "adb shell input keyevent 191",
"key_button_5": "adb shell input keyevent 192",
"key_button_6": "adb shell input keyevent 193",
"key_button_7": "adb shell input keyevent 194",
"key_button_8": "adb shell input keyevent 195",
"key_button_9": "adb shell input keyevent 196",
"key_button_10": "adb shell input keyevent 197",
"key_button_11": "adb shell input keyevent 198",
"key_button_12": "adb shell input keyevent 199",
"key_button_13": "adb shell input keyevent 200",
"key_button_14": "adb shell input keyevent 201",
"key_button_15": "adb shell input keyevent 202",
"key_button_16": "adb shell input keyevent 203",
"key_language_switch": "adb shell input keyevent 204",
"key_manner_mode": "adb shell input keyevent 205",
"key_3d_mode": "adb shell input keyevent 206",
"key_contacts": "adb shell input keyevent 207",
"key_calendar": "adb shell input keyevent 208",
"key_music": "adb shell input keyevent 209",
"key_calculator": "adb shell input keyevent 210",
"key_zenkaku_hankaku": "adb shell input keyevent 211",
"key_eisu": "adb shell input keyevent 212",
"key_muhenkan": "adb shell input keyevent 213",
"key_henkan": "adb shell input keyevent 214",
"key_katakana_hiragana": "adb shell input keyevent 215",
"key_yen": "adb shell input keyevent 216",
"key_ro": "adb shell input keyevent 217",
"key_kana": "adb shell input keyevent 218",
"key_assist": "adb shell input keyevent 219",
"key_brightness_down": "adb shell input keyevent 220",
"key_brightness_up": "adb shell input keyevent 221",
"key_media_audio_track": "adb shell input keyevent 222",
"key_sleep": "adb shell input keyevent 223",
"key_wakeup": "adb shell input keyevent 224",
"key_pairing": "adb shell input keyevent 225",
"key_media_top_menu": "adb shell input keyevent 226",
"key_11": "adb shell input keyevent 227",
"key_12": "adb shell input keyevent 228",
"key_last_channel": "adb shell input keyevent 229",
"key_tv_data_service": "adb shell input keyevent 230",
"key_voice_assist": "adb shell input keyevent 231",
"key_tv_radio_service": "adb shell input keyevent 232",
"key_tv_teletext": "adb shell input keyevent 233",
"key_tv_number_entry": "adb shell input keyevent 234",
"key_tv_terrestrial_analog": "adb shell input keyevent 235",
"key_tv_terrestrial_digital": "adb shell input keyevent 236",
"key_tv_satellite": "adb shell input keyevent 237",
"key_tv_satellite_bs": "adb shell input keyevent 238",
"key_tv_satellite_cs": "adb shell input keyevent 239",
"key_tv_satellite_service": "adb shell input keyevent 240",
"key_tv_network": "adb shell input keyevent 241",
"key_tv_antenna_cable": "adb shell input keyevent 242",
"key_tv_input_hdmi_1": "adb shell input keyevent 243",
"key_tv_input_hdmi_2": "adb shell input keyevent 244",
"key_tv_input_hdmi_3": "adb shell input keyevent 245",
"key_tv_input_hdmi_4": "adb shell input keyevent 246",
"key_tv_input_composite_1": "adb shell input keyevent 247",
"key_tv_input_composite_2": "adb shell input keyevent 248",
"key_tv_input_component_1": "adb shell input keyevent 249",
"key_tv_input_component_2": "adb shell input keyevent 250",
"key_tv_input_vga_1": "adb shell input keyevent 251",
"key_tv_audio_description": "adb shell input keyevent 252",
"key_tv_audio_description_mix_up": "adb shell input keyevent 253",
"key_tv_audio_description_mix_down": "adb shell input keyevent 254",
"key_tv_zoom_mode": "adb shell input keyevent 255",
"key_tv_contents_menu": "adb shell input keyevent 256",
"key_tv_media_context_menu": "adb shell input keyevent 257",
"key_tv_timer_programming": "adb shell input keyevent 258",
"key_help": "adb shell input keyevent 259",
"key_navigate_previous": "adb shell input keyevent 260",
"key_navigate_next": "adb shell input keyevent 261",
"key_navigate_in": "adb shell input keyevent 262",
"key_navigate_out": "adb shell input keyevent 263",
"key_stem_primary": "adb shell input keyevent 264",
"key_stem_1": "adb shell input keyevent 265",
"key_stem_2": "adb shell input keyevent 266",
"key_stem_3": "adb shell input keyevent 267",
"key_dpad_up_left": "adb shell input keyevent 268",
"key_dpad_down_left": "adb shell input keyevent 269",
"key_dpad_up_right": "adb shell input keyevent 270",
"key_dpad_down_right": "adb shell input keyevent 271",
"key_media_skip_forward": "adb shell input keyevent 272",
"key_media_skip_backward": "adb shell input keyevent 273",
"key_media_step_forward": "adb shell input keyevent 274",
"key_media_step_backward": "adb shell input keyevent 275",
"key_soft_sleep": "adb shell input keyevent 276",
"key_cut": "adb shell input keyevent 277",
"key_copy": "adb shell input keyevent 278",
"key_paste": "adb shell input keyevent 279",
"key_system_navigation_up": "adb shell input keyevent 280",
"key_system_navigation_down": "adb shell input keyevent 281",
"key_system_navigation_left": "adb shell input keyevent 282",
"key_system_navigation_right": "adb shell input keyevent 283",
"key_all_apps": "adb shell input keyevent 284",
"key_refresh": "adb shell input keyevent 285"
}