Skip to content

Commit fa968e3

Browse files
committed
fix InvalidIDFindView param value
1 parent dc7089a commit fa968e3

File tree

4 files changed

+51
-23
lines changed

4 files changed

+51
-23
lines changed

src/uniandes/tsdl/mutapk/MutAPK.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public static void runMutAPK(String[] args) throws Exception {
7676
apkName = apkPath.substring(apkPath.lastIndexOf("/"));
7777
}
7878
// Decode the APK
79-
//APKToolWrapper.openAPK(apkPath, extraPath);
79+
APKToolWrapper.openAPK(apkPath, extraPath);
8080

8181
//Read selected operators
8282
OperatorBundle operatorBundle = new OperatorBundle(operatorsDir);

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

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static CommonTree getFirstUncleNamedOfType(int type, String name, CommonT
6969
}
7070
return null;
7171
}
72-
72+
7373
public static CommonTree getFirstBackUncleNamedOfType(int type, String name, CommonTree t) {
7474
CommonTree parent = (CommonTree) t.getParent();
7575
List<CommonTree> uncles = (List<CommonTree>)((CommonTree)parent.getParent()).getChildren();
@@ -116,13 +116,13 @@ public static CommonTree hasIPutAndIGet(CommonTree t) {
116116

117117
public static int[] isValidLocation(CommonTree t){
118118
// if(t.getType()==159) {
119-
// System.out.println(t.toStringTree());
120-
// System.out.println(t.getType());
119+
// System.out.println(t.toStringTree());
120+
// System.out.println(t.getType());
121121
// System.out.println(t.getChild(2));
122122
// System.out.println(t.getChild(3));
123123
// System.out.println(t.getChild(2).toStringTree().equals("Ljava/net/URI;") && t.getChild(3).toStringTree().equals("<init>") );
124124
// }
125-
125+
126126
if(t.getType()==smaliParser.I_STATEMENT_FORMAT35c_METHOD) {
127127
ArrayList<Integer> resp = new ArrayList<Integer>();
128128
if(t.getFirstChildWithType(smaliParser.I_REGISTER_LIST).getChildCount()==3
@@ -164,11 +164,11 @@ public static int[] isValidLocation(CommonTree t){
164164
} else if(isNullOutputStream(t)) {
165165
resp.add(37);
166166
}
167-
167+
168168
if(t.getChild(1).getChildCount()>1) {
169169
resp.add(22);
170170
}
171-
171+
172172
if(resp.size()>0) {
173173
int[] ret = new int[resp.size()];
174174
for (int i=0; i < ret.length; i++)
@@ -177,15 +177,25 @@ public static int[] isValidLocation(CommonTree t){
177177
}
178178
return ret;
179179
}
180-
180+
181181
} else if(t.getType()==191) {
182182
if(t.getText().equals("putExtra")){ //InvalidKeyIntentPutExtra && NullValueIntentPutExtra
183183
return new int[]{4, 7};
184-
} else if(t.getText().equals("findViewById") && hasIPutAndIGet(t)!=null) {
185-
return new int[]{26, 29};
186-
} else if (t.getText().equals("findViewById")) {
187-
return new int[]{27, 31};
188-
}
184+
} else if(t.getText().equals("findViewById")) {
185+
ArrayList<Integer> resp = new ArrayList<Integer>();
186+
resp.add(27);
187+
resp.add(31);
188+
if (hasIPutAndIGet(t)!=null) {
189+
resp.add(26);
190+
resp.add(29);
191+
}
192+
int[] ret = new int[resp.size()];
193+
for (int i=0; i < ret.length; i++)
194+
{
195+
ret[i] = resp.get(i).intValue();
196+
}
197+
return ret;
198+
}
189199
} else if(t.getType()==161) {
190200
if(t.getChild(2).toStringTree().equals("Landroid/bluetooth/BluetoothAdapter;")
191201
&& t.getChild(3).toStringTree().equals("isEnabled")
@@ -266,7 +276,7 @@ private static boolean isOnCreateMethod(CommonTree t) {
266276
}
267277
return resp;
268278
}
269-
279+
270280
private static boolean isOnClickMethod(CommonTree t) {
271281
boolean resp = t.getChild(0).toString().equals("onClick");
272282
if(resp) {

src/uniandes/tsdl/mutapk/operators/gui/android/InvalidIDFindView.java

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,54 @@ public class InvalidIDFindView implements MutationOperator {
1919

2020
@Override
2121
public boolean performMutation(MutationLocation location, BufferedWriter writer, int mutantIndex) throws Exception {
22-
22+
2323
ASTMutationLocation mLocation = (ASTMutationLocation) location;
2424
CommonTree parent = (CommonTree) mLocation.getTree().getParent();
25+
boolean isParam = false;
26+
String constVarName = "";
27+
int linee = -1;
2528
CommonTree uncle = ASTHelper.getFirstBackUncleNamedOfType(smaliParser.I_STATEMENT_FORMAT31i, "const", mLocation.getTree());
26-
String constVarName = uncle.getChild(1).getText();
27-
29+
if (uncle == null) {
30+
uncle = ASTHelper.getFirstBackUncleNamedOfType(smaliParser.I_STATEMENT_FORMAT21ih, "const/high16", mLocation.getTree());
31+
if (uncle == null && parent.getChild(1).getChild(1).getText().startsWith("p")) {
32+
isParam=true;
33+
constVarName = parent.getChild(1).getChild(1).getText();
34+
linee = parent.getLine();
35+
}
36+
}
37+
38+
if (!isParam) {
39+
constVarName = uncle.getChild(1).getText();
40+
linee = uncle.getLine();
41+
}
42+
43+
2844
List<String> newLines = new ArrayList<String>();
2945
List<String> lines = FileHelper.readLines(location.getFilePath());
3046

3147
//Add lines before the MutationLocation
32-
for(int i=0; i < uncle.getLine()-1; i++){
48+
for(int i=0; i < linee-1; i++){
3349
newLines.add(lines.get(i));
3450
}
35-
51+
3652
//Apply mutation
3753
newLines.add("");
3854
newLines.add(" const "+constVarName+", 0x"+HexadecimalGenerator.generateRandomHexa());
3955
newLines.add("");
40-
41-
for(int i=uncle.getLine(); i < lines.size() ; i++){
56+
if(isParam) {
57+
newLines.add(lines.get(linee-1));
58+
}
59+
60+
for(int i=linee; i < lines.size() ; i++){
4261
newLines.add(lines.get(i));
4362
}
4463

4564
FileHelper.writeLines(location.getFilePath(), newLines);
4665
Helper.mutationSuccess(mutantIndex);
47-
Helper.writeBasicLogInfo(mutantIndex, location.getFilePath(), location.getType().getName(), new int[] {uncle.getLine()}, writer);
66+
Helper.writeBasicLogInfo(mutantIndex, location.getFilePath(), location.getType().getName(), new int[] {linee}, writer);
4867
writer.write(" For mutant "+mutantIndex+" the id of the element retrieved at line "+location.getStartLine()+" has been set to a random value");
4968
writer.newLine();
5069
writer.flush();
5170
return true;
5271
}
53-
5472
}

test/MutAPK-0.0.1.jar

117 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)