22
33API_URL=" https://aln.kavishdevar.me/api"
44TEMP_DIR=" $TMPDIR /aln_patch"
5- UNZIP_DIR=" /data/local/tmp/aln_unzip"
65PATCHED_FILE_NAME=" "
76SOURCE_FILE=" "
87LIBRARY_NAME=" "
98APEX_DIR=false
109
1110mkdir -p " $TEMP_DIR "
12- mkdir -p " $UNZIP_DIR "
13-
14- # Manually extract the $ZIPFILE to a temporary directory
15- ui_print " Extracting module files..."
16- unzip -o " $ZIPFILE " -d " $UNZIP_DIR " > /dev/null 2>&1
17- if [ $? -ne 0 ]; then
18- ui_print " Error: Failed to extract module files."
19- abort " Failed to unzip $ZIPFILE "
20- fi
21-
22- # Determine architecture
23- IS64BIT=false
24- if [ " $( uname -m) " = " aarch64" ]; then
25- IS64BIT=true
26- fi
2711
28- if [ " $IS64BIT " = true ]; then
29- export LD_LIBRARY_PATH=" $UNZIP_DIR /libcurl-android/libs/arm64-v8a"
30- export PATH=" $UNZIP_DIR /libcurl-android/bin/arm64-v8a:$PATH "
31- export CURL_CMD=" $UNZIP_DIR /libcurl-android/bin/arm64-v8a/curl"
32- ln -s " $UNZIP_DIR /libcurl-android/libs/arm64-v8a/libz.so" " $UNZIP_DIR /libcurl-android/libs/arm64-v8a/libz.so.1"
33- else
34- export LD_LIBRARY_PATH=" $UNZIP_DIR /libcurl-android/libs/armeabi-v7a"
35- export PATH=" $UNZIP_DIR /libcurl-android/bin/armeabi-v7a:$PATH "
36- export CURL_CMD=" $UNZIP_DIR /libcurl-android/bin/armeabi-v7a/curl"
37- ln -s " $UNZIP_DIR /libcurl-android/libs/armeabi-v7a/libz.so" " $UNZIP_DIR /libcurl-android/libs/armeabi-v7a/libz.so.1"
38- fi
39-
40- set_perm " $CURL_CMD " 0 0 755
41-
42- if [ -f " $CURL_CMD " ]; then
43- ui_print " curl binary is ready."
44- else
45- ui_print " Error: curl binary not found."
46- abort " curl binary not found."
47- fi
12+ CURL_CMD=$( command -v curl || echo " $MODPATH /system/bin/curl" )
13+ export LD_LIBRARY_PATH=" $MODPATH /system/lib64:$LD_LIBRARY_PATH "
4814
4915if [ -f " /apex/com.android.btservices/lib64/libbluetooth_jni.so" ]; then
5016 SOURCE_FILE=" /apex/com.android.btservices/lib64/libbluetooth_jni.so"
5117 LIBRARY_NAME=" libbluetooth_jni.so"
5218 PATCHED_FILE_NAME=" libbluetooth_jni_patched.so"
53- ui_print " Detected library: libbluetooth_jni.so"
19+ ui_print " Detected library: libbluetooth_jni.so in /apex/com.android.btservices/lib64/ "
5420elif [ -f " /system/lib64/libbluetooth_jni.so" ]; then
5521 SOURCE_FILE=" /system/lib64/libbluetooth_jni.so"
5622 LIBRARY_NAME=" libbluetooth_jni.so"
5723 PATCHED_FILE_NAME=" libbluetooth_jni_patched.so"
58- ui_print " Detected library: libbluetooth_jni.so"
24+ ui_print " Detected library: libbluetooth_jni.so in /system/lib64/ "
5925elif [ -f " /system/lib64/libbluetooth_qti.so" ]; then
6026 SOURCE_FILE=" /system/lib64/libbluetooth_qti.so"
6127 LIBRARY_NAME=" libbluetooth_qti.so"
6228 PATCHED_FILE_NAME=" libbluetooth_qti_patched.so"
63- ui_print " Detected QTI library: libbluetooth_qti.so"
29+ ui_print " Detected QTI library: libbluetooth_qti.so in /system/lib64/ "
6430elif [ -f " /system_ext/lib64/libbluetooth_qti.so" ]; then
6531 SOURCE_FILE=" /system_ext/lib64/libbluetooth_qti.so"
6632 LIBRARY_NAME=" libbluetooth_qti.so"
6733 PATCHED_FILE_NAME=" libbluetooth_qti_patched.so"
68- ui_print " Detected QTI library: libbluetooth_qti.so"
34+ ui_print " Detected QTI library: libbluetooth_qti.so in /system_ext/lib64/ "
6935else
70- ui_print " Error: No target library found."
36+ ui_print " No target library found. Exiting ."
7137 abort " No target library found."
7238fi
7339
74- ui_print " Uploading $LIBRARY_NAME for patching..."
40+ ui_print " Uploading $LIBRARY_NAME to the API for patching..."
41+ ui_print " If you're concerned about privacy, review the source code of the API at https://github.com/kavishdevar/aln/blob/main/root-module-manual/server.py"
7542PATCHED_FILE_NAME=" patched_$LIBRARY_NAME "
7643
77- $CURL_CMD -k -X POST $API_URL -F file=@" $SOURCE_FILE " -F library_name=" $LIBRARY_NAME " -o " $TEMP_DIR /$PATCHED_FILE_NAME " > " $TEMP_DIR /headers.txt" 2>&1
44+ $CURL_CMD -s -X POST " $API_URL " \
45+ -F " file=@$SOURCE_FILE " \
46+ -F " library_name=$LIBRARY_NAME " \
47+ -o " $TEMP_DIR /$PATCHED_FILE_NAME " \
48+ -D " $TEMP_DIR /headers.txt"
7849
7950if [ -f " $TEMP_DIR /$PATCHED_FILE_NAME " ]; then
80- ui_print " Patched file received ."
81- ui_print " Installing patched file..."
51+ ui_print " Received patched file from the API ."
52+ ui_print " Installing patched file to the module's directory ..."
8253
8354 if [[ " $SOURCE_FILE " == * " /system/lib64" * ]]; then
8455 TARGET_DIR=" $MODPATH /system/lib64"
@@ -113,14 +84,13 @@ mount -t overlay overlay -o lowerdir=$APEX_LIB_DIR,upperdir=$MOD_APEX_LIB_DIR,wo
11384EOF
11485
11586 set_perm " $POST_DATA_FS_SCRIPT " 0 0 755
116- ui_print " Created script for apex library handling."
87+ ui_print " Created post-data-fs.sh script for apex library handling."
11788 fi
11889else
119- ui_print " Error: Failed to receive patched file."
90+ ERROR_MESSAGE=$( grep -oP ' (?<="error": ")[^"]+' " $TEMP_DIR /headers.txt" )
91+ ui_print " API Error: $ERROR_MESSAGE "
12092 rm -rf " $TEMP_DIR "
12193 abort " Failed to patch the library."
12294fi
12395
124- rm -rf " $TEMP_DIR "
125- rm -rf " $UNZIP_DIR "
126- rm -rf " $MODPATH /libcurl-android"
96+ rm -rf " $TEMP_DIR "
0 commit comments