Merge branch 'master' of github.com:Parabot/Parabot

This commit is contained in:
JKetelaar
2015-05-03 18:36:50 +02:00
8 changed files with 113 additions and 27 deletions
+16 -2
View File
@@ -171,10 +171,24 @@ public class Context {
classPath.dump(new File(Directories.getWorkspace(), "dump.jar"));
Core.verbose("Done.");
}
gameApplet = serverProvider.fetchApplet();
if (getClient() == null) {
Applet applet = serverProvider.fetchApplet();
// 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);
}
Core.verbose("Applet fetched.");
final GamePanel panel = GamePanel.getInstance();
@@ -5,6 +5,7 @@ import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.ClassNode;
import org.parabot.core.classpath.ClassPath;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.AllPermission;
import java.security.CodeSource;
@@ -36,7 +37,12 @@ public class ASMClassLoader extends ClassLoader {
protected URL findResource(String name) {
if (getSystemResource(name) == null) {
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 {
return null;
}
@@ -5,6 +5,7 @@ import java.lang.reflect.Modifier;
import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.InsnNode;
import org.objectweb.asm.tree.JumpInsnNode;
@@ -67,10 +68,31 @@ public class AddCallbackAdapter implements Injectable, Opcodes {
if(this.conditional) {
LabelNode ln = new LabelNode(new Label());
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);
}
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;
import org.objectweb.asm.Label;
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.IntInsnNode;
import org.objectweb.asm.tree.LabelNode;
import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
public class AddDebugAdapter {
private ClassNode owner;
private MethodNode mn;
public AddDebugAdapter(ClassNode owner, MethodNode mn) {
this.owner = owner;
this.mn = mn;
}
public AddDebugAdapter(MethodNode mn) {
this.mn = mn;
}
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.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.zip.ZipEntry;
@@ -38,7 +40,7 @@ import org.parabot.core.ui.components.VerboseLoader;
public class ClassPath {
public final ArrayList<String> classNames;
public final HashMap<String, ClassNode> classes;
public final Map<String, URL> resources;
public final Map<String, File> resources;
public URL lastParsed;
private ClassRemapper classRemapper;
private boolean isJar;
@@ -53,7 +55,7 @@ public class ClassPath {
public ClassPath(final boolean isJar) {
this.classNames = new ArrayList<String>();
this.classes = new HashMap<String, ClassNode>();
this.resources = new HashMap<String, URL>();
this.resources = new HashMap<String, File>();
this.classRemapper = new ClassRemapper();
this.parseJar = true;
this.jarFiles = new ArrayList<URL>();
@@ -247,7 +249,7 @@ public class ClassPath {
out.write(buffer, 0, len);
} 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);
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();
stream.close();
} catch (Exception e) {
@@ -130,6 +130,9 @@ public class RefMethod extends RefModifiers {
throw new IllegalStateException(
"Can not invoke non static method without an instance.");
}
if(!isAccessible()) {
method.setAccessible(true);
}
try {
Object retObject = method.invoke(instance, args);
return retObject;
@@ -74,6 +74,7 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
JMenuItem proxy = new JMenuItem("Network");
JMenuItem randoms = new JMenuItem("Randoms");
JMenuItem dialog = new JCheckBoxMenuItem("Disable dialog");
JMenuItem logger = new JCheckBoxMenuItem("Logger");
if (!OperatingSystem.getOS().equals(OperatingSystem.WINDOWS)) {
dialog.setSelected(true);
@@ -97,6 +98,7 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
proxy.addActionListener(this);
randoms.addActionListener(this);
dialog.addActionListener(this);
logger.addActionListener(this);
explorer.addActionListener(this);
exit.addActionListener(this);
@@ -108,6 +110,7 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
file.add(proxy);
file.add(randoms);
file.add(dialog);
file.add(logger);
file.add(explorer);
file.add(exit);
@@ -164,6 +167,11 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
case "Stop":
setScriptState(Script.STATE_STOPPED);
break;
case "Logger":
Logger.getInstance().setVisible(!Logger.getInstance().isVisible());
BotUI.getInstance().pack();
BotUI.getInstance().revalidate();
break;
case "Disable dialog":
BotDialog.getInstance().setVisible(!dialog.isVisible());
break;
+21 -5
View File
@@ -1,16 +1,28 @@
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.ui.components.GamePanel;
import javax.swing.*;
import java.awt.*;
/**
* @author JKetelaar
*/
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 Logger(){
@@ -26,11 +38,15 @@ public class Logger extends JPanel {
list.setModel(model);
setPreferredSize(new Dimension((int) GamePanel.getInstance().getPreferredSize().getWidth(), 150));
model.addElement("Logger started");
setVisible(false);
}
private ListCellRenderer<? super String> getRenderer() {
return new DefaultListCellRenderer(){
@Override
private static final long serialVersionUID = -3589192791360628745L;
@Override
public Component getListCellRendererComponent(JList<?> list,
Object value, int index, boolean isSelected,
boolean cellHasFocus) {