Page 2 of 6 FirstFirst 1234 ... LastLast
Results 26 to 50 of 128

Thread: Java: How To Create Your Own Bot Interface

  1. #26
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by Shatterhand View Post
    How do you set up Keylistener or Keybindings for the applet?

    Keylistener doesnt work at all. When I add it to the applet, nothing happens when I fire an event. When I add it the the Frame, nothing happens when the focus is on the applet, even thought after setFocusable(false) on the applet or the ClientApplet.

    Keybindings only works with WHEN_IN_FOCUSED_WINDOW and when focus is on another JComponent. I tried playing with the focus (disabling, enabling, requesting) but I cant find the solution.

    This tutorial only went so far as creating a GUI and loading the applet. It did not go into creating an entire bot with colour grabbing and event listening.. I say @NKN; should write that tutorial.

    Also, why not look at Smart's source? Fairly easy to follow IMO. Or if Pulsebot is opensource, can always take a quick look at that.

    What @NKN; said is what you need to do. I did however, upload the source of an old client I made last year, this morning:

    KeyListener:
    https://github.com/Brandon-T/Acid-Lo...yListener.java

    All listeners:
    https://github.com/Brandon-T/Acid-Lo...rc/acid/events
    Last edited by Brandon; 01-02-2014 at 07:43 PM.
    I am Ggzz..
    Hackintosher

  2. #27
    Join Date
    Jan 2014
    Posts
    13
    Mentioned
    0 Post(s)
    Quoted
    6 Post(s)

    Default

    thanks, found this rather useful.

  3. #28
    Join Date
    Jul 2012
    Posts
    5
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Hey guys I know this code is specifically directed to Runescape, but could it be modified for other games, say Yahoo! Puzzle Pirates or would some basic aspects of the above need to be changed?

  4. #29
    Join Date
    Sep 2012
    Location
    Here.
    Posts
    2,007
    Mentioned
    88 Post(s)
    Quoted
    1014 Post(s)

    Default

    Quote Originally Posted by lii View Post
    Hey guys I know this code is specifically directed to Runescape, but could it be modified for other games, say Yahoo! Puzzle Pirates or would some basic aspects of the above need to be changed?
    Well, it should work for anything with an applet with some basic aspects (like location of applet) being changed. Also keep in mind this just lets you draw any other app within your own custom frame - it does not cover other details such as event listeners/color grabbing.

  5. #30
    Join Date
    Jul 2012
    Posts
    5
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    oh hmm and how about a Java client game not an applet? From reading thru the program again it seems to only work with applets, will the same concept work with client games or not? If not is there a tutorial for building a reflection client for a java client?

  6. #31
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    1,164
    Mentioned
    26 Post(s)
    Quoted
    433 Post(s)

  7. #32
    Join Date
    Jan 2012
    Posts
    1,104
    Mentioned
    18 Post(s)
    Quoted
    211 Post(s)

    Default

    Started working on my client again. Managed to make keylisteners work (screenshot button, replaced F keys).

    Now im trying to add reflection. I decided to get the player's name first as an example.

    I looked into the simba hooks and reflection functions. (http://osrreflection.googlecode.com/...re/Hooks.simba).

    Simba Code:
    function R_GetPlayerName: String;
    var
      _Player, _PlayerName: Integer;
    begin
      _Player := SmartGetFieldObject(SmartCurrentTarget, 0, client_player);
      _PlayerName := SmartGetFieldObject(SmartCurrentTarget, _Player, Player_name);
      Result := R_GetJavaString(_PlayerName, 512);
      SmartFreeObject(SmartCurrentTarget, _PlayerName);
      SmartFreeObject(SmartCurrentTarget, _Player);
    end;
    First it gets an object "client_player" (z.hs). Then it gets the object's field "Player_name" (b). So the full path is z.hs.b.
    I checked it with decompiler too:


    So first I tried to get z.hs with reflection. Failed. (java.lang.NoSuchFieldException: z.hs).

    Code:
    Class cls = client.getApplet().getClass();
    
    Field f = cls.getDeclaredField("z.hs");
    So then I tried to find z first, then find its field hs. Failed.
    Code:
    Class cls = client.getApplet().getClass();
    
    Field f = cls.getDeclaredField("z");
    f.setAccessible(true);
    Object o = f.get(cls);
    
    for (Field ff : o.getClass().getDeclaredFields()){
        ff.setAccessible(true);
        System.out.println("DeclaredField: " + ff.getName());
    
    }
    z's declared fields:
    Code:
    DeclaredField: MIN_VALUE
    DeclaredField: MAX_VALUE
    DeclaredField: TYPE
    DeclaredField: digits
    DeclaredField: DigitTens
    DeclaredField: DigitOnes
    DeclaredField: sizeTable
    DeclaredField: value
    DeclaredField: SIZE
    DeclaredField: serialVersionUID
    DeclaredField: $assertionsDisabled
    I am clueless now, can somebody help me please?

  8. #33
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by Shatterhand View Post
    I am clueless now, can somebody help me please?

    Java Code:
    ClassLoader loader = applet.getClassLoader();
    Field player = loader.loadClass("z").getDeclaredField("hs");
    player.setAccessible(true);

    Field name = loader.loadClass("x").getDeclaredField("b");
    name.setAccessible(true);

    System.out.println((String)name.get(player.get(null)));
    I am Ggzz..
    Hackintosher

  9. #34
    Join Date
    Jan 2012
    Posts
    1,104
    Mentioned
    18 Post(s)
    Quoted
    211 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    Java Code:
    ClassLoader loader = applet.getClassLoader();
    Field player = loader.loadClass("z").getDeclaredField("hs");
    player.setAccessible(true);

    Field name = loader.loadClass("x").getDeclaredField("b");
    name.setAccessible(true);

    System.out.println((String)name.get(player.get(null)));
    That makes sense now, thank you!

  10. #35
    Join Date
    Jun 2008
    Posts
    15
    Mentioned
    0 Post(s)
    Quoted
    11 Post(s)

    Default

    Quote Originally Posted by NKN View Post
    Alright cool. Trying to get it so you can run the jar file, and not have to use a .bat file.
    Hey, so you're not the only one attempting this. Did you ever come to finding a solution to overriding the canvas? I would be grateful if you lead me in the right direction to make this possible, thanks.

  11. #36
    Join Date
    Mar 2012
    Location
    127.0.0.1
    Posts
    3,383
    Mentioned
    95 Post(s)
    Quoted
    717 Post(s)

    Default

    Quote Originally Posted by computerichy View Post
    Hey, so you're not the only one attempting this. Did you ever come to finding a solution to overriding the canvas? I would be grateful if you lead me in the right direction to make this possible, thanks.
    Well I did it via injection.

    Analyzed the class through bytecode then changed the super of it to my custom canvas, instead of Java's canvas.

  12. #37
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by computerichy View Post
    Hey, so you're not the only one attempting this. Did you ever come to finding a solution to overriding the canvas? I would be grateful if you lead me in the right direction to make this possible, thanks.

    In my colour bot, I use this.. Add it to your project and make this the main class of your jar file (in the manifest). After doing that, change the one line below to the "Main" class that loads your bot.. The key to it is to have two mains. The first main will create a JVM instance that runs the second main. The first main will then die off after launching the second one unless you keep it communicating with the second one (in this case, there is no need to do that).

    This is the first main (similar to the one I actually use.. it will work):
    Java Code:
    package eos;

    import java.io.IOException;
    import java.net.URLDecoder;

    /**
     * Created by Brandon on 2014-06-28.
     */

    public class Bootloader {
        private static final String BOOT_FLAGS = "-Xbootclasspath/p:";


        public static void main(String[] args) throws IOException {

            String path = Bootloader.class.getProtectionDomain().getCodeSource().getLocation().getPath();
            path = URLDecoder.decode(path, "UTF-8").replaceAll("\\\\", "/");

            String mainName = Main.class.getCanonicalName();  //change this "Main" to your actual main class.

            StringBuilder commands = new StringBuilder();
            commands.append("javaw ").append(BOOT_FLAGS);
            commands.append('"').append("MyBot.jar").append('"'); //jar file containing your custom canvas..
            commands.append(" -cp ").append('"').append("MyBot.jar").append('"').append(' ').append(mainName);

            Runtime.getRuntime().exec(commands.toString());
        }
    }
    Last edited by Brandon; 07-01-2014 at 12:20 AM.
    I am Ggzz..
    Hackintosher

  13. #38
    Join Date
    Jan 2012
    Posts
    1,104
    Mentioned
    18 Post(s)
    Quoted
    211 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    In my colour bot, I use this.. Add it to your project and make this the main class of your jar file (in the manifest). After doing that, change the one line below to the "Main" class that loads your bot.. The key to it is to have two mains. The first main will create a JVM instance that runs the second main. The first main will then die off after launching the second one unless you keep it communicating with the second one (in this case, there is no need to do that).

    This is the first main (similar to the one I actually use.. it will work):
    Java Code:
    package eos;

    import java.io.IOException;
    import java.net.URLDecoder;

    /**
     * Created by Brandon on 2014-06-28.
     */

    public class Bootloader {
        private static final String BOOT_FLAGS = "-Xbootclasspath/p:";


        public static void main(String[] args) throws IOException {

            String path = Bootloader.class.getProtectionDomain().getCodeSource().getLocation().getPath();
            path = URLDecoder.decode(path, "UTF-8").replaceAll("\\\\", "/");

            String mainName = Main.class.getCanonicalName();  //change this "Main" to your actual main class.

            StringBuilder commands = new StringBuilder();
            commands.append("javaw ").append(BOOT_FLAGS);
            commands.append('"').append("MyBot.jar").append('"'); //jar file containing your custom canvas..
            commands.append(" -cp ").append('"').append("MyBot.jar").append('"').append(' ').append(mainName);

            Runtime.getRuntime().exec(commands.toString());
        }
    }
    This is exactly what I did too. Tricky.

    EDIT: The only problem with this so far is that I need to build it every time I want to run again.

  14. #39
    Join Date
    Jun 2008
    Posts
    15
    Mentioned
    0 Post(s)
    Quoted
    11 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    In my colour bot, I use this.. Add it to your project and make this the main class of your jar file (in the manifest). After doing that, change the one line below to the "Main" class that loads your bot.. The key to it is to have two mains. The first main will create a JVM instance that runs the second main. The first main will then die off after launching the second one unless you keep it communicating with the second one (in this case, there is no need to do that).

    This is the first main (similar to the one I actually use.. it will work):
    Java Code:
    package eos;

    import java.io.IOException;
    import java.net.URLDecoder;

    /**
     * Created by Brandon on 2014-06-28.
     */

    public class Bootloader {
        private static final String BOOT_FLAGS = "-Xbootclasspath/p:";


        public static void main(String[] args) throws IOException {

            String path = Bootloader.class.getProtectionDomain().getCodeSource().getLocation().getPath();
            path = URLDecoder.decode(path, "UTF-8").replaceAll("\\\\", "/");

            String mainName = Main.class.getCanonicalName();  //change this "Main" to your actual main class.

            StringBuilder commands = new StringBuilder();
            commands.append("javaw ").append(BOOT_FLAGS);
            commands.append('"').append("MyBot.jar").append('"'); //jar file containing your custom canvas..
            commands.append(" -cp ").append('"').append("MyBot.jar").append('"').append(' ').append(mainName);

            Runtime.getRuntime().exec(commands.toString());
        }
    }

    Thank you very much for your help Brandon and NKN, this is the concept I had to go about automatically passing arguments in runtime.
    I originally thought I would have to create an external jar bootloader which executed the interface with the arguments, but this makes it a whole lot better :P

    EDIT: With this bootloader intact, am I also able to load runtime libraries from a relative directory, e.g. '/lib' without causing conflicts?
    Last edited by computerichy; 07-03-2014 at 04:14 PM.

  15. #40
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by computerichy View Post
    Thank you very much for your help Brandon and NKN, this is the concept I had to go about automatically passing arguments in runtime.
    I originally thought I would have to create an external jar bootloader which executed the interface with the arguments, but this makes it a whole lot better :P

    EDIT: With this bootloader intact, am I also able to load runtime libraries from a relative directory, e.g. '/lib' without causing conflicts?
    It does not affect your jar. All it does is run the jar with the XBoot arguments as if you were to do it yourself via command line or batch. Your jar has to do the rest.


    Think of it like this:

    *User double clicks jar*
    Bootloader runs (JVM1 starts).
    *Bootloader creates a process/jvm instance and runs jar->Main (JVM2 starts)*
    jar->Main runs and shows the gui, loads the applet, does everything as it normally would
    *Bootloader stops running (JVM1 dies)*
    jar->Main continues to run as it normally would (JVM2 continues).

    All in all, you do everything like you normally would. Load your relative libraries, etc.. etc..


    Full example:


    Bootloader.java (DO NOT load your /lib files here.. Load them in any other file except this one):
    Java Code:
    package eos;

    import java.io.IOException;
    import java.net.URLDecoder;

    /**
     * Created by Brandon on 2014-06-28.
     */

    public class Bootloader {
        private static final String BOOT_FLAGS = "-Xbootclasspath/p:";


        public static void main(String[] args) throws IOException {

            String path = Bootloader.class.getProtectionDomain().getCodeSource().getLocation().getPath();
            path = URLDecoder.decode(path, "UTF-8").replaceAll("\\\\", "/");

            String mainName = Main.class.getCanonicalName();  //change this "Main" to your actual main class.

            StringBuilder commands = new StringBuilder();
            commands.append("javaw ").append(BOOT_FLAGS);
            commands.append('"').append("MyBot.jar").append('"'); //jar file containing your custom canvas..
            commands.append(" -cp ").append('"').append("MyBot.jar").append('"').append(' ').append(mainName);

            Runtime.getRuntime().exec(commands.toString());
        }
    }

    Main.java
    Java Code:
    package eos;

    import javafx.application.Platform;
    import javafx.embed.swing.JFXPanel;
    import javafx.fxml.FXMLLoader;
    import javafx.scene.Parent;
    import javafx.scene.Scene;

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.io.IOException;
    import java.net.URL;
    import java.net.URLClassLoader;
    import java.util.ResourceBundle;

    public class Main {

        void init(String world, int width, int height) throws IOException {
            Parent root = FXMLLoader.load(getClass().getResource("/Resources/Eos.fxml"), ResourceBundle.getBundle("Resources.Main"));

            JFrame frame = new JFrame("Eos");
            JFXPanel panel = new JFXPanel();
            panel.setScene(new Scene(root, 0, 0));

            root.getChildrenUnmodifiable().stream().filter(n -> n.getId().equals("toolBar")).forEach(n -> {
                new ClientApplet(frame, world, width, height, n); //add your applet to a frame. JFrame or SwingNode.. Either one..
            });
        }

        public static void main(String[] args) {
            new JFXPanel();
            Platform.runLater(() -> {
                try {
                    new Main().init("http://runescape.com", 800, 600);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });
        }
    }


    Then in the manifest it'd look like:

    Code Code:
    Manifest-Version: 1.0
    Main-Class: eos.Bootloader
    Boot-Class-Path: eos

    Notice that the manifest's loader is set to "BootLoader". This way, when the user double clicks the jar, bootloader is ran FIRST. THEN main is ran. Also notice that if you DO NOT want to use the BootLoader class then you can set "Boot-Class-Path" in the manifest itself. I haven't tested BootClassPath in manifest yet but it should work too. Currently I just use the BootLoader class.
    Last edited by Brandon; 07-03-2014 at 05:35 PM.
    I am Ggzz..
    Hackintosher

  16. #41
    Join Date
    Jun 2008
    Posts
    15
    Mentioned
    0 Post(s)
    Quoted
    11 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    It does not affect your jar. All it does is run the jar with the XBoot arguments as if you were to do it yourself via command line or batch. Your jar has to do the rest.


    Think of it like this:

    *User double clicks jar*
    Bootloader runs (JVM1 starts).
    *Bootloader creates a process/jvm instance and runs jar->Main (JVM2 starts)*
    jar->Main runs and shows the gui, loads the applet, does everything as it normally would
    *Bootloader stops running (JVM1 dies)*
    jar->Main continues to run as it normally would (JVM2 continues).

    All in all, you do everything like you normally would. Load your relative libraries, etc.. etc..


    Full example:


    Bootloader.java:
    Java Code:
    package eos;

    import java.io.IOException;
    import java.net.URLDecoder;

    /**
     * Created by Brandon on 2014-06-28.
     */

    public class Bootloader {
        private static final String BOOT_FLAGS = "-Xbootclasspath/p:";


        public static void main(String[] args) throws IOException {

            String path = Bootloader.class.getProtectionDomain().getCodeSource().getLocation().getPath();
            path = URLDecoder.decode(path, "UTF-8").replaceAll("\\\\", "/");

            String mainName = Main.class.getCanonicalName();  //change this "Main" to your actual main class.

            StringBuilder commands = new StringBuilder();
            commands.append("javaw ").append(BOOT_FLAGS);
            commands.append('"').append("MyBot.jar").append('"'); //jar file containing your custom canvas..
            commands.append(" -cp ").append('"').append("MyBot.jar").append('"').append(' ').append(mainName);

            Runtime.getRuntime().exec(commands.toString());
        }
    }

    Main.java
    Java Code:
    package eos;

    import javafx.application.Platform;
    import javafx.embed.swing.JFXPanel;
    import javafx.fxml.FXMLLoader;
    import javafx.scene.Parent;
    import javafx.scene.Scene;

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.io.IOException;
    import java.net.URL;
    import java.net.URLClassLoader;
    import java.util.ResourceBundle;

    public class Main {

        void init(String world, int width, int height) throws IOException {
            Parent root = FXMLLoader.load(getClass().getResource("/Resources/Eos.fxml"), ResourceBundle.getBundle("Resources.Main"));

            JFrame frame = new JFrame("Eos");
            JFXPanel panel = new JFXPanel();
            panel.setLayout(new BorderLayout(0, 0));
            panel.setScene(new Scene(root, 0, 0));
            frame.add(panel, BorderLayout.NORTH);
            frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            frame.setResizable(false);

            root.getChildrenUnmodifiable().stream().filter(n -> n.getId().equals("toolBar")).forEach(n -> {
                int menuWidth = (int)n.getBoundsInParent().getMinX() + (int)n.getBoundsInParent().getWidth();
                int menuHeight = (int)n.getBoundsInParent().getMinY() + (int)n.getBoundsInParent().getHeight();

                ClientApplet applet = new ClientApplet(world, width, height);
                applet.initializeListeners();

                panel.setPreferredSize(new Dimension(menuWidth, menuHeight));
                frame.add(applet, BorderLayout.CENTER);

                applet.start();
                frame.revalidate();
                frame.pack();

                frame.setMinimumSize(frame.getSize());
                frame.setVisible(true);
                frame.setResizable(true);

                frame.addWindowListener(new WindowAdapter() {
                    @Override
                    public void windowClosing(WindowEvent e) {
                        frame.setVisible(false);
                        applet.stop();
                    }
                });
            });
        }

        public static void main(String[] args) {
            new JFXPanel();
            Platform.runLater(() -> {
                try {
                    new Main().init("http://runescape.com", 800, 600);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });
        }
    }


    Then in the manifest it'd look like:

    Code Code:
    Manifest-Version: 1.0
    Main-Class: eos.Bootloader
    Boot-Class-Path: eos

    Notice that the manifest's loader is set to "BootLoader". This way, when the user double clicks the jar, bootloader is ran FIRST. THEN main is ran. Also notice that if you DO NOT want to use the BootLoader class then you can set "Boot-Class-Path" in the manifest itself. I haven't tested BootClassPath in manifest yet but it should work too. Currently I just use the BootLoader class.
    Alright, that just about clarifies everything I need to finish the core of the client. Thanks to your support, this is the progress I've made so far:


    Next up, the plugin -- and API -- system for the panel to the right.
    Attached Images Attached Images
    Last edited by computerichy; 07-07-2014 at 08:13 PM.

  17. #42
    Join Date
    Jun 2008
    Posts
    15
    Mentioned
    0 Post(s)
    Quoted
    11 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    In my colour bot, I use this.. Add it to your project and make this the main class of your jar file (in the manifest). After doing that, change the one line below to the "Main" class that loads your bot.. The key to it is to have two mains. The first main will create a JVM instance that runs the second main. The first main will then die off after launching the second one unless you keep it communicating with the second one (in this case, there is no need to do that).

    This is the first main (similar to the one I actually use.. it will work):
    Java Code:
    package eos;

    import java.io.IOException;
    import java.net.URLDecoder;

    /**
     * Created by Brandon on 2014-06-28.
     */

    public class Bootloader {
        private static final String BOOT_FLAGS = "-Xbootclasspath/p:";


        public static void main(String[] args) throws IOException {

            String path = Bootloader.class.getProtectionDomain().getCodeSource().getLocation().getPath();
            path = URLDecoder.decode(path, "UTF-8").replaceAll("\\\\", "/");

            String mainName = Main.class.getCanonicalName();  //change this "Main" to your actual main class.

            StringBuilder commands = new StringBuilder();
            commands.append("javaw ").append(BOOT_FLAGS);
            commands.append('"').append("MyBot.jar").append('"'); //jar file containing your custom canvas..
            commands.append(" -cp ").append('"').append("MyBot.jar").append('"').append(' ').append(mainName);

            Runtime.getRuntime().exec(commands.toString());
        }
    }
    Hmm, I've just discovered that this violates the Java's Runtime Environment binary code license; do you know of any alternative solutions to gaining the same effect of the overridden canvas?

    PS: It's not a bot that I intend to create, instead I am creating a legit, useful client

  18. #43
    Join Date
    Mar 2012
    Location
    127.0.0.1
    Posts
    3,383
    Mentioned
    95 Post(s)
    Quoted
    717 Post(s)

    Default

    Quote Originally Posted by computerichy View Post
    Hmm, I've just discovered that this violates the Java's Runtime Environment binary code license; do you know of any alternative solutions to gaining the same effect of the overridden canvas?

    PS: It's not a bot that I intend to create, instead I am creating a legit, useful client
    Not sure if this breaks it, but here we go.



    This is the class we replace, you can use your own or w/e.
    Java Code:
    package org.pulsebot.injection.generic;

    import org.pulsebot.loader.Client;
    import org.pulsebot.loader.utils.ClientPool;

    import javax.accessibility.AccessibleRole;
    import java.awt.*;
    import java.awt.image.BufferStrategy;
    import java.awt.peer.CanvasPeer;

    /**
     * @author SunJava
     * @author Modified by: JJ
     */

    public class RSCanvas extends Canvas {

        private static final String base = "canvas";
        private static int nameCounter = 0;
        private static final long serialVersionUID = -2284879212465893870L;

        private Client client = null;

        public RSCanvas() {
            super();
            System.out.println("[Canvas] constructor called!");
        }

        public RSCanvas(GraphicsConfiguration config) {
            this();
            setGraphicsConfiguration(config);
        }

        void setGraphicsConfiguration(GraphicsConfiguration gc) {
            synchronized (getTreeLock()) {
                CanvasPeer peer = (CanvasPeer) getPeer();
                if (peer != null) {
                    gc = peer.getAppropriateGraphicsConfiguration(gc);
                }
                setGraphicsConfiguration(gc);
            }
        }

        @Override
        public Graphics getGraphics() {
            if (client == null) {
                client = ClientPool.getClient(this);
            }

            if (client != null) {
                return client.drawGraphics((Graphics2D) super.getGraphics());
            }

            return super.getGraphics();
        }

        @Override
        public void setVisible(boolean b) {
            // TODO: Modify
            super.setVisible(b);
        }

        String constructComponentName() {
            synchronized (Canvas.class) {
                return base + nameCounter++;
            }
        }

        boolean postsOldMouseEvents() {
            return true;
        }

        public void createBufferStrategy(int numBuffers) {
            super.createBufferStrategy(numBuffers);
        }

        public void createBufferStrategy(int numBuffers, BufferCapabilities caps) throws AWTException {
            super.createBufferStrategy(numBuffers, caps);
        }

        public BufferStrategy getBufferStrategy() {
            return super.getBufferStrategy();
        }


        protected class AccessibleAWTCanvas extends AccessibleAWTComponent {
            private static final long serialVersionUID = -6325592262103146699L;

            /**
             * Get the role of this object.
             *
             * @return an instance of AccessibleRole describing the role of the
             *         object
             * @see AccessibleRole
             */

            public AccessibleRole getAccessibleRole() {
                return AccessibleRole.CANVAS;
            }

        }
    }



    This is what I wrote to detect the class and send the modification command.
    Java Code:
    package org.pulsebot.injection.impl;

    import org.objectweb.asm.tree.ClassNode;
    import org.pulsebot.injection.generic.AbstractAnalyser;
    import org.pulsebot.injection.utils.GenericUtils;

    /**
     * Created with IntelliJ IDEA.
     * User: NKN
     * Date: 6/2/13
     * Time: 12:40 PM
     */

    public class CanvasAnalyser extends AbstractAnalyser {

        @Override
        protected boolean canRun(ClassNode node) {
            if (node.superName.contains("Canvas"))
                return true;
            return false;
        }

        @Override
        protected String analyse(ClassNode node) {
            System.out.println("Canvas is: " + node.superName);
            GenericUtils.setSuper(node, "org/pulsebot/injection/generic/RSCanvas"); //Path to your canvas.
            System.out.println("Canvas is now: " + node.superName);
            System.out.println("Canvas successfully hacked.");
            return "Canvas";
        }

    }

    This is just what the prior class extends.

    Java Code:
    package org.pulsebot.injection.generic;

    import org.objectweb.asm.tree.ClassNode;

    /**
     * Created with IntelliJ IDEA.
     * User: Chris
     * Date: 3/1/13
     * Time: 11:28 PM
     * To change this template use File | Settings | File Templates.
     */

    public abstract class AbstractAnalyser {

        public String run(ClassNode node) {
            if (this.canRun(node))
                return this.analyse(node);
            return null;
        }

        protected abstract boolean canRun(ClassNode node);

        protected abstract String analyse(ClassNode node);
    }


    And this is the method that actually renames it.
    Java Code:
    public static void setSuper(ClassNode node, String superClass) {
            String replacedSuper = "";
            if (node.superName != "")
                replacedSuper = node.superName;
            if (replacedSuper != "") {
                ListIterator<?> mli = node.methods.listIterator();
                while (mli.hasNext()) {
                    MethodNode mn = (MethodNode) mli.next();
                    ListIterator<?> ili = mn.instructions.iterator();
                    while (ili.hasNext()) {
                        AbstractInsnNode ain = (AbstractInsnNode) ili.next();
                        if (ain.getOpcode() == Opcodes.INVOKESPECIAL) {
                            MethodInsnNode min = (MethodInsnNode) ain;
                            if (min.owner.equals(replacedSuper)) {
                                min.owner = superClass;
                            }
                        }
                    }
                }
            }
            node.superName = superClass;
        }



    So that's the injection way. Probably could be done better, but ah well.
    http://asm.ow2.org/download/index.html <--- Bytecode library, hook it up with your project

  19. #44
    Join Date
    Jun 2008
    Posts
    15
    Mentioned
    0 Post(s)
    Quoted
    11 Post(s)

    Default

    Quote Originally Posted by NKN View Post
    Not sure if this breaks it, but here we go.



    This is the class we replace, you can use your own or w/e.
    Java Code:
    package org.pulsebot.injection.generic;

    import org.pulsebot.loader.Client;
    import org.pulsebot.loader.utils.ClientPool;

    import javax.accessibility.AccessibleRole;
    import java.awt.*;
    import java.awt.image.BufferStrategy;
    import java.awt.peer.CanvasPeer;

    /**
     * @author SunJava
     * @author Modified by: JJ
     */

    public class RSCanvas extends Canvas {

        private static final String base = "canvas";
        private static int nameCounter = 0;
        private static final long serialVersionUID = -2284879212465893870L;

        private Client client = null;

        public RSCanvas() {
            super();
            System.out.println("[Canvas] constructor called!");
        }

        public RSCanvas(GraphicsConfiguration config) {
            this();
            setGraphicsConfiguration(config);
        }

        void setGraphicsConfiguration(GraphicsConfiguration gc) {
            synchronized (getTreeLock()) {
                CanvasPeer peer = (CanvasPeer) getPeer();
                if (peer != null) {
                    gc = peer.getAppropriateGraphicsConfiguration(gc);
                }
                setGraphicsConfiguration(gc);
            }
        }

        @Override
        public Graphics getGraphics() {
            if (client == null) {
                client = ClientPool.getClient(this);
            }

            if (client != null) {
                return client.drawGraphics((Graphics2D) super.getGraphics());
            }

            return super.getGraphics();
        }

        @Override
        public void setVisible(boolean b) {
            // TODO: Modify
            super.setVisible(b);
        }

        String constructComponentName() {
            synchronized (Canvas.class) {
                return base + nameCounter++;
            }
        }

        boolean postsOldMouseEvents() {
            return true;
        }

        public void createBufferStrategy(int numBuffers) {
            super.createBufferStrategy(numBuffers);
        }

        public void createBufferStrategy(int numBuffers, BufferCapabilities caps) throws AWTException {
            super.createBufferStrategy(numBuffers, caps);
        }

        public BufferStrategy getBufferStrategy() {
            return super.getBufferStrategy();
        }


        protected class AccessibleAWTCanvas extends AccessibleAWTComponent {
            private static final long serialVersionUID = -6325592262103146699L;

            /**
             * Get the role of this object.
             *
             * @return an instance of AccessibleRole describing the role of the
             *         object
             * @see AccessibleRole
             */

            public AccessibleRole getAccessibleRole() {
                return AccessibleRole.CANVAS;
            }

        }
    }



    This is what I wrote to detect the class and send the modification command.
    Java Code:
    package org.pulsebot.injection.impl;

    import org.objectweb.asm.tree.ClassNode;
    import org.pulsebot.injection.generic.AbstractAnalyser;
    import org.pulsebot.injection.utils.GenericUtils;

    /**
     * Created with IntelliJ IDEA.
     * User: NKN
     * Date: 6/2/13
     * Time: 12:40 PM
     */

    public class CanvasAnalyser extends AbstractAnalyser {

        @Override
        protected boolean canRun(ClassNode node) {
            if (node.superName.contains("Canvas"))
                return true;
            return false;
        }

        @Override
        protected String analyse(ClassNode node) {
            System.out.println("Canvas is: " + node.superName);
            GenericUtils.setSuper(node, "org/pulsebot/injection/generic/RSCanvas"); //Path to your canvas.
            System.out.println("Canvas is now: " + node.superName);
            System.out.println("Canvas successfully hacked.");
            return "Canvas";
        }

    }

    This is just what the prior class extends.

    Java Code:
    package org.pulsebot.injection.generic;

    import org.objectweb.asm.tree.ClassNode;

    /**
     * Created with IntelliJ IDEA.
     * User: Chris
     * Date: 3/1/13
     * Time: 11:28 PM
     * To change this template use File | Settings | File Templates.
     */

    public abstract class AbstractAnalyser {

        public String run(ClassNode node) {
            if (this.canRun(node))
                return this.analyse(node);
            return null;
        }

        protected abstract boolean canRun(ClassNode node);

        protected abstract String analyse(ClassNode node);
    }


    And this is the method that actually renames it.
    Java Code:
    public static void setSuper(ClassNode node, String superClass) {
            String replacedSuper = "";
            if (node.superName != "")
                replacedSuper = node.superName;
            if (replacedSuper != "") {
                ListIterator<?> mli = node.methods.listIterator();
                while (mli.hasNext()) {
                    MethodNode mn = (MethodNode) mli.next();
                    ListIterator<?> ili = mn.instructions.iterator();
                    while (ili.hasNext()) {
                        AbstractInsnNode ain = (AbstractInsnNode) ili.next();
                        if (ain.getOpcode() == Opcodes.INVOKESPECIAL) {
                            MethodInsnNode min = (MethodInsnNode) ain;
                            if (min.owner.equals(replacedSuper)) {
                                min.owner = superClass;
                            }
                        }
                    }
                }
            }
            node.superName = superClass;
        }



    So that's the injection way. Probably could be done better, but ah well.
    http://asm.ow2.org/download/index.html <--- Bytecode library, hook it up with your project

    Thanks, I'll look into this later and tell you how it goes. What do you think of the loader by the way?

  20. #45
    Join Date
    Jun 2008
    Posts
    15
    Mentioned
    0 Post(s)
    Quoted
    11 Post(s)

    Default

    @NKN; I have implemented the above, however I am not entirely sure how I go about calling the injection proccess (I'm assuming the analyser classes aren't automatically called). Is this some of the basic usage of ASM I am not familiar with? If so I am having difficulty finding suitable documentation/tutorials.

  21. #46
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by computerichy View Post
    @NKN; I have implemented the above, however I am not entirely sure how I go about calling the injection proccess (I'm assuming the analyser classes aren't automatically called). Is this some of the basic usage of ASM I am not familiar with? If so I am having difficulty finding suitable documentation/tutorials.
    Just remember that with both methods you'll be copying the java canvas so.. Either way, you'll be doing some sort of violation of terms. The only way is to use visitors and inject code into the official canvas.

    Again, SMART has been running with the method I mentioned for a long time now. Not sure what you're frightened of.
    I am Ggzz..
    Hackintosher

  22. #47
    Join Date
    Jun 2008
    Posts
    15
    Mentioned
    0 Post(s)
    Quoted
    11 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    Just remember that with both methods you'll be copying the java canvas so.. Either way, you'll be doing some sort of violation of terms. The only way is to use visitors and inject code into the official canvas.

    Again, SMART has been running with the method I mentioned for a long time now. Not sure what you're frightened of.
    Yes, I agree with what you're saying. I am happy to go forward with injecting the canvas. The initial reason I was concerned is because my intention is to create a legit client, avoiding any potential violations of laws/terms. I do doubt doing so causes any harm, and I'm happy to proceed with implementing the injector.

    Anyway, as I said previously, I'm very new to the concept of Java bytecode and the manipulation of it. I'm unsure how to call the above methods that @NKN; kindly posted, could you lead me in the right direction? I like to ensure I learn rather than copy-pasting and coming across problems in the future.

    Thanks.
    Last edited by computerichy; 09-15-2014 at 05:14 PM.

  23. #48
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by computerichy View Post
    Yes, I agree with what you're saying. I am happy to go forward with injecting the canvas. The initial reason I was concerned is because my intention is to create a legit client, avoiding any potential violations of laws/terms. I do doubt doing so causes any harm, and I'm happy to proceed with implementing the injector.

    Anyway, as I said previously, I'm very new to the concept of Java bytecode and the manipulation of it. I'm unsure how to call the above methods that @NKN; kindly posted, could you lead me in the right direction? I like to ensure I learn rather than copy-pasting and coming across problems in the future.

    Thanks.
    :S you're confusing me. What methods are you trying to call?

    NKN gave you an example of a canvas class that he injects into the client. SetSuper just sets the official canvas' super class to his.

    So now the RS canvas class inherits from his instead of the usual hierarchy. You call setSuper after loading the jar (not the applet). It means you need to read all the classes in the jar into classNodes and call analyser.canRun() on all of them. It will determine which class is the canvas and then you run setSuper on it to change the hierarchy.

    He did not give you the code to load the jar into classNodes and explain how to use the above. I assume he wants you to figure out how and learn how. If he did intend that, then you'd have to read the docs or check out his updater/bot's source.
    Last edited by Brandon; 09-15-2014 at 06:04 PM.
    I am Ggzz..
    Hackintosher

  24. #49
    Join Date
    Jun 2008
    Posts
    15
    Mentioned
    0 Post(s)
    Quoted
    11 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    :S you're confusing me. What methods are you trying to call?

    NKN gave you an example of a canvas class that he injects into the client. SetSuper just sets the official canvas' super class to his.

    So now the RS canvas class inherits from his instead of the usual hierarchy. You call setSuper after loading the jar (not the applet). It means you need to read all the classes in the jar into classNodes and call analyser.canRun() on all of them. It will determine which class is the canvas and then you run setSuper on it to change the hierarchy.

    He did not give you the code to load the jar into classNodes and explain how to use the above. I assume he wants you to figure out how and learn how. If he did intend that, then you'd have to read the docs or check out his updater/bot's source.
    Thank you for your quick response, these were the 2 ways of understanding I had in mind. I'm going to read the neccessary information from the docs and compare what I've learnt against NKN's source to make sure it's valid.

    Thanks.

  25. #50
    Join Date
    Jan 2012
    Posts
    1,104
    Mentioned
    18 Post(s)
    Quoted
    211 Post(s)

    Default

    Can anyone help me with JMenuBar?

    I tried adding the client JPanel to the frame or its contentpane too:
    Code:
    add(client.getLoader(), BorderLayout.CENTER);
    Code:
    getContentPane().add(client.getLoader(), BorderLayout.CENTER);
    But the menu would get behind the JPanel.



    EDIT: Solved. Applet and Canvas were AWT, heavy weight, and Swing is light weight, mixing these werent that good. This line solved it:
    menu.getPopupMenu().setLightWeightPopupEnabled(fal se);
    Last edited by Shatterhand; 10-12-2014 at 10:16 AM.

Page 2 of 6 FirstFirst 1234 ... LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •