Skip to content

Commit b13ea87

Browse files
moetayukoSebaUbuntu
authored andcommitted
AIK: fix detecting AVBv2-signed bootimg
1 parent e0c689b commit b13ea87

6 files changed

Lines changed: 60 additions & 56 deletions

File tree

authors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ gzip, bzip2, lzop, xz;
6262
awk, basename, bash, cpio, cut, dd, dirname, env, file, find, grep, hexdump, java, printf, rev, sed, stat, sudo, tail, truncate, wc (Linux):
6363
(required system packages/commands)
6464

65-
androidbootimg.magic:
65+
androidbootimg.magic, androidsign.magic:
6666
osm0sis @ xda-developers
6767

6868
shell scripts:

bin/androidbootimg.magic

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,6 @@
33
# osm0sis @ xda-developers
44
#------------------------------------------------------------------------------
55

6-
# ASUS Blob Signature
7-
0 string -SIGNED-BY-SIGNBLOB- BLOB signing
8-
9-
# Barnes & Noble Nook Signature
10-
64 string Red\x20Loader NOOK signing (red loader)
11-
64 string Green\x20Loader NOOK signing (green loader)
12-
64 string Green\x20Recovery NOOK signing (green recovery)
13-
64 string eMMC\x20boot.img+secondloader NOOK signing (emmc boot)
14-
64 string eMMC\x20recovery.img+secondloader NOOK signing (emmc recovery)
15-
48 string BauwksBoot NOOKTAB signing (bauwks)
16-
17-
# Google ChromeOS Signature
18-
0 string CHROMEOS CHROMEOS signing
19-
20-
# Samsung/Spreadtrum DHTB Signature
21-
0 string DHTB\x01\x00\x00 DHTB signing
22-
23-
# Sony SIN Packaging/Signature
24-
0 string \x01\x00\x00\x00 SINv1 signing
25-
0 string \x02\x00\x00\x00 SINv2 signing
26-
0 string \x03SIN SINv3 signing
27-
286
# Google Pixel/Nexus/AOSP Standard
297
# [test "x" as workaround to odd file/magic behavior not allowing search here]
308
0 string x
@@ -83,29 +61,3 @@
8361
# [for detection after boot image has already been split]
8462
0 string QCDT QCDT header
8563
!:strength / 20
86-
87-
# Google Android Verified Boot 1.0 Signature
88-
# [for detection with the tail of the boot image]
89-
0 search \x02\x01\x01\x30\x82 AVBv1 signing footer
90-
>0 search /boot \b, boot type
91-
>0 search /recovery \b, recovery type
92-
!:strength / 20
93-
94-
# Google Android Verified Boot 2.0 Signature
95-
# [for detection with the tail of the boot image]
96-
# [test "x" as workaround to odd file/magic behavior not allowing search here]
97-
0 string x
98-
>0 search AVBf AVBv2 signing footer
99-
!:strength / 20
100-
101-
# LG Bump
102-
# [for detection with the tail of the boot image]
103-
0 search \x41\xA9\xE4\x67\x74\x4D\x1D\x1B\xA4\x29\xF2\xEC\xEA\x65\x52\x79 Bump footer
104-
!:strength / 20
105-
106-
# Samsung SEAndroid
107-
# [for detection with the tail of the boot image]
108-
# [test "x" as workaround to odd file/magic behavior not allowing search here]
109-
0 string x
110-
>0 search SEANDROIDENFORCE SEAndroid footer
111-
!:strength / 20

bin/androidsign.magic

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#------------------------------------------------------------------------------
2+
# Various Android OEM non-standard boot image related magic entries
3+
# osm0sis @ xda-developers
4+
#------------------------------------------------------------------------------
5+
6+
# ASUS Blob Signature
7+
0 string -SIGNED-BY-SIGNBLOB- BLOB signing
8+
9+
# Barnes & Noble Nook Signature
10+
64 string Red\x20Loader NOOK signing (red loader)
11+
64 string Green\x20Loader NOOK signing (green loader)
12+
64 string Green\x20Recovery NOOK signing (green recovery)
13+
64 string eMMC\x20boot.img+secondloader NOOK signing (emmc boot)
14+
64 string eMMC\x20recovery.img+secondloader NOOK signing (emmc recovery)
15+
48 string BauwksBoot NOOKTAB signing (bauwks)
16+
17+
# Google ChromeOS Signature
18+
0 string CHROMEOS CHROMEOS signing
19+
20+
# Samsung/Spreadtrum DHTB Signature
21+
0 string DHTB\x01\x00\x00 DHTB signing
22+
23+
# Sony SIN Packaging/Signature
24+
0 string \x01\x00\x00\x00 SINv1 signing
25+
0 string \x02\x00\x00\x00 SINv2 signing
26+
0 string \x03SIN SINv3 signing
27+
28+
# Google Android Verified Boot 1.0 Signature
29+
# [for detection with the tail of the boot image]
30+
0 search \x02\x01\x01\x30\x82 AVBv1 signing footer
31+
>0 search /boot \b, boot type
32+
>0 search /recovery \b, recovery type
33+
!:strength / 20
34+
35+
# Google Android Verified Boot 2.0 Signature
36+
# [for detection with the tail of the boot image]
37+
# [test "x" as workaround to odd file/magic behavior not allowing search here]
38+
0 string x
39+
>0 search AVBf AVBv2 signing footer
40+
!:strength / 20
41+
42+
# LG Bump
43+
# [for detection with the tail of the boot image]
44+
0 search \x41\xA9\xE4\x67\x74\x4D\x1D\x1B\xA4\x29\xF2\xEC\xEA\x65\x52\x79 Bump footer
45+
!:strength / 20
46+
47+
# Samsung SEAndroid
48+
# [for detection with the tail of the boot image]
49+
# [test "x" as workaround to odd file/magic behavior not allowing search here]
50+
0 string x
51+
>0 search SEANDROIDENFORCE SEAndroid footer
52+
!:strength / 20

cleanup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ case $1 in
2424
esac;
2525

2626
chmod -R 755 "$bin" "$aik"/*.sh;
27-
chmod 644 "$bin/magic" "$bin/androidbootimg.magic" "$bin/boot_signer.jar" "$bin/avb/"* "$bin/chromeos/"*;
27+
chmod 644 "$bin/magic" "$bin/androidbootimg.magic" "$bin/androidsign.magic" "$bin/boot_signer.jar" "$bin/avb/"* "$bin/chromeos/"*;
2828

2929
if [ -d ramdisk ] && [ "$(stat $statarg ramdisk | head -n 1)" = "root" -o ! "$(find ramdisk 2>&1 | cpio -o >/dev/null 2>&1; echo $?)" -eq "0" ]; then
3030
sudo=sudo;

repackimg.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ case $1 in
5050
*) cd "$aik";;
5151
esac;
5252
chmod -R 755 "$bin" "$aik/"*.sh;
53-
chmod 644 "$bin/magic" "$bin/androidbootimg.magic" "$bin/boot_signer.jar" "$bin/avb/"* "$bin/chromeos/"*;
53+
chmod 644 "$bin/magic" "$bin/androidbootimg.magic" "$bin/androidsign.magic" "$bin/boot_signer.jar" "$bin/avb/"* "$bin/chromeos/"*;
5454

5555
if [ -z "$(ls split_img/* 2>/dev/null)" -o ! -e ramdisk ]; then
5656
echo "No files found to be packed/built.";

unpackimg.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ if [ ! "$local" ]; then
5454
cd "$aik";
5555
fi;
5656
chmod -R 755 "$bin" "$aik"/*.sh;
57-
chmod 644 "$bin/magic" "$bin/androidbootimg.magic" "$bin/boot_signer.jar" "$bin/avb/"* "$bin/chromeos/"*;
57+
chmod 644 "$bin/magic" "$bin/androidbootimg.magic" "$bin/androidsign.magic" "$bin/boot_signer.jar" "$bin/avb/"* "$bin/chromeos/"*;
5858

5959
img="$1";
6060
[ -f "$cur/$1" ] && img="$cur/$1";
@@ -100,7 +100,7 @@ mkdir split_img ramdisk;
100100
cd split_img;
101101
filesize=$(wc -c < "$img");
102102
echo "$filesize" > "$file-origsize";
103-
imgtest="$(file -m "$bin/androidbootimg.magic" "$img" 2>/dev/null | cut -d: -f2-)";
103+
imgtest="$(file -m "$bin/androidsign.magic" "$img" 2>/dev/null | cut -d: -f2-)";
104104
if [ "$(echo $imgtest | awk '{ print $2 }' | cut -d, -f1)" = "signing" ]; then
105105
echo $imgtest | awk '{ print $1 }' > "$file-sigtype";
106106
sigtype=$(cat "$file-sigtype");
@@ -128,7 +128,7 @@ if [ "$(echo $imgtest | awk '{ print $2 }' | cut -d, -f1)" = "signing" ]; then
128128
rm -f "$file-sigtype";
129129
;;
130130
esac;
131-
img="$file";
131+
[ -f "$file" ] && img="$file";
132132
fi;
133133

134134
imgtest="$(file -m "$bin/androidbootimg.magic" "$img" 2>/dev/null | cut -d: -f2-)";
@@ -182,9 +182,9 @@ case $(echo $imgtest | awk '{ print $3 }') in
182182
;;
183183
esac;
184184

185-
tailtest="$(dd if="$img" iflag=skip_bytes skip=$(($(wc -c < "$img") - 8192)) bs=8192 count=1 2>/dev/null | file -m $bin/androidbootimg.magic - 2>/dev/null | cut -d: -f2-)";
185+
tailtest="$(dd if="$img" iflag=skip_bytes skip=$(($(wc -c < "$img") - 8192)) bs=8192 count=1 2>/dev/null | file -m $bin/androidsign.magic - 2>/dev/null | cut -d: -f2-)";
186186
case $tailtest in
187-
*data) tailtest="$(tail -n50 "$img" | file -m "$bin/androidbootimg.magic" - 2>/dev/null | cut -d: -f2-)";;
187+
*data) tailtest="$(tail -n50 "$img" | file -m "$bin/androidsign.magic" - 2>/dev/null | cut -d: -f2-)";;
188188
esac;
189189
tailtype="$(echo $tailtest | awk '{ print $1 }')";
190190
case $tailtype in

0 commit comments

Comments
 (0)