forked from ravindu644/Kitchen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kitchen
147 lines (132 loc) · 4.2 KB
/
kitchen
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
#! /bin/bash
################################################################################
# Copyright (c) [2024] [Ravindu Deshan]
#
# Unauthorized publication is prohibited. Forks and personal use are allowed.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
################################################################################
DIR=$(pwd)
CMD=$1
BOOTIMG=$2
check_termux() {
if [ -n "$PREFIX" ] && [ "$PREFIX" != "/" ]; then
MAGISKBOOT=$DIR/bin/magiskboot_android
TERMUX=1
else
MAGISKBOOT=$DIR/bin/magiskboot_linux
TERMUX=0
fi
}
check_termux
AVBTOOL=$DIR/bin/avbtool
chmod +x $DIR/bin/*
banner(){
clear
source res/colors
source res/banner
}
requirements(){
if [ ! -z "$BOOTIMG" ]; then
echo "$BOOTIMG" > "$DIR/res/.tmp1"
fi
set -e
if [ ! -f "$DIR/res/.req" ]; then
echo -e "${RED}[+] Installing Requirements...${RESET}\n"
if [ $TERMUX == 1 ]; then
pkg update -y > /dev/null 2>&1
echo -e "\n${GREEN}[i] OpenSSL${RESET}\n" ; pkg install openssl openssl-tool -y > /dev/null 2>&1
echo -e "\n${GREEN}[i] Python${RESET}\n" ; pkg install python -y > /dev/null 2>&1
elif [ $TERMUX == 0 ]; then
sudo apt update -y > /dev/null 2>&1
echo -e "\n${GREEN}[i] OpenSSL${RESET}\n" ; sudo apt install openssl -y > /dev/null 2>&1
echo -e "\n${GREEN}[i] Python${RESET}\n" ; sudo apt install python3 python-is-python3 -y > /dev/null 2>&1
else
echo -e "${BOLD_RED}[x] Error: Package manager not found.${RESET}"
exit 1
fi
echo -e "\n${RED}[i] Done...${RESET}\n"
echo "DON'T DELETE ME" > "$DIR/res/.req"
elif [ -f "$DIR/res/.req" ]; then
echo "" > /dev/null
else
echo -e "${BOLD_RED}[x] Error: Requirements installation failed.${RESET}"
fi
}
key(){
if [ ! -d "$DIR/res/key" ]; then
mkdir "$DIR/res/key"
fi
if [ ! -f "$DIR/res/key/sign.pem" ]; then
echo -e "${BOLD_YELLOW}[+] Generating a signing key...${RESET}\n"
openssl genrsa -f4 -out "$DIR/res/key/sign.pem" 4096
fi
}
usage(){
if [ -z "$CMD" ]; then
echo -e "${BOLD_RED}[x] No Command Specified..!${RESET}\n"
cat res/usage
echo -e "\n${BOLD_WHITE}======================================${RESET}"
exit 1
fi
}
checks(){
key
if [ ! -d "workspace" ]; then
mkdir workspace
fi
if [ "$CMD" == "unpack" ] && [ ! -f "$BOOTIMG" ]; then
echo -e "${BOLD_RED}[x] Couldn't find the provided Boot image '${BOOTIMG}' !${RESET}\n"
fi
if [ ! "$CMD" == "unpack" ] && [ ! "$CMD" == "repack" ]; then
echo -e "${BOLD_RED}[x] Invalid Command Specified '${CMD}' !${RESET}\n"
exit 1
fi
}
clean(){
rm -rf "$DIR/workspace"
rm "$DIR/res/.tmp"
rm "$DIR/res/.tmp1"
}
unpack(){
rm -rf "$DIR/workspace/*"
echo -e "${BOLD_GREEN}[i] Unpacking ${BOOTIMG}...${RESET}\n"
echo "$DIR/${BOOTIMG}" > "$DIR/res/.tmp"
cp "$DIR/${BOOTIMG}" "$DIR/workspace" ; cd "$DIR/workspace"
$MAGISKBOOT unpack "$BOOTIMG"
if [ -f "ramdisk.cpio" ]; then
RAMDISK=1
$MAGISKBOOT cpio ramdisk.cpio extract
fi
cd "$DIR"
echo -e "\n${BOLD_GREEN}[i] Unpacking Done..! ${RESET}\n"
}
sign(){
echo -e "\n${BOLD_YELLOW}[+] Signing New Boot image...${RESET}\n"
python3 "$AVBTOOL" extract_public_key --key "$DIR/res/key/sign.pem" --output "$DIR/res/key/sign.pub.bin"
python3 "$AVBTOOL" add_hash_footer --partition_name boot --partition_size $(wc -c new-boot.img |cut -f 1 -d ' ') --image new-boot.img --key "$DIR/res/key/sign.pem" --algorithm SHA256_RSA4096
}
repack(){
echo -e "${BOLD_GREEN}[i] Repacking ${BOOTIMG}...${RESET}\n"
cd "$DIR/workspace"
$MAGISKBOOT repack "$(cat $DIR/res/.tmp)" new-boot.img
sign
mv new-boot.img "../$(cat $DIR/res/.tmp1)-new(signed).img"
cd $DIR
echo -e "\n${BOLD_GREEN}[i] Repacking Done..! ${RESET}\n"
echo -e "\n${BOLD_BLUE}[i] Output : $(cat $DIR/res/.tmp1)-new(signed).img ${RESET}\n"
clean
}
run(){
if [ "$CMD" == "unpack" ]; then
unpack
fi
if [ "$CMD" == "repack" ]; then
repack
fi
}
banner
requirements
usage
checks
run