def toXML(self, root, namespace): """toXML: Create the xml tree associated to this variable. """ xmlVariable = etree.SubElement(root, "{" + namespace + "}variable") # Header specific to the definition of a variable xmlVariable.set("id", str(self.getID())) xmlVariable.set("name", str(self.getName())) xmlVariable.set("{http://www.w3.org/2001/XMLSchema-instance}type", "netzob:BinaryVariable") # Original Value if self.getOriginalValue() is not None: xmlBinaryVariableOriginalValue = etree.SubElement( xmlVariable, "{" + namespace + "}originalValue") xmlBinaryVariableOriginalValue.text = TypeConvertor.bitarray2StrBitarray( self.getOriginalValue()) # Minimum bits xmlBinaryVariableStartValue = etree.SubElement( xmlVariable, "{" + namespace + "}minBits") xmlBinaryVariableStartValue.text = str(self.getMinBits()) # Maximum bits xmlBinaryVariableEndValue = etree.SubElement( xmlVariable, "{" + namespace + "}maxBits") xmlBinaryVariableEndValue.text = str(self.getMaxBits())
def computeCurrentValue(self, binValue): if binValue != None: strCurrentValue = TypeConvertor.bitarray2StrBitarray(binValue) binCurrentValue = binValue self.currentValue = (binCurrentValue, strCurrentValue) else: self.currentValue = None
def computeCurrentValue(self, binValue): """computeCurrentValue: Compute a couple of binary and string values for the current variable. @type strValue: string @param strValue: a string value proposed as default value for this variable. """ if binValue is not None: strCurrentValue = TypeConvertor.bitarray2StrBitarray(binValue) binCurrentValue = binValue self.currentValue = (binCurrentValue, strCurrentValue) else: self.currentValue = None
def toXML(self, root, namespace): xmlVariable = etree.SubElement(root, "{" + namespace + "}variable") # Header specific to the definition of a variable xmlVariable.set("id", str(self.getID())) xmlVariable.set("name", str(self.getName())) xmlVariable.set("{http://www.w3.org/2001/XMLSchema-instance}type", "netzob:BinaryVariable") # Original Value if self.getOriginalValue() != None: xmlBinaryVariableOriginalValue = etree.SubElement(xmlVariable, "{" + namespace + "}originalValue") xmlBinaryVariableOriginalValue.text = TypeConvertor.bitarray2StrBitarray(self.getOriginalValue()) # Minimum bits xmlBinaryVariableStartValue = etree.SubElement(xmlVariable, "{" + namespace + "}minBits") xmlBinaryVariableStartValue.text = str(self.getMinBits()) # Maximum bits xmlBinaryVariableEndValue = etree.SubElement(xmlVariable, "{" + namespace + "}maxBits") xmlBinaryVariableEndValue.text = str(self.getMaxBits())
def getValueToSend(self, negative, vocabulary, memory): if self.getCurrentValue() != None: self.log.debug("BINARY : HAS CURRENT VALUE") return self.getCurrentValue() if memory.hasMemorized(self): self.log.debug("BINARY : HAS NO CURRENT VALUE BUT HAS MEMORY") return memory.recall(self) # We generate a new value binNewValue = self.generateValue() strNewValue = TypeConvertor.bitarray2StrBitarray(self.generateValue()) newValue = (binNewValue, strNewValue) # We save in memory the current value memory.memorize(self, newValue) # We return the newly generated and memorized value return newValue
def getValueToSend(self, negative, vocabulary, memory): """getValueToSend: Get the current value of the variable it can be the original value if its set and not forget or the value in memory if it has one or it generates one and save its value in memory. """ if self.getCurrentValue() is not None: self.log.debug("BINARY : HAS CURRENT VALUE") return self.getCurrentValue() if memory.hasMemorized(self): self.log.debug("BINARY : HAS NO CURRENT VALUE BUT HAS MEMORY") return memory.recall(self) # We generate a new value binNewValue = self.generateValue() strNewValue = TypeConvertor.bitarray2StrBitarray(self.generateValue()) newValue = (binNewValue, strNewValue) # We save in memory the current value memory.memorize(self, newValue) # We return the newly generated and memorized value return newValue