forked from AdrianDC/advanced_development_shell_tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathandroid_adb_flash.rc
101 lines (91 loc) · 3.01 KB
/
android_adb_flash.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
#!/bin/bash
#
# Copyright 2015-2017 Adrian DC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# === Standalone Source Helper ===
# source <(curl -Ls https://github.com/AdrianDC/android_development_shell_tools/raw/master/android_devices.rc)
# source <(curl -Ls https://github.com/AdrianDC/android_development_shell_tools/raw/master/android_adb_tools.rc)
# source <(curl -Ls https://github.com/AdrianDC/android_development_shell_tools/raw/master/android_adb_flash.rc)
# === ADB Bootimage Dumper ===
function adbbootdump()
{
# Usage: adbbootdump (Dump bootimage from device)
# Variables
local cmdaddr;
local cmdsize;
local kernel;
# Dump bootimage from device
kernel=$(androiddevicestarget boot);
cmdaddr=$(adb shell od -j 152 -N 4 -tx4 -An "${kernel}" \
| tr -d ' ' | cut -c 2-9);
cmdsize=$(adb shell od -j 164 -N 4 -tx4 -An "${kernel}" \
| tr -d ' ' | 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;
adbsu 'rm -f /sdcard/boot.img';
else
adbsu "dd if=${kernel} of=/sdcard/boot.dump";
adb pull /sdcard/boot.dump;
adbsu 'rm -f /sdcard/boot.dump';
adbbootcut boot.dump;
fi;
}
# === ADB Bootimage Resizer ===
function adbbootcut()
{
# Usage
if [ -z "${1}" ] || [ ! -f "${1}" ]; then
echo '';
echo ' Usage: adbbootcut <file_path> (Trim bootimage dump)';
echo '';
return;
fi;
# Variables
local bootsize;
local cmdaddr;
local cmdsize;
# Trim bootimage dump
cmdaddr=$(od -j 152 -N 4 -tx4 -An "${1}" \
| cut -c 2-9);
cmdsize=$(od -j 164 -N 4 -tx4 -An "${1}" \
| cut -c 2-9);
bootsize=$((16#${cmdaddr}+16#${cmdsize}));
dd if="${1}" of=boot.img skip=0 bs="${bootsize}" count=1;
}
# === ADB TWRP Installer ===
function adbrecoveryinstall()
{
# Usage
if [ -z "${1}" ] || [ ! -f "${1}" ]; then
echo '';
echo ' Usage: adbrecoveryinstall <file_path> (Inject and reboot recovery)';
echo '';
return;
fi;
# Variables
local filename;
# Inject and reboot recovery
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 'cat /cache/recovery/command';
adb reboot recovery;
}