Skip to content

Commit a72cbf1

Browse files
committed
im soo stupid ;-;
1 parent d197a05 commit a72cbf1

File tree

4 files changed

+65
-40
lines changed

4 files changed

+65
-40
lines changed

root-module-manual/main.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -117,22 +117,9 @@ def copy_file_to_src(file_path, library_name):
117117

118118
def zip_src_files():
119119
"""
120-
Zips all files in the 'src/' directory into 'btl2capfix.zip', preserving symlinks without compression.
120+
Zips all files in the 'src/' directory into 'btl2capfix.zip' using the shell zip command.
121121
"""
122-
with zipfile.ZipFile('btl2capfix.zip', 'w', zipfile.ZIP_STORED, allowZip64=True) as zipf:
123-
for root, dirs, files in os.walk('src/'):
124-
for file in files:
125-
file_path = os.path.join(root, file)
126-
if os.path.islink(file_path):
127-
link_target = os.readlink(file_path)
128-
zip_info = zipfile.ZipInfo(os.path.relpath(file_path, 'src/'))
129-
zip_info.create_system = 3 # Unix
130-
zip_info.external_attr = 0o777 << 16
131-
zip_info.external_attr |= 0xA000
132-
zipf.writestr(zip_info, link_target)
133-
else:
134-
zipf.write(file_path, os.path.relpath(file_path, 'src/'))
135-
logging.info("Zipped files under src/ into btl2capfix.zip")
122+
run_command('cd src && zip -r ../btl2capfix *')
136123

137124
def main():
138125
"""

root-module-manual/server.py

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import json
44
import uuid
55
import time
6-
import threading
6+
import shutil
77
import logging
88
from main import get_symbol_address, patch_address, copy_file_to_src, zip_src_files
99

@@ -293,18 +293,59 @@ def patch():
293293
logger.error(f"Error sending patched file: {str(e)}")
294294
return jsonify({"error": f"Error sending patched file: {str(e)}"}), 500
295295

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
296+
@app.route('/api', methods=['POST'])
297+
def api():
298+
if 'file' not in request.files:
299+
return jsonify({"error": "No file part"}), 400
300+
file = request.files['file']
301+
if file.filename == '':
302+
return jsonify({"error": "No selected file"}), 400
303+
if not file.filename.endswith('.so'):
304+
return jsonify({"error": "Invalid file type. Only .so files are allowed."}), 400
305+
306+
# Generate a unique file path
307+
file_uuid = str(uuid.uuid4())
308+
file_path = os.path.join('uploads', f"{file_uuid}_{file.filename}")
309+
file.save(file_path)
310+
311+
# Determine the library name based on the request data
312+
data = request.form
313+
library_name = data.get('library_name', 'libbluetooth_jni.so')
314+
315+
# Patch the file
316+
try:
317+
l2c_fcr_chk_chan_modes_address = get_symbol_address(file_path, "l2c_fcr_chk_chan_modes")
318+
patch_address(file_path, l2c_fcr_chk_chan_modes_address, "20008052c0035fd6")
319+
l2cu_send_peer_info_req_address = get_symbol_address(file_path, "l2cu_send_peer_info_req")
320+
patch_address(file_path, l2cu_send_peer_info_req_address, "c0035fd6")
321+
except Exception as e:
322+
logger.error(f"Error patching file: {str(e)}")
323+
return jsonify({"error": f"Error patching file: {str(e)}"}), 500
301324

302-
# Remove the '/api' endpoint if it's redundant
303-
# @app.route('/api', methods=['POST'])
304-
# def api():
305-
# # ...existing code...
306-
# pass
325+
# Send the patched .so file directly
326+
patched_filename = f"patched_{library_name}"
327+
patched_file_path = os.path.join('uploads', patched_filename)
328+
shutil.copy(file_path, patched_file_path)
307329

330+
try:
331+
resp = make_response(send_file(
332+
patched_file_path,
333+
mimetype='application/octet-stream',
334+
as_attachment=True,
335+
attachment_filename=patched_filename
336+
))
337+
os.remove(file_path)
338+
os.remove(patched_file_path)
339+
return resp
340+
341+
except Exception as e:
342+
logger.error(f"Error sending patched file: {str(e)}")
343+
344+
os.remove(file_path)
345+
os.remove(patched_file_path)
346+
347+
return jsonify({"error": f"Error sending patched file: {str(e)}"}), 500
348+
308349
def delete_expired_permalink(permalink_id):
309350
if permalink_id in PATCHED_LIBRARIES:
310351
file_path = PATCHED_LIBRARIES[permalink_id]['file_path']

root-module/btl2capfix.zip

3.74 KB
Binary file not shown.

root-module/customize.sh

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ if [ -f "/apex/com.android.btservices/lib64/libbluetooth_jni.so" ]; then
2121
SOURCE_FILE="/apex/com.android.btservices/lib64/libbluetooth_jni.so"
2222
LIBRARY_NAME="libbluetooth_jni.so"
2323
PATCHED_FILE_NAME="libbluetooth_jni_patched.so"
24-
log "Detected Qualcomm library: libbluetooth_jni.so in /apex/com.android.btservices/lib64/"
24+
log "Detected library: libbluetooth_jni.so in /apex/com.android.btservices/lib64/"
2525
elif [ -f "/system/lib64/libbluetooth_jni.so" ]; then
2626
SOURCE_FILE="/system/lib64/libbluetooth_jni.so"
2727
LIBRARY_NAME="libbluetooth_jni.so"
2828
PATCHED_FILE_NAME="libbluetooth_jni_patched.so"
29-
log "Detected Qualcomm library: libbluetooth_jni.so in /system/lib64/"
29+
log "Detected library: libbluetooth_jni.so in /system/lib64/"
3030
elif [ -f "/system/lib64/libbluetooth_qti.so" ]; then
3131
SOURCE_FILE="/system/lib64/libbluetooth_qti.so"
3232
LIBRARY_NAME="libbluetooth_qti.so"
@@ -44,20 +44,18 @@ fi
4444

4545
# Upload the library to the API
4646
log "Uploading $LIBRARY_NAME to the API for patching..."
47-
RESPONSE=$(curl -s -X POST "$API_URL" \
47+
PATCHED_FILE_NAME="patched_$LIBRARY_NAME"
48+
49+
curl -s -X POST "$API_URL" \
4850
-F "file=@$SOURCE_FILE" \
49-
-F "qti=$( [ "$LIBRARY_NAME" = "libbluetooth_qti.so" ] && echo "1" || echo "0")")
51+
-F "library_name=$LIBRARY_NAME" \
52+
-o "$TEMP_DIR/$PATCHED_FILE_NAME" \
53+
-D "$TEMP_DIR/headers.txt"
5054

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+
# Check if the patched file was downloaded successfully
56+
if [ -f "$TEMP_DIR/$PATCHED_FILE_NAME" ]; then
5557
log "Received patched file from the API."
5658

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-
6159
# Move the patched file to the module's directory
6260
log "Installing patched file to the module's directory..."
6361
mkdir -p "$MODPATH/system/lib/"
@@ -68,8 +66,7 @@ if echo "$RESPONSE" | grep -q "Content-Disposition"; then
6866

6967
log "Patched file has been successfully installed at $MODPATH/system/lib/$PATCHED_FILE_NAME"
7068
else
71-
# Assume JSON response with error
72-
ERROR_MESSAGE=$(echo "$RESPONSE" | grep -oP '(?<="error": ")[^"]+')
69+
ERROR_MESSAGE=$(grep -oP '(?<="error": ")[^"]+' "$TEMP_DIR/headers.txt")
7370
log "API Error: $ERROR_MESSAGE"
7471
rm -rf "$TEMP_DIR"
7572
exit 1

0 commit comments

Comments
 (0)