Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #7
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
Beispiel #8
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
Beispiel #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
Beispiel #10
0
 def _getField(self, name, const):
     field = Field._getField(self, name, const)
     if field is None:
         if name in self._fields:
             field = self._fields[name]
         elif self._field_generator is not None and not const:
             field = self._feedUntil(name)
     return field
 def _getField(self, name, const):
     field = Field._getField(self, name, const)
     if field is None:
         if name in self._fields:
             field = self._fields[name]
         elif self._field_generator is not None and not const:
             field = self._feedUntil(name)
     return field
Beispiel #12
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
Beispiel #13
0
 def getField(self, key, const=True):
     if isinstance(key, (int, long)):
         if key < 0:
             raise KeyError("Key must be positive!")
         if not const:
             self.readFirstFields(key+1)
         if len(self._fields.values) <= key:
             raise MissingField(self, key)
         return self._fields.values[key]
     return Field.getField(self, key, const)
    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
 def getField(self, key, const=True):
     if isinstance(key, (int, long)):
         if key < 0:
             raise KeyError("Key must be positive!")
         if not const:
             self.readFirstFields(key + 1)
         if len(self._fields.values) <= key:
             raise MissingField(self, key)
         return self._fields.values[key]
     return Field.getField(self, key, const)
Beispiel #16
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)
Beispiel #17
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)
Beispiel #18
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(' ')
Beispiel #19
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(' ')
Beispiel #20
0
 def _getField(self, key, const):
     field = Field._getField(self, key, const)
     if field is not None:
         return field
     if key in self._field_dict:
         return self._field_dict[key]
     if self._generator and not const:
         try:
             while True:
                 field = self._feedOne()
                 if field.name == key:
                     return field
         except StopIteration:
             self._stopFeed()
         except HACHOIR_ERRORS, err:
             self.error("Error: %s" % makeUnicode(err))
             self._stopFeed()
 def _getField(self, key, const):
     field = Field._getField(self, key, const)
     if field is not None:
         return field
     if key in self._field_dict:
         return self._field_dict[key]
     if self._generator and not const:
         try:
             while True:
                 field = self._feedOne()
                 if field.name == key:
                     return field
         except StopIteration:
             self._stopFeed()
         except HACHOIR_ERRORS, err:
             self.error("Error: %s" % makeUnicode(err))
             self._stopFeed()
Beispiel #22
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
Beispiel #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
Beispiel #24
0
 def __init__(self, parent, name, size, description=None):
     """
     Constructor: see L{Field.__init__} for parameter description
     """
     Field.__init__(self, parent, name, size, description)
 def __init__(self, parent, name, description=None):
     Field.__init__(self, parent, name, 128, description)
Beispiel #26
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)
Beispiel #27
0
 def __init__(self, parent, name, *args, **kw):
     Field.__init__(self, parent, name, 0, *args, **kw)
Beispiel #28
0
 def __init__(self, parent, name, description=None):
     Field.__init__(self, parent, name, 128, description)
Beispiel #29
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
 def __init__(self, parent, name, *args, **kw):
     Field.__init__(self, parent, name, 0, *args, **kw)
Beispiel #31
0
 def __init__(self, parent, name, size, description=None):
     """
     Constructor: see L{Field.__init__} for parameter description
     """
     Field.__init__(self, parent, name, size, description)
Beispiel #32
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
Beispiel #33
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)