diff --git a/src/uniandes/tsdl/mutapk/MutAPK.java b/src/uniandes/tsdl/mutapk/MutAPK.java index 87a97e1..aca7bb2 100644 --- a/src/uniandes/tsdl/mutapk/MutAPK.java +++ b/src/uniandes/tsdl/mutapk/MutAPK.java @@ -19,6 +19,7 @@ import uniandes.tsdl.mutapk.detectors.MutationLocationDetector; import uniandes.tsdl.mutapk.detectors.MutationLocationListBuilder; import uniandes.tsdl.mutapk.helper.APKToolWrapper; +import uniandes.tsdl.mutapk.helper.Helper; import uniandes.tsdl.mutapk.model.MutationType; import uniandes.tsdl.mutapk.model.location.MutationLocation; import uniandes.tsdl.mutapk.operators.OperatorBundle; @@ -78,8 +79,10 @@ public static void runMutAPK(String[] args) throws Exception { } else { apkName = apkPath.substring(apkPath.lastIndexOf("/")); } + Helper.getInstance(); + Helper.setPackageName(appName); // Decode the APK - APKToolWrapper.openAPK(apkPath, extraPath); + //APKToolWrapper.openAPK(apkPath, extraPath); //Read selected operators OperatorBundle operatorBundle = new OperatorBundle(operatorsDir); diff --git a/src/uniandes/tsdl/mutapk/helper/APKToolWrapper.java b/src/uniandes/tsdl/mutapk/helper/APKToolWrapper.java index 8bd2db2..8de3c95 100644 --- a/src/uniandes/tsdl/mutapk/helper/APKToolWrapper.java +++ b/src/uniandes/tsdl/mutapk/helper/APKToolWrapper.java @@ -34,15 +34,17 @@ public static void openAPK(String path, String extraPath) throws IOException, In // System.out.println(decodedPath); } - public static void buildAPK(String path, String extraPath, String appName, int mutantIndex) throws IOException, InterruptedException{ + public static boolean buildAPK(String path, String extraPath, String appName, int mutantIndex) throws IOException, InterruptedException{ String decodedPath = Helper.getInstance().getCurrentDirectory(); Process ps = Runtime.getRuntime().exec(new String[]{"java","-jar",Paths.get(decodedPath,extraPath,"apktool.jar").toAbsolutePath().toString(),"b",Paths.get(decodedPath,path,"src").toAbsolutePath().toString(),"-o",Paths.get(decodedPath,path,appName).toAbsolutePath().toString(),"-f"}); System.out.println("Building mutant "+mutantIndex+"..."); ps.waitFor(); if(Files.exists(Paths.get(decodedPath,path,appName).toAbsolutePath())) { - System.out.println("SUCCESS: The "+mutantIndex+" mutant APK has been generated."); + System.out.println("SUCCESS: The "+mutantIndex+" mutant APK has been generated."); + return true; } else { System.out.println("ERROR: The "+mutantIndex+" mutant APK has not been generated."); + return false; } // InputStream es = ps.getErrorStream(); // byte e[] = new byte[es.available()]; diff --git a/src/uniandes/tsdl/mutapk/helper/Helper.java b/src/uniandes/tsdl/mutapk/helper/Helper.java index 9dd23c5..cd6335b 100644 --- a/src/uniandes/tsdl/mutapk/helper/Helper.java +++ b/src/uniandes/tsdl/mutapk/helper/Helper.java @@ -25,6 +25,7 @@ public class Helper { public static String currDirectory = ""; public static List actNames = new ArrayList(); public static String mainActivity = ""; + public static String packageName = ""; public final static String MANIFEST = "AndroidManifest.xml"; public final static String MAIN_ACTION = "android.intent.action.MAIN"; public static final int MIN_VERSION = 2; @@ -41,6 +42,20 @@ public static Helper getInstance() { } return instance; } + + + + public static String getPackageName() { + return packageName; + } + + + + public static void setPackageName(String packageName) { + Helper.packageName = packageName; + } + + // public String getCurrentDirectory() throws UnsupportedEncodingException { // if (currDirectory.equals("")) { diff --git a/src/uniandes/tsdl/mutapk/operators/activity/DifferentActivityIntentDefinition.java b/src/uniandes/tsdl/mutapk/operators/activity/DifferentActivityIntentDefinition.java index 2e5d3aa..a92eeca 100644 --- a/src/uniandes/tsdl/mutapk/operators/activity/DifferentActivityIntentDefinition.java +++ b/src/uniandes/tsdl/mutapk/operators/activity/DifferentActivityIntentDefinition.java @@ -39,9 +39,19 @@ public boolean performMutation(MutationLocation location, BufferedWriter writer, founded =true; realLine = temp.getLine(); toMutate = hijoss.get(2).getText(); - mutatedString = "L"+activities.get((int)Math.random()*activities.size()).replace(".", "/")+";"; + String activityName =activities.get((int)(Math.random()*activities.size())); + if(!activityName.startsWith(Helper.getPackageName())) { + activityName=Helper.getPackageName()+"."+((activityName.startsWith("."))?activityName.substring(1):activityName); + } + activityName = activityName.replace(".", "/"); + mutatedString = "L"+activityName+";"; while(mutatedString.equals(toMutate)){ - mutatedString = "L"+activities.get((int)Math.random()*activities.size()).replace(".", "/")+";"; + activityName =activities.get((int)(Math.random()*activities.size())); + if(!activityName.startsWith(Helper.getPackageName())) { + activityName=Helper.getPackageName()+"."+((activityName.startsWith("."))?activityName.substring(1):activityName); + } + activityName = activityName.replace(".", "/"); + mutatedString = "L"+activityName+";"; } } } diff --git a/src/uniandes/tsdl/mutapk/processors/MutationsProcessor.java b/src/uniandes/tsdl/mutapk/processors/MutationsProcessor.java index 26e25f3..15ece32 100644 --- a/src/uniandes/tsdl/mutapk/processors/MutationsProcessor.java +++ b/src/uniandes/tsdl/mutapk/processors/MutationsProcessor.java @@ -141,13 +141,13 @@ public String call() { // Perform mutation operator.performMutation(mutationLocation, writer, currentMutationIndex); Long mutationEnd = System.currentTimeMillis(); - APKToolWrapper.buildAPK(mutantRootFolder, extraPath, apkName, currentMutationIndex); + boolean result = APKToolWrapper.buildAPK(mutantRootFolder, extraPath, apkName, currentMutationIndex); File mutatedFile = new File(newMutationPath); String fileName = (new File(newMutationPath)).getName(); File mutantRootFolderDir = new File(mutantRootFolder+fileName); FileUtils.copyFile(mutatedFile, mutantRootFolderDir); File srcFolder = new File(mutantFolder); - FileUtils.deleteDirectory(srcFolder); + if(result) {FileUtils.deleteDirectory(srcFolder);} Long buildEnd = System.currentTimeMillis(); Long mutationTime = mutationEnd-mutationIni; Long buildingTime = buildEnd - mutationEnd; diff --git a/test/MutAPK-0.0.1.jar b/test/MutAPK-0.0.1.jar index 07cd168..264dabd 100644 Binary files a/test/MutAPK-0.0.1.jar and b/test/MutAPK-0.0.1.jar differ diff --git a/test/operators.properties b/test/operators.properties index c3a4606..2ddf1e0 100644 --- a/test/operators.properties +++ b/test/operators.properties @@ -1,3 +1,4 @@ # 30 = BuggyGUIListener -15 = BluetoothAdapterAlwaysEnabled -31 = InvalidIDFindView \ No newline at end of file +# 15 = BluetoothAdapterAlwaysEnabled +# 31 = InvalidIDFindView +2 = DifferentActivityIntentDefinition \ No newline at end of file