Exemple #1
0
    def ExistsTypedProperty(self,
                            id,
                            location=None,
                            _type=None,
                            prefix=True,
                            propertiesInstance=None):
        """
        Determines if the stream with the provided id exists in the location specified.
        If no location is specified, the root directory is searched. The return of this
        function is 2 values, the first being a boolean for if anything was found, and
        the second being how many were found.

        Because of how this function works, any folder that contains it's own
        "__properties_version1.0" file should have this function called from it's class.
        """
        verifyPropertyId(id)
        verifyType(_type)
        id = id.upper()
        if propertiesInstance is None:
            propertiesInstance = self.mainProperties
        prefixList = self.prefixList if prefix else []
        if location is not None:
            prefixList.append(location)
        prefixList = inputToMsgpath(prefixList)
        usableid = id + _type if _type is not None else id
        found_number = 0
        found_streams = []
        for item in self.listDir():
            if len(item) > len(prefixList):
                if item[len(prefixList)].startswith(
                        '__substg1.0_' + usableid) and item[len(
                            prefixList)] not in found_streams:
                    found_number += 1
                    found_streams.append(item[len(prefixList)])
        for x in propertiesInstance:
            if x.startswith(usableid):
                already_found = False
                for y in found_streams:
                    if y.endswith(x):
                        already_found = True
                        break
                if not already_found:
                    found_number += 1
        return (found_number > 0), found_number
Exemple #2
0
    def _getTypedProperty(self, propertyID, _type=None):
        """
        Gets the property with the specified id as the type that it
        is supposed to be. :param id: MUST be a 4 digit hexadecimal
        string.

        If you know for sure what type the property is before hand,
        you can specify it as being one of the strings in the
        constant FIXED_LENGTH_PROPS_STRING or
        VARIABLE_LENGTH_PROPS_STRING.
        """
        verifyPropertyId(propertyID)
        verifyType(_type)
        propertyID = propertyID.upper()
        for x in (propertyID + _type, ) if _type is not None else self.props:
            if x.startswith(propertyID):
                prop = self.props[x]
                return True, (prop.value
                              if isinstance(prop, FixedLengthProp) else prop)
        return False, None
Exemple #3
0
    def _getTypedStream(self, filename, prefix=True, _type=None):
        """
        Gets the contents of the specified stream as the type that
        it is supposed to be.

        Rather than the full filename, you should only feed this
        function the filename sans the type. So if the full name
        is "__substg1.0_001A001F", the filename this function
        should receive should be "__substg1.0_001A".

        If you know for sure what type the stream is before hand,
        you can specify it as being one of the strings in the
        constant FIXED_LENGTH_PROPS_STRING or
        VARIABLE_LENGTH_PROPS_STRING.

        If you have not specified the type, the type this function
        returns in many cases cannot be predicted. As such, when
        using this function it is best for you to check the type
        that it returns. If the function returns None, that means
        it could not find the stream specified.
        """
        verifyType(_type)
        filename = self.fix_path(filename, prefix)
        for x in (filename +
                  _type, ) if _type is not None else self.slistDir():
            if x.startswith(filename) and x.find('-') == -1:
                contents = self._getStream(x, False)
                if len(contents) == 0:
                    return True, None  # We found the file, but it was empty.
                extras = []
                _type = x[-4:]
                if x[-4] == '1':  # It's a multiple
                    if _type in ('101F', '101E'):
                        streams = len(
                            contents) // 4  # These lengths are normal.
                    elif _type == '1102':
                        streams = len(
                            contents
                        ) // 8  # These lengths have 4 0x00 bytes at the end for seemingly no reason. They are "reserved" bytes
                    elif _type in ('1002', '1003', '1004', '1005', '1007',
                                   '1040', '1048'):
                        try:
                            streams = self.mainProperties[x[-8:]].realLength
                        except:
                            logger.error(
                                'Could not find matching VariableLengthProp for stream {}'
                                .format(x))
                            streams = len(contents) // (
                                2 if _type == '1002' else 4 if _type in
                                ('1003', '1004') else 8 if type in
                                ('1005', '1007', '1040') else 16)
                    else:
                        raise NotImplementedError(
                            'The stream specified is of type {}. We don\'t currently understand exactly how this type works. If it is mandatory that you have the contents of this stream, please create an issue labled "NotImplementedError: _getTypedStream {}".'
                            .format(_type, _type))
                    if _type in ('101F', '101E', '1102'):
                        if self.Exists(x + '-00000000', False):
                            for y in range(streams):
                                if self.Exists(x + '-' + properHex(y, 8),
                                               False):
                                    extras.append(
                                        self._getStream(
                                            x + '-' + properHex(y, 8), False))
                    elif _type in ('1002', '1003', '1004', '1005', '1007',
                                   '1040', '1048'):
                        extras = divide(
                            contents,
                            (2 if _type == '1002' else 4 if _type in (
                                '1003',
                                '1004') else 8 if type in ('1005', '1007',
                                                           '1040') else 16))
                        contents = streams
                return True, parseType(int(_type, 16), contents,
                                       self.stringEncoding, extras)
        return False, None  # We didn't find the stream.