From 8b39300b62007f55319fceeca291db8c03b92dd1 Mon Sep 17 00:00:00 2001 From: Tobias Neitzel Date: Wed, 17 Jan 2024 09:45:54 +0100 Subject: [PATCH] Small formatting changes --- pom.xml | 4 +-- .../rmg/internal/ArgumentHandler.java | 7 ++-- src/eu/tneitzel/rmg/operations/Operation.java | 33 +++++++------------ src/eu/tneitzel/rmg/plugin/PluginSystem.java | 14 ++++++++ 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/pom.xml b/pom.xml index b6facdf..ce1395c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ eu.tneitzel remote-method-guesser - 5.0.0 + 5.1.0 jar ${project.artifactId} @@ -51,7 +51,7 @@ eu.tneitzel argparse4j - 1.0.1 + 1.1.0 diff --git a/src/eu/tneitzel/rmg/internal/ArgumentHandler.java b/src/eu/tneitzel/rmg/internal/ArgumentHandler.java index 0be3d4d..4ee4681 100644 --- a/src/eu/tneitzel/rmg/internal/ArgumentHandler.java +++ b/src/eu/tneitzel/rmg/internal/ArgumentHandler.java @@ -11,6 +11,7 @@ import java.util.Set; import eu.tneitzel.argparse4j.ArgumentParsers; +import eu.tneitzel.argparse4j.global.ActionContext; import eu.tneitzel.argparse4j.global.GlobalOption; import eu.tneitzel.argparse4j.global.exceptions.RequirementException; import eu.tneitzel.argparse4j.inf.ArgumentParser; @@ -55,8 +56,10 @@ public ArgumentHandler(String[] argv) parser = ArgumentParsers.newFor("remote-method-guesser").build(); parser.description("rmg v" + ArgumentHandler.class.getPackage().getImplementationVersion() + " - a Java RMI Vulnerability Scanner"); - Subparsers subparsers = parser.addSubparsers().help(" ").metavar("action").dest("action"); - Operation.addSubparsers(subparsers); + ActionContext ctx = Operation.getActionContext(); + Subparsers subParsers = ctx.addSubparsers(parser); + + PluginSystem.addPluginActions(subParsers); try { diff --git a/src/eu/tneitzel/rmg/operations/Operation.java b/src/eu/tneitzel/rmg/operations/Operation.java index 2d51041..90bf0e2 100644 --- a/src/eu/tneitzel/rmg/operations/Operation.java +++ b/src/eu/tneitzel/rmg/operations/Operation.java @@ -2,14 +2,11 @@ import java.lang.reflect.Method; -import eu.tneitzel.argparse4j.global.GlobalOption; +import eu.tneitzel.argparse4j.global.ActionContext; import eu.tneitzel.argparse4j.global.IAction; import eu.tneitzel.argparse4j.global.IOption; -import eu.tneitzel.argparse4j.inf.Subparser; -import eu.tneitzel.argparse4j.inf.Subparsers; import eu.tneitzel.rmg.internal.ExceptionHandler; import eu.tneitzel.rmg.internal.RMGOption; -import eu.tneitzel.rmg.plugin.PluginSystem; /** * The Operation enum class contains one item for each possible rmg action. An enum item consists out of @@ -336,9 +333,13 @@ public enum Operation implements IAction */ Operation(String methodName, String arguments, String description, RMGOption[] options) { - try { + try + { this.method = Dispatcher.class.getDeclaredMethod(methodName, new Class[] {}); - } catch(Exception e) { + } + + catch (Exception e) + { ExceptionHandler.internalException(e, "Operation constructor", true); } @@ -425,29 +426,19 @@ public static Operation getByName(String name) } /** - * Add a new subparser for each operation to the specified argumentParser. + * Create an ActionContext for the Operation enum. * - * @param argumentParser parser to add the subparsers to. + * @return ActionContext that can be used to create argument parsers from. */ - public static void addSubparsers(Subparsers argumentParser) + public static ActionContext getActionContext() { - for (Operation operation : Operation.values()) - { - Subparser parser = argumentParser.addParser(operation.name().toLowerCase()).help(operation.description); - GlobalOption.addOptions(parser, operation); - } - - for (IAction action : PluginSystem.getPluginActions()) - { - Subparser parser = argumentParser.addParser(action.getName().toLowerCase()).help(action.getDescription()); - GlobalOption.addOptions(parser, action); - } + return new ActionContext("action", " ", " ", Operation.values()); } @Override public String getName() { - return method.getName(); + return name().toLowerCase(); } @Override diff --git a/src/eu/tneitzel/rmg/plugin/PluginSystem.java b/src/eu/tneitzel/rmg/plugin/PluginSystem.java index 10fe42b..5eafac0 100644 --- a/src/eu/tneitzel/rmg/plugin/PluginSystem.java +++ b/src/eu/tneitzel/rmg/plugin/PluginSystem.java @@ -10,6 +10,7 @@ import java.util.jar.Manifest; import eu.tneitzel.argparse4j.global.IAction; +import eu.tneitzel.argparse4j.inf.Subparsers; import eu.tneitzel.rmg.exceptions.MalformedPluginException; import eu.tneitzel.rmg.internal.ExceptionHandler; import eu.tneitzel.rmg.internal.RMGOption; @@ -312,4 +313,17 @@ public static IAction[] getPluginActions() return new IAction[] {}; } + + /** + * Add actions added by a user defined plugin to an argument parser. + * + * @param parser the argument parser to add the actions to + */ + public static void addPluginActions(Subparsers parser) + { + for (IAction action : getPluginActions()) + { + action.addSuparser(parser); + } + } }