from os import path
from flask import Blueprint, request, jsonify
import config
import oletools.olevba

olevba_bp = Blueprint('olevba', __name__)

@olevba_bp.route('/analyze', methods=['POST'])
def analyze_vba():
    data = request.form
    file = data['file']
    filepath = path.join(config.Config.FILE_DIRECTORY, file)

    # Analyze with olevba
    vbaparser = oletools.olevba.VBA_Parser(filepath)
    results = vbaparser.analyze_macros()
    

    return jsonify({'filename': file, 'macros': results})
