def dex2jar(apkPath,savePath): """ 解压APK并将dex转为jar :return: bool """ from shutil import move as moveFile from zipfile import ZipFile as unzip from os import popen as cmd try: z = unzip(apkPath, 'r') z.extractall(path=r"{}/files/".format(savePath)) z.close() os.cmd(".\dex2jar\d2j-dex2jar --force ./{}/files/classes.dex".format(savePath)) if os.path.exists("classes-dex2jar.jar"): moveFile("classes-dex2jar.jar", "./{}/{}.jar".format(savePath,apkFile)) return True except Exception as e: # print(e) pass return False
def unzipFile(self): # 解压 zip = unzip(self.path_file,'r') for file in zip.namelist(): zip.extract(file,self.down_folder) zip.close() print('解压成功') self.driver_file = r'%s\%s' % (self.down_folder,FILE_EXE) return self.driver_file
def extract_submission_files(self, student_submission): """Extracts all relevant subroutine files from a submission in order to be graded""" with unzip(student_submission, 'r') as zip_file: #Get a list of all subroutine file names from the zip files = filter( lambda x: x is not None, map(lambda y: match(r'(?:\w+/)*([\w\-]+\.s)', y), zip_file.namelist())) for file in files: with open('{}/{}'.format(self.temp_grading_folder, file.group(1).lower()), mode='wb') as f: f.write(zip_file.read(file.group(0)))