diff --git a/README.md b/README.md index 24afc1b68..a3ccc800d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Enigma -A tool for deobfuscation of Java bytecode. Forked from , copyright Jeff Martin. +A tool for deobfuscation of Java bytecode. Forked from , originally created by [Jeff Martin](https://www.cuchazinteractive.com/). ## License diff --git a/enigma-cli/src/main/java/org/quiltmc/enigma/command/Main.java b/enigma-cli/src/main/java/org/quiltmc/enigma/command/Main.java index fb7193c91..5014feb4e 100644 --- a/enigma-cli/src/main/java/org/quiltmc/enigma/command/Main.java +++ b/enigma-cli/src/main/java/org/quiltmc/enigma/command/Main.java @@ -120,6 +120,7 @@ private static void logEnigmaInfo() { register(new DropInvalidMappingsCommand()); register(new FillClassMappingsCommand()); register(new HelpCommand()); + register(new PrintStatsCommand()); } private static final class CommandHelpException extends IllegalArgumentException { diff --git a/enigma-cli/src/main/java/org/quiltmc/enigma/command/PrintStatsCommand.java b/enigma-cli/src/main/java/org/quiltmc/enigma/command/PrintStatsCommand.java new file mode 100644 index 000000000..47d8067c0 --- /dev/null +++ b/enigma-cli/src/main/java/org/quiltmc/enigma/command/PrintStatsCommand.java @@ -0,0 +1,59 @@ +package org.quiltmc.enigma.command; + +import org.quiltmc.enigma.api.Enigma; +import org.quiltmc.enigma.api.EnigmaPlugin; +import org.quiltmc.enigma.api.EnigmaProfile; +import org.quiltmc.enigma.api.stats.ProjectStatsResult; +import org.quiltmc.enigma.api.stats.StatType; +import org.quiltmc.enigma.api.stats.StatsGenerator; +import org.tinylog.Logger; + +import javax.annotation.Nullable; +import java.nio.file.Path; +import java.util.Set; + +public class PrintStatsCommand extends Command { + public PrintStatsCommand() { + super(Argument.INPUT_JAR.required(), + Argument.INPUT_MAPPINGS.required(), + Argument.ENIGMA_PROFILE.optional()); + } + + @Override + public void run(String... args) throws Exception { + Path inJar = getReadablePath(this.getArg(args, 0)); + Path mappings = getReadablePath(this.getArg(args, 1)); + Path profilePath = getReadablePath(this.getArg(args, 2)); + + run(inJar, mappings, profilePath, null); + } + + @Override + public String getName() { + return "print-stats"; + } + + @Override + public String getDescription() { + return "Generates and prints out the statistics of how well the provided mappings cover the provided JAR file."; + } + + public static void run(Path inJar, Path mappings, @Nullable Path profilePath, @Nullable Iterable plugins) throws Exception { + EnigmaProfile profile = EnigmaProfile.read(profilePath); + Enigma enigma = createEnigma(profile, plugins); + + run(inJar, mappings, enigma); + } + + public static void run(Path inJar, Path mappings, Enigma enigma) throws Exception { + StatsGenerator generator = new StatsGenerator(openProject(inJar, mappings, enigma)); + ProjectStatsResult result = generator.generate(new ConsoleProgressListener(), Set.of(StatType.values()), false); + + Logger.info(String.format("Overall mapped: %.2f%% (%s / %s)", result.getPercentage(), result.getMapped(), result.getMappable())); + Logger.info(String.format("Classes: %.2f%% (%s / %s)", result.getPercentage(StatType.CLASSES), result.getMapped(StatType.CLASSES), result.getMappable(StatType.CLASSES))); + Logger.info(String.format("Fields: %.2f%% (%s / %s)", result.getPercentage(StatType.FIELDS), result.getMapped(StatType.FIELDS), result.getMappable(StatType.FIELDS))); + Logger.info(String.format("Methods: %.2f%% (%s / %s)", result.getPercentage(StatType.METHODS), result.getMapped(StatType.METHODS), result.getMappable(StatType.METHODS))); + Logger.info(String.format("Parameters: %.2f%% (%s / %s)", result.getPercentage(StatType.PARAMETERS), result.getMapped(StatType.PARAMETERS), result.getMappable(StatType.PARAMETERS))); + } +} + diff --git a/enigma-cli/src/test/java/org/quiltmc/enigma/command/PrintStatsCommandTest.java b/enigma-cli/src/test/java/org/quiltmc/enigma/command/PrintStatsCommandTest.java new file mode 100644 index 000000000..f376fe8e9 --- /dev/null +++ b/enigma-cli/src/test/java/org/quiltmc/enigma/command/PrintStatsCommandTest.java @@ -0,0 +1,19 @@ +package org.quiltmc.enigma.command; + +import org.junit.jupiter.api.Test; +import org.quiltmc.enigma.TestUtil; + +import java.nio.file.Path; + +import static org.quiltmc.enigma.TestUtil.getResource; + +public class PrintStatsCommandTest { + private static final Path JAR = TestUtil.obfJar("lone_class"); + private static final Path MAPPINGS = getResource("/print_stats"); + + @Test + public void test() throws Exception { + // just here to manually verify output + PrintStatsCommand.run(JAR, MAPPINGS, null, null); + } +} diff --git a/enigma-cli/src/test/resources/print_stats/AwesomeClass.mapping b/enigma-cli/src/test/resources/print_stats/AwesomeClass.mapping new file mode 100644 index 000000000..5040a48cb --- /dev/null +++ b/enigma-cli/src/test/resources/print_stats/AwesomeClass.mapping @@ -0,0 +1,5 @@ +CLASS a AwesomeClass + FIELD a gaming Ljava/lang/String; + METHOD (Ljava/lang/String;)V + ARG 1 gaming + METHOD a getGaming ()Ljava/lang/String;