-
Notifications
You must be signed in to change notification settings - Fork 5
/
aik_mHideGP.sh
executable file
·289 lines (247 loc) · 6.76 KB
/
aik_mHideGP.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
#!/bin/bash
# Pull prop settings from image files using AIK
# ipdev @ xda-developers
# Originally (and still) written to grab needed/useful props for use with MagiskHide Props Config module
# by Didgeridoohan @ xda-developers
# https://forum.xda-developers.com/apps/magisk/module-magiskhide-props-config-t3789228
# To pull props from a boot or recovery image file requires unpacking the image.
# This script relies on Android Image Kitchen (AIK)
# by osm0sis @ xda-developers
# https://forum.xda-developers.com/showthread.php?t=2073775
# To use.
# Install AIK
# Copy the boot and/or recovery image file(s) into the AIK directory
# Copy aik_mHideGP.sh and mHideGP.sh into the AIK directory
# Copy extra prop files into the AIK directory (optional) (See Update Note below.)
# Run aik_mHideGP.sh
#
# This will run the unpack and mHideGP scripts on all image files in the directory.
# Merge the generated mhp files into mHide-printslist-DATE.sh.
# Remove all the generated mph files.
# If used with another method, make sure to make changes in the script(s) accordingly.
# Update Note.
# This script now supports additional prop files.
# It will also look for files ending in: build.prop default.prop prop.default or getprop.props
# in the same (AIK) directory.
#
# Set variables
TDIR=$(pwd)
DATE=$(date '+%Y%m%d')
# DATE=$(date '+%Y%m%d_%H%M')
OUT=mHide-printslist-"$DATE".sh
SCRIPT=aik_mHideGP.sh
# Set functions
add_notes() {
echo "\"" >> $OUT
echo "######" >> $OUT
echo "## The above \" was added to close custom printslist list early." >> $OUT
echo "## Just to clean it up a little. Lines below will not display on screen." >> $OUT
echo "## Due to updates in Magisk and/or mHide module." >> $OUT
echo "## The rest of the file is now block commented to hide/clean it up further." >> $OUT
echo "######" >> $OUT
}
backup() {
if [ -f "$OUT" ]; then
FLTM=$(date -r "$OUT" '+%H%M')
BACKUPFILE=$(printf "$OUT" | sed 's/.sh/.'"$FLTM"'/g')
mv "$OUT" "$BACKUPFILE"
fi
}
check_files() {
echo ""
if [ ! -f mHideGP.sh ]; then
echo " Missing mHideGP script."
echo ""
exit 1;
elif [ ! -f cleanup.sh ]; then
echo " Missing AIK cleanup script."
echo ""
exit 1;
elif [ ! -f unpackimg.sh ]; then
echo " Missing AIK unpackimg script."
echo ""
exit 1;
fi
}
concat_mhp_files() {
# Add mHide fingerprint from the mhp files(s) to $OUT file.
for mPrint in mhp_*.sh; do
cat $mPrint | sed '1!d' >> "$OUT";
done;
# Add a few notes to $OUT file.
add_notes
# Add all the rest of the device props from the mhp file(s) to the $OUT file.
for dProps in mhp_*.sh; do
cat $dProps | sed '/#/!d' | sed '/##/d' >> "$OUT";
done;
}
exit_0() {
if [ $ANDROID = "TRUE" ]; then
return 0; exit 0;
else
exit 0;
fi
}
exit_1() {
if [ $ANDROID = "TRUE" ]; then
return 1; exit 1;
else
exit 1;
fi
}
rename_prop_files() {
if [ -f build.prop ]; then
FLDT=$(date -r build.prop '+%Y%m%d')
mv build.prop "$FLDT"_build.prop
fi
if [ -f prop.default ]; then
FLDT=$(date -r prop.default '+%Y%m%d')
mv prop.default "$FLDT"_prop.default
fi
if [ -f default.prop ]; then
FLDT=$(date -r default.prop '+%Y%m%d')
mv default.prop "$FLDT"_default.prop
fi
if [ -f getprop.props ]; then
FLDT=$(date -r getprop.props '+%Y%m%d')
mv getprop.props "$FLDT"_getprop.props
fi
}
set_target_directory() {
if [ ! -f "$SCRIPT" ]; then
TDIR=$(lsof 2>/dev/null | grep -o '[^ ]*$' | grep -m1 "$SCRIPT" | sed 's/\/'"$SCRIPT"'//g');
cd $TDIR;
fi
}
# Determine if running on an Android device or MacOS/Linux.
if [ -f /system/bin/sh ] || [ -f /system/bin/toybox ] || [ -f /system/bin/toolbox ]; then
# Android device
ANDROID=TRUE
else
# MacOS/Linux
ANDROID=FALSE
fi
# Reset and move to the target directory if needed.
set_target_directory
# Check for required files.
check_files
# Rename additional prop files if needed.
rename_prop_files
# Start clean
"$TDIR"/cleanup.sh > /dev/null
# # Extra echo just to clean up screen output.
# echo ""
# Unpack and run mHideGP on all image files in the current directory.
if [ $ANDROID = "TRUE" ]; then
# echo "-- Image Files. --"; echo "";
for image in *.img; do
{
echo "$image"
"$TDIR"/unpackimg.sh "$image" > /dev/null
if [ -f ramdisk/prop.default ] || [ -f ramdisk/default.prop ]; then
sh "$TDIR"/mHideGP.sh > /dev/null
elif [ ! -d ramdisk ]; then
echo " No ramdisk directory found. "
else
echo " No prop file found. "
fi;
"$TDIR"/cleanup.sh > /dev/null
}
done
fi
if [ $ANDROID = "FALSE" ]; then
# echo "-- Image Files. --"; echo "";
for image in *.img; do
{
echo "$image"
"$TDIR"/unpackimg.sh "$image" > /dev/null 2>&1
if [ -f ramdisk/prop.default ] || [ -f ramdisk/default.prop ]; then
"$TDIR"/mHideGP.sh > /dev/null
elif [ ! -d ramdisk ]; then
echo " No ramdisk directory found. "
else
echo " No prop file found. "
fi;
"$TDIR"/cleanup.sh > /dev/null
}
done
fi
# Run mHideGP on additional prop files in the current directory.
AdditionalPropFile=('build.prop' 'default.prop' 'prop.default' 'getprop.props')
if [ $ANDROID = "TRUE" ]; then
# echo ""; echo "-- Additional Prop Files. --"; echo "";
for pfile in "${AdditionalPropFile[@]}"; do
{
for propfile in *"$pfile"; do
{
if [ -f "$propfile" ]; then
echo "$propfile"
mv "$propfile" "$pfile"
sh "$TDIR"/mHideGP.sh > /dev/null
if [ -f "$pfile" ]; then
mv "$pfile" "$propfile"
fi;
fi;
}
done;
}
done;
fi;
if [ $ANDROID = "FALSE" ]; then
# echo ""; echo "-- Additional Prop Files. --"; echo "";
for pfile in "${AdditionalPropFile[@]}"; do
{
for propfile in *"$pfile"; do
{
if [ -f "$propfile" ]; then
echo "$propfile"
mv "$propfile" "$pfile"
"$TDIR"/mHideGP.sh > /dev/null
if [ -f "$pfile" ]; then
mv "$pfile" "$propfile"
fi;
fi;
}
done;
}
done;
fi;
# Backup if needed
backup
# Concatenate (Merge multiple files into a new file.)
## The output file is written in order of the mhp file name(s).
## The mHideGP script will hopefully name them in the correct order.
[[ -n $(find -maxdepth 1 -name 'mhp_*.sh') ]] && concat_mhp_files;
# Cleanup
# (Not sure if I like the echo clutter. Removed for now.)
## echo ""; echo "Removing the separate mhp file(s).";
for file in mhp_*.sh; do
{
## echo $file
rm $file 2>/dev/null
}
done
# Note backup
if [ -f "$BACKUPFILE" ]; then
echo ""; echo "Your previous "$OUT" file was renamed to "$BACKUPFILE"";
fi
# Correct permissions if needed
for file in mhc_*; do
chmod 0664 $file 2>/dev/null
done;
for file in mhp_*; do
chmod 0664 $file 2>/dev/null
done;
for file in mHide-*; do
chmod 0664 $file 2>/dev/null
done;
for file in *.img; do
chmod 0664 $file 2>/dev/null
done;
# Finish script
if [ -f "$OUT" ]; then
echo ""; echo "New mHide-printslist file saved as "$OUT"";
fi;
echo ""; echo "Done."; echo "";
#
exit_0;