예제 #1
0
 def build_apk(self, dest):  #编译apk
     remove(dest)
     self.do_cmd(ass_config.cmd_anprohelper + " b -a \"" +
                 ass_config.cmd_aapt + "\" " +
                 self.anprohelper_src_dst(self.apk_file +
                                          ".smali", self.apk_file + ".tmp"))
     if os.path.exists(self.apk_file + ".tmp"):
         self.do_cmd(ass_config.cmd_sign + " " + q(self.apk_file + ".tmp") +
                     " " + q(dest))
         remove(self.apk_file + ".tmp")
    def resign(self, apk_file, dest):
        shutil.copyfile(apk_file, dest + ".tmp")
        self.do_cmd(ass_config.cmd_7za + " d -tzip " + q(dest + ".tmp") +
                    " META-INF")
        if os.path.exists(dest + ".tmp"):
            self.do_cmd(ass_config.cmd_sign + " " + q(dest + ".tmp") + " " +
                        q(dest))
            remove(dest + ".tmp")
            if os.path.exists(dest):
                return True

        return False
    def cap(self, apk_file, apk, step, files):
        for i in range(20):
            files.append(self.screnncap_one())

        pid = self.get_pid(apk)

        last_min = 100
        last_i = 0
        for i in range(len(files)):
            f = files[i]

            if last_min > 10 or i < last_i + 1:
                self.adb("pull /data/" + self.get_screencap_file(f) + " " +
                         q(self.local_cap_file(apk_file, step, f)))
            self.adb("shell rm /data/" + self.get_screencap_file(f))

            if i > 0 and last_min > 10:
                nmin = self.pil_image_similarity(
                    self.local_cap_file(apk_file, step, files[i - 1]),
                    self.local_cap_file(apk_file, step, f))
                if nmin < last_min:
                    last_min = nmin
                    last_i = i

        return files[0], files[last_i], pid
    def inforce_end(self, apk_file, dest):
        filename = os.path.split(apk_file)[1]

        ftp = FTP(ftp_server, ftp_user, ftp_password)
        ftp.getwelcome()
        ftp.debug(1)
        ftp.cwd("test/jg_out")
        f = open(dest + ".tmp", 'wb')
        ftp.retrbinary("RETR " + filename, f.write, 1024)
        f.close()

        ftp.delete(filename)
        ftp.delete("../jg_in/" + filename)
        ftp.close()

        self.do_cmd(ass_config.cmd_sign + " " + q(dest + ".tmp") + " " +
                    q(dest))
        remove(dest + ".tmp")
예제 #5
0
 def so_is_encrypt(self, path):#判断so是否加密
     out_str = self.do_cmd(ass_config.cmd_ndk_nm+" -D "+ass_base.q(path),False)
     java_func = ass_base.mid_str(out_str, " Java_", "\n")
     if len(java_func)>0 or out_str.find('android_log_print')>0:
         return -1
     elif out_str.find("JNI_OnLoad\n")>0:
         return 1
     else:
         return 0
예제 #6
0
 def adb_repair(self):
     self.report.LOG_OUT("start repair adb")
     adbs = " "
     if len(ass_config.adb_server) > 0:
         adbs = " -s " + q(ass_config.adb_server) + " "
     self.do_cmd(ass_config.cmd_adb + adbs + "kill-server")
     time.sleep(2)
     res = self.do_cmd(ass_config.cmd_adb + adbs + "start-server")
     res = self.do_cmd(ass_config.cmd_adb + adbs + "shell aa")
     if res.find("error: device offline") >= 0:
         #修复失败
         #--- 进一步处理
         self.report.LOG_OUT("restart avd")
         #使用socket 发送修复指令,重启虚拟机
         return self.restart_avd()
         #return False
     return True
예제 #7
0
 def adb(self, cmd, timeout=300):  #连接adb
     adbs = " "
     if len(ass_config.adb_server) > 0:
         adbs = " -s " + q(ass_config.adb_server) + " "
     res = self.do_cmd(ass_config.cmd_adb + adbs + cmd, True, timeout)
     need_repair = False
     if res.find("device offline") >= 0:
         need_repair = True
     if need_repair:
         #修复adb
         res_repair = self.adb_repair()
         if res_repair:
             #修复成功继续执行
             time.sleep(2)
             return self.adb(cmd, timeout)
         else:
             #抛出异常
             raise
     return res
예제 #8
0
import os
import sys
from ass_base import q

if __name__=="__main__":
    if len(sys.argv)<3:
        print("usage: ass_test_inforce.py apk_dir csv")
        exit()
    else:
        topdir = sys.argv[1]
        if os.path.isdir(topdir):
            ext_name = ".apk"
            ext_len = len(ext_name)
            for root, dirs, files in os.walk(topdir, topdown=False):
                #hanlde file
                for name in files:
                    if name[-ext_len:] == ext_name:
                        path = os.path.join(root,name)
                        os.system("python ass_module_test_inforce.py "+q(path)+" - "+q(sys.argv[2]))
        else:
            path = topdir
            os.system("python ass_module_test_inforce.py "+q(path)+" - "+q(sys.argv[2]))
            
        
                    
                    

    
    
예제 #9
0
 def get_manifest_icon(self):  #获取主配置文件
     axml = os.path.join(self.smali_dir, "AndroidManifest.xml")
     axml_de = os.path.join(self.smali_dir, "AndroidManifest_de.xml")
     return self.do_cmd(
         ass_config.cmd_axml + " " + q(axml) + " >" + q(axml_de), True)
예제 #10
0
 def get_manifest(self, apk):  #获取主配置文件
     axml = os.path.join(self.smali_dir, "AndroidManifest.xml")
     return self.do_cmd(ass_config.cmd_axml + " " + q(axml), True)
예제 #11
0
 def anprohelper_src_dst(self, src, dst):  #获取源码
     return q(src) + ' -o ' + q(dst)