@@ -281,89 +281,29 @@ def patch():
281281 logger .error (f"Error patching file: { str (e )} " )
282282 return jsonify ({"error" : f"Error patching file: { str (e )} " }), 500
283283
284- # Create permalink
285- permalink_id = str (uuid .uuid4 ())
286- PATCHED_LIBRARIES [permalink_id ] = {
287- 'file_path' : file_path ,
288- 'library_name' : library_name ,
289- 'timestamp' : time .time ()
290- }
291-
292- # Save patch info
293- save_patch_info (permalink_id , file_path )
294-
295- # Schedule deletion
296- threading .Timer (PERMALINK_EXPIRY , delete_expired_permalink , args = [permalink_id ]).start ()
297- logger .info (f"Permalink { permalink_id } created, will expire in { PERMALINK_EXPIRY } seconds" )
298-
299- return jsonify ({'permalink' : f'/download/{ permalink_id } ' })
300-
301- @app .route ('/api' , methods = ['POST' ])
302- def api ():
303- if 'file' not in request .files :
304- return jsonify ({"error" : "No file part" }), 400
305- file = request .files ['file' ]
306- if file .filename == '' :
307- return jsonify ({"error" : "No selected file" }), 400
308- if not file .filename .endswith ('.so' ):
309- return jsonify ({"error" : "Invalid file type. Only .so files are allowed." }), 400
310-
311- # Generate a unique file path
312- file_uuid = str (uuid .uuid4 ())
313- file_path = os .path .join ('uploads' , f"{ file_uuid } _{ file .filename } " )
314- file .save (file_path )
315-
316- # Determine the library name based on the request data
317- data = request .form
318- library_name = data .get ('library_name' , 'libbluetooth_jni.so' )
319-
320- # Patch the file
321- try :
322- l2c_fcr_chk_chan_modes_address = get_symbol_address (file_path , "l2c_fcr_chk_chan_modes" )
323- patch_address (file_path , l2c_fcr_chk_chan_modes_address , "20008052c0035fd6" )
324- l2cu_send_peer_info_req_address = get_symbol_address (file_path , "l2cu_send_peer_info_req" )
325- patch_address (file_path , l2cu_send_peer_info_req_address , "c0035fd6" )
326- except Exception as e :
327- logger .error (f"Error patching file: { str (e )} " )
328- return jsonify ({"error" : f"Error patching file: { str (e )} " }), 500
329-
330- # Create permalink
331- permalink_id = str (uuid .uuid4 ())
332- PATCHED_LIBRARIES [permalink_id ] = {
333- 'file_path' : file_path ,
334- 'library_name' : library_name ,
335- 'timestamp' : time .time ()
336- }
337-
338- # Save patch info
339- save_patch_info (permalink_id , file_path )
340-
341- # Schedule deletion
342- threading .Timer (PERMALINK_EXPIRY , delete_expired_permalink , args = [permalink_id ]).start ()
343- logger .info (f"Permalink { permalink_id } created, will expire in { PERMALINK_EXPIRY } seconds" )
344-
345- return jsonify ({'permalink' : f'/download/{ permalink_id } ' })
346-
347- @app .route ('/download/<permalink_id>' , methods = ['GET' ])
348- def download (permalink_id ):
349- if permalink_id not in PATCHED_LIBRARIES :
350- return "Permalink expired or invalid" , 404
351-
352- file_path = PATCHED_LIBRARIES [permalink_id ]['file_path' ]
353- library_name = PATCHED_LIBRARIES [permalink_id ]['library_name' ]
354- if not os .path .exists (file_path ):
355- return "File not found" , 404
356-
284+ # Send the patched file directly
357285 try :
358- copy_file_to_src (file_path , library_name )
359- zip_src_files ()
286+ return send_file (
287+ file_path ,
288+ mimetype = 'application/octet-stream' ,
289+ as_attachment = True ,
290+ attachment_filename = f"patched_{ library_name } "
291+ )
360292 except Exception as e :
361- logger .error (f"Error preparing download: { str (e )} " )
362- return f"Error preparing download: { str (e )} " , 500
363-
364- resp = make_response (send_file ('btl2capfix.zip' , as_attachment = True ))
365- resp .headers ['Content-Disposition' ] = f'attachment; filename=btl2capfix.zip'
366- return resp
293+ logger .error (f"Error sending patched file: { str (e )} " )
294+ return jsonify ({"error" : f"Error sending patched file: { str (e )} " }), 500
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
301+
302+ # Remove the '/api' endpoint if it's redundant
303+ # @app.route('/api', methods=['POST'])
304+ # def api():
305+ # # ...existing code...
306+ # pass
367307
368308def delete_expired_permalink (permalink_id ):
369309 if permalink_id in PATCHED_LIBRARIES :
0 commit comments