Skip to content

Commit 280a219

Browse files
committed
add parameters validations and some changes to README
1 parent b97c2e8 commit 280a219

File tree

3 files changed

+70
-10
lines changed

3 files changed

+70
-10
lines changed

README.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,37 @@ cd MutAPK
2323
mvn clean
2424
mvn package
2525
```
26-
The generated runnable jar can be found in: ``MutAPK/target/MutAPK-0.0.1.jar``
26+
The generated runnable jar can be found in: ``MutAPK/target/MutAPK-2.0.0.jar``
2727

2828
# Usage
29-
To run MutAPK use the following command, specifying the required arguments:
29+
To run MutAPK use the following command, specifying the path to the config file:
3030
```
31-
java -jar MutAPK-0.0.1.jar <APKPath> <AppPackage> <Output> <ExtraComponentFolder> <operatorsDir> <multithread> <amountMutants>?
31+
java -jar MutAPK-2.0.0.jar <pathToJSONConfigFile>
3232
```
33-
### Arguments
33+
34+
### JSON Configuration File
35+
36+
MutAPK uses a JSON file to define the values to be used during execution, an example of this file can be found in ```./src/main/resources/parameters.json```. Following is the structure of the JSON file:
37+
38+
```json
39+
{
40+
"apkPath": "./apk/com.evancharlton.mileage_3110.apk",
41+
"appName": "com.evancharlton.mileage",
42+
"mutantsFolder": "./mutants",
43+
"operatorsDir": "./",
44+
"multithreadExec": "true",
45+
"extraPath": "./extra",
46+
"selectionStrategy": "all",
47+
"selectionParameters":{
48+
"amountMutants":"34",
49+
"perOperator":"false",
50+
"confidenceLevel":"85",
51+
"marginError":"10",
52+
"baseAPKPath":"./"
53+
}
54+
}
55+
```
56+
3457
Provide the following list of required arguments when running MutAPK:
3558
1. ``APK path``: relative path of the apk to mutate;
3659
2. ``AppPackage``: App main package name;

src/main/java/edu/uniandes/tsdl/mutapk/MutAPK.java

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import java.io.FileNotFoundException;
66
import java.io.FileReader;
77
import java.io.FileWriter;
8+
import java.io.FilenameFilter;
89
import java.io.IOException;
10+
import java.io.UnsupportedEncodingException;
11+
import java.nio.file.Paths;
912
import java.util.HashMap;
1013
import java.util.List;
1114
import java.util.Set;
@@ -242,7 +245,7 @@ private static void readConfig(String configFilePath) throws NumberFormatExcepti
242245
}
243246
}
244247

245-
private static void checkAndPrepareParameters() throws MutAPKException {
248+
private static void checkAndPrepareParameters() throws MutAPKException, IOException {
246249
// TODO Auto-generated method stub
247250

248251
// Preprocess paths to fit to OS filsesystem format
@@ -260,14 +263,48 @@ private static void checkAndPrepareParameters() throws MutAPKException {
260263

261264
// Check general parameters
262265

263-
// apkPath exists and to identify if it is an absolute or a relative path
264-
// appName to not be empty
266+
String decodedPath = Helper.getInstance().getCurrentDirectory();
267+
// apkPath exists
268+
if(!(new File(Paths.get(decodedPath, apkPath).toAbsolutePath().toString())).exists()){
269+
throw new MutAPKException("Path to APK is not correct. The path does not exist.");
270+
}
265271
// mutantsfolder exists (in case it does not exist to create it) and to identify if it is an absolute or a relative path
272+
File mutantsFolderFO = new File(Paths.get(decodedPath, mutantsFolder).toAbsolutePath().toString());
273+
if(!mutantsFolderFO.exists()){
274+
mutantsFolderFO.mkdirs();
275+
}
266276

267-
268-
// operatorsDir if the folder exists, check if exists a .properties file, and if it is an absolute or relative path
277+
// operatorsDir if the folder exists, check if exists a .properties file
278+
File operFolderFO = new File(Paths.get(decodedPath, operatorsDir).toAbsolutePath().toString());
279+
if(!operFolderFO.exists()){
280+
throw new MutAPKException("Path to operator file is not correct. The path does not exist.");
281+
}
282+
System.out.println(operFolderFO.getCanonicalPath().toString());
283+
File[] properties = operFolderFO.listFiles(new FilenameFilter() {
284+
285+
@Override
286+
public boolean accept(File dir, String name) {
287+
return name.endsWith("operators.properties");
288+
}
289+
});
290+
if(properties.length==0) {
291+
throw new MutAPKException("Path to operators config file is not correct. No operators.properties file exist in folder");
292+
}
269293
// extraPath if it is a parameter of JSON, if the folder exists and if it is an absolute or relative path
270-
294+
File extraFolderFO = new File(Paths.get(decodedPath, extraPath).toAbsolutePath().toString());
295+
if(!extraFolderFO.exists()){
296+
throw new MutAPKException("Path to extra folder is not correct. The path does not exist.");
297+
}
298+
File[] extraFO = extraFolderFO.listFiles(new FilenameFilter() {
299+
300+
@Override
301+
public boolean accept(File dir, String name) {
302+
return ( name.endsWith("apktool.jar") || name.endsWith("uber-apk-signer.jar") || name.endsWith("materialistic.jks"));
303+
}
304+
});
305+
if(extraFO.length<3) {
306+
throw new MutAPKException("Path to extra folder is not correct. No valid extra folder was provided.");
307+
}
271308

272309
// Check specific selection strategy parameters
273310
switch (selectionStrategy) {

test/MutAPK-1.0.0.jar

1.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)