-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisable.sh
373 lines (349 loc) · 11.7 KB
/
disable.sh
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
# Run Functions and Get Variables
## Variables
MODPATH="${0%/*}"
BIN="$MODPATH/system/bin"
STOCK="/system/framework"
MOD="$MODPATH/system/framework"
DB="/data/#SFS"
TMPDIR="$DB"/TMP
mkdir -p "$TMPDIR"
disable='
.locals 1
const/4 v0, 0x0
return v0
'
## Functions
# Print Function
sfs() {
echo "$1"
echo ""
}
# Cleanup Function
clean() {
rm -rf "$MODPATH/disable.sh"
rm -rf "$BIN/aapt"
rm -rf "$BIN/apktool.jar"
rm -rf "$BIN/zip"
rm -rf "$BIN/bash"
rm -rf "$DB"/TMP
}
# Set Default value
setdefault() {
read -r -d '' "$1" <<< "$2"
}
# Save State
savestate() {
setdefault "$1" "$(md5sum "$2")"
}
# Set Permissions
set_perm() {
chown "$1:$2" "$4"
chmod "$3" "$4"
}
# Function to edit Smali Files
smali_kit() {
#Smali Tool kit for Dynamic Installer by BlassGO
local dir num line liner old new count=0 restore load try log
local file path method replace limit rim newline oldline check stock edit smaliname remake
local get al al_add bl bl_add staticname dim dim_oldline
local restore flag
restore=()
while [[ $# -gt 0 ]]; do
flag="$1"
case $flag in
-f|-file)
file="$2"
shift 2
;;
-d|-dir)
path="$2"
shift 2
;;
-m|-method)
method="$2"
shift 2
;;
-r|-replace)
replace="$2"
shift 2
;;
-rim|-replace-in-method)
rim=true
oldline="$2"
newline="$3"
shift 3
;;
-dim|-delete-in-method)
dim=true
dim_oldline="$2"
shift 2
;;
-re|-remake)
remake="$2"
shift 2
;;
-al|-after-line)
al="$2"
al_add="$3"
shift 3
;;
-bl|-before-line)
bl="$2"
bl_add="$3"
shift 3
;;
-c|-check)
check=true
shift
;;
-n|-name)
smaliname="$2"
shift 2
;;
-sn|-static-name)
staticname="$2"
shift 2
;;
-l|-limit)
limit="$2"
shift 2
;;
*)
restore+=("$1")
shift
;;
esac
done
set -- "${restore[@]}"
if [[ -z "$file" && -n "$path" && -n "$method" ]]; then
grep -rnw "$path" -e "$method" | while read huh; do
stock=
edit=
dir=$(echo "$huh" | cut -f1 -d:)
num=$(echo "$huh" | cut -f2 -d:)
liner=$(echo "$huh" | cut -f3 -d:)
if [[ "$liner" == *".method"* ]]; then
if [[ -n "$staticname" && "$(basename "$dir")" != "$staticname" ]]; then continue; fi
if [[ -n "$smaliname" && "$(basename "$dir")" != *"$smaliname"* ]]; then continue; fi
line=$(echo "$liner" | sed -e 's/[]\/$*.^[]/\\&/g')
savestate stock "$dir"
if [[ -z "$replace" && -z "$rim" && -z "$remake" && -z "$al" && -z "$bl" && -z "$dim" ]]; then
echo "path="$dir""
sed -n "/$line/,/\.end method/p" "$dir"
fi
if [ -n "$replace" ]; then
load=$(cat "$dir")
old=$(sed -n "/$line/,/\.end method/p" "$dir")
echo "${load/$old/$replace}" > "$dir"
fi
if [[ -n "$rim" && -n "$oldline" && -n "$newline" ]]; then
old=$(sed -n "/$line/,/\.end method/p" "$dir")
try=$(echo "${old/$oldline/$newline}")
load=$(cat "$dir")
echo "${load/$old/$try}" > "$dir"
fi
if [[ -n "$dim" && -n "$dim_oldline" ]]; then
old=$(sed -n "/$line/,/\.end method/p" "$dir")
try=${old//$dim_oldline/}
load=$(cat "$dir")
echo "${load/$old/$try}" > "$dir"
fi
if [ -n "$remake" ]; then
old=$(sed -n "/$line/,/\.end method/p" "$dir")
echo "${liner}" > "$DB/re.tmp"
echo "$remake" >> "$DB/re.tmp"
echo "${n}.end method" >> "$DB/re.tmp"
try=$(cat "$DB/re.tmp")
rm -f "$DB/re.tmp" 2>/dev/null
load=$(cat "$dir")
echo "${load/$old/$try}" > "$dir"
fi
if [[ -n "$bl" && -n "$bl_add" ]]; then
old=$(sed -n "/$line/,/\.end method/p" "$dir")
echo "$bl_add" > "$DB/bl.tmp"
get=$(sed '$!s/$/\\/' $DB/bl.tmp)
rm -f $DB/bl.tmp
try=$(echo "$old" | sed "/$bl/i $get")
load=$(cat "$dir")
echo "${load/$old/$try}" > "$dir"
fi
if [[ -n "$al" && -n "$al_add" ]]; then
old=$(sed -n "/$line/,/\.end method/p" "$dir")
echo "$al_add" > "$DB/al.tmp"
get=$(sed '$!s/$/\\/' $DB/al.tmp)
rm -f $DB/al.tmp
try=$(echo "$old" | sed -e "/$al/a $get")
load=$(cat "$dir")
echo "${load/$old/$try}" > "$dir"
fi
savestate edit "$dir"
count=$(( $count + 1 ))
if [ -n "$check" ]; then if [[ "$edit" != "$stock" ]]; then echo "Edited: "$dir""; else echo "Nothing: "$dir""; fi; fi
setprop SMALI "$dir"
if [[ -n "$limit" && "$limit" == "$count" ]]; then break; fi
fi
done
elif [[ -n "$file" && -z "$path" && -n "$method" ]]; then
grep -nw "$file" -e "$method" | while read huh; do
stock=
edit=
num=$(echo "$huh" | cut -f1 -d:)
liner=$(echo "$huh" | cut -f2 -d:)
if [[ "$liner" == *".method"* ]]; then
if [[ -n "$staticname" && "$(basename "$file")" != "$staticname" ]]; then continue; fi
if [[ -n "$smaliname" && "$(basename "$file")" != *"$smaliname"* ]]; then continue; fi
line=$(echo "$liner" | sed -e 's/[]\/$*.^[]/\\&/g')
savestate stock "$file"
if [[ -z "$replace" && -z "$rim" && -z "$remake" && -z "$al" && -z "$bl" ]]; then
echo "path="$dir""
sed -n "/$line/,/\.end method/p" "$file"
fi
if [ -n "$replace" ]; then
load=$(cat "$file")
old=$(sed -n "/$line/,/\.end method/p" "$file")
echo "${load/$old/$replace}" > "$file"
fi
if [[ -n "$rim" && -n "$oldline" && -n "$newline" ]]; then
old=$(sed -n "/$line/,/\.end method/p" "$file")
try=$(echo "${old/$oldline/$newline}")
load=$(cat "$file")
echo "${load/$old/$try}" > "$file"
fi
if [[ -n "$dim" && -n "$dim_oldline" ]]; then
old=$(sed -n "/$line/,/\.end method/p" "$file")
try=${old//$dim_oldline/}
load=$(cat "$file")
echo "${load/$old/$try}" > "$file"
fi
if [ -n "$remake" ]; then
old=$(sed -n "/$line/,/\.end method/p" "$file")
echo "${liner}" > "$DB/re.tmp"
echo "$remake" >> "$DB/re.tmp"
echo "${n}.end method" >> "$DB/re.tmp"
try=$(cat "$DB/re.tmp")
rm -f "$DB/re.tmp" 2>/dev/null
load=$(cat "$file")
echo "${load/$old/$try}" > "$file"
fi
if [[ -n "$bl" && -n "$bl_add" ]]; then
old=$(sed -n "/$line/,/\.end method/p" "$file")
echo "$bl_add" > "$DB/bl.tmp"
get=$(sed '$!s/$/\\/' $DB/bl.tmp)
rm -f $DB/bl.tmp
try=$(echo "$old" | sed "/$bl/i $get")
load=$(cat "$file")
echo "${load/$old/$try}" > "$file"
fi
if [[ -n "$al" && -n "$al_add" ]]; then
old=$(sed -n "/$line/,/\.end method/p" "$file")
echo "$al_add" > "$DB/al.tmp"
get=$(sed '$!s/$/\\/' $DB/al.tmp)
rm -f $DB/al.tmp
try=$(echo "$old" | sed -e "/$al/a $get")
load=$(cat "$file")
echo "${load/$old/$try}" > "$file"
fi
savestate edit "$file"
count=$(( $count + 1 ))
if [ -n "$check" ]; then if [[ "$edit" != "$stock" ]]; then echo "Edited: "$file""; else echo "Nothing: "$file""; fi; fi
if [[ -n "$limit" && "$limit" == "$count" ]]; then break; fi
fi
done
else
echo " smali_kit: Invalid line " && return
fi
}
# Function to run JAR files using dalvikvm
run_jar() {
local dalvikvm file main
#Inspired in the osm0sis method
if dalvikvm -showversion >/dev/null; then
dalvikvm=dalvikvm
elif /system/bin/dalvikvm -showversion >/dev/null; then
dalvikvm=/system/bin/dalvikvm
else
echo "CANT LOAD DALVIKVM " && return
fi
file="$1"
unzip -o "$file" "META-INF/MANIFEST.MF" -p > "/data/main.tmp"
main=$(cat /data/main.tmp | grep -m1 "^Main-Class:" | cut -f2 -d: | tr -d " " | dos2unix)
rm -f /data/main.tmp
if [ -z "$main" ]; then
echo "Cant get main: $file " && return
fi
shift 1
$dalvikvm -Djava.io.tmpdir=. -Xnodex2oat -Xnoimage-dex2oat -cp "$file" $main "$@" 2>/dev/null \ || $dalvikvm -Djava.io.tmpdir=. -Xnoimage-dex2oat -cp "$file" $main "$@"
}
# Function to Run apktool.jar using run_jar
apktool() {
cp -f /system/framework/framework-res.apk "$TMPDIR"/1.apk
run_jar "$BIN"/apktool.jar --aapt "$BIN"/aapt -p "$TMPDIR" "$@"
}
# Check for Deodex Services.jar
if ! unzip -l "$STOCK"/services.jar | grep classes.dex >/dev/null; then
sfs " ❎ - You need a deodexed services.jar"
exit 1
fi
# Installation Begin
echo ""
sfs " ⚡ Simple Flag Secure ⚡"
sfs " ✨ For Magisk, KSU and APatch"
sfs " ✅ By @ShastikXD"
# Check if Module Already used once
if [ -f "$DB/services.jar" ]; then
sfs " 💾 - Found A Backup, Using it for Faster Installation"
mkdir -p "$MOD"
cp -af "$DB/services.jar" "$MOD/services.jar"
sfs " ✨ - Installation Done Reboot Now"
else
# Make Framework Dir
mkdir -p "$MOD"
sfs " ⚡ - This will take 2-3 mins for the first time flashing"
sfs " ⚡ - Flashing again this module on same rom will be faster. "
# Decompiling with apktool
sfs " 👾 - Decompiling services.jar"
apktool d "$STOCK"/services.jar -o "$TMPDIR/services"
# Apply smali patches
echo ""
sfs " 🧩 - Patching Smali Files"
smali_kit -c -m "isSecureLocked" -re "$disable" -d "$TMPDIR/services"
smali_kit -c -m "preventTakingScreenshotToTargetWindow" -re "$disable" -d "$TMPDIR/services"
# Recompiling with apktool
echo ""
sfs " 👾 - Recompiling services.jar"
apktool b "$TMPDIR/services" -o "$MOD/services.jar"
# Check for Smali Dir which is edited
echo ""
sfs " 🖇️ - Replacing Modified Dex File Only"
Smali="$(getprop SMALI)"
# Loop less then 20 times to get Smali Dir Name
cnt=1
while [[ "$cnt" -lt 20 && "$(basename "$Smali")" != "smali" && "$(basename "$Smali")" != "smali_classes2" && "$(basename "$Smali")" != "smali_classes3" && "$(basename "$Smali")" != "smali_classes4" && "$(basename "$Smali")" != "smali_classes5" ]]; do
Smali=$(dirname "$Smali")
cnt=$((cnt + 1))
done
# Check if Smali dir exist
if [ "$cnt" -lt 20 ]; then
Smali=$(basename "$Smali")
# If Smali Dir exists, change classes.dex according to Smali dir
if [[ "$(basename "$Smali")" == "smali" ]]; then
Class="classes.dex"
else
suffix=$(echo "$Smali" | sed 's/smali_classes//')
Class="classes${suffix}.dex"
fi
# Change Only Modified classes.dex file, keep rest untouched
mkdir -p "$TMPDIR/ORG"
mkdir -p "$TMPDIR/MOD"
unzip -o "$STOCK"/services.jar -d "$TMPDIR/ORG" >> /dev/null;
unzip -o "$MOD/services.jar" -d "$TMPDIR/MOD" >> /dev/null;
cp -af "$TMPDIR/MOD/$Class" "$TMPDIR/ORG/$Class"
cd "$TMPDIR/ORG"
# Recompress services.jar to avoid breaking anything
$BIN/zip -r "$MOD"/services.jar . >> /dev/null;
sfs " 🔗 - Compressing Services JAR"
cp -af "$MOD/services.jar" "$DB/services.jar"
fi
clean
sfs " ✨ - Installation Done Reboot Now"
fi