Skip to content

Commit d197a05

Browse files
committed
try to automate the patching process even further
1 parent ea40372 commit d197a05

File tree

4 files changed

+112
-81
lines changed

4 files changed

+112
-81
lines changed

root-module-manual/server.py

Lines changed: 21 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -281,89 +281,29 @@ def patch():
281281
logger.error(f"Error patching file: {str(e)}")
282282
return jsonify({"error": f"Error patching file: {str(e)}"}), 500
283283

284-
# Create permalink
285-
permalink_id = str(uuid.uuid4())
286-
PATCHED_LIBRARIES[permalink_id] = {
287-
'file_path': file_path,
288-
'library_name': library_name,
289-
'timestamp': time.time()
290-
}
291-
292-
# Save patch info
293-
save_patch_info(permalink_id, file_path)
294-
295-
# Schedule deletion
296-
threading.Timer(PERMALINK_EXPIRY, delete_expired_permalink, args=[permalink_id]).start()
297-
logger.info(f"Permalink {permalink_id} created, will expire in {PERMALINK_EXPIRY} seconds")
298-
299-
return jsonify({'permalink': f'/download/{permalink_id}'})
300-
301-
@app.route('/api', methods=['POST'])
302-
def api():
303-
if 'file' not in request.files:
304-
return jsonify({"error": "No file part"}), 400
305-
file = request.files['file']
306-
if file.filename == '':
307-
return jsonify({"error": "No selected file"}), 400
308-
if not file.filename.endswith('.so'):
309-
return jsonify({"error": "Invalid file type. Only .so files are allowed."}), 400
310-
311-
# Generate a unique file path
312-
file_uuid = str(uuid.uuid4())
313-
file_path = os.path.join('uploads', f"{file_uuid}_{file.filename}")
314-
file.save(file_path)
315-
316-
# Determine the library name based on the request data
317-
data = request.form
318-
library_name = data.get('library_name', 'libbluetooth_jni.so')
319-
320-
# Patch the file
321-
try:
322-
l2c_fcr_chk_chan_modes_address = get_symbol_address(file_path, "l2c_fcr_chk_chan_modes")
323-
patch_address(file_path, l2c_fcr_chk_chan_modes_address, "20008052c0035fd6")
324-
l2cu_send_peer_info_req_address = get_symbol_address(file_path, "l2cu_send_peer_info_req")
325-
patch_address(file_path, l2cu_send_peer_info_req_address, "c0035fd6")
326-
except Exception as e:
327-
logger.error(f"Error patching file: {str(e)}")
328-
return jsonify({"error": f"Error patching file: {str(e)}"}), 500
329-
330-
# Create permalink
331-
permalink_id = str(uuid.uuid4())
332-
PATCHED_LIBRARIES[permalink_id] = {
333-
'file_path': file_path,
334-
'library_name': library_name,
335-
'timestamp': time.time()
336-
}
337-
338-
# Save patch info
339-
save_patch_info(permalink_id, file_path)
340-
341-
# Schedule deletion
342-
threading.Timer(PERMALINK_EXPIRY, delete_expired_permalink, args=[permalink_id]).start()
343-
logger.info(f"Permalink {permalink_id} created, will expire in {PERMALINK_EXPIRY} seconds")
344-
345-
return jsonify({'permalink': f'/download/{permalink_id}'})
346-
347-
@app.route('/download/<permalink_id>', methods=['GET'])
348-
def download(permalink_id):
349-
if permalink_id not in PATCHED_LIBRARIES:
350-
return "Permalink expired or invalid", 404
351-
352-
file_path = PATCHED_LIBRARIES[permalink_id]['file_path']
353-
library_name = PATCHED_LIBRARIES[permalink_id]['library_name']
354-
if not os.path.exists(file_path):
355-
return "File not found", 404
356-
284+
# Send the patched file directly
357285
try:
358-
copy_file_to_src(file_path, library_name)
359-
zip_src_files()
286+
return send_file(
287+
file_path,
288+
mimetype='application/octet-stream',
289+
as_attachment=True,
290+
attachment_filename=f"patched_{library_name}"
291+
)
360292
except Exception as e:
361-
logger.error(f"Error preparing download: {str(e)}")
362-
return f"Error preparing download: {str(e)}", 500
363-
364-
resp = make_response(send_file('btl2capfix.zip', as_attachment=True))
365-
resp.headers['Content-Disposition'] = f'attachment; filename=btl2capfix.zip'
366-
return resp
293+
logger.error(f"Error sending patched file: {str(e)}")
294+
return jsonify({"error": f"Error sending patched file: {str(e)}"}), 500
295+
296+
# Remove or comment out the '/download/<permalink_id>' route as it's no longer needed
297+
# @app.route('/download/<permalink_id>', methods=['GET'])
298+
# def download(permalink_id):
299+
# # ...existing code...
300+
# pass
301+
302+
# Remove the '/api' endpoint if it's redundant
303+
# @app.route('/api', methods=['POST'])
304+
# def api():
305+
# # ...existing code...
306+
# pass
367307

368308
def delete_expired_permalink(permalink_id):
369309
if permalink_id in PATCHED_LIBRARIES:

root-module/customize.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/system/bin/sh
2+
3+
4+
# Define variables
5+
API_URL="https://aln.kavishdevar.me/api"
6+
TEMP_DIR="$TMPDIR/aln_patch"
7+
PATCHED_FILE_NAME=""
8+
SOURCE_FILE=""
9+
LIBRARY_NAME="" # To store the name of the library being patched
10+
11+
# Create temporary directory
12+
mkdir -p "$TEMP_DIR"
13+
14+
# Function to log messages
15+
log() {
16+
echo "[ALN Patch] $1"
17+
}
18+
19+
# Identify the library type
20+
if [ -f "/apex/com.android.btservices/lib64/libbluetooth_jni.so" ]; then
21+
SOURCE_FILE="/apex/com.android.btservices/lib64/libbluetooth_jni.so"
22+
LIBRARY_NAME="libbluetooth_jni.so"
23+
PATCHED_FILE_NAME="libbluetooth_jni_patched.so"
24+
log "Detected Qualcomm library: libbluetooth_jni.so in /apex/com.android.btservices/lib64/"
25+
elif [ -f "/system/lib64/libbluetooth_jni.so" ]; then
26+
SOURCE_FILE="/system/lib64/libbluetooth_jni.so"
27+
LIBRARY_NAME="libbluetooth_jni.so"
28+
PATCHED_FILE_NAME="libbluetooth_jni_patched.so"
29+
log "Detected Qualcomm library: libbluetooth_jni.so in /system/lib64/"
30+
elif [ -f "/system/lib64/libbluetooth_qti.so" ]; then
31+
SOURCE_FILE="/system/lib64/libbluetooth_qti.so"
32+
LIBRARY_NAME="libbluetooth_qti.so"
33+
PATCHED_FILE_NAME="libbluetooth_qti_patched.so"
34+
log "Detected QTI library: libbluetooth_qti.so in /system/lib64/"
35+
elif [ -f "/system_ext/lib64/libbluetooth_qti.so" ]; then
36+
SOURCE_FILE="/system_ext/lib64/libbluetooth_qti.so"
37+
LIBRARY_NAME="libbluetooth_qti.so"
38+
PATCHED_FILE_NAME="libbluetooth_qti_patched.so"
39+
log "Detected QTI library: libbluetooth_qti.so in /system_ext/lib64/"
40+
else
41+
log "No target library found. Exiting."
42+
exit 1
43+
fi
44+
45+
# Upload the library to the API
46+
log "Uploading $LIBRARY_NAME to the API for patching..."
47+
RESPONSE=$(curl -s -X POST "$API_URL" \
48+
-F "file=@$SOURCE_FILE" \
49+
-F "qti=$( [ "$LIBRARY_NAME" = "libbluetooth_qti.so" ] && echo "1" || echo "0")")
50+
51+
# Check if the response is a file (patched .so)
52+
if echo "$RESPONSE" | grep -q "Content-Disposition"; then
53+
# Extract the patched .so file name from Content-Disposition header
54+
PATCHED_FILE_NAME="patched_$LIBRARY_NAME"
55+
log "Received patched file from the API."
56+
57+
# Save the patched .so file
58+
echo "$RESPONSE" > "$TEMP_DIR/$PATCHED_FILE_NAME"
59+
# Note: Depending on how the server sends the file, you might need to handle binary data appropriately.
60+
61+
# Move the patched file to the module's directory
62+
log "Installing patched file to the module's directory..."
63+
mkdir -p "$MODPATH/system/lib/"
64+
cp "$TEMP_DIR/$PATCHED_FILE_NAME" "$MODPATH/system/lib/"
65+
66+
# Set permissions
67+
chmod 644 "$MODPATH/system/lib/$PATCHED_FILE_NAME"
68+
69+
log "Patched file has been successfully installed at $MODPATH/system/lib/$PATCHED_FILE_NAME"
70+
else
71+
# Assume JSON response with error
72+
ERROR_MESSAGE=$(echo "$RESPONSE" | grep -oP '(?<="error": ")[^"]+')
73+
log "API Error: $ERROR_MESSAGE"
74+
rm -rf "$TEMP_DIR"
75+
exit 1
76+
fi
77+
78+
# Cleanup
79+
rm -rf "$TEMP_DIR"
80+
81+
exit 0

root-module/module.prop

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
id=btl2capfix
2+
name=Bluetooth L2CAP workaround for AirPods
3+
version=v1
4+
versionCode=1
5+
author=kavishdevar
6+
description=Fixes the Bluetooth L2CAP connection issue with AirPods

root-module/post-data-fs.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/system/bin/sh
2+
3+
mount -t overlay overlay -o lowerdir=/apex/com.android.btservices/lib64,upperdir=/data/adb/modules/btl2capfix/apex/com.android.btservices/lib64,workdir=/data/adb/modules/btl2capfix/apex/com.android.btservices/work /apex/com.android.btservices/lib64
4+
mount -t overlay overlay -o lowerdir=/apex/com.android.btservices@352090000/lib64,upperdir=/data/adb/modules/btl2capfix/apex/com.android.btservices@352090000/lib64,workdir=/data/adb/modules/btl2capfix/apex/com.android.btservices@352090000/work /apex/com.android.btservices@352090000/lib64

0 commit comments

Comments
 (0)