Skip to content

Commit

Permalink
Added CallRemover component, allowing removing calls to specific methods
Browse files Browse the repository at this point in the history
  • Loading branch information
palant committed Aug 27, 2021
1 parent 607173d commit 552fbb6
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,13 @@ Configuration options:
* `AssignmentRemover.enabled`: add to enable this component
* `AssignmentRemover.filter`: (optional) restricts functionality to a set of methods, for value format see Method filters section above
* `AssignmentRemover.type`: the result type identifying the assignment to be removed

## CallRemover component

This component will remove any calls to the specified method(s).

Configuration options:

* `CallRemover.enabled`: add to enable this component
* `CallRemover.filter`: (optional) restricts functionality to a set of methods, for value format see Method filters section above
* `CallRemover.method`: specifies the method(s) to be removed, for value format see Method filters section above
48 changes: 48 additions & 0 deletions src/info/palant/apkInstrumentation/CallRemover.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* This Source Code is subject to the terms of the Mozilla Public License
* version 2.0 (the "License"). You can obtain a copy of the License at
* http://mozilla.org/MPL/2.0/.
*/

package info.palant.apkInstrumentation;

import java.util.Map;
import java.util.Properties;

import soot.Body;
import soot.BodyTransformer;
import soot.SootMethod;

public class CallRemover extends BodyTransformer
{
private MethodConfig filter;
private MethodConfig methodConfig;

public CallRemover(Properties config)
{
String method = config.getProperty("CallRemover.method");
if (method == null)
throw new RuntimeException("Please add CallRemover.method option to config file.");
this.methodConfig = new MethodConfig(method, "");

String filterSpec = config.getProperty("CallRemover.filter");
if (filterSpec != null)
this.filter = new MethodConfig(filterSpec, "");
else
this.filter = null;
}

@Override
protected void internalTransform(Body body, String phaseName, Map<String, String> options)
{
if (this.filter != null && this.filter.get(body.getMethod()) == null)
return;

body.getUnits().removeIf(unit -> {
SootMethod method = UnitParser.getInvocationMethod(unit);
return method != null && this.methodConfig.get(method) != null;
});

body.validate();
}
}
5 changes: 5 additions & 0 deletions src/info/palant/apkInstrumentation/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ private static void addTransformers(Properties config)
PackManager.v().getPack("jtp").add(new Transform("jtp.AssignmentRemover", new AssignmentRemover(config)));
hasTransformers = true;
}
if (config.getProperty("CallRemover.enabled") != null)
{
PackManager.v().getPack("jtp").add(new Transform("jtp.CallRemover", new CallRemover(config)));
hasTransformers = true;
}
if (config.getProperty("CallLogger.enabled") != null)
{
PackManager.v().getPack("jtp").add(new Transform("jtp.CallLogger", new CallLogger(config)));
Expand Down

0 comments on commit 552fbb6

Please sign in to comment.