-
Notifications
You must be signed in to change notification settings - Fork 10
/
ipa.py
76 lines (68 loc) · 1.94 KB
/
ipa.py
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
## fufluns - Copyright 2019-2021 - deroad
from report import BinDetails
from report import Permissions
from report import Issues
from report import SourceCode
from report import Strings
from report import Extra
from report import WebLogger
import importlib
import os
import rzhelp
import rzpipe
import shutil
import tempfile
import threading
import utils
import zipfile
def _cleanup(o, pipe, crashed):
os.remove(o.filename)
shutil.rmtree(o.directory)
if pipe is not None:
pipe.quit()
if crashed:
o.logger.error(">> THE TOOL HAS CRASHED. CHECK THE LOGS <<")
o.logger.notify("temp files removed, analysis terminated.")
def _ipa_analysis(ipa):
ipa.logger.notify("opening ipa.")
try:
with zipfile.ZipFile(ipa.filename, "r") as zip_ref:
zip_ref.extractall(ipa.directory)
except Exception:
ipa.logger.error("cannot unzip file.")
_cleanup(ipa, None, False)
return
pipe = rzpipe.open("ipa://" + ipa.filename)
if pipe is None:
ipa.logger.error("cannot open file.")
_cleanup(ipa, None, False)
return
for file in os.listdir(os.path.join(os.path.dirname(__file__), "tests")):
if file == "__init__.py" or not file.endswith('.py'):
continue
try:
modpath = 'ios.tests.' + os.path.splitext(file)[0]
mod = importlib.import_module(modpath)
ipa.logger.notify(mod.name_test())
mod.run_tests(ipa, pipe, utils, rzhelp)
except Exception as e:
_cleanup(ipa, pipe, True)
raise e
_cleanup(ipa, pipe, False)
ipa.done.set(True)
class Ipa(object):
"""Ipa class for analysis"""
def __init__(self, temp_filename, done):
super(Ipa, self).__init__()
self.directory = tempfile.mkdtemp()
self.filename = temp_filename
self.logger = WebLogger()
self.binary = BinDetails()
self.permis = Permissions()
self.issues = Issues()
self.strings = Strings()
self.extra = Extra()
self.srccode = SourceCode()
self.done = done
self.thread = threading.Thread(target=_ipa_analysis, args=(self,))
self.thread.start()