Projects STRLCPY jadx Commits 1832f2ae
🤬
  • ■ ■ ■ ■
    jadx-core/build.gradle
    skipped 13 lines
    14 14   
    15 15   testImplementation 'org.apache.commons:commons-lang3:3.12.0'
    16 16   
    17  - testRuntimeOnly(project(':jadx-plugins:jadx-dex-input'))
     17 + testImplementation(project(':jadx-plugins:jadx-dex-input'))
    18 18   testRuntimeOnly(project(':jadx-plugins:jadx-smali-input'))
    19 19   testRuntimeOnly(project(':jadx-plugins:jadx-java-convert'))
    20 20   testRuntimeOnly(project(':jadx-plugins:jadx-java-input'))
    skipped 10 lines
  • ■ ■ ■ ■ ■ ■
    jadx-core/src/main/java/jadx/api/JadxArgsValidator.java
    skipped 12 lines
    13 13   
    14 14   private static final Logger LOG = LoggerFactory.getLogger(JadxArgsValidator.class);
    15 15   
    16  - public static void validate(JadxArgs args) {
    17  - checkInputFiles(args);
     16 + public static void validate(JadxDecompiler jadx) {
     17 + JadxArgs args = jadx.getArgs();
     18 + checkInputFiles(jadx, args);
    18 19   validateOutDirs(args);
    19 20   
    20 21   if (LOG.isDebugEnabled()) {
    skipped 1 lines
    22 23   }
    23 24   }
    24 25   
    25  - private static void checkInputFiles(JadxArgs args) {
     26 + private static void checkInputFiles(JadxDecompiler jadx, JadxArgs args) {
    26 27   List<File> inputFiles = args.getInputFiles();
    27  - if (inputFiles.isEmpty()) {
     28 + if (inputFiles.isEmpty() && jadx.getCustomLoads().isEmpty()) {
    28 29   throw new JadxArgsValidateException("Please specify input file");
    29 30   }
    30 31   for (File inputFile : inputFiles) {
    skipped 35 lines
    66 67   
    67 68   @NotNull
    68 69   private static File makeDirFromInput(JadxArgs args) {
    69  - File outDir;
    70 70   String outDirName;
    71  - File file = args.getInputFiles().get(0);
    72  - String name = file.getName();
    73  - int pos = name.lastIndexOf('.');
    74  - if (pos != -1) {
    75  - outDirName = name.substring(0, pos);
     71 + List<File> inputFiles = args.getInputFiles();
     72 + if (inputFiles.isEmpty()) {
     73 + outDirName = JadxArgs.DEFAULT_OUT_DIR;
    76 74   } else {
    77  - outDirName = name + '-' + JadxArgs.DEFAULT_OUT_DIR;
     75 + File file = inputFiles.get(0);
     76 + String name = file.getName();
     77 + int pos = name.lastIndexOf('.');
     78 + if (pos != -1) {
     79 + outDirName = name.substring(0, pos);
     80 + } else {
     81 + outDirName = name + '-' + JadxArgs.DEFAULT_OUT_DIR;
     82 + }
    78 83   }
    79 84   LOG.info("output directory: {}", outDirName);
    80  - outDir = new File(outDirName);
    81  - return outDir;
     85 + return new File(outDirName);
    82 86   }
    83 87   
    84 88   private static void checkFile(File file) {
    skipped 15 lines
  • ■ ■ ■ ■ ■ ■
    jadx-core/src/main/java/jadx/api/JadxDecompiler.java
    skipped 97 lines
    98 98   
    99 99   private final IDecompileScheduler decompileScheduler = new DecompilerScheduler(this);
    100 100   
     101 + private final List<ILoadResult> customLoads = new ArrayList<>();
     102 + 
    101 103   public JadxDecompiler() {
    102 104   this(new JadxArgs());
    103 105   }
    skipped 4 lines
    108 110   
    109 111   public void load() {
    110 112   reset();
    111  - JadxArgsValidator.validate(args);
     113 + JadxArgsValidator.validate(this);
    112 114   LOG.info("loading ...");
    113 115   loadPlugins(args);
    114 116   loadInputFiles();
    skipped 17 lines
    132 134   loadedInputs.add(loadResult);
    133 135   }
    134 136   }
     137 + loadedInputs.addAll(customLoads);
    135 138   if (LOG.isDebugEnabled()) {
    136 139   LOG.debug("Loaded using {} inputs plugin in {} ms", loadedInputs.size(), System.currentTimeMillis() - start);
    137 140   }
     141 + }
     142 + 
     143 + public void addCustomLoad(ILoadResult customLoad) {
     144 + customLoads.add(customLoad);
     145 + }
     146 + 
     147 + public List<ILoadResult> getCustomLoads() {
     148 + return customLoads;
    138 149   }
    139 150   
    140 151   private void reset() {
    skipped 572 lines
  • ■ ■ ■ ■
    jadx-core/src/test/java/jadx/api/JadxArgsValidatorOutDirsTest.java
    skipped 56 lines
    57 57   }
    58 58   
    59 59   private void checkOutDirs(String outDir, String srcDir, String resDir) {
    60  - JadxArgsValidator.validate(args);
     60 + JadxArgsValidator.validate(new JadxDecompiler(args));
    61 61   LOG.debug("Got dirs: out={}, src={}, res={}", args.getOutDir(), args.getOutDirSrc(), args.getOutDirRes());
    62 62   assertThat(args.getOutDir(), is(toFile(outDir)));
    63 63   assertThat(args.getOutDirSrc(), is(toFile(srcDir)));
    skipped 10 lines
  • ■ ■ ■ ■ ■ ■
    jadx-core/src/test/java/jadx/api/JadxDecompilerTest.java
    1 1  package jadx.api;
    2 2   
    3 3  import java.io.File;
     4 +import java.io.FileInputStream;
     5 +import java.io.IOException;
     6 +import java.io.InputStream;
    4 7  import java.net.URL;
    5 8   
    6 9  import org.hamcrest.Matchers;
    7 10  import org.junit.jupiter.api.Test;
    8 11   
    9 12  import jadx.core.utils.files.FileUtils;
     13 +import jadx.plugins.input.dex.DexInputPlugin;
    10 14   
    11 15  import static org.hamcrest.MatcherAssert.assertThat;
    12 16  import static org.hamcrest.Matchers.notNullValue;
    skipped 21 lines
    34 38   }
    35 39   
    36 40   assertThat(jadx.getClasses(), Matchers.hasSize(3));
     41 + assertThat(jadx.getErrorsCount(), Matchers.is(0));
     42 + }
     43 + }
     44 + 
     45 + @Test
     46 + public void testDirectDexInput() throws IOException {
     47 + try (JadxDecompiler jadx = new JadxDecompiler();
     48 + InputStream in = new FileInputStream(getFileFromSampleDir("hello.dex"))) {
     49 + jadx.addCustomLoad(new DexInputPlugin().loadDexFromInputStream(in, "input"));
     50 + jadx.load();
     51 + for (JavaClass cls : jadx.getClasses()) {
     52 + System.out.println(cls.getCode());
     53 + }
     54 + assertThat(jadx.getClasses(), Matchers.hasSize(1));
    37 55   assertThat(jadx.getErrorsCount(), Matchers.is(0));
    38 56   }
    39 57   }
    skipped 13 lines
  • jadx-core/src/test/resources/test-samples/hello.dex
    Binary file.
  • ■ ■ ■ ■ ■ ■
    jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/DexFileLoader.java
    skipped 63 lines
    64 64   if (isStartWithBytes(magic, DexConsts.DEX_FILE_MAGIC) || fileName.endsWith(".dex")) {
    65 65   in.reset();
    66 66   byte[] content = readAllBytes(in);
    67  - if (options.isVerifyChecksum()) {
    68  - DexCheckSum.verify(content);
    69  - }
    70  - DexReader dexReader = new DexReader(getNextUniqId(), fileName, content);
     67 + DexReader dexReader = loadDexReader(fileName, content);
    71 68   return Collections.singletonList(dexReader);
    72 69   }
    73 70   if (file != null) {
    skipped 4 lines
    78 75   }
    79 76   return Collections.emptyList();
    80 77   }
     78 + }
     79 + 
     80 + public DexReader loadDexReader(String fileName, byte[] content) {
     81 + if (options.isVerifyChecksum()) {
     82 + DexCheckSum.verify(content);
     83 + }
     84 + return new DexReader(getNextUniqId(), fileName, content);
    81 85   }
    82 86   
    83 87   private List<DexReader> collectDexFromZip(File file) {
    skipped 54 lines
  • ■ ■ ■ ■ ■ ■
    jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/DexInputPlugin.java
    1 1  package jadx.plugins.input.dex;
    2 2   
    3 3  import java.io.Closeable;
     4 +import java.io.InputStream;
    4 5  import java.nio.file.Path;
     6 +import java.util.Collections;
    5 7  import java.util.List;
    6 8  import java.util.Map;
    7 9   
    skipped 5 lines
    13 15  import jadx.api.plugins.input.data.impl.EmptyLoadResult;
    14 16  import jadx.api.plugins.options.JadxPluginOptions;
    15 17  import jadx.api.plugins.options.OptionDescription;
     18 +import jadx.api.plugins.utils.CommonFileUtils;
    16 19   
    17 20  public class DexInputPlugin implements JadxInputPlugin, JadxPluginOptions {
    18 21   public static final String PLUGIN_ID = "dex-input";
    skipped 17 lines
    36 39   return EmptyLoadResult.INSTANCE;
    37 40   }
    38 41   return new DexLoadResult(dexReaders, closeable);
     42 + }
     43 + 
     44 + public ILoadResult loadDex(byte[] content, @Nullable String fileName) {
     45 + String fileLabel = fileName == null ? "input.dex" : fileName;
     46 + DexReader dexReader = loader.loadDexReader(fileLabel, content);
     47 + return new DexLoadResult(Collections.singletonList(dexReader), null);
     48 + }
     49 + 
     50 + public ILoadResult loadDexFromInputStream(InputStream in, @Nullable String fileLabel) {
     51 + try {
     52 + return loadDex(CommonFileUtils.loadBytes(in), fileLabel);
     53 + } catch (Exception e) {
     54 + throw new DexException("Failed to read input stream", e);
     55 + }
    39 56   }
    40 57   
    41 58   @Override
    skipped 10 lines
  • ■ ■ ■ ■ ■
    jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/DexLoadResult.java
    skipped 33 lines
    34 34   
    35 35   @Override
    36 36   public void close() throws IOException {
    37  - dexReaders.clear();
    38 37   if (closeable != null) {
    39 38   closeable.close();
    40 39   }
    skipped 8 lines
Please wait...
Page is in error, reload to recover