Skip to content

Commit

Permalink
Adaptions for Flowdroid v2.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Canonize committed Jun 8, 2022
1 parent fa5b4c9 commit d5c43af
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 43 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "interactive"
}
Binary file added lib/soot-infoflow-cmd-jar-with-dependencies.jar
Binary file not shown.
17 changes: 8 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,21 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs
<artifactId>commons-cli</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<!-- <dependency>
<groupId>soot-infoflow-dummy</groupId>
<artifactId>soot-infoflow-dummy</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/soot-infoflow-dummy.jar</systemPath>
<!-- <systemPath>${project.basedir}/lib/soot-infoflow-android-classes.jar</systemPath> -->
</dependency>
<!-- <dependency>
<groupId>soot-infoflow-cmd-2.9.0-jar-with-dependencies</groupId>
<artifactId>soot-infoflow-cmd-2.9.0-jar-with-dependencies</artifactId>
<version>2.9</version>
</dependency> -->
<dependency>
<groupId>soot-infoflow-cmd-jar-with-dependencies</groupId>
<artifactId>soot-infoflow-cmd-jar-with-dependencies</artifactId>
<version>2.11.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/soot-infoflow-cmd-2.9.0-jar-with-dependencies.jar</systemPath>
<systemPath>${project.basedir}/lib/soot-infoflow-cmd-jar-with-dependencies.jar</systemPath>
</dependency>
-->

<dependency>
<groupId>de.tud.sse</groupId>
<artifactId>soot-infoflow</artifactId>
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/analyze/utils/SootUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -826,10 +826,10 @@ public static Set<SootClass> getSootClassesInvoked(SootClass sootClass, Set<Soot
visitiedSootMethods));
} else if (unit instanceof JAssignStmt) {
JAssignStmt assignStmt = (JAssignStmt) unit;
if (assignStmt.rightBox == null) {
if (assignStmt.getRightOpBox() == null) {
continue;
}
Type type = assignStmt.rightBox.getValue().getType();
Type type = assignStmt.getRightOpBox().getValue().getType();
if (type instanceof RefType) {
RefType refType = (RefType) type;
SootClass refClass = refType.getSootClass();
Expand Down Expand Up @@ -1149,7 +1149,7 @@ public static String getTargetClassListenerBelongto(Unit defUnit) {
String className = "";
if (defUnit instanceof JAssignStmt) {
JAssignStmt assignDefUnit = (JAssignStmt) defUnit;
Value rValue = assignDefUnit.rightBox.getValue();
Value rValue = assignDefUnit.getRightOpBox().getValue();
if (rValue instanceof JInstanceFieldRef) {
JInstanceFieldRef fieldRef = (JInstanceFieldRef) rValue;
if (fieldRef.getBase().getType() instanceof PrimType)
Expand Down Expand Up @@ -1194,7 +1194,7 @@ public static String getTargetClassListenerBelongto(Unit defUnit) {
}
} else if (defUnit instanceof JIdentityStmt) {
JIdentityStmt identifyDefUnit = (JIdentityStmt) defUnit;
Value rValue = identifyDefUnit.rightBox.getValue();
Value rValue = identifyDefUnit.getRightOpBox().getValue();
if (rValue instanceof ThisRef) {
ThisRef thisRef = (ThisRef) rValue;
className = thisRef.getType().toString();
Expand All @@ -1217,7 +1217,7 @@ public static String getTargetClassOfUnit(SootMethod sm, Unit defUnit) {
String className = "";
if (defUnit instanceof JAssignStmt) {
JAssignStmt assignDefUnit = (JAssignStmt) defUnit;
Value rValue = assignDefUnit.rightBox.getValue();
Value rValue = assignDefUnit.getRightOpBox().getValue();
if (rValue instanceof JInstanceFieldRef) {
JInstanceFieldRef fieldRef = (JInstanceFieldRef) rValue;
if (fieldRef.getField().getType() instanceof PrimType)
Expand Down Expand Up @@ -1278,7 +1278,7 @@ public static String getTargetClassOfUnit(SootMethod sm, Unit defUnit) {
}
} else if (defUnit instanceof JIdentityStmt) {
JIdentityStmt identifyDefUnit = (JIdentityStmt) defUnit;
Value rValue = identifyDefUnit.rightBox.getValue();
Value rValue = identifyDefUnit.getRightOpBox().getValue();
if (rValue instanceof ThisRef) {
ThisRef thisRef = (ThisRef) rValue;
className = thisRef.getType().toString();
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/analyze/utils/ValueObtainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public NestableObj getValueofVar(Value strVal, Unit u, int depth) {
continue;
if (defUnit instanceof JAssignStmt) {
JAssignStmt jas2 = (JAssignStmt) defUnit;
Value val = jas2.rightBox.getValue();
Value val = jas2.getRightOpBox().getValue();
if (val instanceof JInstanceFieldRef) {
JInstanceFieldRef jifr = (JInstanceFieldRef) val;
if (jifr.getBase() == strVal)
Expand Down Expand Up @@ -369,22 +369,22 @@ private NestableObj stringApisOperation(Unit u, int depth) {
NestableObj resVal = new NestableObj(u.toString());
if (u.toString().contains("toString")) {
JAssignStmt jas1 = (JAssignStmt) u;
Value invoke = jas1.rightBox.getValue();
Value invoke = jas1.getRightOpBox().getValue();
if (invoke instanceof AbstractInstanceInvokeExpr || invoke instanceof JStaticInvokeExpr) {
Value strVal = getValueFromInvokeExpr(invoke);
resVal = getValueofVar(strVal, u, depth + 1);
}
} else if (u.toString().contains("append") || u.toString().contains("concat")) {
JAssignStmt jas1 = (JAssignStmt) u;
if (jas1.rightBox.getValue() instanceof AbstractInstanceInvokeExpr) {
AbstractInstanceInvokeExpr invokeStmt = (AbstractInstanceInvokeExpr) jas1.rightBox.getValue();
if (jas1.getRightOpBox().getValue() instanceof AbstractInstanceInvokeExpr) {
AbstractInstanceInvokeExpr invokeStmt = (AbstractInstanceInvokeExpr) jas1.getRightOpBox().getValue();
Value lv = invokeStmt.getBase();
if (invokeStmt.getArgCount() == 0)
resVal = getValueofVar(lv, u, depth + 1);
else {
Value rv = invokeStmt.getArg(0);
for (String l : getValueofVar(lv, u, depth + 1).getValues()) {
if (u.toString().contains("append") &&lv == jas1.leftBox.getValue()) {
if (u.toString().contains("append") &&lv == jas1.getLeftOpBox().getValue()) {
resVal.addValue(l);
continue;
}
Expand All @@ -402,7 +402,7 @@ private NestableObj stringApisOperation(Unit u, int depth) {
}
} else if (u.toString().contains("substring")) {
JAssignStmt jas1 = (JAssignStmt) u;
AbstractInstanceInvokeExpr invokeStmt = (AbstractInstanceInvokeExpr) jas1.rightBox.getValue();
AbstractInstanceInvokeExpr invokeStmt = (AbstractInstanceInvokeExpr) jas1.getRightOpBox().getValue();
Value strVal = invokeStmt.getBase();
int b = 0;
if (invokeStmt.getArgCount() > 0) {
Expand Down Expand Up @@ -451,23 +451,23 @@ private NestableObj stringApisOperation(Unit u, int depth) {
}
} else if (u.toString().contains("toLowerCase")) {
JAssignStmt jas1 = (JAssignStmt) u;
Value invoke = jas1.rightBox.getValue();
Value invoke = jas1.getRightOpBox().getValue();
if (invoke instanceof AbstractInstanceInvokeExpr || invoke instanceof JStaticInvokeExpr) {
Value strVal = getValueFromInvokeExpr(invoke);
for (String old : getValueofVar(strVal, u, depth + 1).getValues())
resVal.addValue(old.toLowerCase());
}
} else if (u.toString().contains("toUpperCase")) {
JAssignStmt jas1 = (JAssignStmt) u;
Value invoke = jas1.rightBox.getValue();
Value invoke = jas1.getRightOpBox().getValue();
if (invoke instanceof AbstractInstanceInvokeExpr || invoke instanceof JStaticInvokeExpr) {
Value strVal = getValueFromInvokeExpr(invoke);
for (String old : getValueofVar(strVal, u, depth + 1).getValues())
resVal.addValue(old.toUpperCase());
}
} else if (u.toString().contains("trim")) {
JAssignStmt jas1 = (JAssignStmt) u;
Value invoke = jas1.rightBox.getValue();
Value invoke = jas1.getRightOpBox().getValue();
if (invoke instanceof AbstractInstanceInvokeExpr || invoke instanceof JStaticInvokeExpr) {
Value strVal = getValueFromInvokeExpr(invoke);
for (String old : getValueofVar(strVal, u, depth + 1).getValues())
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/client/instrument/InstrumentAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import soot.jimple.infoflow.android.axml.AXmlHandler;
import soot.jimple.infoflow.android.axml.AXmlNode;
import soot.jimple.infoflow.android.manifest.ProcessManifest;
import soot.jimple.infoflow.android.manifest.binary.BinaryManifestActivity;
import soot.jimple.internal.JIdentityStmt;
import soot.jimple.internal.JInvokeStmt;
import soot.jimple.internal.JSpecialInvokeExpr;
Expand Down Expand Up @@ -196,9 +197,10 @@ public void export() {
if (!instrumentedApk.exists())
FileUtils.copyFile(appPath, instrumentedApkPath);
manifestManager = new ProcessManifest(instrumentedApkPath);
List<AXmlNode> acts = manifestManager.getActivities();
for (AXmlNode actNode : acts) {
List<BinaryManifestActivity> acts = manifestManager.getActivities().asList();
for (BinaryManifestActivity act : acts) {
// get the attributes of the activity element
AXmlNode actNode = act.getAXmlNode();
AXmlAttribute<String> attr = new AXmlAttribute<String>("exported", "true",
AXmlHandler.ANDROID_NAMESPACE);
actNode.addAttribute(attr);
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/client/manifest/MainfestAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

import soot.jimple.infoflow.android.axml.AXmlNode;
import soot.jimple.infoflow.android.manifest.ProcessManifest;
import soot.jimple.infoflow.android.manifest.binary.AbstractBinaryAndroidComponent;
import soot.jimple.infoflow.android.manifest.binary.BinaryAndroidApplication;
import soot.jimple.infoflow.android.manifest.binary.BinaryManifestActivity;

/**
* This class is used to parse a manifest XML file Extract all the exported
Expand Down Expand Up @@ -55,18 +58,18 @@ public void analyze() {
appModel.setPackageName(pkg);
appModel.getExtendedPakgs().add(pkg);
appModel.setVersionCode(manifestManager.getVersionCode());
AXmlNode appNode = manifestManager.getApplication();
AXmlNode appNode = ((BinaryAndroidApplication)manifestManager.getApplication()).getAXmlNode();
// get permissions
if (appNode.getAttribute("permission") != null) {
appModel.setPermission(appNode.getAttribute("permission").getValue().toString());// which
// permission?
}
appModel.setUsesPermissionSet(manifestManager.getPermissions());

parseComponent(manifestManager.getActivities(), "Activity");
parseComponent(manifestManager.getServices(), "Service");
parseComponent(manifestManager.getProviders(), "Provider");
parseComponent(manifestManager.getReceivers(), "Receiver");
parseComponent(manifestManager.getActivities().asList(), "Activity");
parseComponent(manifestManager.getServices().asList(), "Service");
parseComponent(manifestManager.getContentProviders().asList(), "Provider");
parseComponent(manifestManager.getBroadcastReceivers().asList(), "Receiver");

mergeAllComponents();

Expand All @@ -92,11 +95,12 @@ public void analyze() {
* parse activity + service + contentProvider + broadcastReceiver node in
* manifest
*/
private void parseComponent(List<AXmlNode> components, String type) {
private void parseComponent(List<? extends AbstractBinaryAndroidComponent> components, String type) {
// get components
HashMap<String, ComponentModel> componentMap = getComponentMap(type);
for (AXmlNode componentNode : components) {
for (AbstractBinaryAndroidComponent component : components) {
// new ActivityData instance
AXmlNode componentNode = component.getAXmlNode();
String componentName = componentNode.getAttribute("name").getValue().toString();
if (!Global.v().getAppModel().getApplicationClassNames().contains(componentName)) {
if (!componentName.contains(appModel.getPackageName())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ else if (useUnit.toString().contains("trim("))
else if (useUnit.toString().contains("substring(")) {
if (useUnit instanceof JAssignStmt) {
JAssignStmt jas1 = (JAssignStmt) useUnit;
AbstractInstanceInvokeExpr invokeStmt = (AbstractInstanceInvokeExpr) jas1.rightBox.getValue();
AbstractInstanceInvokeExpr invokeStmt = (AbstractInstanceInvokeExpr) jas1.getRightOpBox().getValue();
ValueObtainer vo = new ValueObtainer(methodSig, ConstantUtils.FLAGATTRI);
int b = 0, e = 0;
NestableObj res0 = vo.getValueofVar(invokeStmt.getArg(0), useUnit, 0);
Expand Down Expand Up @@ -261,7 +261,7 @@ else if (useUnit.toString().contains("substring(")) {
}
} else if (useUnit.toString().contains("charAt(")) {
JAssignStmt jas1 = (JAssignStmt) useUnit;
AbstractInstanceInvokeExpr invokeStmt = (AbstractInstanceInvokeExpr) jas1.rightBox.getValue();
AbstractInstanceInvokeExpr invokeStmt = (AbstractInstanceInvokeExpr) jas1.getRightOpBox().getValue();
ValueObtainer vo = new ValueObtainer(methodSig, ConstantUtils.FLAGATTRI);

int b = 0;
Expand All @@ -281,7 +281,7 @@ else if (useUnit.toString().contains("substring(")) {
return "";
} else if (useUnit.toString().contains("concat(")) {
JAssignStmt jas1 = (JAssignStmt) useUnit;
AbstractInstanceInvokeExpr invokeStmt = (AbstractInstanceInvokeExpr) jas1.rightBox.getValue();
AbstractInstanceInvokeExpr invokeStmt = (AbstractInstanceInvokeExpr) jas1.getRightOpBox().getValue();
ValueObtainer vo = new ValueObtainer(methodSig, ConstantUtils.FLAGATTRI);
List<String> vals = vo.getValueofVar(invokeStmt.getArg(0), useUnit, 0).getValues();
if (vals.size() > 0) {
Expand Down Expand Up @@ -355,16 +355,16 @@ private Set<String> getValueofUnit2Set(Unit useUnit, Value inputVar, String attr
// target
JAssignStmt jas1 = (JAssignStmt) useUnit;
Value strVal = null;
if (jas1.rightBox.getValue() instanceof AbstractInstanceInvokeExpr) {
AbstractInstanceInvokeExpr invokeStmt = (AbstractInstanceInvokeExpr) jas1.rightBox.getValue();
if (jas1.getRightOpBox().getValue() instanceof AbstractInstanceInvokeExpr) {
AbstractInstanceInvokeExpr invokeStmt = (AbstractInstanceInvokeExpr) jas1.getRightOpBox().getValue();
if (invokeStmt.getArg(0).equals(inputVar)) // actrionVar equals
// xxx
strVal = invokeStmt.getBase();
else
// xxx equals actrionVar
strVal = invokeStmt.getArg(0);
} else if (jas1.rightBox.getValue() instanceof JStaticInvokeExpr) {
JStaticInvokeExpr invokeStmt = (JStaticInvokeExpr) jas1.rightBox.getValue();
} else if (jas1.getRightOpBox().getValue() instanceof JStaticInvokeExpr) {
JStaticInvokeExpr invokeStmt = (JStaticInvokeExpr) jas1.getRightOpBox().getValue();
if (invokeStmt.getArg(0).equals(inputVar)) // actrionVar equals
// xxx
strVal = invokeStmt.getArg(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private Value getVarInExtraStmt(Unit u) throws Exception {
Value res = null;
if (u instanceof JAssignStmt) {
JAssignStmt jas = (JAssignStmt) u;
ValueBox ads = jas.rightBox;
ValueBox ads = jas.getRightOpBox();
Value v = ads.getValue();
if (v instanceof JVirtualInvokeExpr) {
JVirtualInvokeExpr jvie = (JVirtualInvokeExpr) v;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ private Value getVarInExtraStmt(Unit u) throws Exception {
Value res = null;
if (u instanceof JAssignStmt) {
JAssignStmt jas = (JAssignStmt) u;
ValueBox ads = jas.rightBox;
ValueBox ads = jas.getRightOpBox();
Value v = ads.getValue();
if (v instanceof JVirtualInvokeExpr) {
JVirtualInvokeExpr jvie = (JVirtualInvokeExpr) v;
Expand Down Expand Up @@ -382,7 +382,7 @@ private Value getVarInExtraStmt(Unit u, int id) throws Exception {
Value res = null;
if (u instanceof JAssignStmt) {
JAssignStmt jas = (JAssignStmt) u;
ValueBox ads = jas.rightBox;
ValueBox ads = jas.getRightOpBox();
Value v = ads.getValue();
if (v instanceof JVirtualInvokeExpr) {
JVirtualInvokeExpr jvie = (JVirtualInvokeExpr) v;
Expand Down

0 comments on commit d5c43af

Please sign in to comment.