forked from answer-huang/dSYMTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dSYM.py
192 lines (156 loc) · 7.71 KB
/
dSYM.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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#coding=utf-8
__author__ = 'answer-huang'
import sys
reload(sys)
sys.setdefaultencoding('utf8')
import wx
from MyInfo import AboutMe
from AHDropTarget import AHDropTarget
import os
import subprocess
class AHFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self,
parent,
-1,
title,
wx.DefaultPosition,
wx.Size(500, 500)
#style=wx.DEFAULT_FRAME_STYLE
#style=wx.DEFAULT_FRAME_STYLE ^ (wx.RESIZE_BORDER | wx.MAXIMIZE_BOX)
)
#style=wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX)
#拖进到窗口中的文件列表
self.filesList = []
#创建状态栏
self.statusbar = self.CreateStatusBar()
self.statusbar.SetForegroundColour('red')
self.statusbar.SetFieldsCount(2)
self.statusbar.SetStatusWidths([-2, -1]) #大小比例2:1
#创建工具栏
toolbar = self.CreateToolBar()
#TODO: 图片改成相对路径
toolbar.AddSimpleTool(1, wx.Image('./about.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap(), "关于我", "")
toolbar.AddSeparator()
toolbar.Realize() #准备显示工具栏
wx.EVT_TOOL(self, 1, self.OnAboutMe)
#创建panel
self.panel = wx.Panel(self)
self.panel.SetDropTarget(AHDropTarget(self))
#self.font = wx.Font(18, wx.SCRIPT, wx.BOLD, wx.LIGHT)
#self.selectedPath = wx.StaticText(self.panel, -1, u'请将xcarchive文件拖拽到窗口中!', pos=(138, 300))
#self.selectedPath.SetFont(self.font)
self.vbox = wx.BoxSizer(wx.VERTICAL)
self.description = wx.StaticText(self.panel, -1, u'请将xcarchive文件拖拽到窗口中并选中任意一个版本进行分析', style=wx.TE_WORDWRAP | wx.TE_MULTILINE)
self.fileTypeLB = wx.ListBox(self.panel, -1, style = wx.LB_EXTENDED)
self.fileTypeLB.SetBackgroundColour(wx.Colour(232, 232, 232, 255))
self.Bind(wx.EVT_LISTBOX, self.ListBoxClick, self.fileTypeLB)
self.Bind(wx.EVT_LISTBOX_DCLICK, self.ListBoxClick, self.fileTypeLB)
self.fileTypeLBhbox = wx.BoxSizer(wx.HORIZONTAL)
self.fileTypeLBhbox.Add(self.fileTypeLB, 1, wx.EXPAND)
self.vbox.Add(self.description, 0, wx.EXPAND | wx.ALL, 5)
self.vbox.Add(self.fileTypeLBhbox, 1, wx.EXPAND | wx.ALL, 5)
self.vbox.SetItemMinSize(self.fileTypeLBhbox, (200, 100))
self.vbox.Add((-1, 10))
self.UUIDString = wx.StaticText(self.panel, -1, u'选中xcarchive的UUID:')
self.vbox.Add(self.UUIDString, 0, wx.EXPAND | wx.ALL, 5)
self.UUIDStringText = wx.TextCtrl(self.panel, -1)
hbox2 = wx.BoxSizer(wx.HORIZONTAL)
hbox2.Add(self.UUIDStringText, 1, wx.EXPAND)
self.vbox.Add(hbox2, 0, wx.EXPAND | wx.ALL, 5)
self.vbox.Add((-1, 10))
self.memAddressStr = wx.StaticText(self.panel, -1, u'请输入错误信息的内存地址:')
self.vbox.Add(self.memAddressStr, 0, wx.ALL, 5)
self.memAddress = wx.TextCtrl(self.panel, -1)
hbox3 = wx.BoxSizer(wx.HORIZONTAL)
hbox3.Add(self.memAddress, 1, wx.EXPAND)
self.vbox.Add(hbox3, 0, wx.EXPAND | wx.ALL, 5)
self.fileBtn = wx.Button(self.panel, -1, u'分析')
self.fileBtn.Bind(wx.EVT_BUTTON, self.startCalc)
hbox4 = wx.BoxSizer(wx.HORIZONTAL)
hbox4.Add(self.fileBtn, 1, wx.EXPAND)
self.vbox.Add(hbox4, 0, wx.EXPAND | wx.ALL, 5)
self.vbox.Add((-1, 10))
self.maybeReason = wx.StaticText(self.panel, -1, u'有可能错误的地方:', style=wx.TE_WORDWRAP|wx.TE_MULTILINE)#size=(170, 30), pos=(5, 250),
self.vbox.Add(self.maybeReason, 0, wx.EXPAND | wx.ALL, 5)
self.maybeReasonContent = wx.TextCtrl(self.panel, -1, u'', style=wx.TE_WORDWRAP|wx.TE_MULTILINE)#size=(500, 60), pos=(5, 270),
hbox5 = wx.BoxSizer(wx.HORIZONTAL)
hbox5.Add(self.maybeReasonContent, 1, wx.EXPAND)
self.vbox.Add(hbox5, 1, wx.EXPAND | wx.ALL, 5)
self.vbox.SetItemMinSize(hbox5, (200, 100))
self.panel.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterWindow)
self.panel.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveWindow)
self.panel.Bind(wx.EVT_MOTION, self.OnMotion)
self.panel.SetSizer(self.vbox)
#文件列表单击事件
def ListBoxClick(self, event):
self.selectedArchiveFilePath = self.filesList[event.GetSelection()]
self.getFilePath(self.selectedArchiveFilePath)
self.getArchiveUUID()
#获取文件UUID
def getArchiveUUID(self):
comString = 'dwarfdump --uuid ' + self.dsymFilePath
lines = os.popen(comString).readlines()
self.archiveUUIDDic = {}
for line in lines:
uuidString = line.split(' ')[1]
archiveType = line.split(' ')[2][1:-1]
self.archiveUUIDDic[archiveType] = uuidString
if hasattr(self, 'archiveType'):
self.fileTypeLBhbox.Remove(self.fileTypeLBhbox.GetItemIndex(self.archivebox))
self.archiveType.Destroy()
self.archiveType = wx.RadioBox(self.panel, -1, "请选择该archive文件对应的编译类型", choices=self.archiveUUIDDic.keys(), majorDimension=1)
self.archivebox = wx.BoxSizer(wx.HORIZONTAL)
self.archivebox.Add(self.archiveType, 0, wx.ALL, 5)
self.fileTypeLBhbox.Add(self.archivebox, 0, wx.ALL, 5)
self.fileTypeLBhbox.Layout()
self.Bind(wx.EVT_RADIOBOX, self.EvtRadioBox, self.archiveType)
self.UUIDStringText.SetValue(self.archiveUUIDDic[self.archiveType.GetStringSelection()])
self.selectedArchiveType = self.archiveType.GetStringSelection()
#选择编译器事件
def EvtRadioBox(self, event):
self.selectedArchiveType = event.GetString()
self.UUIDStringText.SetValue(self.archiveUUIDDic[self.selectedArchiveType])
def startCalc(self, event):
if self.memAddress.GetValue():
comString = 'xcrun atos -arch ' + self.selectedArchiveType + ' -o ' + str(self.appFilePath) + ' ' + self.memAddress.GetValue()
tmp = os.popen(comString).readlines()
self.maybeReasonContent.SetValue(tmp[0])
def OnEnterWindow(self, event):
event.Skip()
def OnLeaveWindow(self, event):
event.Skip()
def OnMotion(self, event):
if event.Dragging() and event.LeftIsDown():
print '按住了鼠标移动'
event.Skip()
def ShowFileType(self):
self.fileTypeLB.Set(list([os.path.basename(filepath) for filepath in self.filesList]))
#获取最后需要的文件地址
def getFilePath(self, rootPath):
if rootPath.endswith("dSYM"):
self.dsymFilePath = rootPath
fileName = os.path.basename(rootPath)
else:
dsymsPath = os.path.join(rootPath,'dSYMs')
listFiles = os.listdir(dsymsPath)
for fileName in listFiles:
if fileName.endswith('dSYM'):
#dsym文件路径
self.dsymFilePath = os.path.join(dsymsPath, fileName)
appPath = os.path.join(self.dsymFilePath,'Contents/Resources/DWARF')
if os.path.isdir(appPath):
if len(os.listdir(appPath)) is not 0:
#命令行中需要的文件路径
self.appFilePath = os.path.join(appPath,fileName.split(".")[0])
#显示关于我的界面
def OnAboutMe(self, event):
aboutMe = AboutMe(self)
aboutMe.ShowModal()
aboutMe.Destroy()
versions = '1.0.0'
if __name__ == '__main__':
app = wx.App(redirect=False)
frame = AHFrame(None, 'dSYM文件分析工具' + versions)
frame.ShowWithEffect(True)
app.MainLoop()