-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpublish.py
181 lines (155 loc) · 6.26 KB
/
publish.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
# MIT License
#
# Copyright (c) 2021 Yansong Li
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""Bundles ReverseWidget application and all its dependencies into a single package.
This script outputs a single Python package from PyInstaller. And we also integrate
necessary resources isolated from PyInstaller.
Usage:
python publish.py # publish debug package with cmd window
python publish.py release # publish release package without cmd window
"""
"""将PythonGUI程序转换为一个包文件,解决依赖问题。
用法:
python publish.py # 发布debug版本包,有命令行窗口
python publish.py release # 发布release版本包,无命令行窗口
"""
# -*- coding: utf-8 -*-
import shutil
import os
import sys
import zipfile
def copy_dir(src_dir, dst_dir, filter=None):
"""
Copy src_dir to dst_dir
:param src_dir: source directory
:param dst_dir: destination directory
:return: null
"""
if not os.path.exists(dst_dir):
os.makedirs(dst_dir)
if os.path.exists(src_dir):
for file in os.listdir(src_dir):
if not filter or filter and filter in file:
file_path = os.path.join(src_dir, file)
dst_path = os.path.join(dst_dir, file)
if os.path.isfile(os.path.join(src_dir, file)):
shutil.copy(file_path, dst_path)
else:
copy_dir(file_path, dst_path)
def copy_file(src_file, dst_dir):
"""
Copy file to dst_dir
:param src_file: source file
:param dst_dir: destination directory
:return: null
"""
if not os.path.exists(dst_dir):
os.makedirs(dst_dir)
shutil.copy(src_file, dst_dir)
def get_py_path():
"""
Get current python lib path
:return: python lib path
"""
for i in sys.path:
if 'site-packages' in i:
if sys.platform == 'darwin' and '/Library/Frameworks/Python' in i:
return i
elif sys.platform == 'linux' or sys.platform == 'win32':
return i
def modify(file='main.spec', value='console=True', new_value='console=False'):
"""
Modify string in config file, such as console=True -> Fasle
:param file: main.spec
:return: null
"""
file_data = ''
need_update = False
try:
with open(file, 'r', encoding='utf-8') as fp:
for line in fp:
if value in line:
need_update = True
replaced = line.replace(value, new_value)
file_data += replaced
else:
file_data += line
if need_update:
with open(file, 'w', encoding='utf-8') as fp:
fp.write(file_data)
except Exception as e:
print(e)
def compress_folder(folder_path, zip_name):
with zipfile.ZipFile(zip_name, 'w', zipfile.ZIP_DEFLATED) as zipf:
for root, dirs, files in os.walk(folder_path):
for file in files:
file_path = os.path.join(root, file)
zipf.write(file_path, os.path.relpath(file_path, folder_path))
def get_version():
with open("VERSION") as fp:
return fp.readline().strip()
def main():
# 1.PyInstaller bundles a Python application and all its dependencies into a single package.
is_debug = True
platform = ""
if len(sys.argv) == 1:
os.system('pyinstaller -D -y -i ui\\resources\\pictures\\hacker.ico main.py')
elif (sys.argv[1]) == 'release':
is_debug = False
# Need to modify main.spec Console=False
modify('main.spec', 'console=True', 'console=False')
os.system('pyinstaller -y main.spec')
dst_path = 'dist/main/'
src_path = []
# 2.Copy resource files to package generated by PyInstaller
copy_dir('ui/resources', dst_path + 'ui/resources')
copy_dir('config', dst_path + 'config')
copy_file(get_py_path() + '/peid/userdb.txt', dst_path + '/peid')
src_path.append('VERSION')
if sys.platform == 'win32':
src_path.append(get_py_path() + '/keystone/keystone.dll')
src_path.append(get_py_path() + '/capstone/lib/capstone.dll')
platform = "windows"
elif sys.platform == 'linux':
src_path.append(get_py_path() + '/keystone/libkeystone.so')
src_path.append(get_py_path() + '/capstone/lib/libcapstone.so')
platform = "linux"
elif sys.platform == 'darwin':
src_path.append(get_py_path() + '/keystone/libkeystone.dylib')
src_path.append(get_py_path() + '/capstone/lib/libcapstone.dylib')
platform = "macOS"
for i in src_path:
shutil.copy(i, dst_path)
# 3.Create shortcut
# if sys.platform == 'linux':
# os.system('ln -s ./main/main ReverseWidget')
# Copy python_dll_inject
dll_path = 'opensource/python_dll_injector'
copy_dir(dll_path, 'dist/main/_internal/' + dll_path, filter='.py')
if sys.platform == 'win32':
os.rename('dist/main/main.exe', 'dist/main/ReverseWidget.exe')
else:
os.rename('dist/main/main', 'dist/main/ReverseWidget')
if is_debug:
name = 'ReverseWidget-v%s-%s-debug.zip' % (get_version(), platform)
else:
name = 'ReverseWidget-v%s-%s-release.zip' % (get_version(), platform)
compress_folder('dist/main', 'dist/%s' % name)
if __name__ == '__main__':
main()