Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/uniandes/tsdl/mutapk/MutAPK.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions src/uniandes/tsdl/mutapk/helper/APKToolWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()];
Expand Down
15 changes: 15 additions & 0 deletions src/uniandes/tsdl/mutapk/helper/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class Helper {
public static String currDirectory = "";
public static List<String> actNames = new ArrayList<String>();
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;
Expand All @@ -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("")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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+";";
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/uniandes/tsdl/mutapk/processors/MutationsProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Binary file modified test/MutAPK-0.0.1.jar
Binary file not shown.
5 changes: 3 additions & 2 deletions test/operators.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# 30 = BuggyGUIListener
15 = BluetoothAdapterAlwaysEnabled
31 = InvalidIDFindView
# 15 = BluetoothAdapterAlwaysEnabled
# 31 = InvalidIDFindView
2 = DifferentActivityIntentDefinition