Skip to content

Commit 683d4ad

Browse files
committed
First Fixes on MO 2
1 parent 9f6fc32 commit 683d4ad

File tree

7 files changed

+40
-9
lines changed

7 files changed

+40
-9
lines changed

src/uniandes/tsdl/mutapk/MutAPK.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import uniandes.tsdl.mutapk.detectors.MutationLocationDetector;
2020
import uniandes.tsdl.mutapk.detectors.MutationLocationListBuilder;
2121
import uniandes.tsdl.mutapk.helper.APKToolWrapper;
22+
import uniandes.tsdl.mutapk.helper.Helper;
2223
import uniandes.tsdl.mutapk.model.MutationType;
2324
import uniandes.tsdl.mutapk.model.location.MutationLocation;
2425
import uniandes.tsdl.mutapk.operators.OperatorBundle;
@@ -78,8 +79,10 @@ public static void runMutAPK(String[] args) throws Exception {
7879
} else {
7980
apkName = apkPath.substring(apkPath.lastIndexOf("/"));
8081
}
82+
Helper.getInstance();
83+
Helper.setPackageName(appName);
8184
// Decode the APK
82-
APKToolWrapper.openAPK(apkPath, extraPath);
85+
//APKToolWrapper.openAPK(apkPath, extraPath);
8386

8487
//Read selected operators
8588
OperatorBundle operatorBundle = new OperatorBundle(operatorsDir);

src/uniandes/tsdl/mutapk/helper/APKToolWrapper.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,17 @@ public static void openAPK(String path, String extraPath) throws IOException, In
3434
// System.out.println(decodedPath);
3535
}
3636

37-
public static void buildAPK(String path, String extraPath, String appName, int mutantIndex) throws IOException, InterruptedException{
37+
public static boolean buildAPK(String path, String extraPath, String appName, int mutantIndex) throws IOException, InterruptedException{
3838
String decodedPath = Helper.getInstance().getCurrentDirectory();
3939
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"});
4040
System.out.println("Building mutant "+mutantIndex+"...");
4141
ps.waitFor();
4242
if(Files.exists(Paths.get(decodedPath,path,appName).toAbsolutePath())) {
43-
System.out.println("SUCCESS: The "+mutantIndex+" mutant APK has been generated.");
43+
System.out.println("SUCCESS: The "+mutantIndex+" mutant APK has been generated.");
44+
return true;
4445
} else {
4546
System.out.println("ERROR: The "+mutantIndex+" mutant APK has not been generated.");
47+
return false;
4648
}
4749
// InputStream es = ps.getErrorStream();
4850
// byte e[] = new byte[es.available()];

src/uniandes/tsdl/mutapk/helper/Helper.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class Helper {
2525
public static String currDirectory = "";
2626
public static List<String> actNames = new ArrayList<String>();
2727
public static String mainActivity = "";
28+
public static String packageName = "";
2829
public final static String MANIFEST = "AndroidManifest.xml";
2930
public final static String MAIN_ACTION = "android.intent.action.MAIN";
3031
public static final int MIN_VERSION = 2;
@@ -41,6 +42,20 @@ public static Helper getInstance() {
4142
}
4243
return instance;
4344
}
45+
46+
47+
48+
public static String getPackageName() {
49+
return packageName;
50+
}
51+
52+
53+
54+
public static void setPackageName(String packageName) {
55+
Helper.packageName = packageName;
56+
}
57+
58+
4459

4560
// public String getCurrentDirectory() throws UnsupportedEncodingException {
4661
// if (currDirectory.equals("")) {

src/uniandes/tsdl/mutapk/operators/activity/DifferentActivityIntentDefinition.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,19 @@ public boolean performMutation(MutationLocation location, BufferedWriter writer,
3939
founded =true;
4040
realLine = temp.getLine();
4141
toMutate = hijoss.get(2).getText();
42-
mutatedString = "L"+activities.get((int)Math.random()*activities.size()).replace(".", "/")+";";
42+
String activityName =activities.get((int)(Math.random()*activities.size()));
43+
if(!activityName.startsWith(Helper.getPackageName())) {
44+
activityName=Helper.getPackageName()+"."+((activityName.startsWith("."))?activityName.substring(1):activityName);
45+
}
46+
activityName = activityName.replace(".", "/");
47+
mutatedString = "L"+activityName+";";
4348
while(mutatedString.equals(toMutate)){
44-
mutatedString = "L"+activities.get((int)Math.random()*activities.size()).replace(".", "/")+";";
49+
activityName =activities.get((int)(Math.random()*activities.size()));
50+
if(!activityName.startsWith(Helper.getPackageName())) {
51+
activityName=Helper.getPackageName()+"."+((activityName.startsWith("."))?activityName.substring(1):activityName);
52+
}
53+
activityName = activityName.replace(".", "/");
54+
mutatedString = "L"+activityName+";";
4555
}
4656
}
4757
}

src/uniandes/tsdl/mutapk/processors/MutationsProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,13 @@ public String call() {
141141
// Perform mutation
142142
operator.performMutation(mutationLocation, writer, currentMutationIndex);
143143
Long mutationEnd = System.currentTimeMillis();
144-
APKToolWrapper.buildAPK(mutantRootFolder, extraPath, apkName, currentMutationIndex);
144+
boolean result = APKToolWrapper.buildAPK(mutantRootFolder, extraPath, apkName, currentMutationIndex);
145145
File mutatedFile = new File(newMutationPath);
146146
String fileName = (new File(newMutationPath)).getName();
147147
File mutantRootFolderDir = new File(mutantRootFolder+fileName);
148148
FileUtils.copyFile(mutatedFile, mutantRootFolderDir);
149149
File srcFolder = new File(mutantFolder);
150-
FileUtils.deleteDirectory(srcFolder);
150+
if(result) {FileUtils.deleteDirectory(srcFolder);}
151151
Long buildEnd = System.currentTimeMillis();
152152
Long mutationTime = mutationEnd-mutationIni;
153153
Long buildingTime = buildEnd - mutationEnd;

test/MutAPK-0.0.1.jar

378 Bytes
Binary file not shown.

test/operators.properties

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# 30 = BuggyGUIListener
2-
15 = BluetoothAdapterAlwaysEnabled
3-
31 = InvalidIDFindView
2+
# 15 = BluetoothAdapterAlwaysEnabled
3+
# 31 = InvalidIDFindView
4+
2 = DifferentActivityIntentDefinition

0 commit comments

Comments
 (0)