/* * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jetbrains.java.decompiler.main.decompiler; import org.jetbrains.java.decompiler.main.DecompilerContext; import org.jetbrains.java.decompiler.main.Fernflower; import org.jetbrains.java.decompiler.main.decompiler.helper.PrintStreamLogger; import org.jetbrains.java.decompiler.main.extern.IBytecodeProvider; import org.jetbrains.java.decompiler.main.extern.IDecompilatSaver; import org.jetbrains.java.decompiler.main.extern.IFernflowerLogger; import org.jetbrains.java.decompiler.util.InterpreterUtil; import java.io.*; import java.util.*; import java.util.jar.JarOutputStream; import java.util.jar.Manifest; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.util.zip.ZipOutputStream; @SuppressWarnings({"UseOfSystemOutOrSystemErr", "CallToPrintStackTrace"}) public class ConsoleDecompiler implements IBytecodeProvider, IDecompilatSaver { private File root; private Fernflower fernflower; private HashMap mapArchiveStreams = new HashMap(); private HashMap> mapArchiveEntries = new HashMap>(); public ConsoleDecompiler() { this(null); } public ConsoleDecompiler(HashMap propertiesCustom) { this(new PrintStreamLogger(IFernflowerLogger.WARNING, System.out), propertiesCustom); } protected ConsoleDecompiler(IFernflowerLogger logger, HashMap propertiesCustom) { fernflower = new Fernflower(this, this, propertiesCustom); DecompilerContext.setLogger(logger); } public static void main(String[] args) { try { if (args != null && args.length > 1) { HashMap mapOptions = new HashMap(); List lstSources = new ArrayList(); List lstLibraries = new ArrayList(); boolean isOption = true; for (int i = 0; i < args.length - 1; ++i) { // last parameter - destination String arg = args[i]; if (isOption && arg.startsWith("-") && arg.length() > 5 && arg.charAt(4) == '=') { String value = arg.substring(5).toUpperCase(); if ("TRUE".equals(value)) { value = "1"; } else if ("FALSE".equals(value)) { value = "0"; } mapOptions.put(arg.substring(1, 4), value); } else { isOption = false; if (arg.startsWith("-e=")) { lstLibraries.add(arg.substring(3)); } else { lstSources.add(arg); } } } if (lstSources.isEmpty()) { printHelp(); } else { ConsoleDecompiler decompiler = new ConsoleDecompiler( new PrintStreamLogger(IFernflowerLogger.INFO, System.out), mapOptions); for (String source : lstSources) { decompiler.addSpace(new File(source), true); } for (String library : lstLibraries) { decompiler.addSpace(new File(library), false); } decompiler.decompileContext(new File(args[args.length - 1])); } } else { printHelp(); } } catch (Exception ex) { ex.printStackTrace(); } } private static void printHelp() { System.out.println("Usage: java ConsoleDecompiler ( -