Esempio n. 1
0
 def buildApk(self, sourceFolder, destinationApk, force=True):
     #TODO: Maybe it's worth to check later how the apktool behaves in case
     #      if force = False
     '''
     Builds an apk file from the provided folder path.
     
     Args:
     :param sourceFolder: base directory which contains decompiled files of 
         an apk file
     :param destinationApk: the path to the apk file that will be obtained as
         a result of the compilation
     :param force: if True - rewrite apk file if it is exists
     '''
     apktool = ApktoolInterface(javaPath = self.config.getApktoolJavaPath(),
                                javaOpts = self.config.getApktoolJavaOpts(),
                                pathApktool = self.config.getApktoolPath(),
                                jarApktool = self.config.getApktoolJar())
     
     (successfulRun, cmdOutput) = apktool.build(srcPath = sourceFolder,
                                                finalApk = destinationApk,
                                                quiet = True,
                                                forceAll = force,
                                                debug = False,     #maybe true but I did not change
                                                aaptPath=self.config.getAaptPath())
     
     if not successfulRun:
         err = "Cannot build apk file [%s] from folder [%s] using apktool. ERRSTR: %s" % (destinationApk, sourceFolder, cmdOutput)
         raise ApktoolBuildException(err)
Esempio n. 2
0
 def decompileApk(self, pathToApk, dirToDecompile):
     '''
     Using Apktool tries to decompile an apk file. Currently decompile only resources
     (required to decompile AndroidManifest.xml).
     
     Args:
         :param pathToApk: path to a valid apk file that needs to be
             decompiled
         :param dirToDecompile: path to a dir where the result of the
             decompile process will be stored
     
     Returns:
     
     Raises:
         ApkCannotBeDecompiledException: if the provided apk file cannot be decompiled.
     '''
     ensureDirExists(dirToDecompile)
     apktool = ApktoolInterface(javaPath = self.config.getApktoolJavaPath(),
                                javaOpts = self.config.getApktoolJavaOpts(),
                                pathApktool = self.config.getApktoolPath(),
                                jarApktool = self.config.getApktoolJar())
     
     (successfulRun, cmdOutput) = apktool.decode(apkPath = pathToApk,
                                       dirToDecompile = dirToDecompile,
                                       quiet = True,
                                       noSrc = True,
                                       noRes = False,
                                       debug = False,        #maybe true to enable debugging
                                       noDebugInfo = False,  #check this 
                                       force = True, #directory exist so without this this process finishes
                                       frameworkTag = "",
                                       frameworkDir = "",
                                       keepBrokenRes = True)
     
     if not successfulRun:
         err = "Cannot decompile file: [%s] into dir [%s]. ERRSTR: %s" % (pathToApk, dirToDecompile, cmdOutput)
         raise ApkCannotBeDecompiledException(err)