unpack.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env python
  2. # Copyright (C) 2013 thuxnder <patrick@bluebox.com>
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the 'License');
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an 'AS IS' BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import argparse
  16. from zipfile import ZipFile, ZipInfo
  17. class ApkFile(ZipFile):
  18. def extract(self, member, path=None, pwd=None):
  19. if not isinstance(member, ZipInfo):
  20. member = self.getinfo(member)
  21. member.flag_bits ^= member.flag_bits%2
  22. ZipFile.extract(self, member, path, pwd)
  23. print ('extracting %s' % member.filename)
  24. def extractall(self, path=None, members=None, pwd=None):
  25. map(lambda entry: self.extract(entry, path, pwd), members if members is not None and len(members)>0 else self.filelist)
  26. if __name__ == '__main__':
  27. parser = argparse.ArgumentParser(description='unpacks an APK that contains files which are wrongly marked as encrypted')
  28. parser.add_argument('apk', type=str)
  29. parser.add_argument('file', type=str, nargs='*')
  30. args = parser.parse_args()
  31. apk = ApkFile(args.apk,'r')
  32. apk.extractall(members=args.file)