Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filters feature #55

Merged
merged 41 commits into from
Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
c2889c0
Added a new argument placeholder, renamed filter to package-filter
alexzaitsev Jul 9, 2019
c22013e
Prepared for filters file parsing
alexzaitsev Jul 9, 2019
452c46c
Moved all filters to json config. Changed argument reading. FiltersRe…
alexzaitsev Jul 9, 2019
1dd6f0a
Added filters logic, started working on SmaliAnalyzer
alexzaitsev Jul 10, 2019
3c96378
Futher work on filters feature
alexzaitsev Jul 10, 2019
5d242bf
code fixes
alexzaitsev Jul 10, 2019
2efc369
moved source classes to com.alex_zaitsev.adg package, added JUnit4 su…
alexzaitsev Jul 12, 2019
fca3a5e
added tests for ArgumentReader
alexzaitsev Jul 12, 2019
5c02392
removed run task from Ant. Added tests for FiltersReader, improved te…
alexzaitsev Jul 12, 2019
442b386
Fix Gradle build (#53)
SupinePandora43 Jul 15, 2019
234cdf5
enhansed tests
alexzaitsev Jul 15, 2019
eb39b5d
Test logger is added to Gradle (#54)
SupinePandora43 Jul 15, 2019
14fe9a1
started working on SmaliAnalyzer tests
alexzaitsev Jul 15, 2019
26b3116
progress with SmaliAnalyzer tests
alexzaitsev Jul 15, 2019
382c999
moved Filter creation to separate class. Created class for testing Fi…
alexzaitsev Jul 15, 2019
6a1f651
added tests for FilterProvider.makePathFilter
alexzaitsev Jul 16, 2019
b40b503
code improvements. run scripts were adjusted to the feature changes
alexzaitsev Jul 16, 2019
570dc86
added and modified FilterProvider tests
alexzaitsev Jul 16, 2019
5a30cc0
reverted path creation in the tests
alexzaitsev Jul 16, 2019
2ee6912
improved tests
alexzaitsev Jul 16, 2019
7e5cbe2
tests
alexzaitsev Jul 16, 2019
889a51a
tests, fixed SmaliAnalyzer
alexzaitsev Jul 16, 2019
8b5aff5
modified default filterset
alexzaitsev Jul 16, 2019
ce517e0
fix tests for windows
alexzaitsev Jul 16, 2019
323da09
fix tests for windows
alexzaitsev Jul 16, 2019
216b4cf
fix tests for windows
alexzaitsev Jul 16, 2019
91977cc
fix windows tests
alexzaitsev Jul 16, 2019
10fcced
Update instructions.txt
alexzaitsev Jul 16, 2019
7ce5961
Update README.md
alexzaitsev Jul 16, 2019
611d7b7
Update README.md
alexzaitsev Jul 16, 2019
9bb8d4e
Update README.md
alexzaitsev Jul 16, 2019
e81a96a
Update README.md
alexzaitsev Jul 16, 2019
7bf218e
Update README.md
alexzaitsev Jul 16, 2019
d967e0c
Update README.md
alexzaitsev Jul 16, 2019
9336da2
updated release build
alexzaitsev Jul 16, 2019
53a2100
fix release script
alexzaitsev Jul 16, 2019
72106f5
simplified tests
alexzaitsev Jul 16, 2019
d4d4253
improved filters
alexzaitsev Jul 16, 2019
41027d0
fix tests
alexzaitsev Jul 16, 2019
4bef69d
updated version badge
alexzaitsev Jul 17, 2019
339e0a0
updated version badge
alexzaitsev Jul 17, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added a new argument placeholder, renamed filter to package-filter
  • Loading branch information
alexzaitsev committed Jul 9, 2019
commit c2889c007679b2d28ca2cf3d615a2372d7b6ca31
1 change: 1 addition & 0 deletions filters/dagger-butterknife.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["Dagger", "Injector", ".*\\$_ViewBinding$"]
7 changes: 7 additions & 0 deletions filters/instructions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'dagger-butterknife.json' is a default filterset that is shipped with the releases.
It filters Dagger and ButterKnife classes.

The file contains json array of RegExps.
You may extend this array of create a set of your own filter files similar to this one.

Read Usage part of Readme for the details.
12 changes: 7 additions & 5 deletions src/code/SmaliAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public Map<String, Set<String>> getDependencies() {
}

public boolean run() {
String filter = arguments.getFilter();
String filter = arguments.getPackageFilter();
if (filter == null) {
System.err.println("Please check your filter!");
System.err.println("Please check your package filter!");
return false;
}

Expand Down Expand Up @@ -109,7 +109,7 @@ private void processSmaliFile(File file) {

// filtering
for (String fullClassName : classNames) {
if (fullClassName != null && isFilterOk(fullClassName)) {
if (fullClassName != null && areFiltersOk(fullClassName)) {
String simpleClassName = getClassSimpleName(fullClassName);
if (isClassOk(simpleClassName, fileName)) {
dependencyNames.add(simpleClassName);
Expand Down Expand Up @@ -198,8 +198,10 @@ private int getEndGenericIndex(String line, int startGenericIndex) {
return endIndex;
}

private boolean isFilterOk(String className) {
return arguments.getFilter() == null || className.startsWith(arguments.getFilter().replaceAll("\\.", "/"));
private boolean areFiltersOk(String className) {
boolean packageFilterIsOk = arguments.getPackageFilter() == null ||
className.startsWith(arguments.getPackageFilter().replaceAll("\\.", "/"));
return packageFilterIsOk;
}

private void addDependencies(String className, Set<String> dependenciesList) {
Expand Down
14 changes: 14 additions & 0 deletions src/code/UserFilters.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package code;

public class UserFilters {

List<String> regex = new ArrayList<>();

public UserFilters(List<String> regex) {
this.regex.addAll(regex);
}

public boolean isClassOk(String className) {
return true;
}
}
38 changes: 23 additions & 15 deletions src/code/io/ArgumentReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@

public class ArgumentReader {

private static final ARG_PROJ = "-i";
private static final ARG_RES_JS = "-o";
private static final ARG_PACK_F = "-pf";
private static final ARG_FILTER = "-f";
private static final ARG_INNER = "-d";
private static final ARG_APK = "-a";

private static final String USAGE_STRING = "Usage:\n" +
"-i path : path to the decompiled project\n" +
"-o path : path to the result js file\n" +
"-f filter : java package to filter by (to show all dependencies pass '-f nofilter')\n" +
"-d boolean : if true it will contain inner class processing (the ones creating ClassName$InnerClass files)\n" +
"-a path : path to the apk file";
ARG_PROJ + " path : path to the decompiled project\n" +
ARG_RES_JS + " path : path to the result js file\n" +
ARG_PACK_F + " package-filter : java package to filter by (to show all dependencies pass '-f nofilter')\n" +
ARG_FILTER + " filters : json filterset file(s) (can be comma-separated)\n"
ARG_INNER + " boolean : if true it will contain inner class processing (the ones creating ClassName$InnerClass files)\n" +
ARG_APK + " path : path to the apk file";

private String[] args;

Expand All @@ -18,31 +26,31 @@ public ArgumentReader(String[] args) {
}

public Arguments read() {
String projectPath = null, resultPath = null, filter = null;
String projectPath = null, resultPath = null, packageFilter = null;
String apkPath = null;
boolean withInnerClasses = false;
for (int i = 0; i < args.length; i++) {
if (i < args.length - 1) {
if (args[i].equals("-i")) {
if (args[i].equals(ARG_PROJ)) {
projectPath = args[i + 1];
} else if (args[i].equals("-o")) {
} else if (args[i].equals(ARG_RES_JS)) {
resultPath = args[i + 1];
} else if (args[i].equals("-f")) {
filter = args[i + 1];
} else if (args[i].equals("-d")) {
} else if (args[i].equals(ARG_PACK_F)) {
packageFilter = args[i + 1];
} else if (args[i].equals(ARG_INNER)) {
withInnerClasses = Boolean.valueOf(args[i + 1]);
} else if (args[i].equals("-a")) {
} else if (args[i].equals(ARG_APK)) {
apkPath = args[i + 1];
}
}
}
if (projectPath == null || resultPath == null || filter == null ||
if (projectPath == null || resultPath == null || packageFilter == null ||
apkPath == null) {
System.err.println("Arguments are incorrect!");
System.err.println(USAGE_STRING);
return null;
}
if (filter.equals("nofilter")) {
if (packageFilter.equals("nofilter")) {
filter = null;
System.out.println("Warning! Processing without filter.");
}
Expand All @@ -57,6 +65,6 @@ public Arguments read() {
}

return new Arguments(
apkPath, projectPath, resultPath, filter, withInnerClasses);
apkPath, projectPath, resultPath, packageFilter, withInnerClasses);
}
}
14 changes: 7 additions & 7 deletions src/code/io/Arguments.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ public class Arguments {
private String apkFilePath;
private String projectPath;
private String resultPath;
private String filter;
private String packageFilter;
private boolean withInnerClasses;

public Arguments(String apkPath, String projectPath, String resultPath,
String filter, boolean withInnerClasses) {
String packageFilter, boolean withInnerClasses) {
super();
this.apkFilePath = apkPath;
this.projectPath = projectPath;
this.resultPath = resultPath;
this.filter = filter;
this.packageFilter = packageFilter;
this.withInnerClasses = withInnerClasses;
}
public String getProjectPath() {
Expand All @@ -28,11 +28,11 @@ public String getResultPath() {
public void setResultPath(String resultPath) {
this.resultPath = resultPath;
}
public String getFilter() {
return filter;
public String getPackageFilter() {
return packageFilter;
}
public void setFilter(String filter) {
this.filter = filter;
public void setPackageFilter(String packageFilter) {
this.packageFilter = packageFilter;
}
public boolean withInnerClasses() {
return withInnerClasses;
Expand Down