-
Notifications
You must be signed in to change notification settings - Fork 275
/
_base.py
105 lines (89 loc) · 3.8 KB
/
_base.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2013-2014, NewAE Technology Inc
# All rights reserved.
#
# Author: Colin O'Flynn
#
# Find this and more at newae.com - this file is part of the chipwhisperer
# project, http://www.assembla.com/spaces/chipwhisperer
#
# This file is part of chipwhisperer.
#
# chipwhisperer is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# chipwhisperer is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with chipwhisperer. If not, see <http://www.gnu.org/licenses/>.
#=================================================
from chipwhisperer.common.api.autoscript import AutoScript
from chipwhisperer.common.utils.pluginmanager import Plugin
from chipwhisperer.common.utils.tracesource import TraceSource, ActiveTraceObserver
from chipwhisperer.common.utils.parameter import setupSetParam
class PreprocessingBase(TraceSource, ActiveTraceObserver, AutoScript, Plugin):
"""
Base Class for all preprocessing modules
Derivate Classes work like this:
- updateScript is used by the GUI to create the parameters list and generate the API scripts
- the other methods are used by the API to apply the preprocessing filtering
You need to pass the getTraceSource reference in the constructor in order to apply the preprocessing step
"""
_name = "None"
def __init__(self, parentParam=None, traceSource=None):
self.enabled = False
ActiveTraceObserver.__init__(self, parentParam=parentParam)
TraceSource.__init__(self, self.getName())
AutoScript.__init__(self)
self.setTraceSource(traceSource, blockSignal=True)
if traceSource:
traceSource.sigTracesChanged.connect(self.sigTracesChanged.emit) # Forwards the traceChanged signal to the next observer in the chain
self.getParams().addChildren([
{'name':'Enabled', 'key':'enabled', 'type':'bool', 'default':self.getEnabled(), 'get':self.getEnabled, 'set':self.setEnabled}
])
self.findParam('input').hide()
def updateScript(self, ignored=None):
pass
def getEnabled(self):
"""Turn on/off this preprocessing"""
return self.enabled
@setupSetParam("Enabled")
def setEnabled(self, enabled):
"""Turn on/off this preprocessing"""
self.enabled = enabled
self.updateScript()
def getTrace(self, n):
"""Get trace number n"""
if self.enabled:
trace = self._traceSource.getTrace(n)
# Do your preprocessing here
return trace
else:
return self._traceSource.getTrace(n)
def getTextin(self, n):
"""Get text-in number n"""
return self._traceSource.getTextin(n)
def getTextout(self, n):
"""Get text-out number n"""
return self._traceSource.getTextout(n)
def getKnownKey(self, n=None):
"""Get known-key number n"""
return self._traceSource.getKnownKey(n)
def init(self):
"""Do any initilization required once all traces are loaded"""
pass
def getSegmentList(self):
return self._traceSource.getSegmentList()
def getAuxData(self, n, auxDic):
return self._traceSource.getAuxData(n, auxDic)
def findMappedTrace(self, n):
return self._traceSource.findMappedTrace(n)
def numTraces(self):
return self._traceSource.numTraces()