def GetDataAsObject(self): """Retrieves the data as an object. Returns: object: data as a Python type or None if not available. Raises: WinRegistryValueError: if the value data cannot be read. """ if not self._data: return None if self._data_type in self._STRING_VALUE_TYPES: try: return self._data.decode('utf-16-le') # AttributeError is raised when self._data has no decode method. except AttributeError as exception: raise errors.WinRegistryValueError(( 'Unsupported data type: {0!s} of value: {1!s} with error: ' '{2!s}').format(type(self._data), self._name, exception)) except UnicodeError as exception: raise errors.WinRegistryValueError( 'Unable to decode data of value: {0!s} with error: {1!s}'.format( self._name, exception)) elif (self._data_type == definitions.REG_DWORD and self._data_size == 4): return self._INT32_LITTLE_ENDIAN.MapByteStream(self._data) elif (self._data_type == definitions.REG_DWORD_BIG_ENDIAN and self._data_size == 4): return self._INT32_BIG_ENDIAN.MapByteStream(self._data) elif (self._data_type == definitions.REG_QWORD and self._data_size == 8): return self._INT64_LITTLE_ENDIAN.MapByteStream(self._data) elif self._data_type == definitions.REG_MULTI_SZ: try: utf16_string = self._data.decode('utf-16-le') # TODO: evaluate the use of filter here is appropriate behavior. return list(filter(None, utf16_string.split('\x00'))) # AttributeError is raised when self._data has no decode method. except AttributeError as exception: raise errors.WinRegistryValueError(( 'Unsupported data type: {0!s} of value: {1!s} with error: ' '{2!s}').format(type(self._data), self._name, exception)) except UnicodeError as exception: raise errors.WinRegistryValueError( 'Unable to read data from value: {0!s} with error: {1!s}'.format( self._name, exception)) return self._data
def GetDataAsObject(self): """Retrieves the data as an object. Returns: object: data as a Python type. Raises: WinRegistryValueError: if the value data cannot be read. """ try: if self._pyregf_value.type in self._STRING_VALUE_TYPES: value_data = self._pyregf_value.get_data_as_string() elif self._pyregf_value.type in self._INTEGER_VALUE_TYPES: value_data = self._pyregf_value.get_data_as_integer() elif self._pyregf_value.type == definitions.REG_MULTI_SZ: value_data = self._pyregf_value.get_data_as_multi_string() else: value_data = self._pyregf_value.data except (IOError, OverflowError) as exception: raise errors.WinRegistryValueError( 'Unable to read data from value: {0:s} with error: {1!s}'. format(self._pyregf_value.name, exception)) return value_data
def GetDataAsObject(self): """Retrieves the data as an object. Returns: object: data as a Python type. Raises: WinRegistryValueError: if the value data cannot be read. """ if self._pyregf_value.type in self._STRING_VALUE_TYPES: try: return self._pyregf_value.get_data_as_string() except IOError as exception: raise errors.WinRegistryValueError( 'Unable to read data from value: {0:s} with error: {1!s}'. format(self._pyregf_value.name, exception)) if self._pyregf_value.type in self._INTEGER_VALUE_TYPES: try: return self._pyregf_value.get_data_as_integer() except (IOError, OverflowError) as exception: raise errors.WinRegistryValueError( 'Unable to read data from value: {0:s} with error: {1!s}'. format(self._pyregf_value.name, exception)) try: value_data = self._pyregf_value.data except IOError as exception: raise errors.WinRegistryValueError( 'Unable to read data from value: {0:s} with error: {1!s}'. format(self._pyregf_value.name, exception)) if self._pyregf_value.type == definitions.REG_MULTI_SZ: # TODO: Add support for REG_MULTI_SZ to pyregf. if value_data is None: return [] try: utf16_string = value_data.decode('utf-16-le') return list(filter(None, utf16_string.split('\x00'))) except UnicodeError as exception: raise errors.WinRegistryValueError( 'Unable to read data from value: {0:s} with error: {1!s}'. format(self._pyregf_value.name, exception)) return value_data
def data(self): """The value data as a native Python object. Raises: WinRegistryValueError: if the value data cannot be read. """ if not self._data: return None if self._data_type in self._STRING_VALUE_TYPES: try: return self._data.decode(u'utf-16-le') except UnicodeError as exception: raise errors.WinRegistryValueError( u'Unable to read data from value: {0:s} with error: {1:s}'. format(self._name, exception)) elif (self._data_type == definitions.REG_DWORD and self._data_size == 4): return self._INT32_LITTLE_ENDIAN.parse(self._data) elif (self._data_type == definitions.REG_DWORD_BIG_ENDIAN and self._data_size == 4): return self._INT32_BIG_ENDIAN.parse(self._data) elif (self._data_type == definitions.REG_QWORD and self._data_size == 8): return self._INT64_LITTLE_ENDIAN.parse(self._data) elif self._data_type == definitions.REG_MULTI_SZ: try: utf16_string = self._data.decode(u'utf-16-le') return filter(None, utf16_string.split(u'\x00')) except UnicodeError as exception: raise errors.WinRegistryValueError( u'Unable to read data from value: {0:s} with error: {1:s}'. format(self._name, exception)) return self._data
def data(self): """bytes: value data as a byte string. Raises: WinRegistryValueError: if the value data cannot be read. """ try: return self._pyregf_value.data except IOError as exception: raise errors.WinRegistryValueError( 'Unable to read data from value: {0:s} with error: {1!s}'. format(self._pyregf_value.name, exception))
def data(self): """The value data as a native Python object. Raises: WinRegistryValueError: if the value data cannot be read. """ if self._pyregf_value.type in self._STRING_VALUE_TYPES: try: return self._pyregf_value.get_data_as_string() except IOError as exception: raise errors.WinRegistryValueError( u'Unable to read data from value: {0:s} with error: {1:s}'. format(self._pyregf_value.name, exception)) elif self._pyregf_value.type in self._INTEGER_VALUE_TYPES: try: return self._pyregf_value.get_data_as_integer() except (IOError, OverflowError) as exception: raise errors.WinRegistryValueError( u'Unable to read data from value: {0:s} with error: {1:s}'. format(self._pyregf_value.name, exception)) # TODO: Add support for REG_MULTI_SZ to pyregf. elif self._pyregf_value.type == definitions.REG_MULTI_SZ: if self._pyregf_value.data is None: return [] try: utf16_string = self._pyregf_value.data.decode(u'utf-16-le') return filter(None, utf16_string.split(u'\x00')) except (IOError, UnicodeError) as exception: raise errors.WinRegistryValueError( u'Unable to read data from value: {0:s} with error: {1:s}'. format(self._pyregf_value.name, exception)) return self._pyregf_value.data