Commit d23f4ac1 authored by Ahmed Ashour's avatar Ahmed Ashour Committed by skylot

feat: support smali files (#391) (PR #588)

parent 01da127c
......@@ -8,8 +8,11 @@ dependencies {
compile 'org.ow2.asm:asm:7.1'
compile 'org.jetbrains:annotations:17.0.0'
compile 'uk.com.robust-it:cloning:1.9.12'
compile('org.smali:smali:2.2.6') {
exclude group: 'com.google.guava'
}
compile 'com.google.guava:guava:27.1-jre'
testCompile 'org.smali:smali:2.2.6'
testCompile 'org.smali:baksmali:2.2.6'
testCompile 'org.apache.commons:commons-lang3:3.8.1'
......
......@@ -18,6 +18,8 @@ import java.util.zip.ZipFile;
import org.apache.commons.io.IOUtils;
import org.jetbrains.annotations.Nullable;
import org.jf.smali.Smali;
import org.jf.smali.SmaliOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -54,6 +56,14 @@ public class InputFile {
addDexFile(new Dex(file));
return;
}
if (fileName.endsWith(".smali")) {
Path output = Files.createTempFile("jadx", ".dex");
SmaliOptions options = new SmaliOptions();
options.outputDexFile = output.toAbsolutePath().toString();
Smali.assemble(options, file.getAbsolutePath());
addDexFile(new Dex(output.toFile()));
return;
}
if (fileName.endsWith(".class")) {
for (Dex dex : loadFromClassFile(file)) {
addDexFile(dex);
......
......@@ -91,10 +91,10 @@ public abstract class SmaliTest extends IntegrationTest {
private static boolean compileSmali(File output, List<File> inputFiles) {
try {
SmaliOptions params = new SmaliOptions();
params.outputDexFile = output.getAbsolutePath();
SmaliOptions options = new SmaliOptions();
options.outputDexFile = output.getAbsolutePath();
List<String> inputFileNames = inputFiles.stream().map(File::getAbsolutePath).collect(Collectors.toList());
Smali.assemble(params, inputFileNames);
Smali.assemble(options, inputFileNames);
} catch (Exception e) {
throw new AssertionError("Smali assemble error", e);
}
......
......@@ -197,7 +197,7 @@ public class MainWindow extends JFrame {
public void openFileOrProject() {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setAcceptAllFileFilterUsed(true);
String[] exts = {JadxProject.PROJECT_EXTENSION, "apk", "dex", "jar", "class", "zip", "aar", "arsc"};
String[] exts = {JadxProject.PROJECT_EXTENSION, "apk", "dex", "jar", "class", "zip", "aar", "arsc", "smali"};
String description = "supported files: " + Arrays.toString(exts).replace('[', '(').replace(']', ')');
fileChooser.setFileFilter(new FileNameExtensionFilter(description, exts));
fileChooser.setToolTipText(NLS.str("file.open_action"));
......
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