def assemble_and_install(context): """ reassemble the apk file and install it to the device :param context: :return: """ app = Apps.getApp(context.package) logger.info("%s starting reassembling to apk", app.package) newapk = path + app.package + "/" + app.package + "-new.apk" newalignedapk = path + app.package + "/" + app.package + "-aligned.apk" logger.info("%s reassembling to apk", context.package) cmd = ["apktool", "b", path + app.package + "/smali/", "-o", newapk] logger.debug(" ".join(cmd)) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() if err: logger.error(err) return else: logger.debug(out) logger.info("%s signing apk", context.package) cmd = ["jarsigner", "-verbose", "-sigalg", "SHA1withRSA", "-digestalg", "SHA1", "-keystore", "my-release-key.keystore", "--store-pass", "123456", "-keypass", "123456", newapk, "alias_name"] logger.debug(" ".join(cmd)) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() if err: logger.error(err) return else: logger.debug(out) logger.info("%s aligning apk", context.package) cmd = [zipalign, "-f", "-v", "4", newapk, newalignedapk] logger.debug(" ".join(cmd)) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() if err: logger.error(err) return else: logger.debug(out) app = Apps() app.package = context.package app.path_to_apk = newalignedapk deviceHelper.uninstallapk(app) deviceHelper.installapk(app)
def apkTorJar(context): """ unpack apk file to jar; can be loaded with JD GUI :param context: :return: """ app = Apps.getApp(context.package) logger.info("%s starting dex to jar", app.package) cmd = ["d2j-dex2jar", "-o", path + app.package + "/" + app.package + "-dex2jar.jar", app.path_to_apk, ] p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() if err: logger.error(err) return else: logger.debug(out)
def install(): with open(app_list) as lines: packages = [line.rstrip('\n') for line in lines] packages.insert(0, "ALL") packages.append("quit") package, index = pick(packages, "choose package") if package == "ALL": apps = Apps.getAllApps() for a in apps: app = Apps() app.package = a[0] app.path_to_apk = a[1] deviceHelper.installapk(app) else: app = Apps.getApp(package) deviceHelper.installapk(app)
def openJarInJdGui(context): """ opens Jar in JD GUI :param context: :return: """ logger.info("%s opening jar in JD Gui", context.package) app = Apps.getApp(context.package) cmd = [jdgui, path + app.package + "/" + app.package + "-dex2jar.jar"] p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() if err: logger.error(err) return else: logger.debug(out)
def apkToSmali(context): """ extracts smali code form apk file; smali code to be used for further analysis :param context: :return: """ app = Apps.getApp(context.package) logger.info("%s starting dissambly to smali", app.package) cmd = ["apktool", "d", app.path_to_apk, "-o", path + app.package + "/smali/"] p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() if err: logger.error(err) return else: logger.debug(out)