Skip to content

Commit

Permalink
Small formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
qtc-de committed Jan 17, 2024
1 parent 2cb5123 commit 8b39300
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 25 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>eu.tneitzel</groupId>
<artifactId>remote-method-guesser</artifactId>
<version>5.0.0</version>
<version>5.1.0</version>
<packaging>jar</packaging>

<name>${project.artifactId}</name>
Expand Down Expand Up @@ -51,7 +51,7 @@
<dependency>
<groupId>eu.tneitzel</groupId>
<artifactId>argparse4j</artifactId>
<version>1.0.1</version>
<version>1.1.0</version>
</dependency>

<dependency>
Expand Down
7 changes: 5 additions & 2 deletions src/eu/tneitzel/rmg/internal/ArgumentHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down
33 changes: 12 additions & 21 deletions src/eu/tneitzel/rmg/operations/Operation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/eu/tneitzel/rmg/plugin/PluginSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 8b39300

Please sign in to comment.