-
Notifications
You must be signed in to change notification settings - Fork 1
/
selectedSearchSoloUnseal.py
443 lines (370 loc) · 16.4 KB
/
selectedSearchSoloUnseal.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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 25 22:52:31 2018
@author: Loon
"""
import sys
#from PyQt5.QtCore import QTime
from PyQt5.QtWidgets import (QApplication, QWidget, QComboBox,
QLabel, QSpinBox, QLineEdit,
QPushButton, QGridLayout, QMessageBox,
QDesktopWidget)
from PyQt5.QtGui import QIcon
from PyQt5.QtSerialPort import QSerialPortInfo
import serialtransaction as st
import os, pickle, time, random
import winsound
duration = 1000 # millisecond
freq = 440 # Hz
class Dialog(QWidget):
#codeFound = pyqtSignal()
words=''
lastwords=''
canSend = False
requestToSend=''
m_waitTimeout=100
m_attemp=0
stockf021=b''
def __init__(self):
super().__init__()
self.m_transaction = 0
self.haveRightCode = False
self.stop = True
self.m_serialt = st.SerialTransaction()
self.initUI()
#self.longdelay = 0.8
self.shortdelay=0.05
def initUI(self):
self.m_serialPortLabel = QLabel("Serial port:")
self.m_serialPortComboBox = QComboBox()
self.m_waitResponseLabel = QLabel("Wait response, msec:")
self.m_waitResponseSpinBox = QSpinBox()
self.m_longDelayLabel = QLabel("transaction delay, msec:")
self.m_longDelaySpinBox = QSpinBox()
self.m_runTimeoutSpinBox = QSpinBox()
self.m_runTimeoutLabel = QLabel("run timeout in min:")
self.m_randomGroupButton = QPushButton("Random group")
self.m_defaultGroupButton = QPushButton("Default group")
self.m_indexListLabel = QLabel("Warp multiplicators:")
self.m_p0SpinBox = QSpinBox()
self.m_p1SpinBox = QSpinBox()
self.m_p2SpinBox = QSpinBox()
self.m_p3SpinBox = QSpinBox()
self.m_autoFindUnsealCodeButton = QPushButton("autoFindUnsealCode")
#self.m_stopButton = QPushButton("Stop")
self.m_runButton = QPushButton("Send request")
self.m_requestLineEdit = QLineEdit("F020")
self.m_requestLabel = QLabel("Request (hex without 0x):")
self.m_trafficLabel = QLabel("No traffic.")
self.m_statusLabel = QLabel("Status: Not running.")
available_ports = QSerialPortInfo.availablePorts()
for port in available_ports:
self.m_serialPortComboBox.addItem(port.portName())
self.m_waitResponseSpinBox.setRange(0,10000)
self.m_waitResponseSpinBox.setValue(1500)
self.m_longDelaySpinBox.setRange(0,10000)
self.m_longDelaySpinBox.setValue(100)
self.longdelay = 0.1
self.m_runTimeoutSpinBox.setRange(0,10000)
self.m_runTimeoutSpinBox.setValue(5)
self.m_p0SpinBox.setRange(0,2)
self.m_p0SpinBox.setValue(0)
self.m_p1SpinBox.setRange(0,4)
self.m_p1SpinBox.setValue(0)
self.m_p2SpinBox.setRange(0,16)
self.m_p2SpinBox.setValue(4)
self.m_p3SpinBox.setRange(0,256)
self.m_p3SpinBox.setValue(16)
mainLayout = QGridLayout()
mainLayout.addWidget(self.m_serialPortLabel,0,0)
mainLayout.addWidget(self.m_serialPortComboBox,0,1)
mainLayout.addWidget(self.m_waitResponseLabel,1,0)
mainLayout.addWidget(self.m_waitResponseSpinBox,1,1)
mainLayout.addWidget(self.m_longDelayLabel,2,0)
mainLayout.addWidget(self.m_longDelaySpinBox,2,1)
mainLayout.addWidget(self.m_runTimeoutLabel,3,0)
mainLayout.addWidget(self.m_runTimeoutSpinBox,3,1)
mainLayout.addWidget(self.m_randomGroupButton,3,2)
mainLayout.addWidget(self.m_defaultGroupButton,3,3)
mainLayout.addWidget(self.m_indexListLabel,4,0)
mainLayout.addWidget(self.m_p0SpinBox,4,1)
mainLayout.addWidget(self.m_p1SpinBox,4,2)
mainLayout.addWidget(self.m_p2SpinBox,4,3)
mainLayout.addWidget(self.m_p3SpinBox,4,4)
#mainLayout.addWidget(self.m_stopButton,1,2,2,1)
mainLayout.addWidget(self.m_requestLabel,5,0)
mainLayout.addWidget(self.m_requestLineEdit,5,1,1,2)
mainLayout.addWidget(self.m_runButton,6,1)
mainLayout.addWidget(self.m_autoFindUnsealCodeButton,6,2)
mainLayout.addWidget(self.m_trafficLabel,7,0,1,4)
mainLayout.addWidget(self.m_statusLabel,8,0,1,5)
self.setLayout(mainLayout)
self.setWindowTitle("Solo Search Unseal Code")
self.setWindowIcon(QIcon('pinion-icon.png'))
self.m_serialPortComboBox.setFocus()
#connection
#self.codeFound.connect(self.showResult)
self.m_runButton.clicked.connect(self.transactionUI)
self.m_autoFindUnsealCodeButton.clicked.connect(self.autoFindUnsealCode)
#☺self.m_stopButton.clicked.connect(self.stopSearching)
self.m_serialt.responseSignal.connect(self.showResponse)
self.m_serialt.errorSignal.connect(self.processError)
self.m_serialt.timeoutSignal.connect(self.processTimeout)
self.m_longDelaySpinBox.valueChanged.connect(self.updLongDelay)
self.m_waitResponseSpinBox.valueChanged.connect(self.updwaitTimeout)
self.m_randomGroupButton.clicked.connect(self.selectRandomGroup)
self.m_defaultGroupButton.clicked.connect(self.selectDefaultGroup)
self.center()
self.show()
def selectRandomGroup(self):
random.seed()
self.m_p0SpinBox.setValue(random.sample(range(3),1)[0])
self.m_p1SpinBox.setValue(random.sample(range(5),1)[0])
self.m_p2SpinBox.setValue(random.sample(range(17),1)[0])
self.m_p3SpinBox.setValue(random.sample(range(257),1)[0])
return
def selectDefaultGroup(self):
self.m_p0SpinBox.setValue(0)
self.m_p1SpinBox.setValue(0)
self.m_p2SpinBox.setValue(4)
self.m_p3SpinBox.setValue(16)
return
def autoFindUnsealCode(self):
self.m_transaction = 0
self.m_attemp = 0
self.stop = False
self.haveRightCode = False
self.requestToSend = 'f021'
self.stockf021 = self.transaction()
print("stockf021:{}".format(self.stockf021))
filename_remain, remaining2Words = self.selectGroup()
random.seed()
t0 = time.time()
print(time.strftime(" start at %H:%M:%S", time.gmtime()))
while not self.haveRightCode and not self.stop:
self.lastwords = self.words
self.words=random.sample(remaining2Words,1)[0]
self.sendUnsealCode(self.words[:4], self.words[-4:])
#time.sleep(self.longdelay) #wait 10 ms
#self.longdelay=1
if self.checkErrorStatus():
self.haveRightCode = True
self.stop = True
QMessageBox.information(self,"Pwd found!","Youpi! Found unseal password {} in {} attemps".format(self.words,self.m_attemp))
#self.longdelay=0.1
#time.sleep(self.longdelay)
remaining2Words.remove(self.words)
if len(remaining2Words) == 0 or \
time.time()-t0 > 60*self.m_runTimeoutSpinBox.value():
self.stop = True
#self.mutex.unlock()
#print("fin: {}".format(self.canSend))
#if self.words == '04143672':
#print("Traffic, attemp #{}: {} is in.".format(self.m_attemp,self.words))
#self.stop = True
#print("début: {}".format(self.canSend))
#winsound.Beep(2*freq, duration)
#QMessageBox.information(self,"is In","No! known unseal password {} in {} transactions".format(self.words,self.m_transaction))
elapsed = (time.time()-t0)/60
print("duration {} minutes with {} attemps.".format(elapsed,self.m_attemp))
with open(filename_remain, 'wb') as fichier:
mon_pickler = pickle.Pickler(fichier,2)
for w in remaining2Words:
mon_pickler.dump(w)
#if self.haveRightCode:
#winsound.Beep(freq, 2*duration)
#QMessageBox.information(self,"Pwd found!","Youpi! Found unseal password {} in {} transactions".format(self.words,self.m_transaction))
#print(time.strftime(" found at %H:%M:%S", time.gmtime()))
#print(self.words)
return
def selectGroup(self):
lp=[self.m_p0SpinBox.value(),self.m_p1SpinBox.value(),
self.m_p2SpinBox.value(),self.m_p3SpinBox.value()]
filename=''
for i in lp:
filename += str(i) + 'x'
filename_full = filename + 'Warp'
filename_remain = filename + 'WarpRemain'
if not os.path.isfile(filename_full):
filename_full = warpGenerator(lp)
remaining2Words = copyFileToList(filename_full)[0]
else:
if os.path.isfile(filename_remain):
remaining2Words = copyFileToList(filename_remain)[0]
else:
remaining2Words = copyFileToList(filename_full)[0]
return (filename_remain, remaining2Words)
def stopSearching(self):
self.stop = True
return
def sendUnsealCode(self, word1, word2):
self.m_attemp += 1
self.m_statusLabel.setText("Status: Running, connected to port {}.".format(self.m_serialPortComboBox.currentText()))
self.requestToSend = '1f00' + word1
#time.sleep(self.longdelay)
self.transaction()
#time.sleep(1.1)
self.requestToSend = '1f00' + word2
self.transaction()
return
def checkErrorStatus(self):
#self.m_waitTimeout = 200
# read unseal code:
self.requestToSend = 'f060'
#time.sleep(self.longdelay)
self.transaction()
#time.sleep(self.longdelay)
# check error status:¶
self.requestToSend = '1016'
ba=self.transaction()
b=bin(int(ba))
#print(b[-4:])
if b[-4:] != '0000':
return True
#self.m_waitTimeout = self.m_waitResponseSpinBox.value()
return False
def testWrite(self):
#self.m_waitTimeout = 200
# read unseal code:
self.requestToSend = 'ff2103303037' #'007'=0x303037
#time.sleep(self.longdelay)
self.transaction()
#time.sleep(self.longdelay)
# check error status:¶
self.requestToSend = 'f021'
ba=self.transaction()
if ba == b'007':
s=hex(ba.size()).split('x')[-1]
while len(s) < 2:
s = '0' + s
strhex = ba.toHex()
self.requestToSend = 'ff21' + s + str(strhex,'utf-8')
self.transaction()
return True
else:
return False
def transaction(self):
#self.canSend = False
#self.setControlsEnabled(False)
self.m_statusLabel.setText("Status: Running, connected to port {}.".format(self.m_serialPortComboBox.currentText()))
response=self.m_serialt.transaction(self.m_serialPortComboBox.currentText(),\
self.m_waitTimeout,\
self.requestToSend)
#wait_until(self.readyToSend,self.longdelay,self.shortdelay)
return response
def transactionUI(self):
self.m_waitTimeout = 200
#self.canSend = False
#self.setControlsEnabled(False)
self.m_statusLabel.setText("Status: Running, connected to port {}.".format(self.m_serialPortComboBox.currentText()))
#wait_until(self.readyToSend,self.longdelay,self.shortdelay)
response = self.m_serialt.transaction(self.m_serialPortComboBox.currentText(),\
self.m_waitTimeout,\
self.m_requestLineEdit.text())
#wait_until(self.readyToSend,self.longdelay,self.shortdelay)
self.m_waitTimeout = self.m_waitResponseSpinBox.value()
return response
def showResponse(self, ba):
#print("receive at {}".format(QTime.currentTime().toString()))
#self.setControlsEnabled(True)
self.m_transaction += 1
self.m_trafficLabel.setText("response (bytes):{}".format(ba))
#ok = False
#print(ba.toInt(ok))
#print(ba)
#self.canSend=True
return
def readyToSend(self):
return self.canSend
def showResult(self):
winsound.Beep(freq, 2*duration)
QMessageBox.information(self,"Pwd found!","Youpi! Found unseal password {} in {} transactions".format(self.words,self.m_transaction))
print(time.strftime(" found at %H:%M:%S", time.gmtime()))
print(self.words)
def processError(self, s):
self.setControlsEnabled(True)
self.m_statusLabel.setText("Status: Not running, {}.".format(s))
self.m_trafficLabel.setText("No traffic.")
return
def processTimeout(self, s):
self.setControlsEnabled(True)
self.m_statusLabel.setText("Status: Running, {}.".format(s))
self.m_trafficLabel.setText("No traffic.")
return
def updLongDelay(self,val):
#self.longdelay = self.m_longDelaySpinBox.value()/1000
self.londelay = val/1000
print("Long delay = {} s".format(self.londelay))
return
def updwaitTimeout(self,val):
#self.longdelay = self.m_longDelaySpinBox.value()/1000
self.m_waitTimeout = val
print("Long delay = {} s".format(self.m_waitTimeout))
return
def setControlsEnabled(self, enable):
self.m_runButton.setEnabled(enable)
self.m_serialPortComboBox.setEnabled(enable)
self.m_waitResponseSpinBox.setEnabled(enable)
self.m_requestLineEdit.setEnabled(enable)
return
def center(self):
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
def closeEvent(self,event):
reply = QMessageBox.question(self, 'Message',
"Are you sure to quit?", QMessageBox.Yes |
QMessageBox.No, QMessageBox.No)
if reply == QMessageBox.Yes:
event.accept()
else:
event.ignore()
def saveFromTo(filename,start=0x00000000, quantity=0x10000):
with open (filename,'wb') as fichier:
mon_pickler = pickle.Pickler(fichier,2)
hexmaxi=start+quantity;lenmaxi=8
for h in range(start,hexmaxi+1):
s=hex(h).split('x')[-1]
while len(s) < lenmaxi:
s = '0' + s
mon_pickler.dump(s)
return
def copyFileToList(filename):
"""copy les données depuis un fichier vers une liste."""
#t0 = time.time()
with open(filename, 'rb') as fichier:
mon_depickler = pickle.Unpickler(fichier)
data=[];dim = 0
while 1:
try:
data.append(mon_depickler.load())
dim += 1
except EOFError:
print("fin de lecture.")
break
#print("durée : {} s.".format(time.time() - t0))
return (data, dim)
def warpGenerator(list_premiers):
filename = ''
for i in list_premiers:
filename += str(i) + 'x'
filename += 'Warp'
begin = (list_premiers[0]*5*17*257*65537 +
list_premiers[1]*17*257*65537 +
list_premiers[2]*257*65537 +
list_premiers[3]*65537)
saveFromTo(filename,begin)
return filename
def wait_until(somepredicate, timeout, period=0.01, *args, **kwargs):
mustend = time.time() + timeout
while time.time() < mustend:
if somepredicate(*args, **kwargs): return True
time.sleep(period)
return False
# Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
app = QApplication(sys.argv)
w = Dialog()
#w.show()
sys.exit(app.exec_())