File size: 2,087 Bytes
3c086ba
 
0f5b5c9
3c086ba
 
 
 
 
 
8517e83
4856931
8517e83
 
aff9a76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3c086ba
aff9a76
 
 
 
 
 
 
 
 
 
 
13313b0
56dc759
aff9a76
 
 
 
 
 
3c086ba
 
bc57e39
3c086ba
 
 
 
 
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
import os
import sys

import gradio as gr
from androguard.misc import AnalyzeAPK

from DroidDetective.DroidDetective import APK_Analyser

def check_apk(apk_to_check):
    
    if apk_to_check == None:
        return "Provide an APK to analyse."
    
    output_builder = ""


    analyser = APK_Analyser()
    model_path = f"{os.path.dirname(os.path.abspath(__file__))}/DroidDetective/apk_malware.model"
    file_to_check = apk_to_check.name

    if not file_to_check.endswith(".apk"):
        return "Please provide an .apk file."

    # Check should train
    if not os.path.isfile(model_path):
        if os.path.isdir("malware") and os.path.isdir("normal"):
            apk_info = analyser.train_model(malware_apks_folder_path="malware", normal_apks_folder_path="normal")
            
        else:
            return  "When training a model, ensure that a 'malware' and 'normal' folder exist at the root of this project and that training APKs exist in both folders."

    # Check if model exists
    if os.path.exists(model_path):
        print("test0")
        result, apk_data = analyser.identify(file_to_check, model_path)
        print("test1")
        if result == 1:
            output_builder = output_builder + "Analysed file, identified as malware!"
        else:
            output_builder = output_builder + "Analysed file, identified as not malware.".format(file_to_check)
        print("test2")
        output_builder = output_builder + "\n"+"-"*20 +"\n"+"Permissions: \n"
        print("test3")
        permissions = apk_data["permissions"]
        print("permissions: {}".format(permissions))
        print("test4")
        for permission in permissions:
            print(permission)
            output_builder = output_builder + permission + "\n"
        print("test5")
        print(output_builder)
        return output_builder
        print("Test6")
    else:
        return "No model found, please train model"
    print(output_builder)
    return output_builder

demo = gr.Interface(
    fn=check_apk,
    inputs= "file",
    outputs="text",
)

demo.launch()