Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,54 +7,52 @@ from androguard.misc import AnalyzeAPK
|
|
| 7 |
from DroidDetective.DroidDetective import APK_Analyser
|
| 8 |
|
| 9 |
def check_apk(apk_to_check):
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
if
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
output_builder = output_builder + "Analysed file, identified as malware!"
|
| 37 |
-
else:
|
| 38 |
-
output_builder = output_builder + "Analysed file, identified as not malware.".format(file_to_check)
|
| 39 |
-
print("test2")
|
| 40 |
-
output_builder = output_builder + "\n"+"-"*20 +"\n"+"Permissions: \n"
|
| 41 |
-
print("test3")
|
| 42 |
-
permissions = apk_data["permissions"]
|
| 43 |
-
print("permissions: {}".format(permissions))
|
| 44 |
-
print("test4")
|
| 45 |
-
for permission in permissions:
|
| 46 |
-
print(permission)
|
| 47 |
-
output_builder = output_builder + permission + "\n"
|
| 48 |
-
print("test5")
|
| 49 |
-
print(output_builder)
|
| 50 |
-
return output_builder
|
| 51 |
-
print("Test6")
|
| 52 |
else:
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
print(output_builder)
|
| 55 |
return output_builder
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
demo = gr.Interface(
|
| 59 |
fn=check_apk,
|
| 60 |
inputs= "file",
|
|
|
|
| 7 |
from DroidDetective.DroidDetective import APK_Analyser
|
| 8 |
|
| 9 |
def check_apk(apk_to_check):
|
| 10 |
+
|
| 11 |
+
output_builder = ""
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
analyser = APK_Analyser()
|
| 15 |
+
model_path = f"{os.path.dirname(os.path.abspath(__file__))}/DroidDetective/apk_malware.model"
|
| 16 |
+
file_to_check = apk_to_check.name
|
| 17 |
+
|
| 18 |
+
if not file_to_check.endswith(".apk"):
|
| 19 |
+
return "Please provide an .apk file."
|
| 20 |
+
|
| 21 |
+
# Check should train
|
| 22 |
+
if not os.path.isfile(model_path):
|
| 23 |
+
if os.path.isdir("malware") and os.path.isdir("normal"):
|
| 24 |
+
apk_info = analyser.train_model(malware_apks_folder_path="malware", normal_apks_folder_path="normal")
|
| 25 |
+
|
| 26 |
+
else:
|
| 27 |
+
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."
|
| 28 |
+
|
| 29 |
+
# Check if model exists
|
| 30 |
+
if os.path.exists(model_path):
|
| 31 |
+
print("test0")
|
| 32 |
+
result, apk_data = analyser.identify(file_to_check, model_path)
|
| 33 |
+
print("test1")
|
| 34 |
+
if result == 1:
|
| 35 |
+
output_builder = output_builder + "Analysed file, identified as malware!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
else:
|
| 37 |
+
output_builder = output_builder + "Analysed file, identified as not malware.".format(file_to_check)
|
| 38 |
+
print("test2")
|
| 39 |
+
output_builder = output_builder + "\n"+"-"*20 +"\n"+"Permissions: \n"
|
| 40 |
+
print("test3")
|
| 41 |
+
permissions = apk_data["permissions"]
|
| 42 |
+
print("permissions: {}".format(permissions))
|
| 43 |
+
print("test4")
|
| 44 |
+
for permission in permissions:
|
| 45 |
+
print(permission)
|
| 46 |
+
output_builder = output_builder + permission + "\n"
|
| 47 |
+
print("test5")
|
| 48 |
print(output_builder)
|
| 49 |
return output_builder
|
| 50 |
+
print("Test6")
|
| 51 |
+
else:
|
| 52 |
+
return "No model found, please train model"
|
| 53 |
+
print(output_builder)
|
| 54 |
+
return output_builder
|
| 55 |
+
|
| 56 |
demo = gr.Interface(
|
| 57 |
fn=check_apk,
|
| 58 |
inputs= "file",
|