From a3efd25f603665bed35ab20dc2a9e0219886ce4d Mon Sep 17 00:00:00 2001 From: Maximilian Hill Date: Mon, 20 Dec 2021 13:18:02 +0100 Subject: [PATCH] properly set config and metrics --- .../java/de/inett/cmk/log4shell/CliCheck.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/log4j-scanner/src/main/java/de/inett/cmk/log4shell/CliCheck.java b/log4j-scanner/src/main/java/de/inett/cmk/log4shell/CliCheck.java index 397b451..97ed3d6 100644 --- a/log4j-scanner/src/main/java/de/inett/cmk/log4shell/CliCheck.java +++ b/log4j-scanner/src/main/java/de/inett/cmk/log4shell/CliCheck.java @@ -4,14 +4,12 @@ import com.logpresso.scanner.Log4j2Scanner; import com.logpresso.scanner.Metrics; +import java.lang.reflect.Field; import java.util.LinkedList; import java.util.List; public class CliCheck extends Log4j2Scanner { - Configuration config; - Metrics metrics; - public static void main(String[] args) { System.out.println("<<>>"); String[] n_args = prepareArguments(args); @@ -24,13 +22,22 @@ public static void main(String[] args) { System.exit(0); } + /** + * This is a hack, don't change + */ @Override public void run(String[] args) throws Exception { - config = Configuration.parseArguments(args); - metrics = new Metrics(); + Field config = Log4j2Scanner.class.getDeclaredField("config"); + config.setAccessible(true); + config.set(this, Configuration.parseArguments(args)); + + Field metrics = Log4j2Scanner.class.getDeclaredField("metrics"); + metrics.setAccessible(true); + metrics.set(this, new Metrics()); run(); } + private static String[] prepareArguments(String[] cargs) { String[] ret; switch (cargs.length) { @@ -61,4 +68,5 @@ private static String[] prepareArguments(String[] cargs) { } return ret; } + }