-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added CallRemover component, allowing removing calls to specific methods
- Loading branch information
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters