本文整理汇总了Python中netzob.Common.MMSTD.Dictionary.Variables.AbstractVariable.AbstractVariable类的典型用法代码示例。如果您正苦于以下问题:Python AbstractVariable类的具体用法?Python AbstractVariable怎么用?Python AbstractVariable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AbstractVariable类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, _id, name, mutable, learnable, pointedID, symbol):
"""Constructor of AbstractRelationVariable:
@type pointedID: string
@param pointedID: the pointed variable's ID.
"""
AbstractVariable.__init__(self, _id, name, mutable, learnable, False)
self.log = logging.getLogger('netzob.Common.MMSTD.Dictionary.Variable.AbstractRelationVariable.py')
self.pointedID = pointedID
self.symbol = symbol
self.pointedVariable = None
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:11,代码来源:_AbstractRelationVariable.py
示例2: __init__
def __init__(self, _id, name, mutable, random, children=None):
"""Constructor of AbstractNodeVariable:
@type children: netzob.Common.MMSTD.Dictionary.Variable.AbstractVariable.AbstractVariable List
@param children: the list of this variable's children.
"""
AbstractVariable.__init__(self, _id, name, mutable, random, True)
# create logger with the given configuration
self.log = logging.getLogger('netzob.Common.MMSTD.Dictionary.Variable.AbstractNodeVariable.py')
self.children = []
if children is not None:
self.children.extend(children)
self.learning = False # (read access with mutable flag) Tells if the variable reads normally or through an attempt of learning.
开发者ID:lindi2,项目名称:netzob,代码行数:13,代码来源:AbstractNodeVariable.py
示例3: __init__
def __init__(self, _id, name, mutable, learnable, relationType, pointedID, symbol):
"""Constructor of ComputedRelationVariable:
Mutable and learnable are useless.
@type relationType: string
@param relationType: the type of computation we will use.
"""
AbstractVariable.__init__(self, _id, name, mutable, learnable, False)
self.log = logging.getLogger('netzob.Common.MMSTD.Dictionary.Variable.ComputedRelationVariable.py')
self.relationType = relationType
self.currentValue = None
self.pointedID = pointedID
self.symbol = symbol
self.pointedVariable = None
开发者ID:lindi2,项目名称:netzob,代码行数:14,代码来源:ComputedRelationVariable.py
示例4: loadFromXML
def loadFromXML(xmlRoot, namespace, version, symbol):
"""loadFromXML:
Loads a repeat variable from an XML definition.
We do not trust the user and check every field (even mandatory).
"""
logging.debug("[ RepeatVariable: loadFromXML:")
if version == "0.1":
xmlID = xmlRoot.get("id")
xmlName = xmlRoot.get("name")
xmlMutable = xmlRoot.get("mutable") == "True"
xmlLearnable = xmlRoot.get("learnable") == "True"
xmlChild = xmlRoot.find("{" + namespace + "}variable")
child = AbstractVariable.loadFromXML(xmlChild, namespace, version, symbol)
# minIterations
xmlMinIterations = xmlRoot.find("{" + namespace + "}minIterations")
if xmlMinIterations is not None:
minIterations = int(xmlMinIterations.text)
else:
minIterations = 0
# maxIterations
xmlMaxIterations = xmlRoot.find("{" + namespace + "}maxIterations")
if xmlMaxIterations is not None:
maxIterations = int(xmlMaxIterations.text)
else:
maxIterations = RepeatVariable.MAX_ITERATIONS
result = RepeatVariable(xmlID, xmlName, xmlMutable, xmlLearnable, child, minIterations, maxIterations)
logging.debug("RepeatVariable: loadFromXML successes: {0} ]".format(result.toString()))
return result
logging.debug("RepeatVariable: loadFromXML fails")
return None
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:34,代码来源:RepeatVariable.py
示例5: writeChildren
def writeChildren(self, writingToken):
"""write:
Each child tries to write its value..
If it fails, it restore it value and the next child try.
It stops if one child successes.
"""
self.log.debug("[ {0} (Alternate): writeChildren:".format(AbstractVariable.toString(self)))
savedValue = writingToken.getValue()
savedIndex = writingToken.getIndex()
for child in self.getChildren():
# Memorized values for the child and its successor.
dictOfValues = dict()
dictOfValue = child.getDictOfValues(writingToken)
for key, val in dictOfValue.iteritems():
dictOfValues[key] = val
child.write(writingToken)
if writingToken.isOk() and writingToken.getValue() is not None:
break
else:
writingToken.setValue(savedValue)
# We restore values for the child and its successor.
child.restore(writingToken)
vocabulary = writingToken.getVocabulary()
for key, val in dictOfValues.iteritems():
vocabulary.getVariableByID(key).setCurrentValue(val)
if writingToken.isOk():
# The value of the variable is simply the value we made.
self.currentValue = writingToken.getValue()[savedIndex:writingToken.getIndex()]
self.log.debug("Variable {0}: {1}. ]".format(self.getName(), writingToken.toString()))
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:34,代码来源:AlternateVariable.py
示例6: toString
def toString(self):
"""toString:
"""
lgth = 0
if self.children is not None:
lgth = len(self.children)
return _("[Alternate] {0} ({1})").format(AbstractVariable.toString(self), str(lgth))
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:7,代码来源:AlternateVariable.py
示例7: write
def write(self, writingToken):
"""write:
Each child tries sequentially to write its value.
If one of them fails, the whole operation is cancelled.
"""
self.log.debug("[ {0} (Aggregate): write access:".format(AbstractVariable.toString(self)))
self.resetTokenChoppedIndexes() # New write access => new final value and new reference to it.
if self.getChildren() is not None:
if self.isMutable():
# mutable.
self.shuffleChildren()
self.writeChildren(writingToken)
else:
# not mutable.
self.writeChildren(writingToken)
else:
# no child.
self.log.debug("Write abort: the variable has no child.")
writingToken.setOk(False)
# Variable notification
if writingToken.isOk():
self.notifyBoundedVariables("write", writingToken)
self.log.debug("Variable {0}: {1}. ]".format(self.getName(), writingToken.toString()))
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:27,代码来源:AggregateVariable.py
示例8: toString
def toString(self):
"""toString:
"""
lgth = 0
if self.getChildren() is not None:
lgth = len(self.getChildren())
return _("[Aggregate] {0} ({1})").format(AbstractVariable.toString(self), str(lgth))
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:7,代码来源:AggregateVariable.py
示例9: read
def read(self, readingToken):
"""read:
Each child tries sequentially to read a part of the read value.
If one of them fails, the whole operation is cancelled.
"""
self.log.debug("[ {0} (Aggregate): read access:".format(AbstractVariable.toString(self)))
if self.getChildren() is not None:
if self.isMutable():
# mutable.
self.sortChildrenToRead(readingToken)
self.readChildren(readingToken)
else:
# not mutable.
self.readChildren(readingToken)
else:
# no child.
self.log.debug("Write abort: the variable has no child.")
readingToken.setOk(False)
# Variable notification
if readingToken.isOk():
self.notifyBoundedVariables("read", readingToken, self.currentValue)
self.log.debug("Variable {0}: {1}. ]".format(self.getName(), readingToken.toString()))
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:25,代码来源:AggregateVariable.py
示例10: notifiedWrite
def notifiedWrite(self, writingToken):
"""notify:
A write access called by a notification of the pointed variable (when it has finished its own treatment).
It updates the values this variable has written in the writingToken value.
@type writingToken: netzob.Common.MMSTD.Dictionary.VariableProcessingToken.VariableWritingToken.VariableWritingToken
@param writingToken: a token which contains all critical information on this access.
"""
self.log.debug("[ {0} (relation): notifiedWrite access:".format(AbstractVariable.toString(self)))
if self.isDefined(writingToken):
# Compute the value
self.retrieveValue(writingToken)
# replace the new value in the writing token
writingToken.setValueForVariable(self, self.currentValue)
else:
self.log.debug("Write abort: the variable is neither defined, nor random.")
writingToken.setOk(False)
# Variable notification
if writingToken.isOk():
self.notifyBoundedVariables("write", writingToken)
self.log.debug("Variable {0}: {1}. ]".format(self.getName(), writingToken.toString()))
开发者ID:lindi2,项目名称:netzob,代码行数:27,代码来源:ComputedRelationVariable.py
示例11: write
def write(self, writingToken):
"""write:
The relation variable returns a computed or a generated value.
"""
self.log.debug("[ {0} (relation): write access:".format(AbstractVariable.toString(self)))
self.directPointer = self.findDirectPointer()
if self.isDefined(writingToken):
if not self.directPointer:
# We will write the real value at notification time. (An awaiting value is written though.)
self.bindValue(writingToken)
self.guessValue()
else:
# We directly retrieve and write the actual value (which would be deprecated and replaced if the variable is directPointer).
self.retrieveValue(writingToken)
self.writeValue(writingToken)
else:
self.log.debug("Write abort: the variable is not defined.")
writingToken.setOk(False)
# Variable notification
if writingToken.isOk():
self.notifyBoundedVariables("write", writingToken)
self.log.debug("Variable {0}: {1}. ]".format(self.getName(), writingToken.toString()))
开发者ID:lindi2,项目名称:netzob,代码行数:25,代码来源:ComputedRelationVariable.py
示例12: notifiedRead
def notifiedRead(self, readingToken, pointedValue):
"""notifiedRead:
A read access called by a notification of the pointed variable (when it has finished its own treatment).
It checks that the new value complies with the reading token value at this very position.
@type readingToken: netzob.Common.MMSTD.Dictionary.VariableProcessingToken.VariableReadingToken.VariableReadingToken
@param readingToken: a token which contains all critical information on this access.
"""
self.log.debug("[ {0} (relation): read access:".format(AbstractVariable.toString(self)))
if self.isDefined(readingToken):
for linkedValue in readingToken.getLinkedValue():
if linkedValue[0] == self.getID():
# We compare the pointed value to the value the current variable wrote in memory.
if linkedValue[1] != self.computeValue(pointedValue):
readingToken.setOk(False)
break
else:
self.log.debug("Read abort: the variable is neither defined, nor mutable.")
readingToken.setOk(False)
# Variable notification
if readingToken.isOk():
self.notifyBoundedVariables("read", readingToken, pointedValue)
self.log.debug("Variable {0}: {1}. ]".format(self.getName(), readingToken.toString()))
开发者ID:lindi2,项目名称:netzob,代码行数:27,代码来源:ComputedRelationVariable.py
示例13: read
def read(self, readingToken):
"""read:
The relation variable tries to compare/learn the read value.
"""
self.log.debug("[ {0} (relation): read access:".format(AbstractVariable.toString(self)))
self.directPointer = self.findDirectPointer()
if self.isDefined(readingToken):
if self.directPointer:
# We directly retrieve and compare the value.
self.retrieveValue(readingToken)
self.compare(readingToken)
else:
# We make a small format comparison.
self.compareFormat(readingToken)
# We will verify the value at notification time.
self.bindValue(readingToken)
else:
self.log.debug("Read abort: the variable is not defined.")
readingToken.setOk(False)
# Variable notification
if readingToken.isOk():
self.notifyBoundedVariables("read", readingToken, self.currentValue)
self.log.debug("Variable {0}: {1}. ]".format(self.getName(), readingToken.toString()))
开发者ID:lindi2,项目名称:netzob,代码行数:27,代码来源:ComputedRelationVariable.py
示例14: write
def write(self, writingToken):
"""write:
The leaf element returns its value or a generated one.
"""
self.log.debug("[ {0} (leaf): write access:".format(AbstractVariable.toString(self)))
self.resetTokenChoppedIndexes() # New write access => new final value and new reference to it.
if self.isMutable():
if self.isLearnable():
if self.isDefined(writingToken):
# mutable, learnable and defined.
self.mutate(writingToken)
self.writeValue(writingToken)
else:
# mutable, learnable and not defined.
self.generate(writingToken)
self.memorize(writingToken)
self.writeValue(writingToken)
else:
if self.isDefined(writingToken):
# mutable, not learnable, defined.
self.generate(writingToken)
self.writeValue(writingToken)
else:
# mutable, not learnable, not defined.
self.generate(writingToken)
self.writeValue(writingToken)
else:
if self.isLearnable():
if self.isDefined(writingToken):
# not mutable, learnable and defined.
self.writeValue(writingToken)
else:
# not mutable, learnable and not defined.
self.generate(writingToken)
self.memorize(writingToken)
self.writeValue(writingToken)
else:
if self.isDefined(writingToken):
# not mutable, not learnable and defined.
self.writeValue(writingToken)
else:
# not mutable, not learnable and not defined.
self.log.debug("Write abort: the variable is neither defined, nor mutable.")
writingToken.setOk(False)
# Variable notification
if writingToken.isOk():
self.notifyBoundedVariables("write", writingToken)
self.log.debug("Variable {0}: {1}. ]".format(self.getName(), writingToken.toString()))
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:56,代码来源:AbstractLeafVariable.py
示例15: read
def read(self, readingToken):
"""read:
The leaf element tries to compare/learn the read value.
"""
self.log.debug("[ {0} (leaf): read access:".format(AbstractVariable.toString(self)))
if self.isMutable():
if self.isLearnable():
if self.isDefined(readingToken):
# mutable, learnable and defined.
self.forget(readingToken)
self.compareFormat(readingToken)
self.learn(readingToken)
self.memorize(readingToken)
else:
# mutable, learnable and not defined.
self.compareFormat(readingToken)
self.learn(readingToken)
self.memorize(readingToken)
else:
if self.isDefined(readingToken):
# mutable, not learnable and defined.
self.compareFormat(readingToken)
else:
# mutable, learnable and not defined.
self.compareFormat(readingToken)
else:
if self.isLearnable():
if self.isDefined(readingToken):
# not mutable, learnable and defined.
self.compare(readingToken)
else:
# not mutable, learnable and not defined.
self.compareFormat(readingToken)
self.learn(readingToken)
self.memorize(readingToken)
else:
if self.isDefined(readingToken):
# not mutable, not learnable and defined.
self.compare(readingToken)
else:
# not mutable, not learnable and not defined.
self.log.debug("Read abort: the variable is neither defined, nor mutable.")
readingToken.setOk(False)
# Variable notification
if readingToken.isOk():
self.notifyBoundedVariables("read", readingToken, self.getValue(readingToken))
self.log.debug("Variable {0}: {1}. ]".format(self.getName(), readingToken.toString()))
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:56,代码来源:AbstractLeafVariable.py
示例16: toString
def toString(self):
"""toString:
For debugging purpose.
"""
# We simply avoid to print unreadable binary.
if self.type.getType() == BinaryType.TYPE:
readableValue = TypeConvertor.bin2strhex(self.originalValue)
else:
readableValue = self.bin2str(self.originalValue)
return "[Data] {0}, type: {1}, original value: {2}".format(AbstractVariable.toString(self), self.type.toString(), readableValue)
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:11,代码来源:DataVariable.py
示例17: toXML
def toXML(self, root, namespace):
"""toXML:
Creates the xml tree associated to this variable.
Adds every child's own xml definition as xml child to this tree.
"""
self.log.debug("[ {0} (Aggregate): toXML:".format(AbstractVariable.toString(self)))
xmlVariable = etree.SubElement(root, "{" + namespace + "}variable")
xmlVariable.set("id", str(self.getID()))
xmlVariable.set("name", str(self.getName()))
xmlVariable.set("{http://www.w3.org/2001/XMLSchema-instance}type", "netzob:AggregateVariable")
xmlVariable.set("mutable", str(self.isMutable()))
xmlVariable.set("learnable", str(self.isLearnable()))
# Definition of children variables
for child in self.getChildren():
child.toXML(xmlVariable, namespace)
self.log.debug("Variable {0}. ]".format(self.getName()))
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:17,代码来源:AggregateVariable.py
示例18: loadFromXML
def loadFromXML(xmlRoot, namespace, version, symbol):
"""loadFromXML:
Loads an aggregate variable from an XML definition.
"""
logging.debug("[ AggregateVariable: loadFromXML:")
if version == "0.1":
xmlID = xmlRoot.get("id")
xmlName = xmlRoot.get("name")
xmlMutable = xmlRoot.get("mutable") == "True"
xmlLearnable = xmlRoot.get("learnable") == "True"
result = AggregateVariable(xmlID, xmlName, xmlMutable, xmlLearnable, [])
for xmlChildren in xmlRoot.findall("{" + namespace + "}variable"):
child = AbstractVariable.loadFromXML(xmlChildren, namespace, version, symbol)
result.addChild(child)
logging.debug("AggregateVariable: loadFromXML successes: {0} ]".format(result.toString()))
return result
logging.debug("AggregateVariable: loadFromXML fails")
return None
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:19,代码来源:AggregateVariable.py
示例19: readChildren
def readChildren(self, readingToken):
"""read:
Each child tries to read the value.
If it fails, it restore it value and the next child try.
It stops if one child successes.
"""
self.log.debug("[ {0} (Alternate): readChildren:".format(AbstractVariable.toString(self)))
savedIndex = readingToken.getIndex()
for child in self.getChildren():
# Memorized values for the child and its successors.
dictOfValues = dict()
dictOfValue = child.getDictOfValues(readingToken)
for key, val in dictOfValue.iteritems():
dictOfValues[key] = val
child.read(readingToken)
if readingToken.isOk():
break
else:
readingToken.setIndex(savedIndex)
# We restore values for the child and its successors.
child.restore(readingToken)
vocabulary = readingToken.getVocabulary()
for key, val in dictOfValues.iteritems():
vocabulary.getVariableByID(key).setCurrentValue(val)
if readingToken.isOk():
# The value of the variable is simply the value we 'ate'.
self.currentValue = readingToken.getValue()[savedIndex:readingToken.getIndex()]
if self.isLearnable() and not readingToken.isOk() and not self.isLearning():
# If we dont not found a proper child but the node can learn, we learn the value.
self.learn(child, readingToken)
self.log.debug("Variable {0}: {1}. ]".format(self.getName(), readingToken.toString()))
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:36,代码来源:AlternateVariable.py
示例20: toString
def toString(self):
"""toString:
"""
return "[Repeat] {0}, iterations: ({1}, {2})".format(AbstractVariable.toString(self), str(self.minIterations), str(self.maxIterations))
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:4,代码来源:RepeatVariable.py
注:本文中的netzob.Common.MMSTD.Dictionary.Variables.AbstractVariable.AbstractVariable类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论