-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplication.py
More file actions
132 lines (111 loc) · 4.69 KB
/
Application.py
File metadata and controls
132 lines (111 loc) · 4.69 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
from GlobalVariables import *
from SSHSession import *
import plistlib
import os
from datetime import datetime
import shutil
import tkinter as tk
from tkinter import messagebox
import time
class Application:
def __init__(self, sshClient, mainWin):
self.apps=[[]]
self.objSSHClient = sshClient
self.mainWin=mainWin
self.globalVariables=GlobalVariables()
self.currentSelectedAppBundleUUID=''
self.currentSelectedAppName=''
self.currentSelectedAppBundleName=''
self.currentSelectedAppDataUUID=''
self.currentAppName=''
def FillAppInList(self):
rawData = self.objSSHClient.executeCommand(self.globalVariables.appListCmd)
for line in rawData:
line=line.strip()
rfind = line.rfind('/');
bundleName = line[rfind+1:];
bundleId = line[2:rfind];
self.apps.append([bundleName,bundleId])
self.mainWin.listApplication.addItem(bundleName)
self.mainWin.tabWidget.setCurrentIndex(1)
def GetDataDirUUID(self):
isError=False
remotePath="{}{}/{}/Info.plist".format(self.globalVariables.bundlePath, self.currentSelectedAppBundleUUID, self.currentSelectedAppName)
localPath="./Output/{}/Bundle/{}/{}".format(self.currentAppName, self.currentSelectedAppBundleUUID, self.currentSelectedAppName)
try:
os.makedirs(localPath)
except:
pass
localPath="{}/Info.plist".format(localPath)
self.objSSHClient.get(remotePath,localPath)
with open(localPath, 'rb') as fp :
plist_content = plistlib.loads(fp.read())
if 'CFBundleIdentifier' in plist_content:
self.currentSelectedAppBundleName = plist_content['CFBundleIdentifier']
command = "cd {} && find . -name '{}' | grep 'Caches/{}'".format(self.globalVariables.dataPath, self.currentSelectedAppBundleName, self.currentSelectedAppBundleName)
rawData = self.objSSHClient.executeCommand(command)
if not rawData:
self.globalVariables.ShowErrorDailog(self.mainWin, "Open application from device once and try again!")
self.currentSelectedAppDataUUID = ""
isError=True
else:
dataUUID = rawData[0].strip()
self.currentSelectedAppDataUUID = dataUUID[2: dataUUID.find("/", 3)]
localPath="./Output/{}/Bundle/{}".format(self.currentAppName, self.currentSelectedAppBundleUUID)
shutil.rmtree(localPath)
return isError
def isCopyBundleAndDataDirectory(self, appName, force):
for app in self.apps:
if len(app) == 2 and app[0] == appName:
self.currentSelectedAppName = app[0]
self.currentSelectedAppBundleUUID = app[1]
self.currentAppName= self.currentSelectedAppName[0: self.currentSelectedAppName.find(".")]
break
if not force:
outputDirName = "./Output/{}".format(self.currentAppName)
if os.path.exists(outputDirName) and not force:
root = tk.Tk()
root.withdraw() # hide main window
result = messagebox.askyesno("Folder Exists", f"The folder '{outputDirName}' already exists.\n\nDo you want to copy it again?")
root.destroy()
if result:
return True
else:
return False
else:
return True
else:
return True
def CopyBundleAndDataDirectory(self, appName, force=False):
if self.isCopyBundleAndDataDirectory(appName, force):
if not self.GetDataDirUUID():
outputBundleDirName = "./Output/{}/Bundle".format(self.currentAppName)
outputDataDirName = "./Output/{}/Data".format(self.currentAppName)
if force:
dateTime = str(datetime.now())
outDir = "./Output/{}_{}".format(self.currentAppName, str(dateTime).replace(":","_").replace(".","_").replace(" ","__"))
os.rename("./Output/{}".format(self.currentAppName), outDir)
metaDataPath = '{}{}'.format(self.globalVariables.bundlePath, self.currentSelectedAppBundleUUID)
self.objSSHClient.get_all(metaDataPath, outputBundleDirName)
metaDataPath = '{}{}'.format(self.globalVariables.dataPath, self.currentSelectedAppDataUUID)
self.objSSHClient.get_all(metaDataPath, outputDataDirName)
return True
return False
return True
def CreateIPAFileFromSource(self):
payloadDirPath = "./Output/{}/Payload".format(self.currentAppName)
bundleDirPath = "./Output/{}/Bundle".format(self.currentAppName)
appNamePath = "./Output/{}/{}".format(self.currentAppName, self.currentAppName)
zipFileName = "./Output/{}/{}.zip".format(self.currentAppName, self.currentAppName)
iPAFileName = "./Output/{}/{}.ipa".format(self.currentAppName, self.currentAppName)
if os.path.isfile(iPAFileName):
os.remove(iPAFileName)
if os.path.isfile(zipFileName):
os.remove(zipFileName)
if os.path.isdir(appNamePath):
shutil.rmtree(appNamePath)
shutil.copytree(bundleDirPath, payloadDirPath, dirs_exist_ok=True)
shutil.move(payloadDirPath, "{}/Payload".format(appNamePath))
shutil.make_archive(appNamePath, 'zip', appNamePath)
shutil.rmtree(appNamePath)
shutil.move(zipFileName, iPAFileName)