From a72cbf129f49c7649a0d75dc2899405d008f3d19 Mon Sep 17 00:00:00 2001 From: Kavish Devar Date: Sat, 11 Jan 2025 01:10:59 +0530 Subject: [PATCH] im soo stupid ;-; --- root-module-manual/main.py | 17 ++-------- root-module-manual/server.py | 63 +++++++++++++++++++++++++++++------ root-module/btl2capfix.zip | Bin 0 -> 3833 bytes root-module/customize.sh | 25 ++++++-------- 4 files changed, 65 insertions(+), 40 deletions(-) create mode 100644 root-module/btl2capfix.zip 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 0000000000000000000000000000000000000000..7da7e1f23a4b5b4e344159e2478d45bcb3347748 GIT binary patch literal 3833 zcmWIWW@h1H0DC$rL;z0h zGBEA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=eBRX_v1`X(1(9-a`wNSr;rl3XpVl@?|L485uf@x*+Ohz44?JS<6$d1rmzIt^BK=slpU~A zGEuO#u~f|Dx<{|-?`wYxL{#qY4Dc5Enw^ouxstWiLu_h)(RcrSCl;tQ{STZnNAsTG zhDcS5pO5$LH%IjVQ?xqMG@#?PnHU)OfgUKxFD}tdNi0d!O)G{K95|}2wG&Qr9WoGb z{reJZG| z^J-_{`lf>~rBtEsG1YrnC9ukDR1Z)T;o&u#E zh^JsiA>4%3V~k94%(&W262Jrr0s;(w9YHj-1;q+!L7~-O0p7Tcl3_qL${uDE&ejy^ zHYlOkFqMD}un;EQ9z_&;J`%78+H@e@8Z{Jad>El&k3GOpT3n>trGsME8lvqYKM=K1 zY!m_(dEk^q(04=xC$4rFB>e&X#;~Qa9B3hGs|*-upjH{y6pgErK{oLXD+6kkgD(~k z2BH@F$Of)uW5BEe@EM9d3$vpHbPqcNtiTHmA>A-u6vNIU3?n}waHAM0!U1<5&`4mp zMY* ADF6Tf literal 0 HcmV?d00001 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