本文整理汇总了Python中netzob.Common.Models.Types.AbstractType.AbstractType.normalize方法的典型用法代码示例。如果您正苦于以下问题:Python AbstractType.normalize方法的具体用法?Python AbstractType.normalize怎么用?Python AbstractType.normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类netzob.Common.Models.Types.AbstractType.AbstractType
的用法示例。
在下文中一共展示了AbstractType.normalize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: searchDataInMessage
# 需要导入模块: from netzob.Common.Models.Types.AbstractType import AbstractType [as 别名]
# 或者: from netzob.Common.Models.Types.AbstractType.AbstractType import normalize [as 别名]
def searchDataInMessage(self, data, message, addTags=True, dataLabels=None):
"""Search in the specified message any of the given data. These data will be searched as
it but also under various format.
>>> from netzob.all import *
>>> message = RawMessage("Reversing protocols with Netzob")
>>> sData = [ASCII("protocol")]
>>> se = SearchEngine()
>>> results = se.searchDataInMessage(sData, message)
>>> print results
1 occurence(s) found.
>>> for result in results:
... print result
... print repr(result.searchTask.properties["data"])
Found ascii-bits(bigEndian) at [(80L, 144L)] of bitarray('01010010011001010111011001100101011100100111001101101001011011100110011100100000011100000111001001101111011101000110111101100011011011110110110001110011001000000111011101101001011101000110100000100000010011100110010101110100011110100110111101100010')
protocol
:parameter data: the data to search after. Data must be provided with their netzob type.
:type data: a list of :class:`netzob.Common.Models.Types.AbstractType.AbstractType`.
:parameter message: the message in which the search will take place
:type message: :class:`netzob.Common.Models.Vocabulary.Messages.AbstractMessage`
:keyword addTags: if set to True, visualization functions are added to the message to highlights found results.
:type addTags: :class:`bool`
:keyword dataLabels: an optionnal dict to attach to each data a label to simplify search results identification
:type dataLabels: dict
:return: a search results detailling where and how occurrences where found. Occurences are also
identified in the message through dedicated visualization functions automaticaly added to the message.
:rtype: :class:`netzob.Inference.Vocabulary.SearchEngine.SearchResults.SearchResults`
"""
if data is None or len(data) == 0:
raise TypeError("At least one data should be specified.")
if message is None:
raise TypeError("Message cannot be None")
searchTasks = []
for d in data:
# normalize the given data
normedData = AbstractType.normalize(d)
# build search tasks
props = dict()
props['message'] = message
props['data'] = d
if dataLabels is not None and d in dataLabels.keys():
props['label'] = dataLabels[d]
searchTasks.extend(self.__buildSearchTasks(normedData, props))
# fetch the content of the message and convert it to bitarray
target = TypeConverter.convert(message.data, Raw, BitArray)
# Generate search cases
searchCases = itertools.product([target], searchTasks)
searchResults = self.__search(searchCases)
# If requested, we tag the results in the message using visualization functions
# if addTags:
# for searchResult in searchResults:
# for (startPos, endPos) in searchResult.ranges:
# self._logger.info("function from {} to {}".format(startPos, endPos))
# message.visualizationFunctions.append(HighlightFunction(startPos, endPos))
return searchResults
示例2: __normalizeLeafDomain
# 需要导入模块: from netzob.Common.Models.Types.AbstractType import AbstractType [as 别名]
# 或者: from netzob.Common.Models.Types.AbstractType.AbstractType import normalize [as 别名]
def __normalizeLeafDomain(domain):
if isinstance(domain, (Data, AbstractRelationVariableLeaf)):
return domain
else:
return AbstractType.normalize(domain).buildDataRepresentation()