Esempio n. 1
0
 public static Oat getOat(Elf e) throws IOException {
   DataReader r = e.getReader();
   Elf.Elf_Shdr sec = e.getSectionByName(Oat.SECTION_RODATA);
   if (sec != null) {
     r.seek(sec.getOffset());
     return new Oat(r, true);
   }
   throw new IOException("oat not found");
 }
Esempio n. 2
0
  public static void smaliRaw(File inputFile) {
    if (!inputFile.isFile()) {
      LLog.i(inputFile + " is not a file.");
    }
    String folderName = MiscUtil.getFilenamePrefix(inputFile.getName());
    String outputBaseFolder = MiscUtil.path(inputFile.getAbsoluteFile().getParent(), folderName);
    baksmaliOptions options = new baksmaliOptions();
    Opcodes opc = new Opcodes(org.jf.dexlib2.Opcode.LOLLIPOP);
    options.apiLevel = opc.apiLevel;
    options.allowOdex = true;
    options.jobs = 4;

    java.util.List<DexBackedDexFile> dexFiles = new ArrayList<>();
    java.util.List<String> outSubFolders = new ArrayList<>();
    if (Elf.isElf(inputFile)) {
      final byte[] buf = new byte[8192];
      try (Elf e = new Elf(inputFile)) {
        Oat oat = getOat(e);
        for (int i = 0; i < oat.mDexFiles.length; i++) {
          Oat.DexFile df = oat.mDexFiles[i];
          dexFiles.add(readDex(df, df.mHeader.file_size_, opc, buf));
          String opath = new String(oat.mOatDexFiles[i].dex_file_location_data_);
          opath = MiscUtil.getFilenamePrefix(getOuputNameForSubDex(opath));
          outSubFolders.add(MiscUtil.path(outputBaseFolder, opath));
        }
      } catch (IOException ex) {
        LLog.ex(ex);
      }
    } else {
      dexFiles = DexUtil.loadMultiDex(inputFile, opc);
      String subFolder = "classes";
      for (int i = 0; i < dexFiles.size(); i++) {
        outSubFolders.add(MiscUtil.path(outputBaseFolder, subFolder));
        subFolder = "classes" + (i + 2);
      }
    }
    if (outSubFolders.size() == 1) {
      outSubFolders.set(0, outputBaseFolder);
    }

    for (int i = 0; i < dexFiles.size(); i++) {
      options.outputDirectory = outSubFolders.get(i);
      org.jf.baksmali.baksmali.disassembleDexFile(dexFiles.get(i), options);
      LLog.i("Output to " + options.outputDirectory);
    }
    LLog.i("All done");
  }