mirror of
https://github.com/kavishdevar/librepods.git
synced 2026-05-24 18:08:25 +00:00
im soo stupid ;-;
This commit is contained in:
@@ -117,22 +117,9 @@ def copy_file_to_src(file_path, library_name):
|
|||||||
|
|
||||||
def zip_src_files():
|
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:
|
run_command('cd src && zip -r ../btl2capfix *')
|
||||||
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")
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import os
|
|||||||
import json
|
import json
|
||||||
import uuid
|
import uuid
|
||||||
import time
|
import time
|
||||||
import threading
|
import shutil
|
||||||
import logging
|
import logging
|
||||||
from main import get_symbol_address, patch_address, copy_file_to_src, zip_src_files
|
from main import get_symbol_address, patch_address, copy_file_to_src, zip_src_files
|
||||||
|
|
||||||
@@ -293,17 +293,58 @@ def patch():
|
|||||||
logger.error(f"Error sending patched file: {str(e)}")
|
logger.error(f"Error sending patched file: {str(e)}")
|
||||||
return jsonify({"error": f"Error sending patched file: {str(e)}"}), 500
|
return jsonify({"error": f"Error sending patched file: {str(e)}"}), 500
|
||||||
|
|
||||||
# Remove or comment out the '/download/<permalink_id>' route as it's no longer needed
|
@app.route('/api', methods=['POST'])
|
||||||
# @app.route('/download/<permalink_id>', methods=['GET'])
|
def api():
|
||||||
# def download(permalink_id):
|
if 'file' not in request.files:
|
||||||
# # ...existing code...
|
return jsonify({"error": "No file part"}), 400
|
||||||
# pass
|
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
|
# Generate a unique file path
|
||||||
# @app.route('/api', methods=['POST'])
|
file_uuid = str(uuid.uuid4())
|
||||||
# def api():
|
file_path = os.path.join('uploads', f"{file_uuid}_{file.filename}")
|
||||||
# # ...existing code...
|
file.save(file_path)
|
||||||
# pass
|
|
||||||
|
# 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):
|
def delete_expired_permalink(permalink_id):
|
||||||
if permalink_id in PATCHED_LIBRARIES:
|
if permalink_id in PATCHED_LIBRARIES:
|
||||||
|
|||||||
BIN
root-module/btl2capfix.zip
Normal file
BIN
root-module/btl2capfix.zip
Normal file
Binary file not shown.
@@ -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"
|
SOURCE_FILE="/apex/com.android.btservices/lib64/libbluetooth_jni.so"
|
||||||
LIBRARY_NAME="libbluetooth_jni.so"
|
LIBRARY_NAME="libbluetooth_jni.so"
|
||||||
PATCHED_FILE_NAME="libbluetooth_jni_patched.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
|
elif [ -f "/system/lib64/libbluetooth_jni.so" ]; then
|
||||||
SOURCE_FILE="/system/lib64/libbluetooth_jni.so"
|
SOURCE_FILE="/system/lib64/libbluetooth_jni.so"
|
||||||
LIBRARY_NAME="libbluetooth_jni.so"
|
LIBRARY_NAME="libbluetooth_jni.so"
|
||||||
PATCHED_FILE_NAME="libbluetooth_jni_patched.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
|
elif [ -f "/system/lib64/libbluetooth_qti.so" ]; then
|
||||||
SOURCE_FILE="/system/lib64/libbluetooth_qti.so"
|
SOURCE_FILE="/system/lib64/libbluetooth_qti.so"
|
||||||
LIBRARY_NAME="libbluetooth_qti.so"
|
LIBRARY_NAME="libbluetooth_qti.so"
|
||||||
@@ -44,19 +44,17 @@ fi
|
|||||||
|
|
||||||
# Upload the library to the API
|
# Upload the library to the API
|
||||||
log "Uploading $LIBRARY_NAME to the API for patching..."
|
log "Uploading $LIBRARY_NAME to the API for patching..."
|
||||||
RESPONSE=$(curl -s -X POST "$API_URL" \
|
|
||||||
-F "file=@$SOURCE_FILE" \
|
|
||||||
-F "qti=$( [ "$LIBRARY_NAME" = "libbluetooth_qti.so" ] && echo "1" || echo "0")")
|
|
||||||
|
|
||||||
# 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"
|
PATCHED_FILE_NAME="patched_$LIBRARY_NAME"
|
||||||
log "Received patched file from the API."
|
|
||||||
|
|
||||||
# Save the patched .so file
|
curl -s -X POST "$API_URL" \
|
||||||
echo "$RESPONSE" > "$TEMP_DIR/$PATCHED_FILE_NAME"
|
-F "file=@$SOURCE_FILE" \
|
||||||
# Note: Depending on how the server sends the file, you might need to handle binary data appropriately.
|
-F "library_name=$LIBRARY_NAME" \
|
||||||
|
-o "$TEMP_DIR/$PATCHED_FILE_NAME" \
|
||||||
|
-D "$TEMP_DIR/headers.txt"
|
||||||
|
|
||||||
|
# Check if the patched file was downloaded successfully
|
||||||
|
if [ -f "$TEMP_DIR/$PATCHED_FILE_NAME" ]; then
|
||||||
|
log "Received patched file from the API."
|
||||||
|
|
||||||
# Move the patched file to the module's directory
|
# Move the patched file to the module's directory
|
||||||
log "Installing patched file to the module's directory..."
|
log "Installing patched file to the module's directory..."
|
||||||
@@ -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"
|
log "Patched file has been successfully installed at $MODPATH/system/lib/$PATCHED_FILE_NAME"
|
||||||
else
|
else
|
||||||
# Assume JSON response with error
|
ERROR_MESSAGE=$(grep -oP '(?<="error": ")[^"]+' "$TEMP_DIR/headers.txt")
|
||||||
ERROR_MESSAGE=$(echo "$RESPONSE" | grep -oP '(?<="error": ")[^"]+')
|
|
||||||
log "API Error: $ERROR_MESSAGE"
|
log "API Error: $ERROR_MESSAGE"
|
||||||
rm -rf "$TEMP_DIR"
|
rm -rf "$TEMP_DIR"
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
Reference in New Issue
Block a user