diff --git a/root-module-manual/main.py b/root-module-manual/main.py index 0f90a6a..659a06f 100644 --- a/root-module-manual/main.py +++ b/root-module-manual/main.py @@ -117,22 +117,9 @@ def copy_file_to_src(file_path, library_name): def zip_src_files(): """ - Zips all files in the 'src/' directory into 'btl2capfix.zip', preserving symlinks without compression. + Zips all files in the 'src/' directory into 'btl2capfix.zip' using the shell zip command. """ - with zipfile.ZipFile('btl2capfix.zip', 'w', zipfile.ZIP_STORED, allowZip64=True) as zipf: - for root, dirs, files in os.walk('src/'): - for file in files: - file_path = os.path.join(root, file) - if os.path.islink(file_path): - link_target = os.readlink(file_path) - zip_info = zipfile.ZipInfo(os.path.relpath(file_path, 'src/')) - zip_info.create_system = 3 # Unix - zip_info.external_attr = 0o777 << 16 - zip_info.external_attr |= 0xA000 - zipf.writestr(zip_info, link_target) - else: - zipf.write(file_path, os.path.relpath(file_path, 'src/')) - logging.info("Zipped files under src/ into btl2capfix.zip") + run_command('cd src && zip -r ../btl2capfix *') def main(): """ diff --git a/root-module-manual/server.py b/root-module-manual/server.py index 98148e0..a8f8a37 100644 --- a/root-module-manual/server.py +++ b/root-module-manual/server.py @@ -3,7 +3,7 @@ import os import json import uuid import time -import threading +import shutil import logging from main import get_symbol_address, patch_address, copy_file_to_src, zip_src_files @@ -293,18 +293,59 @@ def patch(): logger.error(f"Error sending patched file: {str(e)}") return jsonify({"error": f"Error sending patched file: {str(e)}"}), 500 -# Remove or comment out the '/download/' route as it's no longer needed -# @app.route('/download/', methods=['GET']) -# def download(permalink_id): -# # ...existing code... -# pass +@app.route('/api', methods=['POST']) +def api(): + if 'file' not in request.files: + return jsonify({"error": "No file part"}), 400 + file = request.files['file'] + if file.filename == '': + return jsonify({"error": "No selected file"}), 400 + if not file.filename.endswith('.so'): + return jsonify({"error": "Invalid file type. Only .so files are allowed."}), 400 -# Remove the '/api' endpoint if it's redundant -# @app.route('/api', methods=['POST']) -# def api(): -# # ...existing code... -# pass + # Generate a unique file path + file_uuid = str(uuid.uuid4()) + file_path = os.path.join('uploads', f"{file_uuid}_{file.filename}") + file.save(file_path) + # Determine the library name based on the request data + data = request.form + library_name = data.get('library_name', 'libbluetooth_jni.so') + + # Patch the file + try: + l2c_fcr_chk_chan_modes_address = get_symbol_address(file_path, "l2c_fcr_chk_chan_modes") + patch_address(file_path, l2c_fcr_chk_chan_modes_address, "20008052c0035fd6") + l2cu_send_peer_info_req_address = get_symbol_address(file_path, "l2cu_send_peer_info_req") + patch_address(file_path, l2cu_send_peer_info_req_address, "c0035fd6") + except Exception as e: + logger.error(f"Error patching file: {str(e)}") + return jsonify({"error": f"Error patching file: {str(e)}"}), 500 + + # Send the patched .so file directly + patched_filename = f"patched_{library_name}" + patched_file_path = os.path.join('uploads', patched_filename) + shutil.copy(file_path, patched_file_path) + + try: + resp = make_response(send_file( + patched_file_path, + mimetype='application/octet-stream', + as_attachment=True, + attachment_filename=patched_filename + )) + os.remove(file_path) + os.remove(patched_file_path) + return resp + + except Exception as e: + logger.error(f"Error sending patched file: {str(e)}") + + os.remove(file_path) + os.remove(patched_file_path) + + return jsonify({"error": f"Error sending patched file: {str(e)}"}), 500 + def delete_expired_permalink(permalink_id): if permalink_id in PATCHED_LIBRARIES: file_path = PATCHED_LIBRARIES[permalink_id]['file_path'] diff --git a/root-module/btl2capfix.zip b/root-module/btl2capfix.zip new file mode 100644 index 0000000..7da7e1f Binary files /dev/null and b/root-module/btl2capfix.zip differ diff --git a/root-module/customize.sh b/root-module/customize.sh index 8b33315..555887f 100644 --- a/root-module/customize.sh +++ b/root-module/customize.sh @@ -21,12 +21,12 @@ if [ -f "/apex/com.android.btservices/lib64/libbluetooth_jni.so" ]; then SOURCE_FILE="/apex/com.android.btservices/lib64/libbluetooth_jni.so" LIBRARY_NAME="libbluetooth_jni.so" PATCHED_FILE_NAME="libbluetooth_jni_patched.so" - log "Detected Qualcomm library: libbluetooth_jni.so in /apex/com.android.btservices/lib64/" + log "Detected library: libbluetooth_jni.so in /apex/com.android.btservices/lib64/" elif [ -f "/system/lib64/libbluetooth_jni.so" ]; then SOURCE_FILE="/system/lib64/libbluetooth_jni.so" LIBRARY_NAME="libbluetooth_jni.so" PATCHED_FILE_NAME="libbluetooth_jni_patched.so" - log "Detected Qualcomm library: libbluetooth_jni.so in /system/lib64/" + log "Detected library: libbluetooth_jni.so in /system/lib64/" elif [ -f "/system/lib64/libbluetooth_qti.so" ]; then SOURCE_FILE="/system/lib64/libbluetooth_qti.so" LIBRARY_NAME="libbluetooth_qti.so" @@ -44,20 +44,18 @@ fi # Upload the library to the API log "Uploading $LIBRARY_NAME to the API for patching..." -RESPONSE=$(curl -s -X POST "$API_URL" \ +PATCHED_FILE_NAME="patched_$LIBRARY_NAME" + +curl -s -X POST "$API_URL" \ -F "file=@$SOURCE_FILE" \ - -F "qti=$( [ "$LIBRARY_NAME" = "libbluetooth_qti.so" ] && echo "1" || echo "0")") + -F "library_name=$LIBRARY_NAME" \ + -o "$TEMP_DIR/$PATCHED_FILE_NAME" \ + -D "$TEMP_DIR/headers.txt" -# Check if the response is a file (patched .so) -if echo "$RESPONSE" | grep -q "Content-Disposition"; then - # Extract the patched .so file name from Content-Disposition header - PATCHED_FILE_NAME="patched_$LIBRARY_NAME" +# Check if the patched file was downloaded successfully +if [ -f "$TEMP_DIR/$PATCHED_FILE_NAME" ]; then log "Received patched file from the API." - # Save the patched .so file - echo "$RESPONSE" > "$TEMP_DIR/$PATCHED_FILE_NAME" - # Note: Depending on how the server sends the file, you might need to handle binary data appropriately. - # Move the patched file to the module's directory log "Installing patched file to the module's directory..." mkdir -p "$MODPATH/system/lib/" @@ -68,8 +66,7 @@ if echo "$RESPONSE" | grep -q "Content-Disposition"; then log "Patched file has been successfully installed at $MODPATH/system/lib/$PATCHED_FILE_NAME" else - # Assume JSON response with error - ERROR_MESSAGE=$(echo "$RESPONSE" | grep -oP '(?<="error": ")[^"]+') + ERROR_MESSAGE=$(grep -oP '(?<="error": ")[^"]+' "$TEMP_DIR/headers.txt") log "API Error: $ERROR_MESSAGE" rm -rf "$TEMP_DIR" exit 1