mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-07 08:39:12 +00:00
Merge branch 'master' of github.com:Parabot/Parabot
This commit is contained in:
@@ -171,10 +171,24 @@ public class Context {
|
|||||||
classPath.dump(new File(Directories.getWorkspace(), "dump.jar"));
|
classPath.dump(new File(Directories.getWorkspace(), "dump.jar"));
|
||||||
Core.verbose("Done.");
|
Core.verbose("Done.");
|
||||||
}
|
}
|
||||||
gameApplet = serverProvider.fetchApplet();
|
Applet applet = serverProvider.fetchApplet();
|
||||||
if (getClient() == null) {
|
// if applet is null the server provider will call setApplet itself
|
||||||
|
if(applet != null) {
|
||||||
|
setApplet(applet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the bot target applet
|
||||||
|
* @param applet
|
||||||
|
*/
|
||||||
|
public void setApplet(final Applet applet) {
|
||||||
|
gameApplet = applet;
|
||||||
|
|
||||||
|
if (getClient() == null) {
|
||||||
setClientInstance(gameApplet);
|
setClientInstance(gameApplet);
|
||||||
}
|
}
|
||||||
|
|
||||||
Core.verbose("Applet fetched.");
|
Core.verbose("Applet fetched.");
|
||||||
|
|
||||||
final GamePanel panel = GamePanel.getInstance();
|
final GamePanel panel = GamePanel.getInstance();
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import org.objectweb.asm.ClassWriter;
|
|||||||
import org.objectweb.asm.tree.ClassNode;
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
import org.parabot.core.classpath.ClassPath;
|
import org.parabot.core.classpath.ClassPath;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.security.AllPermission;
|
import java.security.AllPermission;
|
||||||
import java.security.CodeSource;
|
import java.security.CodeSource;
|
||||||
@@ -36,7 +37,12 @@ public class ASMClassLoader extends ClassLoader {
|
|||||||
protected URL findResource(String name) {
|
protected URL findResource(String name) {
|
||||||
if (getSystemResource(name) == null) {
|
if (getSystemResource(name) == null) {
|
||||||
if (classPath.resources.containsKey(name)) {
|
if (classPath.resources.containsKey(name)) {
|
||||||
return classPath.resources.get(name);
|
try {
|
||||||
|
return classPath.resources.get(name).toURI().toURL();
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.lang.reflect.Modifier;
|
|||||||
import org.objectweb.asm.Label;
|
import org.objectweb.asm.Label;
|
||||||
import org.objectweb.asm.Opcodes;
|
import org.objectweb.asm.Opcodes;
|
||||||
import org.objectweb.asm.Type;
|
import org.objectweb.asm.Type;
|
||||||
|
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||||
import org.objectweb.asm.tree.InsnList;
|
import org.objectweb.asm.tree.InsnList;
|
||||||
import org.objectweb.asm.tree.InsnNode;
|
import org.objectweb.asm.tree.InsnNode;
|
||||||
import org.objectweb.asm.tree.JumpInsnNode;
|
import org.objectweb.asm.tree.JumpInsnNode;
|
||||||
@@ -67,10 +68,31 @@ public class AddCallbackAdapter implements Injectable, Opcodes {
|
|||||||
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));
|
||||||
inject.add(new InsnNode(RETURN));
|
if(Type.getReturnType(method.desc).equals(Type.BOOLEAN_TYPE)) {
|
||||||
|
inject.add(new InsnNode(ICONST_1));
|
||||||
|
inject.add(new InsnNode(IRETURN));
|
||||||
|
} else {
|
||||||
|
inject.add(new InsnNode(RETURN));
|
||||||
|
}
|
||||||
inject.add(ln);
|
inject.add(ln);
|
||||||
}
|
}
|
||||||
this.method.instructions.insert(inject);
|
|
||||||
|
if(method.name.startsWith("<") && !Modifier.isStatic(method.access)) {
|
||||||
|
// find target
|
||||||
|
AbstractInsnNode target = null;
|
||||||
|
for(AbstractInsnNode node : this.method.instructions.toArray()) {
|
||||||
|
if(node.getOpcode() == Opcodes.INVOKESPECIAL) {
|
||||||
|
target = node;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(target != null) {
|
||||||
|
this.method.instructions.insert(target, inject);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.method.instructions.insert(inject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,33 +1,43 @@
|
|||||||
package org.parabot.core.asm.adapters;
|
package org.parabot.core.asm.adapters;
|
||||||
|
|
||||||
|
import org.objectweb.asm.Label;
|
||||||
import org.objectweb.asm.Opcodes;
|
import org.objectweb.asm.Opcodes;
|
||||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
import org.objectweb.asm.tree.InsnList;
|
import org.objectweb.asm.tree.InsnList;
|
||||||
import org.objectweb.asm.tree.IntInsnNode;
|
import org.objectweb.asm.tree.LabelNode;
|
||||||
|
import org.objectweb.asm.tree.LdcInsnNode;
|
||||||
import org.objectweb.asm.tree.MethodInsnNode;
|
import org.objectweb.asm.tree.MethodInsnNode;
|
||||||
import org.objectweb.asm.tree.MethodNode;
|
import org.objectweb.asm.tree.MethodNode;
|
||||||
|
|
||||||
public class AddDebugAdapter {
|
public class AddDebugAdapter {
|
||||||
|
private ClassNode owner;
|
||||||
private MethodNode mn;
|
private MethodNode mn;
|
||||||
|
|
||||||
|
public AddDebugAdapter(ClassNode owner, MethodNode mn) {
|
||||||
|
this.owner = owner;
|
||||||
|
this.mn = mn;
|
||||||
|
}
|
||||||
|
|
||||||
public AddDebugAdapter(MethodNode mn) {
|
public AddDebugAdapter(MethodNode mn) {
|
||||||
this.mn = mn;
|
this.mn = mn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void inject() {
|
public void inject() {
|
||||||
|
InsnList inject = new InsnList();
|
||||||
|
Label l0 = new Label();
|
||||||
|
inject.add(new LabelNode(l0));
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
inject.add(ldc);
|
||||||
|
inject.add(methodNode);
|
||||||
|
|
||||||
|
mn.instructions.insert(inject);
|
||||||
|
|
||||||
int i = 20;
|
|
||||||
for(AbstractInsnNode node : mn.instructions.toArray().clone()) {
|
|
||||||
if(node.getType() == AbstractInsnNode.METHOD_INSN || node.getOpcode() == Opcodes.PUTFIELD || node.getOpcode() == Opcodes.ASTORE || node.getOpcode() == Opcodes.ISTORE) {
|
|
||||||
i++;
|
|
||||||
InsnList inject = new InsnList();
|
|
||||||
inject.add(new IntInsnNode(Opcodes.BIPUSH, i));
|
|
||||||
inject.add(new MethodInsnNode(Opcodes.INVOKESTATIC,
|
|
||||||
"org/parabot/core/Core", "debug",
|
|
||||||
"(I)V"));
|
|
||||||
mn.instructions.insertBefore(node.getNext(), inject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,9 +10,11 @@ import java.io.OutputStream;
|
|||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarOutputStream;
|
import java.util.jar.JarOutputStream;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
@@ -38,7 +40,7 @@ import org.parabot.core.ui.components.VerboseLoader;
|
|||||||
public class ClassPath {
|
public class ClassPath {
|
||||||
public final ArrayList<String> classNames;
|
public final ArrayList<String> classNames;
|
||||||
public final HashMap<String, ClassNode> classes;
|
public final HashMap<String, ClassNode> classes;
|
||||||
public final Map<String, URL> resources;
|
public final Map<String, File> resources;
|
||||||
public URL lastParsed;
|
public URL lastParsed;
|
||||||
private ClassRemapper classRemapper;
|
private ClassRemapper classRemapper;
|
||||||
private boolean isJar;
|
private boolean isJar;
|
||||||
@@ -53,7 +55,7 @@ public class ClassPath {
|
|||||||
public ClassPath(final boolean isJar) {
|
public ClassPath(final boolean isJar) {
|
||||||
this.classNames = new ArrayList<String>();
|
this.classNames = new ArrayList<String>();
|
||||||
this.classes = new HashMap<String, ClassNode>();
|
this.classes = new HashMap<String, ClassNode>();
|
||||||
this.resources = new HashMap<String, URL>();
|
this.resources = new HashMap<String, File>();
|
||||||
this.classRemapper = new ClassRemapper();
|
this.classRemapper = new ClassRemapper();
|
||||||
this.parseJar = true;
|
this.parseJar = true;
|
||||||
this.jarFiles = new ArrayList<URL>();
|
this.jarFiles = new ArrayList<URL>();
|
||||||
@@ -247,7 +249,7 @@ public class ClassPath {
|
|||||||
out.write(buffer, 0, len);
|
out.write(buffer, 0, len);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
this.resources.put(name, f.toURI().toURL());
|
this.resources.put(name, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -293,6 +295,11 @@ public class ClassPath {
|
|||||||
cn.accept(cw);
|
cn.accept(cw);
|
||||||
out.write(cw.toByteArray());
|
out.write(cw.toByteArray());
|
||||||
}
|
}
|
||||||
|
for(Entry<String, File> entry : this.resources.entrySet()) {
|
||||||
|
JarEntry je = new JarEntry(entry.getKey());
|
||||||
|
out.putNextEntry(je);
|
||||||
|
out.write(Files.readAllBytes(entry.getValue().toPath()));
|
||||||
|
}
|
||||||
out.close();
|
out.close();
|
||||||
stream.close();
|
stream.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -130,6 +130,9 @@ public class RefMethod extends RefModifiers {
|
|||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"Can not invoke non static method without an instance.");
|
"Can not invoke non static method without an instance.");
|
||||||
}
|
}
|
||||||
|
if(!isAccessible()) {
|
||||||
|
method.setAccessible(true);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
Object retObject = method.invoke(instance, args);
|
Object retObject = method.invoke(instance, args);
|
||||||
return retObject;
|
return retObject;
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
|||||||
JMenuItem proxy = new JMenuItem("Network");
|
JMenuItem proxy = new JMenuItem("Network");
|
||||||
JMenuItem randoms = new JMenuItem("Randoms");
|
JMenuItem randoms = new JMenuItem("Randoms");
|
||||||
JMenuItem dialog = new JCheckBoxMenuItem("Disable dialog");
|
JMenuItem dialog = new JCheckBoxMenuItem("Disable dialog");
|
||||||
|
JMenuItem logger = new JCheckBoxMenuItem("Logger");
|
||||||
|
|
||||||
if (!OperatingSystem.getOS().equals(OperatingSystem.WINDOWS)) {
|
if (!OperatingSystem.getOS().equals(OperatingSystem.WINDOWS)) {
|
||||||
dialog.setSelected(true);
|
dialog.setSelected(true);
|
||||||
@@ -97,6 +98,7 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
|||||||
proxy.addActionListener(this);
|
proxy.addActionListener(this);
|
||||||
randoms.addActionListener(this);
|
randoms.addActionListener(this);
|
||||||
dialog.addActionListener(this);
|
dialog.addActionListener(this);
|
||||||
|
logger.addActionListener(this);
|
||||||
explorer.addActionListener(this);
|
explorer.addActionListener(this);
|
||||||
exit.addActionListener(this);
|
exit.addActionListener(this);
|
||||||
|
|
||||||
@@ -108,6 +110,7 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
|||||||
file.add(proxy);
|
file.add(proxy);
|
||||||
file.add(randoms);
|
file.add(randoms);
|
||||||
file.add(dialog);
|
file.add(dialog);
|
||||||
|
file.add(logger);
|
||||||
file.add(explorer);
|
file.add(explorer);
|
||||||
file.add(exit);
|
file.add(exit);
|
||||||
|
|
||||||
@@ -164,6 +167,11 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
|||||||
case "Stop":
|
case "Stop":
|
||||||
setScriptState(Script.STATE_STOPPED);
|
setScriptState(Script.STATE_STOPPED);
|
||||||
break;
|
break;
|
||||||
|
case "Logger":
|
||||||
|
Logger.getInstance().setVisible(!Logger.getInstance().isVisible());
|
||||||
|
BotUI.getInstance().pack();
|
||||||
|
BotUI.getInstance().revalidate();
|
||||||
|
break;
|
||||||
case "Disable dialog":
|
case "Disable dialog":
|
||||||
BotDialog.getInstance().setVisible(!dialog.isVisible());
|
BotDialog.getInstance().setVisible(!dialog.isVisible());
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1,16 +1,28 @@
|
|||||||
package org.parabot.core.ui;
|
package org.parabot.core.ui;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
|
import javax.swing.DefaultListCellRenderer;
|
||||||
|
import javax.swing.DefaultListModel;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JList;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.ListCellRenderer;
|
||||||
|
|
||||||
import org.parabot.core.Context;
|
import org.parabot.core.Context;
|
||||||
import org.parabot.core.ui.components.GamePanel;
|
import org.parabot.core.ui.components.GamePanel;
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author JKetelaar
|
* @author JKetelaar
|
||||||
*/
|
*/
|
||||||
public class Logger extends JPanel {
|
public class Logger extends JPanel {
|
||||||
private static Logger instance;
|
private static final long serialVersionUID = 1L;
|
||||||
|
private static Logger instance;
|
||||||
private final DefaultListModel<String> model;
|
private final DefaultListModel<String> model;
|
||||||
|
|
||||||
private Logger(){
|
private Logger(){
|
||||||
@@ -26,11 +38,15 @@ public class Logger extends JPanel {
|
|||||||
list.setModel(model);
|
list.setModel(model);
|
||||||
setPreferredSize(new Dimension((int) GamePanel.getInstance().getPreferredSize().getWidth(), 150));
|
setPreferredSize(new Dimension((int) GamePanel.getInstance().getPreferredSize().getWidth(), 150));
|
||||||
model.addElement("Logger started");
|
model.addElement("Logger started");
|
||||||
|
|
||||||
|
setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ListCellRenderer<? super String> getRenderer() {
|
private ListCellRenderer<? super String> getRenderer() {
|
||||||
return new DefaultListCellRenderer(){
|
return new DefaultListCellRenderer(){
|
||||||
@Override
|
private static final long serialVersionUID = -3589192791360628745L;
|
||||||
|
|
||||||
|
@Override
|
||||||
public Component getListCellRendererComponent(JList<?> list,
|
public Component getListCellRendererComponent(JList<?> list,
|
||||||
Object value, int index, boolean isSelected,
|
Object value, int index, boolean isSelected,
|
||||||
boolean cellHasFocus) {
|
boolean cellHasFocus) {
|
||||||
|
|||||||
Reference in New Issue
Block a user