当前位置: 首页>>代码示例>>Python>>正文


Python TypeConvertor.netzobRawToIPv4方法代码示例

本文整理汇总了Python中netzob.Common.Type.TypeConvertor.TypeConvertor.netzobRawToIPv4方法的典型用法代码示例。如果您正苦于以下问题:Python TypeConvertor.netzobRawToIPv4方法的具体用法?Python TypeConvertor.netzobRawToIPv4怎么用?Python TypeConvertor.netzobRawToIPv4使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在netzob.Common.Type.TypeConvertor.TypeConvertor的用法示例。


在下文中一共展示了TypeConvertor.netzobRawToIPv4方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: apply

# 需要导入模块: from netzob.Common.Type.TypeConvertor import TypeConvertor [as 别名]
# 或者: from netzob.Common.Type.TypeConvertor.TypeConvertor import netzobRawToIPv4 [as 别名]
    def apply(self, message):

        if self.unitsize != UnitSize.NONE:
            # First we apply the unit size
            # Default modulo = 2 => 8BITS
            if self.unitsize == UnitSize.BIT:
                modulo = 1
            else:
                modulo = UnitSize.getSizeInBits(self.unitsize) / 4

            splittedData = []
            tmpResult = ""
            for i in range(0, len(message)):
                if i > 0 and i % modulo == 0:
                    splittedData.append(tmpResult)
                    tmpResult = ""
                tmpResult = tmpResult + message[i]
            splittedData.append(tmpResult)
        else:
            splittedData = [message]

        encodedSplittedData = []
        # Now we have the message splitted per unit size
        # we apply endianess on it
        # we consider the normal mode is big-endian
        for i in range(0, len(splittedData)):
            origNetzobRaw = splittedData[i]

            # SPECIAL CASE : ASCII we do not compute endianess neither signed/unsigned
            if not self.formatType == Format.STRING and UnitSize.getSizeInBits(self.unitsize) >= 8 and not self.formatType == Format.BINARY:
                tmpVal = UnitSize.getSizeInBits(self.unitsize) / 4 - len(origNetzobRaw)
                if self.endianness == Endianess.BIG:
                    netzobRaw = (tmpVal * "0") + origNetzobRaw
                else:
                    netzobRaw = origNetzobRaw + (tmpVal * "0")

                # Convert in Python raw
                pythonraw = TypeConvertor.netzobRawToPythonRaw(netzobRaw)

                # Create transformer
                # - ENDIANESS
                transformer = ">"
                if self.endianness == Endianess.LITTLE:
                    transformer = "<"
                # - SIGNED/UNISGNED
                if self.sign == Sign.SIGNED:
                    transformer = transformer + (UnitSize.getPackDefiniton(self.unitsize)).lower()
                else:
                    transformer = transformer + (UnitSize.getPackDefiniton(self.unitsize)).upper()

                # Apply the transformation
                (unpackRaw,) = struct.unpack(transformer, pythonraw)

                localResult = ""
                fmt = "%" + str(UnitSize.getMaxDigitForTypeAndUnitSize(self.formatType, self.unitsize))
                if self.formatType == Format.OCTAL:
                    localResult = (fmt + "o") % unpackRaw
                elif self.formatType == Format.DECIMAL:
                    localResult = (fmt + "d") % unpackRaw
                elif self.formatType == Format.HEX:
                    localResult = (fmt + "s") % origNetzobRaw
                encodedSplittedData.append(localResult)
            elif self.formatType == Format.STRING:
                encodedSplittedData.append(TypeConvertor.netzobRawToString(origNetzobRaw))
            elif self.formatType == Format.BINARY:
                encodedSplittedData.append(TypeConvertor.netzobRawToBinary(origNetzobRaw))
            elif self.formatType == Format.IPv4:
                encodedSplittedData.append(TypeConvertor.netzobRawToIPv4(origNetzobRaw))
            elif UnitSize.getSizeInBits(self.unitsize) < UnitSize.getSizeInBits(UnitSize.BITS8):
                encodedSplittedData.append(TypeConvertor.encodeNetzobRawToGivenType(origNetzobRaw, self.formatType))

        # Before sending back (;D) we join everything
        return " ".join(encodedSplittedData)
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:75,代码来源:FormatFunction.py


注:本文中的netzob.Common.Type.TypeConvertor.TypeConvertor.netzobRawToIPv4方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。