Exemple #1
0
    def find_offsets_for_signature(self, sig, filesize):
        offsets = set()
        # TODO: precompile regexp patterns in bangsignatures
        res = re.finditer(re.escape(bangsignatures.signatures[sig]),
                          self.scanbytes[:self.bytesread])
        if res is not None:
            for r in res:
                if sig in bangsignatures.signaturesoffset:
                    # skip files that aren't big enough if the
                    # signature is not at the start of the data
                    # to be carved (example: ISO9660).
                    if r.start(
                    ) + self.offsetinfile - bangsignatures.signaturesoffset[
                            sig] < 0:
                        continue

                offset = r.start()
                if not bangsignatures.prescan(sig, self.scanbytes,
                                              self.bytesread, filesize, offset,
                                              self.offsetinfile):
                    continue

                # default: store a tuple (offset, signature name)
                if sig in bangsignatures.signaturesoffset:
                    offsets.add((offset + self.offsetinfile -
                                 bangsignatures.signaturesoffset[sig], sig))
                else:
                    offsets.add((offset + self.offsetinfile, sig))
        return offsets
    def find_offsets_for_signature(self, sig, unpackparsers, filesize):
        offsets = set()
        s_offset, s_text = sig
        # TODO: precompile regexp patterns in bangsignatures
        res = re.finditer(re.escape(s_text), self.scanbytes[:self.bytesread])
        if res is not None:
            for r in res:
                # skip files that aren't big enough if the
                # signature is not at the start of the data
                # to be carved (example: ISO9660).
                if r.start() + self.offsetinfile - s_offset < 0:
                    continue

                offset = r.start()
                if not bangsignatures.prescan(s_text, self.scanbytes,
                                              self.bytesread, filesize, offset,
                                              self.offsetinfile):
                    continue

                # default: store a tuple (offset, signature name)
                offsets.update({(offset + self.offsetinfile - s_offset, u)
                                for u in unpackparsers})
        return offsets