From ce498dd1d9be8b8fa7e70663955e91c303683a89 Mon Sep 17 00:00:00 2001 From: som3canadian Date: Sun, 5 Jan 2025 16:29:10 -0500 Subject: [PATCH 1/2] added api route for results (JSON output) --- app/routes.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/app/routes.py b/app/routes.py index ec68b58..9d28361 100644 --- a/app/routes.py +++ b/app/routes.py @@ -754,4 +754,61 @@ def register_routes(app): 'message': str(e) }), 500 + + @app.route('/api/results//static', methods=['GET']) + def api_static_results(target): + try: + result_path = utils.find_file_by_hash(target, app.config['upload']['result_folder']) + if not result_path: + return jsonify({'error': 'Results not found'}), 404 + + static_path = os.path.join(result_path, 'static_analysis_results.json') + if not os.path.exists(static_path): + return jsonify({'error': 'Static analysis results not found'}), 404 + + with open(static_path, 'r') as f: + return jsonify(json.load(f)) + except Exception as e: + return jsonify({'error': str(e)}), 500 + + + @app.route('/api/results//dynamic', methods=['GET']) + def api_dynamic_results(target): + try: + # Handle PID-based results + if target.isdigit(): + result_folder = os.path.join(app.config['upload']['result_folder'], f'dynamic_{target}') + dynamic_path = os.path.join(result_folder, 'dynamic_analysis_results.json') + else: + # Handle file-based results + result_path = utils.find_file_by_hash(target, app.config['upload']['result_folder']) + if not result_path: + return jsonify({'error': 'Results not found'}), 404 + dynamic_path = os.path.join(result_path, 'dynamic_analysis_results.json') + + if not os.path.exists(dynamic_path): + return jsonify({'error': 'Dynamic analysis results not found'}), 404 + + with open(dynamic_path, 'r') as f: + return jsonify(json.load(f)) + except Exception as e: + return jsonify({'error': str(e)}), 500 + + + @app.route('/api/results//info', methods=['GET']) + def api_file_info(target): + try: + result_path = utils.find_file_by_hash(target, app.config['upload']['result_folder']) + if not result_path: + return jsonify({'error': 'File info not found'}), 404 + + file_info_path = os.path.join(result_path, 'file_info.json') + if not os.path.exists(file_info_path): + return jsonify({'error': 'File info not found'}), 404 + + with open(file_info_path, 'r') as f: + return jsonify(json.load(f)) + except Exception as e: + return jsonify({'error': str(e)}), 500 + return app From 3bc46f4a1ebeb7666a86c5342e29d98c5ac40abb Mon Sep 17 00:00:00 2001 From: som3canadian Date: Sun, 5 Jan 2025 16:30:04 -0500 Subject: [PATCH 2/2] update README --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a19254f..06b4f06 100644 --- a/README.md +++ b/README.md @@ -81,10 +81,10 @@ GET /analyze/static/ # Static file analysis POST /analyze/dynamic/ # Dynamic file analysis POST /analyze/dynamic/ # Process analysis GET /files # Get list of processed files -GET /resoults//info # Get file info -GET /resoults//static # Get results for file static analysis -GET /resoults//dynamic # Get results for file dynamic analysis -GET /resoults//dynamic # Get results for pid analysis +GET /api/results//info # Get file info +GET /api/results//static # Get results for file static analysis +GET /api/results//dynamic # Get results for file dynamic analysis +GET /api/results//dynamic # Get results for pid analysis ``` ### System Management