Skip to content

Commit

Permalink
Reuse classpath with reset loaded classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
testwhat committed Jan 7, 2016
1 parent 70c2327 commit ce54c59
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
4 changes: 3 additions & 1 deletion dexlib2/src/main/java/org/jf/dexlib2/analysis/ClassPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import org.jf.dexlib2.DexFileFactory;
import org.jf.dexlib2.analysis.reflection.ReflectionClassDef;
import org.jf.dexlib2.iface.ClassDef;
Expand Down Expand Up @@ -125,7 +126,7 @@ public void addDex(DexFile dexFile, boolean additional) {
}
}

public void cleanupAdditionalDex() {
public void reset() {
if (additionalDexFiles != null) {
for (DexFile dexFile : additionalDexFiles) {
for (ClassDef classDef : dexFile.getClasses()) {
Expand All @@ -134,6 +135,7 @@ public void cleanupAdditionalDex() {
}
additionalDexFiles.clear();
}
loadedClasses = CacheBuilder.newBuilder().build(classLoader);
}

private void loadPrimitiveType(String type) {
Expand Down
Binary file modified smaliex-bin/oat2dex.jar
Binary file not shown.
18 changes: 12 additions & 6 deletions smaliex/src/main/java/org/rh/smaliex/DexUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ public static void odex2dex(String odex, String bootClassPath, String outFolder,
Opcodes opcodes = new Opcodes(apiLevel);
File input = new File(odex);
DexFile odexFile = DexUtil.loadSingleDex(input, opcodes);
DexFile dex = getODexRewriter(bootClassPath, opcodes).rewriteDexFile(odexFile);
ODexRewriter rewriter = getODexRewriter(bootClassPath, opcodes);
if (LLog.VERBOSE) {
rewriter.setFailInfoLocation(outputFolder.getAbsolutePath());
}
DexFile dex = rewriter.rewriteDexFile(odexFile);

File outputFile = MiscUtil.changeExt(new File(outputFolder, input.getName()), "dex");
if (outputFile.exists()) {
Expand Down Expand Up @@ -313,11 +317,11 @@ private static <T> void putCache(Map<String, SoftReference<T>> pool, String key,
pool.put(key, new SoftReference<>(val));
}

public static ODexRewriter getODexRewriter(String bootClassPath, Opcodes opcodes) {
String key = bootClassPath + " " + opcodes.apiLevel;
public static ODexRewriter getODexRewriter(String bootClassPathFolder, Opcodes opcodes) {
String key = bootClassPathFolder + " " + opcodes.apiLevel;
ODexRewriter rewriter = getCache(rewriterCache, key);
if (rewriter == null) {
rewriter = new ODexRewriter(new ODexRewriterModule(bootClassPath, opcodes));
rewriter = new ODexRewriter(new ODexRewriterModule(bootClassPathFolder, opcodes));
putCache(rewriterCache, key, rewriter);
}
return rewriter;
Expand Down Expand Up @@ -348,7 +352,7 @@ public void addDexToClassPath(DexFile dexFile) {
}

public void recycle() {
mRewriterModule.mClassPath.cleanupAdditionalDex();
mRewriterModule.mClassPath.reset();
}

public void setFailInfoLocation(String folder) {
Expand Down Expand Up @@ -444,8 +448,10 @@ void handleAnalysisException(AnalysisException ae) {
if (mFailInfoLocation != null) {
String fileName = mCurrentMethod.getDefiningClass().replace(
"/", "-").replace(";", "") + ".smali";
try (FileWriter writer = new FileWriter(MiscUtil.path(mFailInfoLocation, fileName))) {
String failedCase = MiscUtil.path(mFailInfoLocation, fileName);
try (FileWriter writer = new FileWriter(failedCase)) {
writeSmaliContent(mCurrentMethod.getDefiningClass(), mClassPath, writer);
LLog.i("Output failed class content to " + failedCase);
} catch (IOException e) {
LLog.ex(e);
}
Expand Down
3 changes: 3 additions & 0 deletions smaliex/src/main/java/org/rh/smaliex/OatUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ public static void convertToDexJar(Oat oat, File outputFolder,
deOpt.addDexToClassPath(readDex(dex, dex.mHeader.file_size_, opcodes));
}
}
if (LLog.VERBOSE) {
deOpt.setFailInfoLocation(outputFolder.getAbsolutePath());
}

final byte[] buf = new byte[8192];
for (String jarName : dexFileGroup.keySet()) {
Expand Down

0 comments on commit ce54c59

Please sign in to comment.