Exemple #1
0
    def __convert(self, kind, endian, data):
        # Can raise StandardError and IOError
        value = 0

        # Convert the data from the file
        if kind == 'byte':
            if len(data) < 1:
                raise StandardError, "Should never happen, not enough data"
            value = ord(data[0])

        elif kind == 'short':
            if len(data) < 2:
                raise StandardError, "Should never happen, not enough data"
            if endian == 'local':
                value = convert.local2(data)
            elif endian == 'little':
                value = convert.little2(data)
            elif endian == 'big':
                value = convert.big2(data)
            else:
                raise StandardError, "Endian type unknown"

        elif kind == 'long':
            if len(data) < 4:
                raise StandardError, "Should never happen, not enough data"
            if endian == 'local':
                value = convert.local4(data)
            elif endian == 'little':
                value = convert.little4(data)
            elif endian == 'big':
                value = convert.big4(data)
            else:
                raise StandardError, "Endian type unknown"

        elif kind == 'date':
            # XXX: Not done yet
            pass
        elif kind == 'ldate':
            # XXX: Not done yet
            pass
        elif kind == 'string':
            # Nothing to do
            pass
        elif kind == 'pstring':
            # Not done here anymore
            pass
            #	#Convert it to be like a string
            #	size=ord(data[0])
            #	# Not sure the test is right (at one byte)
            #	if file_length < offset + size:
            #		value= self.__read(f,size)
            #		leng = size
            #		kind = "string"
        else:
            raise StandardError, "Type " + str(kind) + " not recognised"

        return value
Exemple #2
0
	def __convert (self,kind,endian,data):
		# Can raise StandardError and IOError
		value = 0

		# Convert the data from the file
		if kind == 'byte':
			if len(data) < 1:
				raise StandardError, "Should never happen, not enough data"
			value= ord(data[0])
		
		elif kind == 'short':
			if len(data) < 2:
				raise StandardError, "Should never happen, not enough data"
			if endian == 'local':
				value= convert.local2(data)
			elif endian == 'little':
				value= convert.little2(data)
			elif endian == 'big':
				value= convert.big2(data)
			else:
				raise StandardError, "Endian type unknown"
			
		elif kind == 'long':
			if len(data) < 4:
				raise StandardError, "Should never happen, not enough data"
			if endian == 'local':
				value= convert.local4(data)
			elif endian == 'little':
				value= convert.little4(data)
			elif endian == 'big':
				value= convert.big4(data)
			else:
				raise StandardError, "Endian type unknown"
			
		elif kind == 'date':
			# XXX: Not done yet
			pass
		elif kind == 'ldate':
			# XXX: Not done yet
			pass
		elif kind == 'string':
			# Nothing to do
			pass
		elif kind == 'pstring':
			# Not done here anymore
			pass
			#	#Convert it to be like a string
			#	size=ord(data[0])
			#	# Not sure the test is right (at one byte)
			#	if file_length < offset + size:
			#		value= self.__read(f,size)
			#		leng = size
			#		kind = "string"
		else:
			raise StandardError, "Type " + str(kind) + " not recognised"

		return value
Exemple #3
0
    def __indirect_offset(self, file, type, offset):
        # Raise file error if file too short
        f.seek(offset)
        if type == 'l':
            delta = convert.little4(self.__read(f, 4))
        elif type == 'L':
            delta = convert.big4(self.__read(f, 4))
        elif type == 's':
            delta = convert.little2(self.__read(f, 2))
        elif type == 'S':
            delta = convert.big2(self.__read(f, 2))
        elif type == 'b':
            delta = ord(self.__read(f, 1))
        elif type == 'B':
            delta = ord(self.__read(f, 1))

        return offset + delta
Exemple #4
0
	def __indirect_offset (self,file,type,offset):
		# Raise file error if file too short	
		f.seek(offset)
		if type == 'l':
			delta = convert.little4(self.__read(f,4))
		elif type == 'L':
			delta = convert.big4(self.__read(f,4))
		elif type == 's':
			delta = convert.little2(self.__read(f,2))
		elif type == 'S':
			delta = convert.big2(self.__read(f,2))
		elif type == 'b':
			delta = ord(self.__read(f,1))
		elif type == 'B':
			delta = ord(self.__read(f,1))

		return offset + delta