1010import javax .swing .filechooser .FileNameExtensionFilter ;
1111import java .awt .*;
1212import java .io .File ;
13- import java .io .PrintStream ;
1413import java .nio .file .Path ;
1514import java .nio .file .Paths ;
1615
@@ -29,6 +28,13 @@ public class MainForm implements Constants {
2928 private JLabel packageLabel ;
3029 private JLabel operationLabel ;
3130 private JPanel operationPanel ;
31+ private JLabel keyLabel ;
32+ private JTextField keyText ;
33+ private JButton showCommandButton ;
34+ private static String pack ;
35+ private static String globalKey ;
36+ private static String libAbs ;
37+ private static String jarAbs ;
3238
3339 public static void start () {
3440 JFrame frame = new JFrame ("code-encryptor-plus" );
@@ -75,17 +81,56 @@ public MainForm() {
7581 log ("jar is null" );
7682 return ;
7783 }
84+ String key = keyText .getText ();
85+ if (key == null || key .isEmpty ()) {
86+ log ("jar is null" );
87+ return ;
88+ }
89+ key = key .trim ();
90+ if (key .getBytes ().length != 16 ) {
91+ JOptionPane .showMessageDialog (rootPanel , "KEY LENGTH MUST BE 16" );
92+ return ;
93+ }
94+ byte [] keyBytes = key .getBytes ();
95+
96+ String finalKey = key ;
7897 new Thread (() -> {
7998 JNIUtil .extractDllSo (EncryptorDLL , null , true );
8099 Path libPath = Paths .get (TempDir ).resolve (EncryptorDLL );
81- PatchHelper .patchJar (Paths .get (jar ), libPath , packageName ,new byte []{});
100+ Path jarPath = Paths .get (jar );
101+
102+ PatchHelper .patchJar (jarPath , libPath , packageName , keyBytes );
103+
104+ String srcName = jarPath .getFileName ().toString ();
105+ jarAbs = Paths .get (String .format ("%s_%s.jar" , srcName .substring (0 ,
106+ srcName .lastIndexOf ("." )), NewFileSuffix )).toAbsolutePath ().toString ();
107+ log ("final key: " + finalKey );
108+ log ("package: " + packageName );
109+ globalKey = finalKey ;
110+ pack = packageName ;
82111 }).start ();
83112 });
84113
85114 exportAgentLibButton .addActionListener (e -> {
86115 JNIUtil .extractDllSo (DecrypterDLL , null , false );
87- JOptionPane .showMessageDialog (rootPanel ,
88- "File: " + TempDir + "/" + "decrypter.dll" );
116+ String sb = "File: " +
117+ TempDir +
118+ "/" +
119+ "decrypter.dll" ;
120+ libAbs = Paths .get (TempDir ).resolve ("decrypter.dll" ).toAbsolutePath ().toString ();
121+ JOptionPane .showMessageDialog (rootPanel , sb );
122+ });
123+
124+ showCommandButton .addActionListener (e -> {
125+ if (jarAbs .isEmpty () || pack .isEmpty () || libAbs .isEmpty () || globalKey .isEmpty ()) {
126+ JOptionPane .showMessageDialog (rootPanel , "NOT ALLOWED" );
127+ return ;
128+ }
129+ JFrame frame = new JFrame ("Show Command" );
130+ frame .setContentPane (new Show (jarAbs , libAbs , pack , globalKey ).rootPanel );
131+ frame .pack ();
132+ frame .setVisible (true );
133+ frame .setResizable (false );
89134 });
90135 }
91136
@@ -107,7 +152,7 @@ public MainForm() {
107152 masterPanel = new JPanel ();
108153 masterPanel .setLayout (new GridLayoutManager (2 , 1 , new Insets (0 , 0 , 0 , 0 ), -1 , -1 ));
109154 rootPanel = new JPanel ();
110- rootPanel .setLayout (new GridLayoutManager (3 , 3 , new Insets (0 , 0 , 0 , 3 ), -1 , -1 ));
155+ rootPanel .setLayout (new GridLayoutManager (4 , 3 , new Insets (0 , 0 , 0 , 3 ), -1 , -1 ));
111156 masterPanel .add (rootPanel , new GridConstraints (0 , 0 , 1 , 1 , GridConstraints .ANCHOR_CENTER , GridConstraints .FILL_BOTH , GridConstraints .SIZEPOLICY_CAN_SHRINK | GridConstraints .SIZEPOLICY_CAN_GROW , GridConstraints .SIZEPOLICY_CAN_SHRINK | GridConstraints .SIZEPOLICY_CAN_GROW , null , null , null , 0 , false ));
112157 jarLabel = new JLabel ();
113158 jarLabel .setText ("Jar File" );
@@ -124,16 +169,24 @@ public MainForm() {
124169 rootPanel .add (packageText , new GridConstraints (1 , 1 , 1 , 2 , GridConstraints .ANCHOR_WEST , GridConstraints .FILL_HORIZONTAL , GridConstraints .SIZEPOLICY_WANT_GROW , GridConstraints .SIZEPOLICY_FIXED , null , new Dimension (150 , -1 ), null , 0 , false ));
125170 operationLabel = new JLabel ();
126171 operationLabel .setText ("Operation" );
127- rootPanel .add (operationLabel , new GridConstraints (2 , 0 , 1 , 1 , GridConstraints .ANCHOR_WEST , GridConstraints .FILL_NONE , GridConstraints .SIZEPOLICY_FIXED , GridConstraints .SIZEPOLICY_FIXED , null , null , null , 1 , false ));
172+ rootPanel .add (operationLabel , new GridConstraints (3 , 0 , 1 , 1 , GridConstraints .ANCHOR_WEST , GridConstraints .FILL_NONE , GridConstraints .SIZEPOLICY_FIXED , GridConstraints .SIZEPOLICY_FIXED , null , null , null , 1 , false ));
128173 operationPanel = new JPanel ();
129- operationPanel .setLayout (new GridLayoutManager (1 , 2 , new Insets (0 , 0 , 0 , 0 ), -1 , -1 ));
130- rootPanel .add (operationPanel , new GridConstraints (2 , 1 , 1 , 2 , GridConstraints .ANCHOR_CENTER , GridConstraints .FILL_BOTH , GridConstraints .SIZEPOLICY_CAN_SHRINK | GridConstraints .SIZEPOLICY_CAN_GROW , GridConstraints .SIZEPOLICY_CAN_SHRINK | GridConstraints .SIZEPOLICY_CAN_GROW , null , null , null , 0 , false ));
174+ operationPanel .setLayout (new GridLayoutManager (1 , 3 , new Insets (0 , 0 , 0 , 0 ), -1 , -1 ));
175+ rootPanel .add (operationPanel , new GridConstraints (3 , 1 , 1 , 2 , GridConstraints .ANCHOR_CENTER , GridConstraints .FILL_BOTH , GridConstraints .SIZEPOLICY_CAN_SHRINK | GridConstraints .SIZEPOLICY_CAN_GROW , GridConstraints .SIZEPOLICY_CAN_SHRINK | GridConstraints .SIZEPOLICY_CAN_GROW , null , null , null , 0 , false ));
131176 encryptJarFileButton = new JButton ();
132177 encryptJarFileButton .setText ("Encrypt Jar File" );
133178 operationPanel .add (encryptJarFileButton , new GridConstraints (0 , 0 , 1 , 1 , GridConstraints .ANCHOR_CENTER , GridConstraints .FILL_HORIZONTAL , GridConstraints .SIZEPOLICY_CAN_SHRINK | GridConstraints .SIZEPOLICY_CAN_GROW , GridConstraints .SIZEPOLICY_FIXED , null , null , null , 0 , false ));
134179 exportAgentLibButton = new JButton ();
135- exportAgentLibButton .setText ("Export Agent Lib" );
180+ exportAgentLibButton .setText ("Export Lib" );
136181 operationPanel .add (exportAgentLibButton , new GridConstraints (0 , 1 , 1 , 1 , GridConstraints .ANCHOR_CENTER , GridConstraints .FILL_HORIZONTAL , GridConstraints .SIZEPOLICY_CAN_SHRINK | GridConstraints .SIZEPOLICY_CAN_GROW , GridConstraints .SIZEPOLICY_FIXED , null , null , null , 0 , false ));
182+ showCommandButton = new JButton ();
183+ showCommandButton .setText ("Show Command" );
184+ operationPanel .add (showCommandButton , new GridConstraints (0 , 2 , 1 , 1 , GridConstraints .ANCHOR_CENTER , GridConstraints .FILL_HORIZONTAL , GridConstraints .SIZEPOLICY_CAN_SHRINK | GridConstraints .SIZEPOLICY_CAN_GROW , GridConstraints .SIZEPOLICY_FIXED , null , null , null , 0 , false ));
185+ keyLabel = new JLabel ();
186+ keyLabel .setText ("Your KEY" );
187+ rootPanel .add (keyLabel , new GridConstraints (2 , 0 , 1 , 1 , GridConstraints .ANCHOR_WEST , GridConstraints .FILL_NONE , GridConstraints .SIZEPOLICY_FIXED , GridConstraints .SIZEPOLICY_FIXED , null , null , null , 1 , false ));
188+ keyText = new JTextField ();
189+ rootPanel .add (keyText , new GridConstraints (2 , 1 , 1 , 2 , GridConstraints .ANCHOR_WEST , GridConstraints .FILL_HORIZONTAL , GridConstraints .SIZEPOLICY_WANT_GROW , GridConstraints .SIZEPOLICY_FIXED , null , new Dimension (150 , -1 ), null , 0 , false ));
137190 logPanel = new JPanel ();
138191 logPanel .setLayout (new GridLayoutManager (1 , 1 , new Insets (3 , 3 , 3 , 3 ), -1 , -1 ));
139192 masterPanel .add (logPanel , new GridConstraints (1 , 0 , 1 , 1 , GridConstraints .ANCHOR_CENTER , GridConstraints .FILL_BOTH , GridConstraints .SIZEPOLICY_CAN_SHRINK | GridConstraints .SIZEPOLICY_CAN_GROW , GridConstraints .SIZEPOLICY_CAN_SHRINK | GridConstraints .SIZEPOLICY_CAN_GROW , new Dimension (500 , 200 ), new Dimension (500 , 200 ), new Dimension (500 , 200 ), 0 , false ));
0 commit comments