Skip to content
Permalink
Browse files

[dex038] write class version 1.7 if dex version > DEX_037

  • Loading branch information...
pxb1988 committed Jun 6, 2018
1 parent 5341bd1 commit 85b1b3b8ddabd285b02921fce0713660e8eb0cfe
@@ -51,4 +51,9 @@
String ANNOTATION_ENCLOSING_METHOD_TYPE = "Ldalvik/annotation/EnclosingMethod;";
String ANNOTATION_INNER_CLASS_TYPE = "Ldalvik/annotation/InnerClass;";
String ANNOTATION_MEMBER_CLASSES_TYPE = "Ldalvik/annotation/MemberClasses;";

int DEX_035 = 0x00303335;
int DEX_036 = 0x00303336;
int DEX_037 = 0x00303337;
int DEX_038 = 0x00303338;
}
@@ -16,6 +16,7 @@
*/
package com.googlecode.d2j.node;

import com.googlecode.d2j.DexConstants;
import com.googlecode.d2j.visitors.DexClassVisitor;
import com.googlecode.d2j.visitors.DexFileVisitor;

@@ -24,6 +25,13 @@

public class DexFileNode extends DexFileVisitor {
public List<DexClassNode> clzs = new ArrayList<>();
public int dexVersion = DexConstants.DEX_035;

@Override
public void visitDexFileVersion(int version) {
this.dexVersion = version;
super.visitDexFileVersion(version);
}

@Override
public DexClassVisitor visit(int access_flags, String className, String superClass, String[] interfaceNames) {
@@ -31,6 +31,12 @@ public DexFileVisitor(DexFileVisitor visitor) {
this.visitor = visitor;
}

public void visitDexFileVersion(int version) {
if (visitor != null) {
visitor.visitDexFileVersion(version);
}
}

public DexClassVisitor visit(int access_flags, String className, String superClass, String[] interfaceNames) {
if (visitor == null) {
return null;
@@ -5,10 +5,6 @@
import java.util.List;

public interface BaseDexFileReader {
int DEX_035 = 0x00303335;
int DEX_036 = 0x00303336;
int DEX_037 = 0x00303337;
int DEX_038 = 0x00303338;

int getDexVersion();

@@ -27,6 +27,8 @@
import com.googlecode.d2j.util.Mutf8;
import com.googlecode.d2j.visitors.*;

import static com.googlecode.d2j.DexConstants.*;

/**
* Open and read a dex file.this is the entrance of dex-reader. to read a dex/odex, use the following code:
*
@@ -618,6 +620,7 @@ public void accept(DexFileVisitor dv) {
*/
@Override
public void accept(DexFileVisitor dv, int config) {
dv.visitDexFileVersion(this.dex_version);
for (int cid = 0; cid < class_defs_size; cid++) {
accept(dv, cid, config);
}
@@ -1,5 +1,6 @@
package com.googlecode.d2j.reader;

import com.googlecode.d2j.DexConstants;
import com.googlecode.d2j.util.zip.AccessBufByteArrayOutputStream;
import com.googlecode.d2j.util.zip.ZipEntry;
import com.googlecode.d2j.util.zip.ZipFile;
@@ -72,7 +73,7 @@ void init() {

@Override
public int getDexVersion() {
int max = DEX_035;
int max = DexConstants.DEX_035;
for (DexFileReader r : readers) {
int v = r.getDexVersion();
if (v > max) {
@@ -138,15 +138,15 @@ public void visitEnd() {
new ExDex2Asm(exceptionHandler) {

@Override
public void convertDex(DexFileNode fileNode, final ClassVisitorFactory cvf) {
public void convertDex(final DexFileNode fileNode, final ClassVisitorFactory cvf) {
if (fileNode.clzs != null) {
final Map<String, Clz> classes = collectClzInfo(fileNode);
final List<Future<?>> results = new ArrayList<>(fileNode.clzs.size());
for (final DexClassNode classNode : fileNode.clzs) {
results.add(executorService.submit(new Runnable() {
@Override
public void run() {
convertClass(classNode, cvf, classes);
convertClass(fileNode, classNode, cvf, classes);
}
}));
}
@@ -325,11 +325,14 @@ private static MethodVisitor collectBasicMethodInfo(DexMethodNode methodNode, Cl
}

public void convertClass(DexClassNode classNode, ClassVisitorFactory cvf, DexFileNode fileNode) {
convertClass(classNode, cvf, collectClzInfo(fileNode));
convertClass(fileNode.dexVersion, classNode, cvf, collectClzInfo(fileNode));
}

public void convertClass(DexClassNode classNode, ClassVisitorFactory cvf) {
convertClass(classNode, cvf, new HashMap<String, Clz>());
convertClass(DexConstants.DEX_035, classNode, cvf);
}
public void convertClass(int dexVersion, DexClassNode classNode, ClassVisitorFactory cvf) {
convertClass(dexVersion, classNode, cvf, new HashMap<String, Clz>());
}

private static boolean isJavaIdentifier(String str) {
@@ -348,6 +351,12 @@ private static boolean isJavaIdentifier(String str) {
}

public void convertClass(DexClassNode classNode, ClassVisitorFactory cvf, Map<String, Clz> classes) {
convertClass(DexConstants.DEX_035, classNode, cvf, classes);
}
public void convertClass(DexFileNode dfn, DexClassNode classNode, ClassVisitorFactory cvf, Map<String, Clz> classes) {
convertClass(dfn.dexVersion, classNode, cvf, classes);
}
public void convertClass(int dexVersion, DexClassNode classNode, ClassVisitorFactory cvf, Map<String, Clz> classes) {
ClassVisitor cv = cvf.create(toInternalName(classNode.className));
if (cv == null) {
return;
@@ -391,7 +400,8 @@ public void convertClass(DexClassNode classNode, ClassVisitorFactory cvf, Map<St
}
access = clearClassAccess(isInnerClass, access);

cv.visit(Opcodes.V1_6, access, toInternalName(classNode.className), signature,
int version = dexVersion >= DexConstants.DEX_037 ? Opcodes.V1_7 : Opcodes.V1_6;

This comment has been minimized.

Copy link
@Lanchon
cv.visit(version, access, toInternalName(classNode.className), signature,
classNode.superClass == null ? null : toInternalName(classNode.superClass), interfaceInterNames);

List<InnerClassNode> innerClassNodes = new ArrayList<InnerClassNode>(5);
@@ -447,7 +457,7 @@ public void convertDex(DexFileNode fileNode, ClassVisitorFactory cvf) {
if (fileNode.clzs != null) {
Map<String, Clz> classes = collectClzInfo(fileNode);
for (DexClassNode classNode : fileNode.clzs) {
convertClass(classNode, cvf, classes);
convertClass(fileNode, classNode, cvf, classes);
}
}
}
@@ -335,6 +335,9 @@ public ClassVisitor create(String classInternalName) {
CfOptions cfOptions = new CfOptions();
cfOptions.strictNameCheck = false;
DexOptions dexOptions = new DexOptions();
if (fileNode.dexVersion >= DexConstants.DEX_037) {
dexOptions.minSdkVersion = 26;
}

DirectClassFile dcf = new DirectClassFile(data, rca.getClassName() + ".class", true);
dcf.setAttributeFactory(new StdAttributeFactory());

0 comments on commit 85b1b3b

Please sign in to comment.
You can’t perform that action at this time.