From f15b2ae4365d69fac9415b16ea464d6304debee1 Mon Sep 17 00:00:00 2001 From: Jeroen Ketelaar Date: Sat, 18 May 2019 00:46:27 -0500 Subject: [PATCH 1/5] [FEATURE] Added valid class path --- .../core/asm/redirect/SystemRedirect.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/parabot/core/asm/redirect/SystemRedirect.java b/src/main/java/org/parabot/core/asm/redirect/SystemRedirect.java index d00fc1f..5c28a6a 100644 --- a/src/main/java/org/parabot/core/asm/redirect/SystemRedirect.java +++ b/src/main/java/org/parabot/core/asm/redirect/SystemRedirect.java @@ -9,7 +9,7 @@ public class SystemRedirect { public static PrintStream out = System.out; public static PrintStream err = System.err; - public static InputStream in = System.in; + public static InputStream in = System.in; public static long currentTimeMillis() { return System.currentTimeMillis(); @@ -23,11 +23,23 @@ public class SystemRedirect { System.exit(i); } + private static String getClassPath(){ + String classPath = System.getProperty("java.class.path"); + StringBuilder finalClassPath = new StringBuilder(); + for (String path : classPath.split(":")) { + if (!path.toLowerCase().contains("parabot")) { + finalClassPath.append(path).append(":"); + } + } + + return finalClassPath.toString(); + } + public static String getProperty(String s) { String value; switch (s) { case "java.class.path": - value = "."; + value = getClassPath(); break; default: value = System.getProperty(s); @@ -42,14 +54,14 @@ public class SystemRedirect { String value = null; switch (s2) { case "java.class.path": - value = "."; + value = getClassPath(); break; } if (value == null) { switch (s) { case "java.class.path": - value = "."; + value = getClassPath(); break; default: value = System.getProperty(s); From 08e7e59d5739d7f2b8167edc847bd8a2f2145622 Mon Sep 17 00:00:00 2001 From: Jeroen Ketelaar Date: Sat, 18 May 2019 01:08:39 -0500 Subject: [PATCH 2/5] [FEATURE] Added values view for int-array --- .../java/org/parabot/core/ui/ReflectUI.java | 46 ++++++++++++------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/parabot/core/ui/ReflectUI.java b/src/main/java/org/parabot/core/ui/ReflectUI.java index a35ba39..9475ce0 100644 --- a/src/main/java/org/parabot/core/ui/ReflectUI.java +++ b/src/main/java/org/parabot/core/ui/ReflectUI.java @@ -27,11 +27,11 @@ import java.util.HashMap; */ public class ReflectUI extends JFrame { private static final long serialVersionUID = 98565034137367257L; - private JTree tree; + private JTree tree; private DefaultMutableTreeNode root; - private DefaultTreeModel model; - private JEditorPane basicInfoPane; - private JEditorPane selectionInfoPane; + private DefaultTreeModel model; + private JEditorPane basicInfoPane; + private JEditorPane selectionInfoPane; private Object instance; @@ -82,7 +82,7 @@ public class ReflectUI extends JFrame { @Override public void actionPerformed(ActionEvent e) { RefField result = null; - String search = searchFunction.getText(); + String search = searchFunction.getText(); for (RefField f : fields.values()) { if (f != null && (f.asObject()) != null) { String value; @@ -137,9 +137,9 @@ public class ReflectUI extends JFrame { @Override public void valueChanged(TreeSelectionEvent event) { - TreePath path = event.getPath(); + TreePath path = event.getPath(); Object[] pathElements = path.getPath(); - Object element = pathElements[pathElements.length - 1]; + Object element = pathElements[pathElements.length - 1]; if (pathElements.length == 2) { setClassInfo(classes.get(element)); } else if (pathElements.length == 3) { @@ -179,7 +179,7 @@ public class ReflectUI extends JFrame { content.add(searchContent); JScrollPane contentPane = new JScrollPane(content); - Dimension prefSize = content.getPreferredSize(); + Dimension prefSize = content.getPreferredSize(); contentPane.setPreferredSize(new Dimension(prefSize.width + contentPane.getVerticalScrollBar().getPreferredSize().width, prefSize.height + contentPane.getHorizontalScrollBar().getPreferredSize().height)); setContentPane(contentPane); pack(); @@ -188,8 +188,8 @@ public class ReflectUI extends JFrame { } private void fillModel() { - Context context = Context.getInstance(); - ClassPath classPath = context.getClassPath(); + Context context = Context.getInstance(); + ClassPath classPath = context.getClassPath(); ASMClassLoader classLoader = context.getASMClassLoader(); for (String className : classPath.classNames) { try { @@ -219,7 +219,7 @@ public class ReflectUI extends JFrame { } private void fillBasicInfoPane() { - Context context = Context.getInstance(); + Context context = Context.getInstance(); ClassPath classPath = context.getClassPath(); StringBuilder builder = new StringBuilder(); @@ -231,8 +231,8 @@ public class ReflectUI extends JFrame { } private void setFieldInfo(RefField refField) { - StringBuilder builder = new StringBuilder(); - RefClass refClass = refField.getOwner(); + StringBuilder builder = new StringBuilder(); + RefClass refClass = refField.getOwner(); builder.append("

").append(refClass.getClassName()).append(".").append(refField.getName()).append("


"); builder.append("Class: ").append(refClass.getClassName()).append("
"); builder.append("Value: ").append(refField.asObject()).append("
"); @@ -240,11 +240,23 @@ public class ReflectUI extends JFrame { builder.append("Static: ").append(refField.isStatic() ? "yes" : "no").append("
"); builder.append("Array: ").append(refField.isArray() ? refField.getArrayDimensions() + " dimension(s)" : "no").append("
"); - if (refField.isArray() && refField.getASMType().getClassName().contains("String") && refField.getArrayDimensions() == 1) { - String[] strings = (String[]) refField.asObject(); - String values = StringUtils.implode(", ", strings); + if (refField.isArray()) { + if (refField.getArrayDimensions() == 1) { + if (refField.getASMType().getClassName().contains("int")) { + int[] ints = (int[]) refField.asObject(); + String values = ""; + for (int i = 0; i < ints.length; i++) { + values += (ints[i] + (i < ints.length - 1 ? ", " : "")); + } - builder.append("Values: ").append(values).append("
"); + builder.append("Values: ").append(values).append("
"); + } else if (refField.getASMType().getClassName().contains("String")) { + String[] strings = (String[]) refField.asObject(); + String values = StringUtils.implode(", ", strings); + + builder.append("Values: ").append(values).append("
"); + } + } } selectionInfoPane.setText(builder.toString()); From 384d1e4085b725efa137232bec24b64ed9970f6e Mon Sep 17 00:00:00 2001 From: Jeroen Ketelaar Date: Tue, 21 May 2019 23:52:50 -0500 Subject: [PATCH 3/5] [BUGFIX] Fixed deprecation warnings --- src/main/java/org/parabot/core/Core.java | 106 ++++++++++-------- .../core/asm/adapters/AddCallbackAdapter.java | 2 +- .../core/asm/adapters/AddDebugAdapter.java | 17 ++- .../core/asm/adapters/AddInvokerAdapter.java | 4 +- 4 files changed, 72 insertions(+), 57 deletions(-) diff --git a/src/main/java/org/parabot/core/Core.java b/src/main/java/org/parabot/core/Core.java index 0688108..c4cbef5 100644 --- a/src/main/java/org/parabot/core/Core.java +++ b/src/main/java/org/parabot/core/Core.java @@ -35,7 +35,7 @@ public class Core { private static boolean loadLocal; //Loads both local and public scripts/servers private static boolean validate = true; - private static boolean secure = true; + private static boolean secure = true; private static Version currentVersion = Configuration.BOT_VERSION; @@ -140,46 +140,13 @@ public class Core { } /** - * Checks the version of the bot using a checksum of the jar comparison against checksum given by the website + * Prints a debug line to the Logger and System PrintStream + * Meant for the debug adapter within hooks * - * @return true if no new version is found, otherwise false. + * @param line */ - private static boolean checksumValid() { - File f = new File(Landing.class.getProtectionDomain().getCodeSource().getLocation().getFile()); - if (f.isFile()) { - try { - MessageDigest md = MessageDigest.getInstance("MD5"); - File location = new File(Landing.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()); - if (location.exists()) { - FileInputStream fis = new FileInputStream(location); - byte[] dataBytes = new byte[1024]; - - int nread; - - while ((nread = fis.read(dataBytes)) != -1) { - md.update(dataBytes, 0, nread); - } - - byte[] mdbytes = md.digest(); - - StringBuilder sb = new StringBuilder(""); - for (byte mdbyte : mdbytes) { - sb.append(Integer.toString((mdbyte & 0xff) + 0x100, 16).substring(1)); - } - - String result; - if ((result = WebUtil.getContents(String.format(Configuration.COMPARE_CHECKSUM_URL, "client", currentVersion.get()), "checksum=" + URLEncoder.encode(sb.toString(), "UTF-8"))) != null) { - JSONObject object = (JSONObject) WebUtil.getJsonParser().parse(result); - boolean upToDate = (boolean) object.get("result"); - Core.verbose("Local checksum: " + URLEncoder.encode(sb.toString(), "UTF-8") + ". " + (upToDate ? "This matches BDN and is up to date." : "BDN mismatch, must be Out Of Date.")); - return upToDate; - } - } - } catch (NoSuchAlgorithmException | ParseException | IOException | URISyntaxException e) { - e.printStackTrace(); - } - } - return true; + public static void debug(final String line) { + System.out.println(line); } /** @@ -194,7 +161,7 @@ public class Core { try { if (br != null) { JSONObject object = (JSONObject) WebUtil.getJsonParser().parse(br); - boolean latest = (Boolean) object.get("result"); + boolean latest = (Boolean) object.get("result"); if (!latest) { Directories.clearCache(); } @@ -216,14 +183,6 @@ public class Core { return true; } - /** - * Method that removes the cache contents after 3 days - */ - private static void validateCache() { - // Already handled by Directories initiating - // Method will be used once BDN V3 has a functionality for this - } - public static void downloadNewVersion() { UILog.log(TranslationHelper.translate("UPDATES"), TranslationHelper.translate("DOWNLOAD_UPDATE_PARABOT_AT") @@ -268,4 +227,55 @@ public class Core { public static int newVersionAlert() { return UILog.alert("Parabot Update", "There's a new version of Parabot! \nDo you wish to download it?\n\nThe current version could have some problems!", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); } + + /** + * Checks the version of the bot using a checksum of the jar comparison against checksum given by the website + * + * @return true if no new version is found, otherwise false. + */ + private static boolean checksumValid() { + File f = new File(Landing.class.getProtectionDomain().getCodeSource().getLocation().getFile()); + if (f.isFile()) { + try { + MessageDigest md = MessageDigest.getInstance("MD5"); + File location = new File(Landing.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()); + if (location.exists()) { + FileInputStream fis = new FileInputStream(location); + byte[] dataBytes = new byte[1024]; + + int nread; + + while ((nread = fis.read(dataBytes)) != -1) { + md.update(dataBytes, 0, nread); + } + + byte[] mdbytes = md.digest(); + + StringBuilder sb = new StringBuilder(""); + for (byte mdbyte : mdbytes) { + sb.append(Integer.toString((mdbyte & 0xff) + 0x100, 16).substring(1)); + } + + String result; + if ((result = WebUtil.getContents(String.format(Configuration.COMPARE_CHECKSUM_URL, "client", currentVersion.get()), "checksum=" + URLEncoder.encode(sb.toString(), "UTF-8"))) != null) { + JSONObject object = (JSONObject) WebUtil.getJsonParser().parse(result); + boolean upToDate = (boolean) object.get("result"); + Core.verbose("Local checksum: " + URLEncoder.encode(sb.toString(), "UTF-8") + ". " + (upToDate ? "This matches BDN and is up to date." : "BDN mismatch, must be Out Of Date.")); + return upToDate; + } + } + } catch (NoSuchAlgorithmException | ParseException | IOException | URISyntaxException e) { + e.printStackTrace(); + } + } + return true; + } + + /** + * Method that removes the cache contents after 3 days + */ + private static void validateCache() { + // Already handled by Directories initiating + // Method will be used once BDN V3 has a functionality for this + } } \ No newline at end of file diff --git a/src/main/java/org/parabot/core/asm/adapters/AddCallbackAdapter.java b/src/main/java/org/parabot/core/asm/adapters/AddCallbackAdapter.java index 8b26227..3cc10f8 100644 --- a/src/main/java/org/parabot/core/asm/adapters/AddCallbackAdapter.java +++ b/src/main/java/org/parabot/core/asm/adapters/AddCallbackAdapter.java @@ -57,7 +57,7 @@ public class AddCallbackAdapter implements Injectable, Opcodes { } inject.add(new MethodInsnNode(INVOKESTATIC, this.invokeClass, this.invokeMethod, - this.desc)); + this.desc, false)); if (this.conditional) { LabelNode ln = new LabelNode(new Label()); inject.add(new JumpInsnNode(IFEQ, ln)); diff --git a/src/main/java/org/parabot/core/asm/adapters/AddDebugAdapter.java b/src/main/java/org/parabot/core/asm/adapters/AddDebugAdapter.java index e6c14f7..9fa7c17 100644 --- a/src/main/java/org/parabot/core/asm/adapters/AddDebugAdapter.java +++ b/src/main/java/org/parabot/core/asm/adapters/AddDebugAdapter.java @@ -5,7 +5,7 @@ import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.*; public class AddDebugAdapter { - private ClassNode owner; + private ClassNode owner; private MethodNode mn; public AddDebugAdapter(ClassNode owner, MethodNode mn) { @@ -19,14 +19,19 @@ public class AddDebugAdapter { public void inject() { InsnList inject = new InsnList(); - Label l0 = new Label(); + Label l0 = new Label(); inject.add(new LabelNode(l0)); - String callString = owner.name + "." + mn.name + " " + mn.desc; - LdcInsnNode ldc = new LdcInsnNode(callString); + String callString = owner.name + "." + mn.name + " " + mn.desc; + LdcInsnNode ldc = new LdcInsnNode(callString); - MethodInsnNode methodNode = new MethodInsnNode(Opcodes.INVOKESTATIC, "org/parabot/core/Core", "debug", - "(Ljava/lang/String;)V"); + MethodInsnNode methodNode = new MethodInsnNode( + Opcodes.INVOKESTATIC, + "org/parabot/core/Core", + "debug", + "(Ljava/lang/String;)V", + false + ); inject.add(ldc); inject.add(methodNode); diff --git a/src/main/java/org/parabot/core/asm/adapters/AddInvokerAdapter.java b/src/main/java/org/parabot/core/asm/adapters/AddInvokerAdapter.java index 74f5a54..d0fbf54 100644 --- a/src/main/java/org/parabot/core/asm/adapters/AddInvokerAdapter.java +++ b/src/main/java/org/parabot/core/asm/adapters/AddInvokerAdapter.java @@ -94,9 +94,9 @@ public class AddInvokerAdapter implements Opcodes, Injectable { } if (isInterface) { - m.visitMethodInsn(INVOKEINTERFACE, instanceCast, mName, mDesc); + m.visitMethodInsn(INVOKEINTERFACE, instanceCast, mName, mDesc, true); } else { - m.visitMethodInsn(isStatic ? INVOKESTATIC : INVOKEVIRTUAL, methodLocation.name, mn.name, mn.desc); + m.visitMethodInsn(isStatic ? INVOKESTATIC : INVOKEVIRTUAL, methodLocation.name, mn.name, mn.desc, false); } if (this.returnDesc.contains("L")) { if (!this.returnDesc.contains("[")) { From 2c97fd5177629343095386b465c2c833aea019a5 Mon Sep 17 00:00:00 2001 From: Jeroen Ketelaar Date: Wed, 22 May 2019 00:34:33 -0500 Subject: [PATCH 4/5] [TASK] Improved JavaScriptLoader To look further than just the main class --- .../parsers/scripts/LocalJavaScripts.java | 1 - .../scripts/loader/JavaScriptLoader.java | 50 +++++++++++++++++-- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/parabot/core/parsers/scripts/LocalJavaScripts.java b/src/main/java/org/parabot/core/parsers/scripts/LocalJavaScripts.java index 3374944..d34de1c 100644 --- a/src/main/java/org/parabot/core/parsers/scripts/LocalJavaScripts.java +++ b/src/main/java/org/parabot/core/parsers/scripts/LocalJavaScripts.java @@ -60,7 +60,6 @@ public class LocalJavaScripts extends ScriptParser { t.printStackTrace(); } } - } } diff --git a/src/main/java/org/parabot/environment/scripts/loader/JavaScriptLoader.java b/src/main/java/org/parabot/environment/scripts/loader/JavaScriptLoader.java index 4fd5466..5e37b82 100644 --- a/src/main/java/org/parabot/environment/scripts/loader/JavaScriptLoader.java +++ b/src/main/java/org/parabot/environment/scripts/loader/JavaScriptLoader.java @@ -11,7 +11,7 @@ import java.util.List; /** * An environment to load a script * - * @author Everel + * @author Everel, JKetelaar */ public class JavaScriptLoader extends ASMClassLoader { private ClassPath classPath; @@ -27,15 +27,55 @@ public class JavaScriptLoader extends ASMClassLoader { * @return string array of class names that extends ServerProvider */ public final String[] getScriptClassNames() { - final List classNames = new ArrayList(); + final List classNames = new ArrayList<>(); for (ClassNode c : classPath.classes.values()) { - if (c.superName.replace('/', '.').equals( - Script.class.getName())) { + if (isScriptClass(c)) { classNames.add(c.name.replace('/', '.')); + } else { + ClassNode superClass = findClassNodeForName(c.superName); + if (superClass != null && isScriptClass(superClass)) { + classNames.add(c.name.replace('/', '.')); + } } } - return classNames.toArray(new String[classNames.size()]); + + String[] classes = new String[classNames.size()]; + for (int i = 0; i < classNames.size(); i++) { + classes[i] = classNames.get(i); + } + + return classes; } + /** + * Checks if given ClassNode is Script class + * + * @param classNode + * + * @return + */ + private boolean isScriptClass(ClassNode classNode) { + return classNode + .superName + .replace('/', '.') + .equals(Script.class.getName()); + } + + /** + * Finds a ClassNode instance for a given class name + * + * @param name + * + * @return + */ + private ClassNode findClassNodeForName(String name) { + for (ClassNode classNode : classPath.classes.values()) { + if (classNode.name.equals(name)) { + return classNode; + } + } + + return null; + } } From ff5f02091980f9dd6cc53d45a6d33bde01ad0d8e Mon Sep 17 00:00:00 2001 From: Jeroen Ketelaar Date: Wed, 22 May 2019 14:06:19 +0200 Subject: [PATCH 5/5] Revert "[TASK] Improved JavaScriptLoader" This reverts commit 2c97fd5177629343095386b465c2c833aea019a5. --- .../parsers/scripts/LocalJavaScripts.java | 1 + .../scripts/loader/JavaScriptLoader.java | 50 ++----------------- 2 files changed, 6 insertions(+), 45 deletions(-) diff --git a/src/main/java/org/parabot/core/parsers/scripts/LocalJavaScripts.java b/src/main/java/org/parabot/core/parsers/scripts/LocalJavaScripts.java index d34de1c..3374944 100644 --- a/src/main/java/org/parabot/core/parsers/scripts/LocalJavaScripts.java +++ b/src/main/java/org/parabot/core/parsers/scripts/LocalJavaScripts.java @@ -60,6 +60,7 @@ public class LocalJavaScripts extends ScriptParser { t.printStackTrace(); } } + } } diff --git a/src/main/java/org/parabot/environment/scripts/loader/JavaScriptLoader.java b/src/main/java/org/parabot/environment/scripts/loader/JavaScriptLoader.java index 5e37b82..4fd5466 100644 --- a/src/main/java/org/parabot/environment/scripts/loader/JavaScriptLoader.java +++ b/src/main/java/org/parabot/environment/scripts/loader/JavaScriptLoader.java @@ -11,7 +11,7 @@ import java.util.List; /** * An environment to load a script * - * @author Everel, JKetelaar + * @author Everel */ public class JavaScriptLoader extends ASMClassLoader { private ClassPath classPath; @@ -27,55 +27,15 @@ public class JavaScriptLoader extends ASMClassLoader { * @return string array of class names that extends ServerProvider */ public final String[] getScriptClassNames() { - final List classNames = new ArrayList<>(); + final List classNames = new ArrayList(); for (ClassNode c : classPath.classes.values()) { - if (isScriptClass(c)) { + if (c.superName.replace('/', '.').equals( + Script.class.getName())) { classNames.add(c.name.replace('/', '.')); - } else { - ClassNode superClass = findClassNodeForName(c.superName); - if (superClass != null && isScriptClass(superClass)) { - classNames.add(c.name.replace('/', '.')); - } } } - - String[] classes = new String[classNames.size()]; - for (int i = 0; i < classNames.size(); i++) { - classes[i] = classNames.get(i); - } - - return classes; + return classNames.toArray(new String[classNames.size()]); } - /** - * Checks if given ClassNode is Script class - * - * @param classNode - * - * @return - */ - private boolean isScriptClass(ClassNode classNode) { - return classNode - .superName - .replace('/', '.') - .equals(Script.class.getName()); - } - - /** - * Finds a ClassNode instance for a given class name - * - * @param name - * - * @return - */ - private ClassNode findClassNodeForName(String name) { - for (ClassNode classNode : classPath.classes.values()) { - if (classNode.name.equals(name)) { - return classNode; - } - } - - return null; - } }