Skip to content

Commit b1ef207

Browse files
committed
[WIP] On-device patcher with Magisk module
Almost there but just need to fix this error: ``` WARN: Cannot find asm.parser for arm.pseudo INFO: Fallback to null ```
1 parent 39f0ae7 commit b1ef207

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+50
-30
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
root-module/btl2capfix.zip
2+
13
.vscode
24
testing.py
35
.DS_Store

build-magisk-module.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
set -eux
4+
5+
(cd root-module && rm -f btl2capfix.zip && zip -r btl2capfix.zip . -x \*.DS_Store \*__MACOSX \*DEBIAN -x btl2capfix.zip)

root-module/customize.sh

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#!/system/bin/sh
22

3-
API_URL="https://aln.kavishdevar.me/api"
43
TEMP_DIR="$TMPDIR/aln_patch"
54
UNZIP_DIR="/data/local/tmp/aln_unzip"
6-
PATCHED_FILE_NAME=""
75
SOURCE_FILE=""
86
LIBRARY_NAME=""
97
APEX_DIR=false
@@ -26,58 +24,73 @@ if [ "$(uname -m)" = "aarch64" ]; then
2624
fi
2725

2826
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"
27+
export LD_LIBRARY_PATH="$UNZIP_DIR/radare2-android/libs/arm64-v8a"
28+
export PATH="$UNZIP_DIR/radare2-android/bin/arm64-v8a:$PATH"
29+
export RABIN2="$UNZIP_DIR/radare2-android/bin/arm64-v8a/rabin2"
30+
export RADARE2="$UNZIP_DIR/radare2-android/bin/arm64-v8a/radare2"
3331
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"
32+
export LD_LIBRARY_PATH="$UNZIP_DIR/radare2-android/libs/armeabi-v7a"
33+
export PATH="$UNZIP_DIR/radare2-android/bin/armeabi-v7a:$PATH"
34+
export RABIN2="$UNZIP_DIR/radare2-android/bin/armeabi-v7a/rabin2"
35+
export RADARE2="$UNZIP_DIR/radare2-android/bin/armeabi-v7a/radare2"
3836
fi
3937

40-
set_perm "$CURL_CMD" 0 0 755
38+
set_perm "$RABIN2" 0 0 755
39+
set_perm "$RADARE2" 0 0 755
4140

42-
if [ -f "$CURL_CMD" ]; then
43-
ui_print "curl binary is ready."
41+
if [ -f "$RABIN2" ]; then
42+
ui_print "rabin2 binary is ready."
4443
else
45-
ui_print "Error: curl binary not found."
46-
abort "curl binary not found."
44+
ui_print "Error: rabin2 binary not found."
45+
abort "rabin2 binary not found."
46+
fi
47+
48+
if [ -f "$RADARE2" ]; then
49+
ui_print "radare2 binary is ready."
50+
else
51+
ui_print "Error: radare2 binary not found."
52+
abort "radare2 binary not found."
4753
fi
4854

4955
if [ -f "/apex/com.android.btservices/lib64/libbluetooth_jni.so" ]; then
5056
SOURCE_FILE="/apex/com.android.btservices/lib64/libbluetooth_jni.so"
5157
LIBRARY_NAME="libbluetooth_jni.so"
52-
PATCHED_FILE_NAME="libbluetooth_jni_patched.so"
5358
ui_print "Detected library: libbluetooth_jni.so"
5459
elif [ -f "/system/lib64/libbluetooth_jni.so" ]; then
5560
SOURCE_FILE="/system/lib64/libbluetooth_jni.so"
5661
LIBRARY_NAME="libbluetooth_jni.so"
57-
PATCHED_FILE_NAME="libbluetooth_jni_patched.so"
5862
ui_print "Detected library: libbluetooth_jni.so"
5963
elif [ -f "/system/lib64/libbluetooth_qti.so" ]; then
6064
SOURCE_FILE="/system/lib64/libbluetooth_qti.so"
6165
LIBRARY_NAME="libbluetooth_qti.so"
62-
PATCHED_FILE_NAME="libbluetooth_qti_patched.so"
6366
ui_print "Detected QTI library: libbluetooth_qti.so"
6467
elif [ -f "/system_ext/lib64/libbluetooth_qti.so" ]; then
6568
SOURCE_FILE="/system_ext/lib64/libbluetooth_qti.so"
6669
LIBRARY_NAME="libbluetooth_qti.so"
67-
PATCHED_FILE_NAME="libbluetooth_qti_patched.so"
6870
ui_print "Detected QTI library: libbluetooth_qti.so"
6971
else
7072
ui_print "Error: No target library found."
7173
abort "No target library found."
7274
fi
7375

74-
ui_print "Uploading $LIBRARY_NAME for patching..."
75-
PATCHED_FILE_NAME="patched_$LIBRARY_NAME"
76+
ui_print "Calculating patch addresses for $LIBRARY_NAME..."
77+
78+
exec 2> >(while read -r line; do ui_print "[E] $line"; done)
79+
80+
export l2c_fcr_chk_chan_modes_address="$($RABIN2 -q -E \"$SOURCE_FILE\" | grep l2c_fcr_chk_chan_modes | cut -d ' ' -f1 | tr -d \"\n\")"
81+
export l2cu_send_peer_info_req_address="$($RABIN2 -q -E \"$SOURCE_FILE\" | grep l2cu_send_peer_info_req | cut -d ' ' -f1 | tr -d \"\n\")"
82+
83+
ui_print "Found l2c_fcr_chk_chan_modes_address=$l2c_fcr_chk_chan_modes_address"
84+
ui_print "Found l2cu_send_peer_info_req_address=$l2cu_send_peer_info_req_address"
85+
86+
cp "$SOURCE_FILE" "$TEMP_DIR"
87+
88+
ui_print "Patching $LIBRARY_NAME..."
7689

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
90+
$RADARE2 -q -w -c "s $l2c_fcr_chk_chan_modes_address; wx 20008052c0035fd6; wci" "$TEMP_DIR/$LIBRARY_NAME"
91+
$RADARE2 -q -w -c "s $l2cu_send_peer_info_req_address; wx c0035fd6; wci" "$TEMP_DIR/$LIBRARY_NAME"
7892

79-
if [ -f "$TEMP_DIR/$PATCHED_FILE_NAME" ]; then
80-
ui_print "Patched file received."
93+
if [ -f "$TEMP_DIR/$LIBRARY_NAME" ]; then
8194
ui_print "Installing patched file..."
8295

8396
if [[ "$SOURCE_FILE" == *"/system/lib64"* ]]; then
@@ -91,7 +104,7 @@ if [ -f "$TEMP_DIR/$PATCHED_FILE_NAME" ]; then
91104

92105
mkdir -p "$TARGET_DIR"
93106

94-
cp "$TEMP_DIR/$PATCHED_FILE_NAME" "$TARGET_DIR/$LIBRARY_NAME"
107+
cp "$TEMP_DIR/$LIBRARY_NAME" "$TARGET_DIR/$LIBRARY_NAME"
95108
set_perm "$TARGET_DIR/$LIBRARY_NAME" 0 0 644
96109
ui_print "Patched file installed at $TARGET_DIR/$LIBRARY_NAME"
97110

@@ -104,7 +117,7 @@ if [ -f "$TEMP_DIR/$PATCHED_FILE_NAME" ]; then
104117
mkdir -p "$MOD_APEX_LIB_DIR"
105118
mkdir -p "$WORK_DIR"
106119

107-
cp "$TEMP_DIR/$PATCHED_FILE_NAME" "$MOD_APEX_LIB_DIR/$LIBRARY_NAME"
120+
cp "$TEMP_DIR/$LIBRARY_NAME" "$MOD_APEX_LIB_DIR/$LIBRARY_NAME"
108121
set_perm "$MOD_APEX_LIB_DIR/$LIBRARY_NAME" 0 0 644
109122

110123
cat <<EOF > "$POST_DATA_FS_SCRIPT"
@@ -116,11 +129,11 @@ EOF
116129
ui_print "Created script for apex library handling."
117130
fi
118131
else
119-
ui_print "Error: Failed to receive patched file."
132+
ui_print "Error: patched file missing."
120133
rm -rf "$TEMP_DIR"
121134
abort "Failed to patch the library."
122135
fi
123136

124-
rm -rf "$TEMP_DIR"
125-
rm -rf "$UNZIP_DIR"
126-
rm -rf "$MODPATH/libcurl-android"
137+
# rm -rf "$TEMP_DIR"
138+
# rm -rf "$UNZIP_DIR"
139+
# rm -rf "$MODPATH/radare2-android"
1.71 MB
Binary file not shown.
1.24 MB
Binary file not shown.
16.1 KB
Binary file not shown.
9.1 KB
Binary file not shown.
16.1 KB
Binary file not shown.
9.09 KB
Binary file not shown.
157 KB
Binary file not shown.

0 commit comments

Comments
 (0)