1111public class App {
1212
1313 public static void main (String [] args ){
14+ System .out .println ();
1415 System .out .println ("SafeLog4j by Contrast Security" );
1516 System .out .println ( "https://contrastsecurity.com" );
1617
@@ -27,6 +28,7 @@ public static void main(String[] args){
2728 File agentFile = new File (filename );
2829 ByteBuddyAgent .attach (agentFile .getAbsoluteFile (), pid , options );
2930 System .out .println ("Attached to target jvm and loaded agent successfully" );
31+ System .out .println ();
3032 }catch (Exception e ){
3133 e .printStackTrace ();
3234 }
@@ -35,6 +37,21 @@ public static void main(String[] args){
3537 }
3638 }
3739
40+ private static void showHelp (){
41+ System .out .println ();
42+ System .out .println ("List of eligible JVM PIDs (must be running as same user):" );
43+ try {
44+ listProcesses ();
45+ }catch (NoClassDefFoundError err ){
46+ System .err .println ("Error. Try using 'jps' or 'jcmd' to list Java processes." );
47+ }
48+ System .out .println ();
49+ System .out .println ("To attach Safelog4j to your application, either:" );
50+ System .out .println ("1. Launch with -javaagent:safelog4j-x.x.x" );
51+ System .out .println ("2. Attach to a running JVM with java -jar safelog4j-x.x.x PID [both|check|block|none]" );
52+ System .out .println ();
53+ }
54+
3855 public static void listProcesses (){
3956 List <VirtualMachineDescriptor > vms = VirtualMachine .list ();
4057 vms .stream ()
@@ -44,19 +61,4 @@ public static void listProcesses(){
4461 });
4562 }
4663
47- private static void showHelp (){
48- System .out .println ("This tool can be used in two modes for custom and third party applications:" );
49- System .out .println ("1. At application startup, through the -javaagent flag." );
50- System .out .println ("2. Without application restart, if supported." );
51- System .out .println ();
52- System .out .println ("SafeLog4j can connect to and patch the following Java processes:" );
53- try {
54- listProcesses ();
55- System .out .println ();
56- System .out .println ("To patch a process, add an argument of the ID or use the word all." );
57- }catch (NoClassDefFoundError err ){
58- System .err .println ("Please use jcmd to list Java processes." );
59- }
60- }
61-
6264}
0 commit comments