■ ■ ■ ■ ■ ■
jadx-core/src/test/java/jadx/tests/api/SmaliTest.java
1 1 package jadx.tests.api; 2 2 3 3 import java.io.File; 4 + import java.util.Arrays; 5 + import java.util.Collections; 6 + import java.util.List; 7 + import java.util.stream.Collectors; 4 8 5 9 import org.jf.smali.Smali; 6 10 import org.jf.smali.SmaliOptions; skipped 9 lines 16 20 protected ClassNode getClassNodeFromSmali(String file, String clsName) { 17 21 File smaliFile = getSmaliFile(file); 18 22 File outDex = createTempFile(".dex"); 19 - compileSmali(smaliFile, outDex); 23 + compileSmali(outDex, Collections.singletonList(smaliFile)); 20 24 return getClassNodeFromFile(outDex, clsName); 21 25 } 22 26 skipped 5 lines 28 32 return getClassNodeFromSmali(pkg + File.separatorChar + clsName, pkg + '.' + clsName); 29 33 } 30 34 35 + protected ClassNode getClassNodeFromSmaliFiles(String pkg, String testName, String clsName, String... smaliFileNames) { 36 + File outDex = createTempFile(".dex"); 37 + List<File> smaliFiles = Arrays.stream(smaliFileNames) 38 + .map(file -> getSmaliFile(pkg + File.separatorChar + testName + File.separatorChar + file)) 39 + .collect(Collectors.toList()); 40 + compileSmali(outDex, smaliFiles); 41 + return getClassNodeFromFile(outDex, pkg + "." + clsName); 42 + } 43 + 31 44 protected ClassNode getClassNodeFromSmali(String clsName) { 32 45 return getClassNodeFromSmali(clsName, clsName); 33 46 } 34 47 35 - private static File getSmaliFile(String clsName ) { 36 - File smaliFile = new File(SMALI_TESTS_DIR, clsName + SMALI_TESTS_EXT); 48 + private static File getSmaliFile(String baseName ) { 49 + File smaliFile = new File(SMALI_TESTS_DIR, baseName + SMALI_TESTS_EXT); 37 50 if (smaliFile.exists()) { 38 51 return smaliFile; 39 52 } 40 - smaliFile = new File(SMALI_TESTS_PROJECT, smaliFile.getPath()); 41 - if (smaliFile .exists()) { 42 - return smaliFile; 53 + File pathFromRoot = new File(SMALI_TESTS_PROJECT, smaliFile.getPath()); 54 + if (pathFromRoot .exists()) { 55 + return pathFromRoot; 43 56 } 44 - throw new AssertionError("Smali file not found: " + smaliFile.getAbsolutePath ()); 57 + throw new AssertionError("Smali file not found: " + smaliFile.getPath ()); 45 58 } 46 59 47 - private static boolean compileSmali(File input , File output ) { 60 + private static boolean compileSmali(File output , List < File> inputFiles ) { 48 61 try { 49 62 SmaliOptions params = new SmaliOptions(); 50 63 params.outputDexFile = output.getAbsolutePath(); 51 - Smali.assemble(params, input.getAbsolutePath()); 64 + List<String> inputFileNames = inputFiles.stream().map(File::getAbsolutePath).collect(Collectors.toList()); 65 + Smali.assemble(params, inputFileNames); 52 66 } catch (Exception e) { 53 67 throw new AssertionError("Smali assemble error", e); 54 68 } skipped 4 lines