Changeset 657:0cc465ecd7c9

Show
Ignore:
Timestamp:
06/13/07 16:40:16 (2 years ago)
Author:
Phil <phil@secdev.org>
Message:

Made fields taking their length from another field be able to take it absolutely

PacketLenField?, PacketListField?, StrLenField?, FieldListField now can
be provided a fld parameter set to None, in which case the length
will be initialized with the shift value. If the shift is 0, it will
mean to take as many bytes as possible.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • scapy.py

    r656 r657  
    37183718        self.fld = fld 
    37193719    def getfield(self, pkt, s): 
    3720         l = getattr(pkt, self.fld) 
    3721         l -= self.shift 
     3720        if self.fld is None: 
     3721            l = self.shift 
     3722            if l == 0: 
     3723                l = None 
     3724        else: 
     3725            l = getattr(pkt, self.fld) 
     3726            l -= self.shift 
    37223727        i = self.m2i(pkt, s[:l]) 
    37233728        return s[l:],i 
     
    37323737        if self.fld is None: 
    37333738            l = self.shift 
     3739            if l == 0: 
     3740                l = -1 
    37343741        else: 
    37353742            l = getattr(pkt, self.fld) 
     
    37843791        self.fld = fld 
    37853792    def getfield(self, pkt, s): 
    3786         l = getattr(pkt, self.fld) 
    3787         l -= self.shift 
     3793        if self.fld is None: 
     3794            l = self.shift 
     3795            if l == 0: 
     3796                l = None 
     3797        else: 
     3798            l = getattr(pkt, self.fld) 
     3799            l -= self.shift 
    37883800        return s[l:], self.m2i(pkt,s[:l]) 
    37893801 
     
    38103822        return s 
    38113823    def getfield(self, pkt, s): 
    3812         l = getattr(pkt, self.fld)         
    3813         # add the shift from the length field 
    3814         f = pkt.get_field(self.fld) 
    3815         l -= self.shift 
     3824        if self.fld is None: 
     3825            l = self.shift 
     3826            if l == 0: 
     3827                l = -1 
     3828        else: 
     3829            l = getattr(pkt, self.fld)         
     3830            l -= self.shift 
    38163831        val = [] 
    3817         for i in range(l): 
     3832        while s and l != 0: 
     3833            l -= 1 
    38183834            s,v = self.cls.getfield(pkt, s) 
    38193835            val.append(v)