| Home | Trees | Indices | Help |
|
|---|
|
|
1 2 ''' 3 A few standard fixups. 4 ''' 5 6 # 7 # Copyright (c) 2008 Michael Eddington 8 # 9 # Permission is hereby granted, free of charge, to any person obtaining a copy 10 # of this software and associated documentation files (the "Software"), to deal 11 # in the Software without restriction, including without limitation the rights 12 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 # copies of the Software, and to permit persons to whom the Software is 14 # furnished to do so, subject to the following conditions: 15 # 16 # The above copyright notice and this permission notice shall be included in 17 # all copies or substantial portions of the Software. 18 # 19 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 # SOFTWARE. 26 # 27 28 # Authors: 29 # Michael Eddington (mike@phed.org) 30 31 # $Id$ 32 33 import zlib, struct, binascii, array 34 from Peach.fixup import Fixup 35 from Peach.Engine.common import * 3638 ''' 39 Sometimes you need to perform some math as the fixup. This 40 relation will take a ref, then an expression (python). 41 ''' 42 4755 5649 ref = self._findDataElementByName(self.ref) 50 stuff = ref.getValue() 51 if stuff == None: 52 raise Exception("Error: ExpressionFixup was unable to locate [%s]" % self.ref) 53 54 return evalEvent(self.expression, { "self" : self, "ref" : ref, "data" : stuff })58 ''' 59 Standard CRC32 as defined by ISO 3309. Used by PNG, zip, etc. 60 ''' 61 6572 7367 stuff = self._findDataElementByName(self.ref).getValue() 68 if stuff == None: 69 raise Exception("Error: Crc32Fixup was unable to locate [%s]" % self.ref) 70 71 return zlib.crc32(stuff)75 ''' 76 Standard CRC32 as defined by ISO 3309. Used by PNG, zip, etc. 77 ''' 78 8392 9385 stuff1 = self._findDataElementByName(self.ref1).getValue() 86 stuff2 = self._findDataElementByName(self.ref2).getValue() 87 if stuff1 == None or stuff2 == None: 88 raise Exception("Error: Crc32DualFixup was unable to locate [%s] or [%s]" % (self.ref1, self.ref2)) 89 90 crc1 = zlib.crc32(stuff1) 91 return zlib.crc32(stuff2, crc1)95 ''' 96 Ethernet Chucksum Fixup. 97 ''' 98 102114 115104 """Calculate checksum""" 105 ethernetKey = 0x04C11DB7 106 return binascii.crc32(checksum_packet, ethernetKey)107109 stuff = self._findDataElementByName(self.ref).getValue() 110 if stuff == None: 111 raise Exception("Error: EthernetChecksumFixup was unable to locate [%s]" % self.ref) 112 113 return self._checksum(stuff)117 ''' 118 Ethernet Chucksum Fixup. 119 ''' 120 124151 152 # end 153126 """Calculate checksum""" 127 # add byte if not dividable by 2 128 if len(checksum_packet) & 1: 129 checksum_packet = checksum_packet + '\0' 130 # split into 16-bit word and insert into a binary array 131 words = array.array('h', checksum_packet) 132 sum = 0 133 134 # perform ones complement arithmetic on 16-bit words 135 for word in words: 136 sum += (word & 0xffff) 137 138 hi = sum >> 16 139 lo = sum & 0xffff 140 sum = hi + lo 141 sum = sum + (sum >> 16) 142 143 return (~sum) & 0xffff # return ones complement144146 stuff = self._findDataElementByName(self.ref).getValue() 147 if stuff == None: 148 raise Exception("Error: IcmpChecksumFixup was unable to locate [%s]" % self.ref) 149 150 return self._checksum(stuff)
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Sat Aug 16 12:17:16 2008 | http://epydoc.sourceforge.net |