Ejemplo n.º 1
1
  @Override
  public String decompileClassNode(ClassNode cn, byte[] b) {
    String exception = "";
    try {
      String fileStart = BytecodeViewer.tempDirectory + BytecodeViewer.fs + "temp";

      final File tempClass = new File(MiscUtils.getUniqueName(fileStart, ".class") + ".class");

      try {
        final FileOutputStream fos = new FileOutputStream(tempClass);

        fos.write(b);

        fos.close();
      } catch (final IOException e) {
        new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
      }

      DecompilerSettings settings = getDecompilerSettings();

      LuytenTypeLoader typeLoader = new LuytenTypeLoader();
      MetadataSystem metadataSystem = new MetadataSystem(typeLoader);
      TypeReference type = metadataSystem.lookupType(tempClass.getCanonicalPath());

      DecompilationOptions decompilationOptions = new DecompilationOptions();
      decompilationOptions.setSettings(DecompilerSettings.javaDefaults());
      decompilationOptions.setFullDecompilation(true);

      TypeDefinition resolvedType = null;
      if (type == null || ((resolvedType = type.resolve()) == null)) {
        throw new Exception("Unable to resolve type.");
      }
      StringWriter stringwriter = new StringWriter();
      settings
          .getLanguage()
          .decompileType(resolvedType, new PlainTextOutput(stringwriter), decompilationOptions);
      String decompiledSource = stringwriter.toString();

      return decompiledSource;
    } catch (Exception e) {
      StringWriter sw = new StringWriter();
      e.printStackTrace(new PrintWriter(sw));
      e.printStackTrace();

      exception =
          "Bytecode Viewer Version: "
              + BytecodeViewer.version
              + BytecodeViewer.nl
              + BytecodeViewer.nl
              + sw.toString();
    }
    return "Procyon error! Send the stacktrace to Konloch at http://the.bytecode.club or [email protected]"
        + BytecodeViewer.nl
        + BytecodeViewer.nl
        + "Suggested Fix: Click refresh class, if it fails again try another decompiler."
        + BytecodeViewer.nl
        + BytecodeViewer.nl
        + exception;
  }
  public String decompileClassNode(ClassNode cn, byte[] b) {
    String fileStart = BytecodeViewer.tempDir.getAbsolutePath() + BytecodeViewer.fs + "temp";

    String start = MiscUtils.getUniqueName(fileStart, ".class");

    final File tempClass = new File(start + ".class");
    final File tempZip = new File(start + ".jar");
    final File tempDex = new File(start + ".dex");
    final File tempSmali = new File(start + "-smali"); // output directory

    try {
      final FileOutputStream fos = new FileOutputStream(tempClass);

      fos.write(b);

      fos.close();
    } catch (final IOException e) {
      new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
    }

    ZipUtil.packEntry(tempClass, tempZip);

    Dex2Jar.saveAsDex(tempZip, tempDex);

    try {
      org.jf.baksmali.main.main(
          new String[] {"-o", tempSmali.getAbsolutePath(), "-x", tempDex.getAbsolutePath()});
    } catch (Exception e) {
      new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
    }

    File outputSmali = null;

    boolean found = false;
    File current = tempSmali;
    while (!found) {
      File f = current.listFiles()[0];
      if (f.isDirectory()) current = f;
      else {
        outputSmali = f;
        found = true;
      }
    }
    try {
      return FileUtils.readFileToString(outputSmali, "UTF-8");
    } catch (Exception e) {
      new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
    }

    return null;
  }
Ejemplo n.º 3
1
    @Override
    public boolean accept(File f) {
      if (f.isDirectory()) return true;

      return PluginManager.pluginExtensions().contains(MiscUtils.extension(f.getAbsolutePath()));
    }