File size: 4,258 Bytes
95f7268
195790b
 
 
 
 
bc27a0c
95f7268
bc27a0c
 
 
 
 
95f7268
bc27a0c
 
 
 
 
 
 
 
 
95f7268
 
195790b
 
 
 
 
 
 
 
bc27a0c
 
195790b
bc27a0c
 
 
 
 
95f7268
bc27a0c
 
 
 
 
 
95f7268
bc27a0c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95f7268
195790b
 
 
 
bc27a0c
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import streamlit as st
import tempfile
import os
from utils.apk_analyzer import ApkAnalyzer
from utils.report_generator import ReportGenerator

st.set_page_config(page_title="APK Analyzer", page_icon="🔍", layout="wide")

# Sidebar
with st.sidebar:
    st.title("APK Security Analyzer")
    st.write("Upload an APK file for security analysis")
    uploaded_file = st.file_uploader("Choose an APK file", type=["apk"])

    if uploaded_file:
        st.success("File uploaded successfully!")
        file_details = {
            "Filename": uploaded_file.name,
            "File size": f"{uploaded_file.size / 1024:.2f} KB",
        }
        st.write("File Details:")
        for key, value in file_details.items():
            st.write(f"- {key}: {value}")

if uploaded_file:
    with tempfile.NamedTemporaryFile(delete=False, suffix=".apk") as tmp_file:
        tmp_file.write(uploaded_file.getvalue())
        tmp_file_path = tmp_file.name

    with st.spinner("Analyzing APK..."):
        try:
            analyzer = ApkAnalyzer(tmp_file_path)

            # Create two columns for main content
            col1, col2 = st.columns(2)

            with col1:
                with st.container():
                    st.header("Basic Information")
                    basic_info = analyzer.basic_info()
                    st.json(basic_info)

            with col2:
                with st.container():
                    st.header("Security Issues")
                    security_issues = analyzer.security_analysis()
                    for issue in security_issues:
                        st.warning(issue, icon="⚠️")

            # Bottom section for AI Analysis
            st.markdown("---")
            with st.container():
                st.header("AI Analysis Report")

                # Create tabs for different views
                tab1, tab2 = st.tabs(["Report", "Summary"])

                with tab1:
                    report_gen = ReportGenerator()
                    report = report_gen.generate_report(basic_info, security_issues)
                    st.write(report)

                    # Download report button with improved styling
                    st.download_button(
                        label="📥 Download Full Report",
                        data=report,
                        file_name="security_report.txt",
                        mime="text/plain",
                    )

                with tab2:
                    st.subheader("Analysis Summary")
                    
                    # Get existing summary from session state or initialize empty
                    if 'user_summary' not in st.session_state:
                        st.session_state.user_summary = ""
                    
                    # Text area for user input
                    user_summary = st.text_area(
                        "Write your analysis summary here:",
                        value=st.session_state.user_summary,
                        height=300,
                        placeholder="Enter your observations, findings, and recommendations..."
                    )
                    
                    # Save button for the summary
                    if st.button("Save Summary"):
                        st.session_state.user_summary = user_summary
                        st.success("Summary saved successfully!")
                    
                    # Option to download the summary
                    if user_summary:
                        st.download_button(
                            label="📥 Download Summary",
                            data=user_summary,
                            file_name="apk_analysis_summary.txt",
                            mime="text/plain"
                        )

        except Exception as e:
            st.error(f"Error analyzing APK: {str(e)}")
        finally:
            os.unlink(tmp_file_path)
else:
    # Display welcome message when no file is uploaded
    st.markdown(
        """
        <div style='text-align: center; padding: 50px;'>
            <h2>Welcome to APK Security Analyzer</h2>
            <p>Upload an APK file using the sidebar to begin analysis</p>
        </div>
    """,
        unsafe_allow_html=True,
    )