Skip to content

Commit

Permalink
Implemented fine-grained merging using annotations (#4)
Browse files Browse the repository at this point in the history
- fixes #1 by merging only Codelib functions annotated with a certain annotation type
- removed confusing error messages
- fixed a problem when unpacking apks containing filenames with invalid UTF-8 characters
  • Loading branch information
alfink authored and sweisgerber-dev committed May 22, 2018
1 parent 3253508 commit fd5a845
Show file tree
Hide file tree
Showing 11 changed files with 801 additions and 152 deletions.
22 changes: 22 additions & 0 deletions src/main/java/comm/android/dex/Dex.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import comm.android.dex.util.ByteOutput;
import comm.android.dex.util.FileUtils;
import comm.android.dex.util.ByteOutput;
import comm.android.dx.merge.DexMerger;
import comm.android.dx.merge.MethodFilter;

import java.io.ByteArrayOutputStream;
import java.io.File;
Expand Down Expand Up @@ -69,6 +71,17 @@ public final class Dex {
private final FieldIdTable fieldIds = new FieldIdTable();
private final MethodIdTable methodIds = new MethodIdTable();

private MethodFilter methodFilter;

{
try {
methodFilter = new MethodFilter(this, null);
} catch (DexMerger.MergeException e) {
// should never happen
e.printStackTrace();
}
}

/**
* Creates a new dex that reads from {@code data}. It is an error to modify
* {@code data} after using it to create a dex buffer.
Expand Down Expand Up @@ -337,6 +350,14 @@ public void setName(final String dexName) {
this.dexName = dexName;
}

public MethodFilter getMethodFilter() {
return methodFilter;
}

public void setWhitelistedAnnotation(String s) throws DexMerger.MergeException {
this.methodFilter = new MethodFilter(this, s);
}

public final class Section implements ByteInput, ByteOutput {
private final String name;
private final ByteBuffer data;
Expand Down Expand Up @@ -592,6 +613,7 @@ private byte[] getBytesFrom(int start) {
}

public Annotation readAnnotation() {
//Log.w("SECTION", data.position()+"/"+ data.limit());
byte visibility = readByte();
int start = data.position();
new EncodedValueReader(this, EncodedValueReader.ENCODED_ANNOTATION).skipValue();
Expand Down
Loading

0 comments on commit fd5a845

Please sign in to comment.