Commit c7645467 authored by pcregut's avatar pcregut

Remove project dependency on baksmali through reflection.

parent 79345427
......@@ -4,7 +4,6 @@
<classpathentry kind="src" path="test/conform"/>
<classpathentry kind="src" path="test/perf"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="lib" path="lib/baksmali-1.2.6.jar"/>
<classpathentry kind="lib" path="lib/junit-4.8.2.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
......@@ -296,7 +296,7 @@ public class ApplicationAdapterTest {
TestUtil.TEMP_FOLDER_ROOT + TestUtil.FILENAME_ADAPTED_DEX);
// Uses baksmali to generate the smali files related to the adapted file.
org.jf.baksmali.main.main(new String[] { adaptedFile.getAbsolutePath(),
TestUtil.baksmali(new String[] { adaptedFile.getAbsolutePath(),
"-o" + TestUtil.TEMP_FOLDER_GENERATED});
// Generates the "expected" dex file thanks to the writer.
......@@ -304,7 +304,7 @@ public class ApplicationAdapterTest {
TestUtil.TEMP_FOLDER_ROOT + TestUtil.FILENAME_EXPECTED_DEX);
// Uses baksmali to generate the smali files related to the "expected" file.
org.jf.baksmali.main.main(new String[] { expectedFile.getAbsolutePath(),
TestUtil.baksmali(new String[] { expectedFile.getAbsolutePath(),
"-o" + TestUtil.TEMP_FOLDER_EXPECTED});
// Compares the two outputs.
......
......@@ -215,7 +215,7 @@ public class ApplicationWriterTest {
TestUtil.removeTemporaryFolder();
// Executes Baksmali to disassemble the current dex file.
org.jf.baksmali.main.main(new String[] { fullDexFileName,
TestUtil.baksmali(new String[] { fullDexFileName,
"-o" + TestUtil.TEMP_FOLDER_EXPECTED});
// Uses the Reader and Writer to generate our own dex file from the current dex file.
......@@ -238,7 +238,7 @@ public class ApplicationWriterTest {
assertTrue("Unequal Map between " + dexFileName + " and the generated file.", TestUtil.testMapDexFiles(createdDexFile, dexFile));
// Executes Baksmali once again to disassemble our generated dex file.
org.jf.baksmali.main.main(new String[] { fullGeneratedDexFileName,
TestUtil.baksmali(new String[] { fullGeneratedDexFileName,
"-o" + TestUtil.TEMP_FOLDER_GENERATED});
// Compare the folders and the .smali files inside.
......
......@@ -120,7 +120,7 @@ public class ApplicationWriterTreeTest {
TestUtil.removeTemporaryFolder();
// Executes Baksmali to disassemble the current dex file.
org.jf.baksmali.main.main(new String[] { fullDexFileName,
TestUtil.baksmali(new String[] { fullDexFileName,
"-o" + TestUtil.TEMP_FOLDER_EXPECTED});
// Uses the Tree API with the Reader and Writer to generate our own dex file from the current dex file.
......@@ -140,7 +140,7 @@ public class ApplicationWriterTreeTest {
assertTrue("Unequal Map between " + dexFileName + " and the generated file.", TestUtil.testMapDexFiles(createdDexFile, dexFile));
// Executes Baksmali once again to disassemble our generated dex file.
org.jf.baksmali.main.main(new String[] { fullGeneratedDexFileName,
TestUtil.baksmali(new String[] { fullGeneratedDexFileName,
"-o" + TestUtil.TEMP_FOLDER_GENERATED});
// Compare the folders and the .smali files inside.
......
......@@ -201,11 +201,11 @@ public class AsmDexifierTest {
assertTrue("Unequal Map between the original and the generated file.", TestUtil.testMapDexFiles(createdDexFile, dexFile));
// Executes Baksmali to disassemble the current dex file.
org.jf.baksmali.main.main(new String[] { dexFile.getAbsolutePath(),
TestUtil.baksmali(new String[] { dexFile.getAbsolutePath(),
"-o" + TestUtil.TEMP_FOLDER_EXPECTED});
// Executes Baksmali once again to disassemble our generated dex file.
org.jf.baksmali.main.main(new String[] { TestUtil.TEMP_FOLDER_ROOT + TestUtil.FILENAME_GENERATED_DEX,
TestUtil.baksmali(new String[] { TestUtil.TEMP_FOLDER_ROOT + TestUtil.FILENAME_GENERATED_DEX,
"-o" + TestUtil.TEMP_FOLDER_GENERATED});
// Compare the folders and the .smali files inside.
......
......@@ -46,6 +46,9 @@ import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Arrays;
/**
......@@ -171,6 +174,11 @@ public class TestUtil {
*/
public static final String TEMP_FOLDER_EXPECTED = TEMP_FOLDER_ROOT + TEMP_SUBFOLDER_EXPECTED;
/**
* Baksmali jar
*/
private static final String BAKSMALI_JAR = "lib/baksmali.jar";
/** String to look after in order to find a Line information in the Baksmali output. */
private static final String DEBUG_LINE_MNEMONIC = ".line";
......@@ -548,4 +556,23 @@ public class TestUtil {
return map;
}
/**
* Run baksmali with a given set of arguments. org.jf.baksmali.main.main
* @param args
* @return
*/
public static void baksmali(String [] args) throws IOException {
File file = new File(BAKSMALI_JAR);
URL url;
try {
url = new URL("jar:" + file.toURI().toString() + "!/");
System.err.println(url);
URLClassLoader jfl = new URLClassLoader(new URL[]{url});
Class <?> baksmaliClass = jfl.loadClass("org.jf.baksmali.main");
Method meth = baksmaliClass.getMethod("main", String[].class);
meth.invoke(null, (Object) args);
} catch (Exception e) {
throw new IOException("Cannot launch baksmali", e);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment