org.jetbrains.java.decompiler.main.Fernflower Java Examples

The following examples show how to use org.jetbrains.java.decompiler.main.Fernflower. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RuntimeDecompiler.java    From Mixin with MIT License 6 votes vote down vote up
@Override
public void decompile(final File file) {
    try {
        Fernflower fernflower = new Fernflower(new IBytecodeProvider() {
            
            private byte[] byteCode;
            
            @Override
            public byte[] getBytecode(String externalPath, String internalPath) throws IOException {
                if (this.byteCode == null) {
                    this.byteCode = InterpreterUtil.getBytes(new File(externalPath));
                }
                return this.byteCode;
            }
            
        }, this, this.options, this);
        
        fernflower.getStructContext().addSpace(file, true);
        fernflower.decompileContext();
    } catch (Throwable ex) {
        this.logger.warn("Decompilation error while processing {}", file.getName());
    }
}
 
Example #2
Source File: FernflowerDecompiler.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
public String decompile(byte[] b, MethodNode mn) {
  try {
  	//TODO decompile method only
    this.bytes = b;
    HashMap<String, Object> map = new HashMap<>();
    for (String key : options.keySet()) {
      map.put(key, JByteMod.ops.get("ff_" + key).getBoolean() ? "1" : "0");
    }
    Fernflower f = new Fernflower(this, this, map, new PrintStreamLogger(JByteMod.LOGGER));
    StructContext sc = f.getStructContext();
    StructClass cl = new StructClass(b, true, sc.getLoader());
    sc.getClasses().put(cn.name, cl);
    //instead of loading a file use custom bridge, created a few getters
    String fakePath = new File("none.class").getAbsolutePath();
    ContextUnit unit = new ContextUnit(ContextUnit.TYPE_FOLDER, null, fakePath, true, sc.getSaver(), sc.getDecompiledData());
    sc.getUnits().put(fakePath, unit);
    unit.addClass(cl, "none.class");
    sc.getLoader().addClassLink(cn.name, new LazyLoader.Link(LazyLoader.Link.CLASS, fakePath, null));

    f.decompileContext();
    return returned;
  } catch (Exception e) {
    e.printStackTrace();
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    e.printStackTrace(pw);
    return sw.toString();
  }
}
 
Example #3
Source File: ConsoleDecompiler.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
protected ConsoleDecompiler(File destination, Map<String, Object> options, IFernflowerLogger logger) {
    root = destination;
    engine = new Fernflower(this, this, options, logger);
}
 
Example #4
Source File: BaseDecompiler.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
public BaseDecompiler(IBytecodeProvider provider, IResultSaver saver, Map<String, Object> options, IFernflowerLogger logger) {
    engine = new Fernflower(provider, saver, options, logger);
}
 
Example #5
Source File: ConsoleDecompiler.java    From JByteMod-Beta with GNU General Public License v2.0 4 votes vote down vote up
protected ConsoleDecompiler(File destination, Map<String, Object> options, IFernflowerLogger logger) {
  root = destination;
  fernflower = new Fernflower(this, this, options, logger);
}
 
Example #6
Source File: BaseDecompiler.java    From JByteMod-Beta with GNU General Public License v2.0 4 votes vote down vote up
public BaseDecompiler(IBytecodeProvider provider, IResultSaver saver, Map<String, Object> options, IFernflowerLogger logger) {
  fernflower = new Fernflower(provider, saver, options, logger);
}
 
Example #7
Source File: FernflowerDecompiler.java    From windup with Eclipse Public License 1.0 4 votes vote down vote up
public Collection<Callable<File>> getDecompileTasks(final Map<String, List<ClassDecompileRequest>> requestMap,
            final DecompilationListener listener)
{
    Collection<Callable<File>> tasks = new ArrayList<>(requestMap.size());
    for (Map.Entry<String, List<ClassDecompileRequest>> entry : requestMap.entrySet())
    {
        final String key = entry.getKey();
        final List<ClassDecompileRequest> requests = entry.getValue();

        Callable<File> task = new Callable<File>()
        {
            @Override
            public File call() throws Exception
            {
                if (listener.isCancelled())
                    return null;

                ClassDecompileRequest firstRequest = requests.get(0);
                List<String> classFiles = pathsFromDecompilationRequests(requests);
                FernFlowerResultSaver resultSaver = getResultSaver(
                            pathsFromDecompilationRequests(requests), firstRequest.getOutputDirectory().toFile(),
                            listener);
                Fernflower fernflower = new Fernflower(getByteCodeProvider(), resultSaver, getOptions(), new FernflowerJDKLogger());
                for (ClassDecompileRequest request : requests)
                {
                    if (listener.isCancelled())
                        return null;
                    fernflower.getStructContext().addSpace(request.getClassFile().toFile(), true);
                }
                try
                {
                    fernflower.decompileContext();
                    if (!resultSaver.isFileSaved())
                        listener.decompilationFailed(classFiles, "File was not decompiled!");
                }
                catch (WindupStopException stop)
                {
                    throw new WindupStopException(stop);
                }
                catch (Throwable t)
                {
                    listener.decompilationFailed(classFiles, "Decompilation failed due to: " + t.getMessage());
                    LOG.warning("Decompilation of " + key + " failed due to: " + t.getMessage());
                }

                return null;
            }
        };
        tasks.add(task);
    }

    return tasks;
}