Example #1
0
def getLaunchTime(apk_name,profile):
	apk_folder = Constant.apk_path + apk_name
	manifest = apk_folder + "\\" + apk_name  +"\\AndroidManifest.xml"
	print manifest
	if not os.path.exists(manifest):		
		decompile(apk_name)
	apko = ApkOpearate(apk_name,apk_folder)  

	package = apko.getPackage()
	main = apko.getMain()
	print "MainActivity is "+ main 
	
	os.system('adb shell am force-stop '+package)
	os.system('adb shell am  start -n' +package+'/'+main)
	
	start=datetime.now()
	end = start 
	
	p = os.popen('adb shell dumpsys activity | findstr "mFocusedActivity"')
	res = loadRes = p.read()

	while loadRes == res:
		p = os.popen('adb shell dumpsys activity | findstr "mFocusedActivity"')
		res = p.read()
		end=datetime.now()
		if (end - start).seconds >10:
			print 'No splash Activity'
			end = start 
			break
			
	f=open(profile,'a')
	#f.write("\n")
	f.write("[#application launch time --more than splash time]\n")

	if start == end:
		print "sleeptime 1000" 
		f.write("sleeptime:1000\n")
	else:
		gap = (end - start).seconds * 1000
		print "sleeptime " +str(gap) 
		f.write("sleeptime:"+str(gap)+'\n')
	f.close()
Example #2
0
def closeCurrentApp(apk_name,windowPackageName):
	apk_folder = Constant.apk_path + apk_name
	apko = ApkOpearate(apk_name, apk_folder)
	currentPackageName = getCurrentPackageName()
	if( currentPackageName != windowPackageName):
		apko.stopAPP(currentPackageName)
Example #3
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
from ApkOpearate import *
from Calculator import *
from common.constant import *

if __name__ == '__main__':

    apk_name = sys.argv[1]
    apk_folder = Constant.apk_path + apk_name
    apk_path = apk_folder + "\\" + apk_name
    apk_info_path = Constant.file_path + apk_name + "\\"

    apko = ApkOpearate(apk_name, apk_folder)
    apko.get_methods()
    package = apko.getPackage()
    main = apko.getMain()

    instrument_log = apk_info_path + Constant.info_path + Constant.instrument_log
    instrument_log_this = apk_info_path + Constant.info_path + Constant.instrument_log_this
    instrument_log_this_target = apk_info_path + Constant.info_path + Constant.instrument_log_this_target

    cal = Calculator(apk_name, instrument_log_this, package.replace('.', '/'))
    cal.filterInstrumentLog(instrument_log, instrument_log_this)
    cal.filterTestInstrumentLog(instrument_log_this,
                                instrument_log_this_target)

    cal.getCoverage()
Example #4
0
import sys

from ApkOpearate import *
from common.constant import *


def makeDir(dir):
    if (not os.path.exists(dir)):
        os.makedirs(dir)


if __name__ == '__main__':

    apk_name = sys.argv[1]
    apk_folder = Constant.apk_path + apk_name
    apko = ApkOpearate(apk_name, apk_folder)

    infoDir = Constant.file_path + apk_name + "\\" + Constant.info_path
    makeDir(infoDir)

    #set target pkg (e.g., -P pkg_name)
    targetPkg = ""

    apko.addStake2(targetPkg)
    apko.addPermission()
    apko.rebuild_bat()
    apko.resign_bat()

    ins_info_file = Constant.file_path + apk_name + "\\" + Constant.ins_info_file
    shutil.copy(Constant.apk_path + apk_name + "\ins_info", ins_info_file)
Example #5
0
	jimpleDir = Constant.file_path + apk_name + "\\" + Constant.jimple_path
	
	makeDir(logsDir)
	makeDir(infoDir)
	makeDir(monkeyDir)
	makeDir(jimpleDir)
	
	apk_folder = Constant.apk_path + apk_name
	apk_robt_folder = Constant.apk_robt_path + apk_robt_name
	removeDir(apk_robt_folder)
	  
	apk_path = apk_folder + "\\" + apk_name 
	apk_robt_path = apk_robt_folder+ "\\" + apk_robt_name 
	
	
	apko = ApkOpearate(apk_name,apk_folder)  
	package = apko.getPackage()
	
	# buile robotium apk
	apko2 = ApkOpearate(apk_name,apk_robt_folder)
	apko2.createRobotProject(package)
	apko2.buildApk()
	
	
	print 'install apk under test'
	os.popen("adb uninstall "+package)
	os.system("adb install "+ apk_path+"_signed.apk")

	print '\ninstall apk for exploration'
	os.popen("adb uninstall "+package+".test")
	os.system("adb install "+ apk_robt_path+"_signed.apk")
Example #6
0
        shutil.rmtree(dir)


def makeDir(dir):
    if (not os.path.exists(dir)):
        os.makedirs(dir)


if __name__ == '__main__':
    apk_name = sys.argv[1]
    apk_folder = Constant.apk_path + apk_name

    InfoDir = Constant.file_path + apk_name + "\\" + Constant.info_path
    print apk_folder
    if (os.path.exists(apk_folder)):
        apko = ApkOpearate(apk_name, apk_folder)
        if (not os.path.exists(InfoDir)):
            os.makedirs(InfoDir)

        apko.decompile_bat()
        print apk_name + " decompile finish"
        package = apko.getPackage()

        name_file = Constant.file_path + apk_name + "\\" + Constant.name_file
        removeFile(name_file)
        writeNameFile(name_file)

        manifestStartFlagFile = Constant.file_path + apk_name + "\\" + Constant.manifestStartFlagFile
        removeFile(manifestStartFlagFile)
        writeManifestFile(manifestStartFlagFile)
    else:
Example #7
0
    # removeFile(recordEvents_file)
    # removeFile(ser_file)
    # removeFile(currentATG_file)
    # removeFile(GUIinfo_file)
    # removeFile(screenshot_file)

    removeFile(instrument_log)
    removeFile(instrument_log_this)
    removeFile(instrument_log_this_target)

    removeFile(re_auto_file)
    removeFile(re_stake_file)
    removeFile(re_calculate_file)

    #write file about package and classname
    apko = ApkOpearate(apk_name, apk_folder)
    apko.get_methods()

    acts = apko.getAct()
    package = apko.getPackage()  #package name of app under testing
    main = apko.getMain()  #main activity name of app under testing

    print "push file to phone"
    os.system("adb push " + name_file + " sdcard/getName.txt")
    os.system("adb push " + manifestStartFlagFile +
              " sdcard/manifestStartFlag.txt")
    os.system("adb push " + profile + " sdcard/profile.txt")
    os.system("adb push " + EditTextFile + " sdcard/EditTextFile.txt")

    print "start exploration\n"
Example #8
0
    method_file = apk_info_path + Constant.method_file
    recordEvents_file = apk_info_path + Constant.recordEvents_file
    manifestStartFlagFile = apk_info_path + Constant.manifestStartFlagFile
    ser_file = apk_info_path + Constant.ser_file
    atg_file = apk_info_path + Constant.atg_file

    instrument_log = apk_info_path + Constant.info_path + Constant.instrument_log
    instrument_log_this = apk_info_path + Constant.info_path + Constant.instrument_log_this
    instrument_log_this_target = apk_info_path + Constant.info_path + Constant.instrument_log_this_target

    re_auto_file = apk_info_path + Constant.re_auto_file
    re_stake_file = apk_info_path + Constant.re_stake_file
    re_calculate_file = apk_info_path + Constant.re_calculate_file

    #part1.2 write file about package and classname
    apko = ApkOpearate(apk_name, apk_folder)
    apko.get_methods()

    acts = apko.getAct()
    package = apko.getPackage()  #package name of app under testing
    main = apko.getMain()  #main activity name of app under testing

    #generate test sequence through calling jar file
    #print "java -jar "+Constant.testGenerator+" "+ package+" "+main  +" " +apk_name
    #os.system("java -jar "+Constant.testGenerator+" "+ package+" "+main+" " +apk_name )

    #generate robotium DFS test apk file
    apko3 = ApkOpearate(apk_name, apk_test_folder)
    apko3.createTestProject(package)
    apko3.buildApk()