Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
Change DexBuilder for new dexlib version
  • Loading branch information
CalebFenton committed Nov 7, 2016
1 parent 7d7e936 commit a9766e7
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 32 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ subprojects {

ext {
depends = [
commons_lang: 'org.apache.commons:commons-lang3:3.4',
commons_lang: 'org.apache.commons:commons-lang3:3.5',
findbugs: 'com.google.code.findbugs:jsr305:3.0.1',
guava: 'com.google.guava:guava:19.0',
junit: 'junit:junit:4.12',
Expand Down
10 changes: 5 additions & 5 deletions smalivm/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ buildscript {

dependencies {
// Object cloning
compile 'uk.com.robust-it:cloning:1.9.2'
compile 'uk.com.robust-it:cloning:1.9.3'

// Easy method reflection
compile 'commons-beanutils:commons-beanutils:1.9.2'
compile 'commons-beanutils:commons-beanutils:1.9.3'

// Lazy
compile depends.commons_lang
Expand All @@ -25,9 +25,9 @@ dependencies {
compile depends.slf4j_api

// Parsing and writing dex files
compile 'org.smali:dexlib2:2.1.3'
compile 'org.smali:smali:2.1.3'
compile 'org.smali:baksmali:2.1.3'
compile group: 'org.smali', name: 'dexlib2', version: '2.2b4'
compile group: 'org.smali', name: 'smali', version: '2.2b4'
compile group: 'org.smali', name: 'baksmali', version: '2.2b4'

// For dynamic java.lang.Class generation
compile 'org.ow2.asm:asm:5.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.List;

import org.cf.util.Utils;
import org.jf.dexlib2.Opcodes;
import org.jf.dexlib2.util.ReferenceUtil;
import org.jf.dexlib2.writer.builder.BuilderClassDef;
import org.jf.dexlib2.writer.builder.DexBuilder;
Expand Down Expand Up @@ -51,7 +52,7 @@ public static String buildFrameworkCache(String resPath) throws Exception {
e.printStackTrace();
}

DexBuilder dexBuilder = DexBuilder.makeDexBuilder();
DexBuilder dexBuilder = new DexBuilder(Opcodes.getDefault());
StringBuilder sb = new StringBuilder();
for (File resFile : resFiles) {
String absPath = resFile.getAbsolutePath();
Expand Down
4 changes: 2 additions & 2 deletions smalivm/src/main/java/org/cf/smalivm/dex/SmaliParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class SmaliParser {
private static final Logger log = LoggerFactory.getLogger(SmaliParser.class.getSimpleName());

public static List<BuilderClassDef> parse(String path) throws Exception {
DexBuilder dexBuilder = DexBuilder.makeDexBuilder(Opcodes.forApi(SmaliParser.DEFAULT_API_LEVEL));
DexBuilder dexBuilder = new DexBuilder(Opcodes.forApi(SmaliParser.DEFAULT_API_LEVEL));

return parseFiles(new File(path), dexBuilder);
}
Expand Down Expand Up @@ -72,7 +72,7 @@ public static BuilderClassDef parse(String path, InputStream is,
CommonTokenStream tokens = new CommonTokenStream((TokenSource) lexer);

smaliParser parser = new smaliParser(tokens);
parser.setApiLevel(DEFAULT_API_LEVEL, false);
parser.setApiLevel(DEFAULT_API_LEVEL);

smaliParser.smali_file_return result = parser.smali_file();
if ((parser.getNumberOfSyntaxErrors() > 0) || (lexer.getNumberOfSyntaxErrors() > 0)) {
Expand Down
3 changes: 2 additions & 1 deletion smalivm/src/main/java/org/cf/smalivm/type/ClassManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.cf.smalivm.dex.SmaliFileFactory;
import org.cf.smalivm.dex.SmaliParser;
import org.cf.util.ClassNameUtils;
import org.jf.dexlib2.Opcodes;
import org.jf.dexlib2.iface.reference.TypeReference;
import org.jf.dexlib2.writer.builder.BuilderClassDef;
import org.jf.dexlib2.writer.builder.DexBuilder;
Expand Down Expand Up @@ -32,7 +33,7 @@ public class ClassManager {
private final SmaliFileFactory smaliFileFactory;
private final DexBuilder dexBuilder;
// Use separate DexBuilder to intern framework classes to avoid including in output dex
private final DexBuilder frameworkDexBuilder = DexBuilder.makeDexBuilder();
private final DexBuilder frameworkDexBuilder = new DexBuilder(Opcodes.getDefault());

ClassManager(DexBuilder dexBuilder) {
this(dexBuilder, false);
Expand Down
35 changes: 17 additions & 18 deletions smalivm/src/main/java/org/cf/smalivm/type/ClassManagerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,36 @@ public class ClassManagerFactory {

private static File disassemble(File file) throws IOException {
Path tempDir = Files.createTempDirectory(TEMP_DIR_NAME);
String[] args = new String[] { "--use-locals", "--sequential-labels", "--code-offsets", file.getAbsolutePath(),
"--output", tempDir.toString(), };
org.jf.baksmali.main.main(args);
String[] args = new String[]{"disassemble", "--use-locals", "--sequential-labels", "--code-offsets", file.getAbsolutePath(),
"--output", tempDir.toString(),};
org.jf.baksmali.Main.main(args);

return tempDir.toFile();
}

/**
* Create a ClassManager with no input Smali classes. It will only contain parse library classes.
* Create a ClassManager with no input Smali classes. It will only contain parse library
* classes.
*/
public ClassManager build() throws IOException {
DexBuilder dexBuilder = DexBuilder.makeDexBuilder();
DexBuilder dexBuilder = new DexBuilder(Opcodes.getDefault());

return build(dexBuilder);
}

/**
* Create a ClassManager with no input Smali classes. It will only contain parse library classes.
* Create a ClassManager with no input Smali classes. It will only contain parse library
* classes.
*/
public ClassManager build(int outputAPILevel) throws IOException {
DexBuilder dexBuilder = DexBuilder.makeDexBuilder(Opcodes.forApi(outputAPILevel));
DexBuilder dexBuilder = new DexBuilder(Opcodes.forApi(outputAPILevel));

return build(dexBuilder);
}

/**
* Create a ClassManager with no input Smali classes. It will only contain input library classes.
* Create a ClassManager with no input Smali classes. It will only contain input library
* classes.
*/
public ClassManager build(DexBuilder dexBuilder) throws IOException {
return new ClassManager(dexBuilder);
Expand All @@ -58,32 +61,28 @@ public ClassManager build(File inFile, DexBuilder dexBuilder) throws IOException
}

/**
* @param smaliPath
* Path to Smali file or folder
* @param smaliPath Path to Smali file or folder
*/
public ClassManager build(String smaliPath) throws IOException {
return build(smaliPath, DexBuilder.makeDexBuilder());
return build(smaliPath, new DexBuilder(Opcodes.getDefault()));
}

/**
* @param smaliPath
* Path to Smali file or folder
* @param smaliPath Path to Smali file or folder
*/
public ClassManager build(String smaliPath, int outputAPILevel) throws IOException {
return build(new File(smaliPath), outputAPILevel);
}

/**
* @param smaliPath
* Path to Smali file or folder
* @param smaliPath Path to Smali file or folder
*/
public ClassManager build(File smaliPath, int outputAPILevel) throws IOException {
return build(smaliPath, DexBuilder.makeDexBuilder(Opcodes.forApi(outputAPILevel)));
return build(smaliPath, new DexBuilder(Opcodes.forApi(outputAPILevel)));
}

/**
* @param smaliPath
* Path to Smali file or folder
* @param smaliPath Path to Smali file or folder
*/
public ClassManager build(String smaliPath, DexBuilder dexBuilder) throws IOException {
return build(new File(smaliPath), dexBuilder);
Expand Down
9 changes: 5 additions & 4 deletions smalivm/src/test/java/org/cf/smalivm/VMTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static ClassManager getClassManager() {
}

public static DexBuilder getDexBuilder() {
return DexBuilder.makeDexBuilder(Opcodes.forApi(SmaliParser.DEFAULT_API_LEVEL));
return new DexBuilder(Opcodes.forApi(SmaliParser.DEFAULT_API_LEVEL));
}

public static void setRegisterMock(MethodState mState, int register, Object value, String type) {
Expand All @@ -96,8 +96,9 @@ public static VirtualMachine spawnVM() {
}

/**
* Create a new virtual machine and class manager. This is necessary when class implementations are changing, such
* as testing the optimization strategies and when dealing with class loading and dynamic creation.
* Create a new virtual machine and class manager. This is necessary when class implementations
* are changing, such as testing the optimization strategies and when dealing with class loading
* and dynamic creation.
*/
public static VirtualMachine spawnVM(boolean reloadClasses) {
if ((null == classManager) || reloadClasses) {
Expand Down Expand Up @@ -219,7 +220,7 @@ private static void setupMethodState(ExecutionContext context, Map<Integer, Heap
private static void testClassState(ExecutionGraph graph,
Map<String, Map<String, HeapItem>> classNameToFieldDescriptorToItem) {
for (Entry<String, Map<String, HeapItem>> fieldDescriptorMapEntry : classNameToFieldDescriptorToItem
.entrySet()) {
.entrySet()) {
String className = fieldDescriptorMapEntry.getKey();
VirtualClass virtualClass = graph.getVM().getClassManager().getVirtualClass(className);
Map<String, HeapItem> fieldDescriptorToItem = fieldDescriptorMapEntry.getValue();
Expand Down

0 comments on commit a9766e7

Please sign in to comment.