mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-03 00:37:55 +00:00
Merge branch 'development' into feature/error-reporting
This commit is contained in:
@@ -35,7 +35,7 @@ public class Core {
|
|||||||
private static boolean loadLocal; //Loads both local and public scripts/servers
|
private static boolean loadLocal; //Loads both local and public scripts/servers
|
||||||
|
|
||||||
private static boolean validate = true;
|
private static boolean validate = true;
|
||||||
private static boolean secure = true;
|
private static boolean secure = true;
|
||||||
|
|
||||||
private static Version currentVersion = Configuration.BOT_VERSION;
|
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 <b>true</b> if no new version is found, otherwise <b>false</b>.
|
* @param line
|
||||||
*/
|
*/
|
||||||
private static boolean checksumValid() {
|
public static void debug(final String line) {
|
||||||
File f = new File(Landing.class.getProtectionDomain().getCodeSource().getLocation().getFile());
|
System.out.println(line);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -194,7 +161,7 @@ public class Core {
|
|||||||
try {
|
try {
|
||||||
if (br != null) {
|
if (br != null) {
|
||||||
JSONObject object = (JSONObject) WebUtil.getJsonParser().parse(br);
|
JSONObject object = (JSONObject) WebUtil.getJsonParser().parse(br);
|
||||||
boolean latest = (Boolean) object.get("result");
|
boolean latest = (Boolean) object.get("result");
|
||||||
if (!latest) {
|
if (!latest) {
|
||||||
Directories.clearCache();
|
Directories.clearCache();
|
||||||
}
|
}
|
||||||
@@ -216,14 +183,6 @@ public class Core {
|
|||||||
return true;
|
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() {
|
public static void downloadNewVersion() {
|
||||||
UILog.log(TranslationHelper.translate("UPDATES"),
|
UILog.log(TranslationHelper.translate("UPDATES"),
|
||||||
TranslationHelper.translate("DOWNLOAD_UPDATE_PARABOT_AT")
|
TranslationHelper.translate("DOWNLOAD_UPDATE_PARABOT_AT")
|
||||||
@@ -268,4 +227,55 @@ public class Core {
|
|||||||
public static int newVersionAlert() {
|
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);
|
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 <b>true</b> if no new version is found, otherwise <b>false</b>.
|
||||||
|
*/
|
||||||
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -57,7 +57,7 @@ public class AddCallbackAdapter implements Injectable, Opcodes {
|
|||||||
}
|
}
|
||||||
inject.add(new MethodInsnNode(INVOKESTATIC,
|
inject.add(new MethodInsnNode(INVOKESTATIC,
|
||||||
this.invokeClass, this.invokeMethod,
|
this.invokeClass, this.invokeMethod,
|
||||||
this.desc));
|
this.desc, false));
|
||||||
if (this.conditional) {
|
if (this.conditional) {
|
||||||
LabelNode ln = new LabelNode(new Label());
|
LabelNode ln = new LabelNode(new Label());
|
||||||
inject.add(new JumpInsnNode(IFEQ, ln));
|
inject.add(new JumpInsnNode(IFEQ, ln));
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import org.objectweb.asm.Opcodes;
|
|||||||
import org.objectweb.asm.tree.*;
|
import org.objectweb.asm.tree.*;
|
||||||
|
|
||||||
public class AddDebugAdapter {
|
public class AddDebugAdapter {
|
||||||
private ClassNode owner;
|
private ClassNode owner;
|
||||||
private MethodNode mn;
|
private MethodNode mn;
|
||||||
|
|
||||||
public AddDebugAdapter(ClassNode owner, MethodNode mn) {
|
public AddDebugAdapter(ClassNode owner, MethodNode mn) {
|
||||||
@@ -19,14 +19,19 @@ public class AddDebugAdapter {
|
|||||||
|
|
||||||
public void inject() {
|
public void inject() {
|
||||||
InsnList inject = new InsnList();
|
InsnList inject = new InsnList();
|
||||||
Label l0 = new Label();
|
Label l0 = new Label();
|
||||||
inject.add(new LabelNode(l0));
|
inject.add(new LabelNode(l0));
|
||||||
|
|
||||||
String callString = owner.name + "." + mn.name + " " + mn.desc;
|
String callString = owner.name + "." + mn.name + " " + mn.desc;
|
||||||
LdcInsnNode ldc = new LdcInsnNode(callString);
|
LdcInsnNode ldc = new LdcInsnNode(callString);
|
||||||
|
|
||||||
MethodInsnNode methodNode = new MethodInsnNode(Opcodes.INVOKESTATIC, "org/parabot/core/Core", "debug",
|
MethodInsnNode methodNode = new MethodInsnNode(
|
||||||
"(Ljava/lang/String;)V");
|
Opcodes.INVOKESTATIC,
|
||||||
|
"org/parabot/core/Core",
|
||||||
|
"debug",
|
||||||
|
"(Ljava/lang/String;)V",
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
inject.add(ldc);
|
inject.add(ldc);
|
||||||
inject.add(methodNode);
|
inject.add(methodNode);
|
||||||
|
|||||||
@@ -94,9 +94,9 @@ public class AddInvokerAdapter implements Opcodes, Injectable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isInterface) {
|
if (isInterface) {
|
||||||
m.visitMethodInsn(INVOKEINTERFACE, instanceCast, mName, mDesc);
|
m.visitMethodInsn(INVOKEINTERFACE, instanceCast, mName, mDesc, true);
|
||||||
} else {
|
} 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("L")) {
|
||||||
if (!this.returnDesc.contains("[")) {
|
if (!this.returnDesc.contains("[")) {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public class SystemRedirect {
|
|||||||
|
|
||||||
public static PrintStream out = System.out;
|
public static PrintStream out = System.out;
|
||||||
public static PrintStream err = System.err;
|
public static PrintStream err = System.err;
|
||||||
public static InputStream in = System.in;
|
public static InputStream in = System.in;
|
||||||
|
|
||||||
public static long currentTimeMillis() {
|
public static long currentTimeMillis() {
|
||||||
return System.currentTimeMillis();
|
return System.currentTimeMillis();
|
||||||
@@ -23,11 +23,23 @@ public class SystemRedirect {
|
|||||||
System.exit(i);
|
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) {
|
public static String getProperty(String s) {
|
||||||
String value;
|
String value;
|
||||||
switch (s) {
|
switch (s) {
|
||||||
case "java.class.path":
|
case "java.class.path":
|
||||||
value = ".";
|
value = getClassPath();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
value = System.getProperty(s);
|
value = System.getProperty(s);
|
||||||
@@ -42,14 +54,14 @@ public class SystemRedirect {
|
|||||||
String value = null;
|
String value = null;
|
||||||
switch (s2) {
|
switch (s2) {
|
||||||
case "java.class.path":
|
case "java.class.path":
|
||||||
value = ".";
|
value = getClassPath();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
switch (s) {
|
switch (s) {
|
||||||
case "java.class.path":
|
case "java.class.path":
|
||||||
value = ".";
|
value = getClassPath();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
value = System.getProperty(s);
|
value = System.getProperty(s);
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ import java.util.HashMap;
|
|||||||
*/
|
*/
|
||||||
public class ReflectUI extends JFrame {
|
public class ReflectUI extends JFrame {
|
||||||
private static final long serialVersionUID = 98565034137367257L;
|
private static final long serialVersionUID = 98565034137367257L;
|
||||||
private JTree tree;
|
private JTree tree;
|
||||||
private DefaultMutableTreeNode root;
|
private DefaultMutableTreeNode root;
|
||||||
private DefaultTreeModel model;
|
private DefaultTreeModel model;
|
||||||
private JEditorPane basicInfoPane;
|
private JEditorPane basicInfoPane;
|
||||||
private JEditorPane selectionInfoPane;
|
private JEditorPane selectionInfoPane;
|
||||||
|
|
||||||
private Object instance;
|
private Object instance;
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ public class ReflectUI extends JFrame {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
RefField result = null;
|
RefField result = null;
|
||||||
String search = searchFunction.getText();
|
String search = searchFunction.getText();
|
||||||
for (RefField f : fields.values()) {
|
for (RefField f : fields.values()) {
|
||||||
if (f != null && (f.asObject()) != null) {
|
if (f != null && (f.asObject()) != null) {
|
||||||
String value;
|
String value;
|
||||||
@@ -137,9 +137,9 @@ public class ReflectUI extends JFrame {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void valueChanged(TreeSelectionEvent event) {
|
public void valueChanged(TreeSelectionEvent event) {
|
||||||
TreePath path = event.getPath();
|
TreePath path = event.getPath();
|
||||||
Object[] pathElements = path.getPath();
|
Object[] pathElements = path.getPath();
|
||||||
Object element = pathElements[pathElements.length - 1];
|
Object element = pathElements[pathElements.length - 1];
|
||||||
if (pathElements.length == 2) {
|
if (pathElements.length == 2) {
|
||||||
setClassInfo(classes.get(element));
|
setClassInfo(classes.get(element));
|
||||||
} else if (pathElements.length == 3) {
|
} else if (pathElements.length == 3) {
|
||||||
@@ -179,7 +179,7 @@ public class ReflectUI extends JFrame {
|
|||||||
content.add(searchContent);
|
content.add(searchContent);
|
||||||
|
|
||||||
JScrollPane contentPane = new JScrollPane(content);
|
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));
|
contentPane.setPreferredSize(new Dimension(prefSize.width + contentPane.getVerticalScrollBar().getPreferredSize().width, prefSize.height + contentPane.getHorizontalScrollBar().getPreferredSize().height));
|
||||||
setContentPane(contentPane);
|
setContentPane(contentPane);
|
||||||
pack();
|
pack();
|
||||||
@@ -188,8 +188,8 @@ public class ReflectUI extends JFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void fillModel() {
|
private void fillModel() {
|
||||||
Context context = Context.getInstance();
|
Context context = Context.getInstance();
|
||||||
ClassPath classPath = context.getClassPath();
|
ClassPath classPath = context.getClassPath();
|
||||||
ASMClassLoader classLoader = context.getASMClassLoader();
|
ASMClassLoader classLoader = context.getASMClassLoader();
|
||||||
for (String className : classPath.classNames) {
|
for (String className : classPath.classNames) {
|
||||||
try {
|
try {
|
||||||
@@ -219,7 +219,7 @@ public class ReflectUI extends JFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void fillBasicInfoPane() {
|
private void fillBasicInfoPane() {
|
||||||
Context context = Context.getInstance();
|
Context context = Context.getInstance();
|
||||||
ClassPath classPath = context.getClassPath();
|
ClassPath classPath = context.getClassPath();
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
@@ -231,8 +231,8 @@ public class ReflectUI extends JFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setFieldInfo(RefField refField) {
|
private void setFieldInfo(RefField refField) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
RefClass refClass = refField.getOwner();
|
RefClass refClass = refField.getOwner();
|
||||||
builder.append("<h1>").append(refClass.getClassName()).append(".").append(refField.getName()).append("</h1><br/>");
|
builder.append("<h1>").append(refClass.getClassName()).append(".").append(refField.getName()).append("</h1><br/>");
|
||||||
builder.append("<b>Class: </b>").append(refClass.getClassName()).append("<br/>");
|
builder.append("<b>Class: </b>").append(refClass.getClassName()).append("<br/>");
|
||||||
builder.append("<b>Value: </b>").append(refField.asObject()).append("<br/>");
|
builder.append("<b>Value: </b>").append(refField.asObject()).append("<br/>");
|
||||||
@@ -240,11 +240,23 @@ public class ReflectUI extends JFrame {
|
|||||||
builder.append("<b>Static: </b>").append(refField.isStatic() ? "yes" : "no").append("<br/>");
|
builder.append("<b>Static: </b>").append(refField.isStatic() ? "yes" : "no").append("<br/>");
|
||||||
builder.append("<b>Array: </b>").append(refField.isArray() ? refField.getArrayDimensions() + " dimension(s)" : "no").append("<br/>");
|
builder.append("<b>Array: </b>").append(refField.isArray() ? refField.getArrayDimensions() + " dimension(s)" : "no").append("<br/>");
|
||||||
|
|
||||||
if (refField.isArray() && refField.getASMType().getClassName().contains("String") && refField.getArrayDimensions() == 1) {
|
if (refField.isArray()) {
|
||||||
String[] strings = (String[]) refField.asObject();
|
if (refField.getArrayDimensions() == 1) {
|
||||||
String values = StringUtils.implode(", ", strings);
|
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("<b>Values: </b>").append(values).append("<br/>");
|
builder.append("<b>Values: </b>").append(values).append("<br/>");
|
||||||
|
} else if (refField.getASMType().getClassName().contains("String")) {
|
||||||
|
String[] strings = (String[]) refField.asObject();
|
||||||
|
String values = StringUtils.implode(", ", strings);
|
||||||
|
|
||||||
|
builder.append("<b>Values: </b>").append(values).append("<br/>");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
selectionInfoPane.setText(builder.toString());
|
selectionInfoPane.setText(builder.toString());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user