예제 #1
0
파일: Tencent.py 프로젝트: fireall/unpacker
    def __init__(self, apk, outdir=None, outname=None):
        ZipFile.__init__(self, apk)

        with open(apk, 'rb') as f:
            sha1obj = hashlib.sha1()
            sha1obj.update(f.read())
            self.sha1 = sha1obj.hexdigest()

        self.outdir = outdir if outdir != None else os.path.join(os.path.dirname(self.filename))
        self.outname = outname if outname else 'tencent_%s.dex' % (self.sha1) 

        if not os.path.exists(self.outdir):
            os.makedirs(self.outdir)

        self.__total = 0
        self.sections = defaultdict(dict)
        self.classes_dex = StringStream( self.read('classes.dex') )
        self.new_classes_dex = FileStream(os.path.join(self.outdir, self.outname))
        self.new_classes_dex.write_bytes(self.classes_dex.get_data())

        add_attr = lambda pos, attr : (self.classes_dex.set_position(pos), setattr(self, attr, self.classes_dex.read_int()))

        add_attr(56, 'string_ids_size')
        add_attr(60, 'string_ids_off')
        add_attr(68, 'type_ids_off')
        add_attr(84, 'field_ids_off')
        add_attr(92, 'method_ids_off')
        add_attr(76, 'proto_ids_off')
        add_attr(100, 'class_defs_off')
        add_attr(48, 'link_off')
        add_attr(32, 'file_size')
        add_attr(104, 'data_size')
        add_attr(108, 'data_off')

        self.__read_encode_sections()
예제 #2
0
 def __init__(self, dest, *args, **kwargs):
     if not isinstance(dest, str):
         try:
             dest.tell()
         except (AttributeError, IOError):
             dest = _Tellable(dest)
     ZipFile.__init__(self, dest, *args, **kwargs)
예제 #3
0
 def __init__(self, *args, **kwargs):
     """
     Validates the zip file
     """
     try:
         ZipFile.__init__(self, *args, **kwargs)
     except BadZipfile:
         print(_("Manifest zip is invalid."))
         sys.exit(1)
 def __init__(self, *args, **kwargs):
     """
     Validates the zip file
     """
     try:
         ZipFile.__init__(self, *args, **kwargs)
     except BadZipfile:
         print _("Manifest zip is invalid.")
         sys.exit(1)
예제 #5
0
파일: wheelfile.py 프로젝트: hugovk/wheel
    def __init__(self, file, mode="r", compression=ZIP_DEFLATED):
        basename = os.path.basename(file)
        self.parsed_filename = WHEEL_INFO_RE.match(basename)
        if not basename.endswith(".whl") or self.parsed_filename is None:
            raise WheelError(f"Bad wheel filename {basename!r}")

        ZipFile.__init__(self,
                         file,
                         mode,
                         compression=compression,
                         allowZip64=True)

        self.dist_info_path = "{}.dist-info".format(
            self.parsed_filename.group("namever"))
        self.record_path = self.dist_info_path + "/RECORD"
        self._file_hashes = OrderedDict()
        self._file_sizes = {}
        if mode == "r":
            # Ignore RECORD and any embedded wheel signatures
            self._file_hashes[self.record_path] = None, None
            self._file_hashes[self.record_path + ".jws"] = None, None
            self._file_hashes[self.record_path + ".p7s"] = None, None

            # Fill in the expected hashes by reading them from RECORD
            try:
                record = self.open(self.record_path)
            except KeyError:
                raise WheelError(f"Missing {self.record_path} file")

            with record:
                for line in csv.reader(
                        TextIOWrapper(record, newline="", encoding="utf-8")):
                    path, hash_sum, size = line
                    if not hash_sum:
                        continue

                    algorithm, hash_sum = hash_sum.split("=")
                    try:
                        hashlib.new(algorithm)
                    except ValueError:
                        raise WheelError(
                            f"Unsupported hash algorithm: {algorithm}")

                    if algorithm.lower() in {"md5", "sha1"}:
                        raise WheelError(
                            "Weak hash algorithm ({}) is not permitted by PEP "
                            "427".format(algorithm))

                    self._file_hashes[path] = (
                        algorithm,
                        urlsafe_b64decode(hash_sum.encode("ascii")),
                    )
예제 #6
0
 def __init__(self, archive):
     ZipFile.__init__(self, archive)
     for name in self.namelist():
         if os.path.splitext(name)[1] == '.class':
             self.agent_class = os.path.splitext(os.path.split(name)[1])[0]
             self.agent_package = os.path.split(name)[0]
         elif os.path.splitext(name)[1] == '.xml':
             self.agent_xml = os.path.splitext(name)[0]
         elif os.path.splitext(name)[1] == '.jar':
             self.agent_jar = os.path.splitext(name)[0]
         elif name.lower() == 'presentation/':
             self.agent_presentation = name[:-1]
         else:
             self.agent_other.append(name)
예제 #7
0
    def __init__(self, file, mode='r'):
        basename = os.path.basename(file)
        self.parsed_filename = WHEEL_INFO_RE.match(basename)
        if not basename.endswith('.whl') or self.parsed_filename is None:
            raise WheelError("Bad wheel filename {!r}".format(basename))

        ZipFile.__init__(self,
                         file,
                         mode,
                         compression=ZIP_DEFLATED,
                         allowZip64=True)

        self.dist_info_path = '{}.dist-info'.format(
            self.parsed_filename.group('namever'))
        self.record_path = self.dist_info_path + '/RECORD'
        self._file_hashes = OrderedDict()
        self._file_sizes = {}
        if mode == 'r':
            # Ignore RECORD and any embedded wheel signatures
            self._file_hashes[self.record_path] = None, None
            self._file_hashes[self.record_path + '.jws'] = None, None
            self._file_hashes[self.record_path + '.p7s'] = None, None

            # Fill in the expected hashes by reading them from RECORD
            try:
                record = self.open(self.record_path)
            except KeyError:
                raise WheelError('Missing {} file'.format(self.record_path))

            with record:
                for line in record:
                    line = line.decode('utf-8')
                    path, hash_sum, size = line.rsplit(u',', 2)
                    if hash_sum:
                        algorithm, hash_sum = hash_sum.split(u'=')
                        try:
                            hashlib.new(algorithm)
                        except ValueError:
                            raise WheelError(
                                'Unsupported hash algorithm: {}'.format(
                                    algorithm))

                        if algorithm.lower() in {'md5', 'sha1'}:
                            raise WheelError(
                                'Weak hash algorithm ({}) is not permitted by PEP 427'
                                .format(algorithm))

                        self._file_hashes[path] = (
                            algorithm,
                            urlsafe_b64decode(hash_sum.encode('ascii')))
예제 #8
0
    def __init__(self, zip_string):
        buffer = StringIO()
        if zip_string:
            if is_zipfile(zip_string):
                fp = open(zip_string, "rb")
                while 1:
                    data = fp.read(1024 * 8)
                    if not data:
                        break
                    buffer.write(data)
                fp.close()
            else:
                buffer.write(zip_string)

        ZipFile.__init__(self, buffer, 'a', compression=ZIP_DEFLATED)
예제 #9
0
파일: __init__.py 프로젝트: Tatsh/libipa
    def __init__(self,
                 file,
                 strict=False,
                 mode='r',
                 compression=ZIP_STORED,
                 allowZip64=True):
        """Open IPA file. Primary difference from ZipFile is that allowZip64
        is set to True by default because many IPA files are larger than 2
        GiB in file size."""
        ZipFile.__init__(self,
                         file,
                         mode=mode,
                         compression=compression,
                         allowZip64=allowZip64)

        filenames = self.namelist()

        self._logger.debug('Files within the archive.\n{0}'.format(filenames))

        matched = len([x for x in [re.match(self.info_plist_regex, y)
                                   for y in filenames]
                       if x]) == 1

        self._logger.debug('IPA file passes test phase one: {0}'.format(
            _yn(matched)))
        if strict:
            is_ipa = 'iTunesMetadata.plist' in filenames and matched
            self._logger.debug('IPA file passes test phase two: {0}'.format(
                _yn(is_ipa)))
        else:
            is_ipa = matched

        if not is_ipa:
            self._logger.debug(
                'IPA file failed {0}/2 test phases, IPA file is invalid.'.
                format(_tests_fails(matched, is_ipa)))

            self._logger.debug('IPA file test phase report: {0}'.format(
                _tests_report(matched, is_ipa)))

            self._raise_ipa_error('Not an IPA')

        self._logger.debug(
            'IPA file passes all test phases, IPA file is valid.')

        self._get_app_info()
예제 #10
0
    def __init__(self, file, mode='r'):
        basename = os.path.basename(file)
        self.parsed_filename = WHEEL_INFO_RE.match(basename)
        if not basename.endswith('.whl') or self.parsed_filename is None:
            raise WheelError("Bad wheel filename {!r}".format(basename))

        ZipFile.__init__(self, file, mode, compression=ZIP_DEFLATED, allowZip64=True)

        self.dist_info_path = '{}.dist-info'.format(self.parsed_filename.group('namever'))
        self.record_path = self.dist_info_path + '/RECORD'
        self._file_hashes = OrderedDict()
        self._file_sizes = {}
        if mode == 'r':
            # Ignore RECORD and any embedded wheel signatures
            self._file_hashes[self.record_path] = None, None
            self._file_hashes[self.record_path + '.jws'] = None, None
            self._file_hashes[self.record_path + '.p7s'] = None, None

            # Fill in the expected hashes by reading them from RECORD
            try:
                record = self.open(self.record_path)
            except KeyError:
                raise WheelError('Missing {} file'.format(self.record_path))

            with record:
                for line in record:
                    line = line.decode('utf-8')
                    path, hash_sum, size = line.rsplit(u',', 2)
                    if hash_sum:
                        algorithm, hash_sum = hash_sum.split(u'=')
                        try:
                            hashlib.new(algorithm)
                        except ValueError:
                            raise WheelError('Unsupported hash algorithm: {}'.format(algorithm))

                        if algorithm.lower() in {'md5', 'sha1'}:
                            raise WheelError(
                                'Weak hash algorithm ({}) is not permitted by PEP 427'
                                .format(algorithm))

                        self._file_hashes[path] = (
                            algorithm, urlsafe_b64decode(hash_sum.encode('ascii')))
예제 #11
0
    def __init__(self, apk, outdir=None, outname=None):
        ZipFile.__init__(self, apk)

        f = open(apk, 'rb')
        sha1obj = hashlib.sha1()
        sha1obj.update(f.read())
        self.sha1 = sha1obj.hexdigest()
        f.close()

        self.outdir = outdir if outdir != None else os.path.join(os.path.dirname(self.filename))
        self.outname = outname if outname else 'apkprotect_%s.dex' % (self.sha1) 

        if not os.path.exists(self.outdir):
            os.makedirs(self.outdir)

        self.classes_dex = StringStream( self.read('classes.dex') )
        self.libAPKProtect_so = StringStream( self.read('lib/armeabi/libAPKProtect.so') )
        self.sections = []

        self.new_classes_dex = FileStream( os.path.join( self.outdir, self.outname ) )
예제 #12
0
    def __init__(self, apk, outdir=None, outname=None):
        ZipFile.__init__(self, apk)

        with open(apk, 'rb') as f:
            sha1obj = hashlib.sha1()
            sha1obj.update(f.read())
            self.sha1 = sha1obj.hexdigest()

        self.outdir = outdir if outdir != None else os.path.join(
            os.path.dirname(self.filename))
        self.outname = outname if outname else 'tencent_%s.dex' % (self.sha1)

        if not os.path.exists(self.outdir):
            os.makedirs(self.outdir)

        self.__total = 0
        self.sections = defaultdict(dict)
        self.classes_dex = StringStream(self.read('classes.dex'))
        self.new_classes_dex = FileStream(
            os.path.join(self.outdir, self.outname))
        self.new_classes_dex.write_bytes(self.classes_dex.get_data())

        add_attr = lambda pos, attr: (self.classes_dex.set_position(
            pos), setattr(self, attr, self.classes_dex.read_int()))

        add_attr(56, 'string_ids_size')
        add_attr(60, 'string_ids_off')
        add_attr(68, 'type_ids_off')
        add_attr(84, 'field_ids_off')
        add_attr(92, 'method_ids_off')
        add_attr(76, 'proto_ids_off')
        add_attr(100, 'class_defs_off')
        add_attr(48, 'link_off')
        add_attr(32, 'file_size')
        add_attr(104, 'data_size')
        add_attr(108, 'data_off')

        self.__read_encode_sections()
예제 #13
0
파일: build.py 프로젝트: ysard/mintrayr
 def __init__(self, zfile, method=None):
     self.zfile = zfile
     zfile.seek(0, 0)
     ZipFile.__init__(self, zfile, "a", method or ZIP_STORED)
예제 #14
0
 def __init__(self, file, mode="r", compression=ZIP_STORED, allowZip64=False):
     ZipFile.__init__(self, file, mode, compression, allowZip64)
예제 #15
0
 def __init__(self, name, folder):
     ZipFile.__init__(self, name, 'w')
     self.folder = folder
예제 #16
0
 def __init__(self, url, username, password):
     FtpFile.__init__(self, url, username, password)
     byteIO = io.BytesIO()
     self.load(byteIO)
     ZipFile.__init__(self, byteIO)
예제 #17
0
파일: epub.py 프로젝트: zyqhi/SimpleEpub
 def __init__(self, name):
     ZipFile.__init__(self, name, 'w')
     # write the first file minetype
     self.write_mimetype()
     self.write_index_file()
예제 #18
0
 def __init__(self, fname, mode='r'):
     ZipFile.__init__(
         self, as_posix(fname), mode=mode, compression=ZIP_DEFLATED, allowZip64=True)
예제 #19
0
 def __init__(self, zfile):
     ZipFile.__init__(self, zfile, "w", ZIP_DEFLATED)
예제 #20
0
파일: download.py 프로젝트: iiman/mytardis
 def __init__(self,
              file,
              mode="r",
              compression=ZIP_STORED,
              allowZip64=False):
     ZipFile.__init__(self, file, mode, compression, allowZip64)
예제 #21
0
 def __init__(self, path: str):
     BaseWrapper.__init__(self, path)
     ZipFile.__init__(self, path)
예제 #22
0
 def __init__(self, dest_path, mode="r"):
     ZipFile.__init__(self, dest_path, mode, ZIP_DEFLATED, True)
예제 #23
0
    def __init__(self, target):
        zip_destination = target.rstrip(os.path.sep) + '.zip'

        ZipFile.__init__(self, zip_destination, 'w', zipfile.ZIP_DEFLATED)
        self.source_path = target
        self.archive_path = zip_destination
예제 #24
0
 def __init__(self, file):
     ZipFile.__init__(self, file, mode='w', allowZip64=True)
예제 #25
0
 def __init__(self, dest_path, mode="r"):
     ZipFile.__init__(self, dest_path, mode, ZIP_DEFLATED, True)
예제 #26
0
파일: location.py 프로젝트: yuanf225/Coffee
	def __init__(self, path):
		ZipFile.__init__(self, path)
		self.path = path
예제 #27
0
파일: build.py 프로젝트: joepie91/mintrayr
 def __init__(self, zfile, method=None):
     self.zfile = zfile
     zfile.seek(0,0)
     ZipFile.__init__(self, zfile, "a", method or ZIP_STORED)
예제 #28
0
 def __init__(self, zfile):
     ZipFile.__init__(self, zfile, "w", ZIP_DEFLATED)
예제 #29
0
파일: zippack.py 프로젝트: yougov/openpack
 def __init__(self, *args, **kwargs):
     ZipFile.__init__(self, *args, **kwargs)
     # each piece of content will be created with the same date_time
     # attribute (set to now)
     now = time.localtime(time.time())
     self.zip_info_factory = functools.partial(ZipInfo, date_time=now)
예제 #30
0
 def __init__(self, file, mode="r", compression=ZIP_STORED, allowZip64=False):
     if not isinstance(file, basestring):
         return _ZipFile.__init__(self, file, mode, compression, allowZip64)
     else:
         raise NotImplemented("Paths not supported by SafeZipFile")
예제 #31
0
 def __init__(self, *args, **kwargs):
     ZipFile.__init__(self, *args, **kwargs)
     self.mapping = {}
예제 #32
0
 def __init__(self, filename):
     """Initialises ZipFile object, and adds member_count attribute"""
     ZipFile.__init__(self, filename)
     self.member_count = len(self.filelist)
예제 #33
0
 def __init__(self, datastring):
     ZipFile.__init__(self, StringIO(datastring))  # 省略建立临时.zip文件,在ZipFile打开