Skip to content

Commit

Permalink
merge patch from t3stwhat
Browse files Browse the repository at this point in the history
add ability to keep clinit method for DexFix
ONLY_CLINIT equals to (KEEP_CLINIT | SKIP_CODE)

--HG--
branch : 2.x
  • Loading branch information
pxb1988 committed Aug 7, 2014
1 parent 6d945c4 commit 0f030e4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,18 @@ public class DexFileReader {
* ingore read exception
*/
public static final int IGNORE_READ_EXCEPTION = 1 << 5;
// private static final int REVERSE_ENDIAN_CONSTANT = 0x78563412;
/**
* read all methods, even if they are glitch
*/
public static final int KEEP_ALL_METHODS = 1 << 6;
/**
* keep clinit method when {@link #SKIP_DEBUG}
*/
public static final int KEEP_CLINIT = 1 << 7;


// private static final int REVERSE_ENDIAN_CONSTANT = 0x78563412;

static final int DBG_END_SEQUENCE = 0x00;
static final int DBG_ADVANCE_PC = 0x01;
static final int DBG_ADVANCE_LINE = 0x02;
Expand Down Expand Up @@ -952,15 +959,21 @@ private int acceptMethod(ByteBuffer in, int lastIndex, DexClassVisitor cv, Map<I
}
}
}
if (code_off != 0 && (0 == (SKIP_CODE & config))) {
DexCodeVisitor dcv = dmv.visitCode();
if (dcv != null) {
try {
acceptCode(code_off, dcv, config, (method_access_flags & DexConstants.ACC_STATIC) != 0,
method);
} catch (Exception e) {
throw new DexException(e, "while accept code in method:[%s] @%08x", method.toString(),
code_off);
if (code_off != 0) {
boolean keep = true;
if (0 != (SKIP_CODE & config)) {
keep = 0 != (KEEP_CLINIT & config) && method.getName().equals("<clinit>");
}
if(keep) {
DexCodeVisitor dcv = dmv.visitCode();
if (dcv != null) {
try {
acceptCode(code_off, dcv, config, (method_access_flags & DexConstants.ACC_STATIC) != 0,
method);
} catch (Exception e) {
throw new DexException(e, "while accept code in method:[%s] @%08x", method.toString(),
code_off);
}
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions dex-translator/src/main/java/com/googlecode/d2j/dex/Dex2jar.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.HashMap;
import java.util.Map;

import com.googlecode.d2j.node.DexMethodNode;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor;
Expand Down Expand Up @@ -116,6 +117,13 @@ public void visitEnd() {
};

new ExDex2Asm(exceptionHandler) {
public void convertCode(DexMethodNode methodNode, MethodVisitor mv) {
if ((readerConfig & DexFileReader.SKIP_CODE) != 0 && methodNode.method.getName().equals("<clinit>")) {
// also skip clinit
return;
}
super.convertCode(methodNode, mv);
}

@Override
public void optimize(IrMethod irMethod) {
Expand Down Expand Up @@ -190,9 +198,9 @@ public Dex2jar topoLogicalSort(boolean b) {

public Dex2jar noCode(boolean b) {
if (b) {
this.readerConfig |= DexFileReader.SKIP_CODE;
this.readerConfig |= DexFileReader.SKIP_CODE | DexFileReader.KEEP_CLINIT;
} else {
this.readerConfig &= ~DexFileReader.SKIP_CODE;
this.readerConfig &= ~(DexFileReader.SKIP_CODE | DexFileReader.KEEP_CLINIT);
}
return this;
}
Expand Down

0 comments on commit 0f030e4

Please sign in to comment.