|
3 | 3 | import json |
4 | 4 | import uuid |
5 | 5 | import time |
6 | | -import threading |
| 6 | +import shutil |
7 | 7 | import logging |
8 | 8 | from main import get_symbol_address, patch_address, copy_file_to_src, zip_src_files |
9 | 9 |
|
@@ -293,18 +293,59 @@ def patch(): |
293 | 293 | logger.error(f"Error sending patched file: {str(e)}") |
294 | 294 | return jsonify({"error": f"Error sending patched file: {str(e)}"}), 500 |
295 | 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 |
| 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 |
301 | 324 |
|
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) |
307 | 329 |
|
| 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 | + |
308 | 349 | def delete_expired_permalink(permalink_id): |
309 | 350 | if permalink_id in PATCHED_LIBRARIES: |
310 | 351 | file_path = PATCHED_LIBRARIES[permalink_id]['file_path'] |
|
0 commit comments