Exemple #1
0
    def __init__(self, parent, name, desc=None):
        Field.__init__(self, parent, name, description=desc)
        val = ""
        count = 1
        off = 1
        while not parent.eof:
            char = parent.stream.readBytes(self.absolute_address+8*off, 1)
            # Non-ASCII
            if not char.isalpha() or char == '\\':
                off += 1
                continue
            if char == '(':
                count += 1
            if char == ')':
                count -= 1
            # Parenthesis block = 0 => end of string
            if count == 0:
                off += 1
                break

            # Add it to the string
            val += char

        self._size = 8*off
        self.createValue = lambda: val
Exemple #2
0
    def __init__(self, parent, name, desc=None):
        Field.__init__(self, parent, name, description=desc)
        val = ""
        count = 1
        off = 1
        while not parent.eof:
            char = parent.stream.readBytes(self.absolute_address+8*off, 1)
            # Non-ASCII
            if not char.isalpha() or char == '\\':
                off += 1
                continue
            if char == '(':
                count += 1
            if char == ')':
                count -= 1
            # Parenthesis block = 0 => end of string
            if count == 0:
                off += 1
                break

            # Add it to the string
            val += char

        self._size = 8*off
        self.createValue = lambda: val
Exemple #3
0
 def __init__(self, parent, name, desc=None):
     Field.__init__(self, parent, name, description=desc)
     if parent.stream.readBytes(self.absolute_address, 4) == "true":
         self._size = 4
         self.createValue = lambda: True
     elif parent.stream.readBytes(self.absolute_address, 5) == "false":
         self._size = 5
         self.createValue = lambda: False
     raise NotABool
Exemple #4
0
 def __init__(self, parent, name, desc=None):
     Field.__init__(self, parent, name, description=desc)
     if parent.stream.readBytes(self.absolute_address, 4) == "true":
         self._size = 4
         self.createValue = lambda: True
     elif parent.stream.readBytes(self.absolute_address, 5) == "false":
         self._size = 5
         self.createValue = lambda: False
     raise NotABool
 def __init__(self, parent, name, max_size=None, description=None):
     Field.__init__(self, parent, name, size=0, description=description)
     value = 0
     addr = self.absolute_address
     while max_size is None or self._size < max_size:
         byte = parent.stream.readBits(addr, 8, LITTLE_ENDIAN)
         value += byte
         self._size += 8
         if byte != 0xff:
             break
         addr += 8
     self.createValue = lambda: value
Exemple #6
0
 def __init__(self, parent, name, max_size=None, description=None):
     Field.__init__(self, parent, name, size=0, description=description)
     value = 0
     addr = self.absolute_address
     while max_size is None or self._size < max_size:
         byte = parent.stream.readBits(addr, 8, LITTLE_ENDIAN)
         value += byte
         self._size += 8
         if byte != 0xff:
             break
         addr += 8
     self.createValue = lambda: value
Exemple #7
0
 def __init__(self, parent, name, max_size=None, description=None):
     Field.__init__(self, parent, name, size=8, description=description)
     value = 0
     addr = self.absolute_address
     mask = 0x80
     firstByte = parent.stream.readBits(addr, 8, LITTLE_ENDIAN)
     for i in xrange(8):
         addr += 8
         if not (firstByte & mask):
             value += ((firstByte & (mask-1)) << (8*i))
             break
         value |= (parent.stream.readBits(addr, 8, LITTLE_ENDIAN) << (8*i))
         mask >>= 1
         self._size += 8
     self.createValue = lambda: value
Exemple #8
0
 def __init__(self, parent, name, description=None):
     Field.__init__(self, parent, name, 8, description)
     stream = self._parent.stream
     addr = self.absolute_address
     value = stream.readBits(addr, 8, BIG_ENDIAN)
     if 128 <= value:
         nbits = (value & 127) * 8
         if not nbits:
             raise ParserError("ASN.1: invalid ASN integer size (zero)")
         if 64 < nbits:
             # Arbitrary limit to catch errors
             raise ParserError("ASN.1: ASN integer is limited to 64 bits")
         self._size = 8 + nbits
         value = stream.readBits(addr+8, nbits, BIG_ENDIAN)
     self.createValue = lambda: value
Exemple #9
0
 def __init__(self, parent, name, max_size=None, description=None):
     Field.__init__(self, parent, name, size=8, description=description)
     value = 0
     addr = self.absolute_address
     mask = 0x80
     firstByte = parent.stream.readBits(addr, 8, LITTLE_ENDIAN)
     for i in xrange(8):
         addr += 8
         if not (firstByte & mask):
             value += ((firstByte & (mask-1)) << (8*i))
             break
         value |= (parent.stream.readBits(addr, 8, LITTLE_ENDIAN) << (8*i))
         mask >>= 1
         self._size += 8
     self.createValue = lambda: value
    def __init__(self, parent, name, description=None):
        Field.__init__(self, parent, name, 8, description)

        endian = self._parent.endian
        stream = self._parent.stream
        addr = self.absolute_address

        value = 0
        byte = stream.readBits(addr, 8, endian)
        while byte & 0x80:
            value <<= 7
            value += (byte & 0x7f)
            self._size += 8
            if 64 < self._size:
                raise ParserError("CHM: CWord is limited to 64 bits")
            addr += 8
            byte = stream.readBits(addr, 8, endian)
        value += byte
        self.createValue = lambda: value
Exemple #11
0
    def __init__(self, parent, name, description=None):
        Field.__init__(self, parent, name, 8, description)

        endian = self._parent.endian
        stream = self._parent.stream
        addr = self.absolute_address

        value = 0
        byte = stream.readBits(addr, 8, endian)
        while byte & 0x80:
            value <<= 7
            value += (byte & 0x7f)
            self._size += 8
            if 64 < self._size:
                raise ParserError("CHM: CWord is limited to 64 bits")
            addr += 8
            byte = stream.readBits(addr, 8, endian)
        value += byte
        self.createValue = lambda: value
Exemple #12
0
    def __init__(self, parent, name, desc=None):
        Field.__init__(self, parent, name, description=desc)
        if parent.stream.readBytes(self.absolute_address, 1) != '/':
            raise ParserError("Unknown PDFName '%s'" %
                              parent.stream.readBytes(self.absolute_address, 10))
        size = getElementEnd(parent, offset=1)
        #other_size = getElementEnd(parent, '[')-1
        #if size == None or (other_size != None and other_size < size):
        #    size = other_size
        for limit in self.LIMITS:
            other_size = getElementEnd(parent, limit, 1)
            if other_size != None:
                other_size -= 1
                if size == None or other_size < size:
                    #self.info("New size: %u" % other_size)
                    size = other_size

        self._size = 8*(size+1)
        # Value should be without the initial '/' and final ' '
        self.createValue = lambda: parent.stream.readBytes(self.absolute_address+8, size).strip(' ')
Exemple #13
0
    def __init__(self, parent, name, desc=None):
        Field.__init__(self, parent, name, description=desc)
        # Get size
        size = getElementEnd(parent)
        for limit in self.LIMITS:
            other_size = getElementEnd(parent, limit)
            if other_size != None:
                other_size -= 1
                if size == None or other_size < size:
                    size = other_size

        self._size = 8*size

        # Get value
        val = parent.stream.readBytes(self.absolute_address, size)
        self.info("Number: size=%u value='%s'" % (size, val))
        if val.find('.') != -1:
            self.createValue = lambda: float(val)
        else:
            self.createValue = lambda: int(val)
Exemple #14
0
    def __init__(self, parent, name, desc=None):
        Field.__init__(self, parent, name, description=desc)
        if parent.stream.readBytes(self.absolute_address, 1) != '/':
            raise ParserError("Unknown PDFName '%s'" %
                              parent.stream.readBytes(self.absolute_address, 10))
        size = getElementEnd(parent, offset=1)
        #other_size = getElementEnd(parent, '[')-1
        #if size == None or (other_size != None and other_size < size):
        #    size = other_size
        for limit in self.LIMITS:
            other_size = getElementEnd(parent, limit, 1)
            if other_size != None:
                other_size -= 1
                if size == None or other_size < size:
                    #self.info("New size: %u" % other_size)
                    size = other_size

        self._size = 8*(size+1)
        # Value should be without the initial '/' and final ' '
        self.createValue = lambda: parent.stream.readBytes(self.absolute_address+8, size).strip(' ')
Exemple #15
0
    def __init__(self, parent, name, desc=None):
        Field.__init__(self, parent, name, description=desc)
        # Get size
        size = getElementEnd(parent)
        for limit in self.LIMITS:
            other_size = getElementEnd(parent, limit)
            if other_size != None:
                other_size -= 1
                if size == None or other_size < size:
                    size = other_size

        self._size = 8*size

        # Get value
        val = parent.stream.readBytes(self.absolute_address, size)
        self.info("Number: size=%u value='%s'" % (size, val))
        if val.find('.') != -1:
            self.createValue = lambda: float(val)
        else:
            self.createValue = lambda: int(val)
Exemple #16
0
 def __init__(self, parent, name, desc=None):
     Field.__init__(self, parent, name, description=desc)
     self._size = 8*getElementEnd(parent, '>')
     self.createValue = lambda: parent.stream.readBytes(self.absolute_address+8, (self._size//8)-1)
Exemple #17
0
 def __init__(self, parent, name, length, description="Raw data"):
     assert issubclass(parent.__class__, Field)
     if not (0 < length <= MAX_LENGTH):
         raise FieldError("Invalid RawBytes length (%s)!" % length)
     Field.__init__(self, parent, name, length * 8, description)
     self._display = None
Exemple #18
0
 def __init__(self, parent, name, *args, **kw):
     Field.__init__(self, parent, name, 0, *args, **kw)
 def __init__(self, parent, name, *args, **kw):
     Field.__init__(self, parent, name, 0, *args, **kw)
Exemple #20
0
 def __init__(self, parent, name, size, description=None):
     """
     Constructor: see L{Field.__init__} for parameter description
     """
     Field.__init__(self, parent, name, size, description)
Exemple #21
0
 def __init__(self, parent, name, description=None):
     Field.__init__(self, parent, name, 128, description)
 def __init__(self, parent, name, description=None):
     Field.__init__(self, parent, name, 128, description)
Exemple #23
0
 def __init__(self, parent, name, length, description="Raw data"):
     assert issubclass(parent.__class__, Field)
     if not(0 < length <= MAX_LENGTH):
         raise FieldError("Invalid RawBytes length (%s)!" % length)
     Field.__init__(self, parent, name, length*8, description)
     self._display = None
Exemple #24
0
 def __init__(self, parent, name, desc=None):
     Field.__init__(self, parent, name, size=24, description=desc)
     addr = self.absolute_address
     val = parent.stream.readBits(addr, 8, LITTLE_ENDIAN) << 20
     val += parent.stream.readBits(addr+8, 16, LITTLE_ENDIAN) << 4
     self.createValue = lambda: val
Exemple #25
0
 def __init__(self, parent, name, desc=None):
     Field.__init__(self, parent, name, description=desc)
     self._size = 8*getElementEnd(parent, '>')
     self.createValue = lambda: parent.stream.readBytes(self.absolute_address+8, (self._size//8)-1)
Exemple #26
0
 def __init__(self, parent, name, desc=None):
     Field.__init__(self, parent, name, size=24, description=desc)
     addr = self.absolute_address
     val = parent.stream.readBits(addr, 8, LITTLE_ENDIAN) << 20
     val += parent.stream.readBits(addr+8, 16, LITTLE_ENDIAN) << 4
     self.createValue = lambda: val
Exemple #27
0
 def __init__(self, parent, name, size, description=None):
     """
     Constructor: see L{Field.__init__} for parameter description
     """
     Field.__init__(self, parent, name, size, description)