From 4be005617b3b8c3578cca07c5d085d12916f0d1d Mon Sep 17 00:00:00 2001 From: lclc98 Date: Thu, 30 Jun 2016 00:49:21 +1000 Subject: Json format (#2) * Added new format * Fixed bug * Updated Version --- src/main/java/cuchaz/enigma/CommandMain.java | 186 +++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 src/main/java/cuchaz/enigma/CommandMain.java (limited to 'src/main/java/cuchaz/enigma/CommandMain.java') diff --git a/src/main/java/cuchaz/enigma/CommandMain.java b/src/main/java/cuchaz/enigma/CommandMain.java new file mode 100644 index 0000000..69f5684 --- /dev/null +++ b/src/main/java/cuchaz/enigma/CommandMain.java @@ -0,0 +1,186 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + *
+ * Contributors:
+ * Jeff Martin - initial API and implementation
+ ******************************************************************************/
+package cuchaz.enigma;
+
+import java.io.File;
+import java.io.FileReader;
+import java.util.jar.JarFile;
+
+import cuchaz.enigma.Deobfuscator.ProgressListener;
+import cuchaz.enigma.mapping.Mappings;
+import cuchaz.enigma.mapping.MappingsReader;
+
+public class CommandMain {
+
+ public static class ConsoleProgressListener implements ProgressListener {
+
+ private static final int ReportTime = 5000; // 5s
+
+ private int m_totalWork;
+ private long m_startTime;
+ private long m_lastReportTime;
+
+ @Override
+ public void init(int totalWork, String title) {
+ m_totalWork = totalWork;
+ m_startTime = System.currentTimeMillis();
+ m_lastReportTime = m_startTime;
+ System.out.println(title);
+ }
+
+ @Override
+ public void onProgress(int numDone, String message) {
+
+ long now = System.currentTimeMillis();
+ boolean isLastUpdate = numDone == m_totalWork;
+ boolean shouldReport = isLastUpdate || now - m_lastReportTime > ReportTime;
+
+ if (shouldReport) {
+ int percent = numDone * 100 / m_totalWork;
+ System.out.println(String.format("\tProgress: %3d%%", percent));
+ m_lastReportTime = now;
+ }
+ if (isLastUpdate) {
+ double elapsedSeconds = (now - m_startTime) / 1000;
+ System.out.println(String.format("Finished in %.1f seconds", elapsedSeconds));
+ }
+ }
+ }
+
+ public static void main(String[] args)
+ throws Exception {
+
+ try {
+
+ // process the command
+ String command = getArg(args, 0, "command", true);
+ if (command.equalsIgnoreCase("deobfuscate")) {
+ deobfuscate(args);
+ } else if (command.equalsIgnoreCase("decompile")) {
+ decompile(args);
+ } else if (command.equalsIgnoreCase("protectify")) {
+ protectify(args);
+ } else if (command.equalsIgnoreCase("publify")) {
+ publify(args);
+ } else {
+ throw new IllegalArgumentException("Command not recognized: " + command);
+ }
+ } catch (IllegalArgumentException ex) {
+ System.out.println(ex.getMessage());
+ printHelp();
+ }
+ }
+
+ private static void printHelp() {
+ System.out.println(String.format("%s - %s", Constants.Name, Constants.Version));
+ System.out.println("Usage:");
+ System.out.println("\tjava -cp enigma.jar cuchaz.enigma.CommandMain