Jump to content

  • Log in with Facebook Log in with Twitter Log In with Google Sign In
  • Create Account




Photo

[Mini Tut] How to write your own bot


This topic has been archived. This means that you cannot reply to this topic.
29 replies to this topic

#1
trDna

trDna
  • Scholars
  • 1713 posts
  • Joined 18 June 12
  • LocationCanada
This is intended to be a short summary on how people create their own bots (not scripts). It may not be the best tutorial, but I hope to give people an idea of how to make them.
Note: If you wish to use ASM, then feel free to look at my repo.
http://www.powerbot.org/community/topic/812449-asm-experimentationsamples-repository/

Requirements
  • Knowledge of basic Java
  • An IDE of your choice.
  • Basic knowledge of BCEL or ASM (will provide links below).
  • Common sense
  • Knowing how to use Google
  • Patience
  • The ability to cope with legal issues if you plan to hack Jagex's RS client.
Tips
  • First off, I do not recommend hacking into the official RS client.
  • If you plan to create the bot quickly, then I suggest you hack into an RS private server client. They usually have most things de-obfuscated and therefore, it's easier to grab the data you will need.
  • Only grab the data that you will need for your scripts for your bot.
Steps
Go through all of these links. It will teach you how to start to make a bot from scratch using BCEL (can't find any detailed ASM tutorials).
Make sure that you download the external JARs for BCEL and ASM and add it as external JARs for your bot project folder.

Credits: Freddy of rs-hacking.com

You will need to make an account there to view these links. I'm going to post his tutorial threads in order.Alternatively, you can also go to rs-hacking.com, login to their site, and go Reflection/Injection -> Tutorials & FAQ

I'll be explaining how to continue this in BCEL.
Here is a sample injector that I've found using Google.
I could of just posted my own, but I'm trying to prove that Google can be your best friend.

Credits to Echo_ at villavu.com (Simba's community):
import org.apache.*;
import org.apache.bcel.*;
import org.apache.bcel.classfile.*;
import org.apache.bcel.generic.*;
import org.apache.bcel.util.*;
import org.apache.bcel.verifier.*;
import org.apache.bcel.verifier.exc.*;
import org.apache.bcel.verifier.statics.*;
import org.apache.bcel.verifier.structurals.*;
import java.io.IOException;
/**
*
* BCEL Injector
*
* @author: Echo_
*
*/
public class Injector {
private ClassGen cGen;
public Injector() {
loadClass();
modify();
dumpClass();
}
private void loadClass() {
try {
cGen = new ClassGen(new ClassParser("vs.class").parse());
} catch (ClassFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private void modify() {
cGen.addInterface("Animable");
for(Method m : cGen.getMethods()) {
if(m.getName().equals("p")) {
System.out.println("Method p found!");
break;
}
}
InstructionList methodIList = new InstructionList();
ConstantPoolGen theCPool = cGen.getConstantPool();
MethodGen pixelXMethod = new MethodGen(Constants.ACC_PUBLIC,Type.INT,Type.NO_AR GS,new String[]{},"pixelX",cGen.getClassName(),methodIList,theCPool);
InstructionFactory iFactory = new InstructionFactory(cGen,theCPool);
Instruction pushThis = new ALOAD(0);
Instruction pixelXField = iFactory.createFieldAccess(cGen.getClassName(),"p",Type.INT,Constants.GETSTATIC);
Instruction returnPixelX = InstructionFactory.createReturn(Type.INT);
methodIList.append(pushThis);
methodIList.append(pixelXField);
methodIList.append(returnPixelX);
pixelXMethod.setMaxStack();
pixelXMethod.setMaxLocals();
cGen.addMethod(pixelXMethod.getMethod());
}
public void dumpClass() {
try {
cGen.getJavaClass().dump("vs.class");
} catch (IOException ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) {
new Injector();
}
}
He does go more in detail in his post here: http://villavu.com/f...hp/t-62265.html

If you look at that, he explains that he uses a decompiler so that way, you can see the code of the .class file that you want to hack. I recommend using the JAD decompiler in order to see a .class file's variables and code (Google it).

The next part is pretty much the end of my mini-tutorial.

Most people usually have trouble of getting their information from their accessor methods, (which is the interfaces that you make to get your data).
Below is an example of how one may get their data, and is just an example using random Java files that I've made.

Example of getting the data from accessor methods (Done completely by myself)
Lets say that there is a program that you want to hack to get "theSecretString" 's value. I've commented each file out to help understand what's happening.
If you look below, notice how it's STATIC.

Assume that all files (including the files that you use to inject and extract the data, as well as the program's file) are all in the same package/folder (no imports will be needed).
/**
*
* @author A nerdy programmer
*
*/
public class TheProgram { //Using a BCEL or an ASM-based injector, you must make the class implement the interface (accessor) in order to retrieve the data.

private static String theSecretString = "Hello. My name is Bob."; //You will need to return this value.
public static void main(String[]args){ //Pretend its some sort of epic program.
System.out.println("TheProgram's string value = " + theSecretString);
}
}
As you can see above, you will need to make your injector so that it implements the interface to get what theSecretString is.
Before doing that, you will need to make the interface that you implement. Since theSecretString is a String, then you must make an accessor interface which retrieves the data of theSecretString.
public interface Accessor {
/**
*
* @return Retrieves the data of theSecretString.
*/
public String nameOfString();
}

Make the injector using BCEL or ASM and implement the Accessor interface. Remember to also add the method that the interface requires through the injector. TheProgram class would look something like this (excluding the comments):
/**
*
* @author A nerdy programmer
*
*/
public class TheProgram implements Accessor { //Using a BCEL or an ASM-based injector, you must make the class implement the interface (accessor) in order to retrieve the data.

private static String theSecretString = "Hello. My name is Bob."; //You will need to return this value.
public static void main(String[]args){ //Pretend its some sort of epic program.
System.out.println("TheProgram's string value = " + theSecretString);
}
@Override
public String nameOfString() {
return theSecretString; //Using a BCEL or an ASM-based injector, you must make the theString as the return type.
}
}

After this, make an abstract class that would "get" the accessor's interface.
public abstract class GetAccessorClass {
/**
*
* @return The Accessor interface.
*/
public abstract Accessor getAccessor();
}

After this, most people choose to make another interface which is similar to the Accessor method, for use of bot scripts.
public interface MethodInterface {
/**
*
* @return The string that we want from TheProgram.
*/
public String getTheHiddenString();
}

After that, you would need to make a class that gets theHiddenString. This class would have similar methods for use in scripts.
For example, "PlayerInfoGetter.java" may contain methods that retrieve data related to player operations.

In this case, we are hacking the whole program in total, and not just one aspect of it. That's why I've named the class "Getter" because its related to getting methods of the whole program (all in one class).
I've also left a SoftReference, as I've seen RSBot's old bot code, and it seems like a great way of saving memory on a computer while running your bot.
import java.lang.ref.SoftReference;
/**
*
* @author trDna
*
*/
/*
* Pretty much a class that contains similar methods that are retrieved from the Accessor accessor.
* For example, "PlayerInfoGetter.java" may contain methods that retrieve data related to player operations.
*/
public class Getter extends GetAccessorClass implements MethodInterface{
private SoftReference<Accessor> sr; //optional, allows for garbage collection, which makes the Accessor accessor perform faster (less memory would be used up).


public Getter(final Accessor acx){ //Accepts any class that implements Accessor.
sr = new SoftReference<Accessor>(acx);
}

@Override
public Accessor getAccessor() {
return sr.get();
}
@Override
public String getTheHiddenString() {
return getAccessor().nameOfString();
}

}

Now you must start up your "bot" (really just a data retriever) through your program. You need to inject your code before hand, and then create an instance of TheProgram. I've invoked the main method of TheProgram in order to mimic what would happen when the RS/RSPS client loads (however, this just displays a string). After this, you would need to set up the Getter class, and use TheProgram's instance as an argument, because it implements the Accessor interface that we made.
After this, you could simply print out the String that you have retrieved.
/**
*
* @author trDna
*
*/
public class Setter {
public static void main(String[]args){
//Your injection code must go here, so that you can get theSecretString, for example.

TheProgram tp = new TheProgram(); //A new instance of TheProgram, which is supposed to be modified.

TheProgram.main(null); //Invoking the main method. We're just doing this to replicate how the RS client would load and display something. In this case, "Hello. My name is Bob". This line isn't needed.

Getter get = new Getter(tp); //The Accessor accessor (lol).


/*
* You could make a method context class to get the data from the Getter class so its easier to utilise the methods that you would make.
* I've simply made it shorter by getting theHiddenString straight from the Getter class to speed things up.
* This may not be perfect (or technically "correct"), but it shows an approach of how to access the accessor methods that you inject.
*
*/
System.out.println("The setter class's reference of the string: " + get.getTheHiddenString());


}

}


Your output should be:
TheProgram's string value = Hello. My name is Bob.
The setter class's reference of the string: Hello. My name is Bob.

If you got this output, congratulations! You have just retrieved the accessor data by injection!

There are better ways of doing that, but this is just a really simple way of doing it, and it may be a lot harder when hacking into the client of your choice.

Note: Accessor methods only work out when you are returning a value of a STATIC variable. This is because non-static variables' method signatures change here and there, and as a result, you will most likely get an NPE.

Here are some more links you could use to help yourself out:I hope that this tutorial helped some of you out. Feel free to leave suggestions, and I can add/edit this thread Posted Image

Edited by 0, 01 October 2012 - 10:36 PM.


#2
robbiegast

robbiegast
  • Members
  • 6019 posts
  • Joined 06 January 10
a mini tutorial for making a bot while scripters need a whole page for a yak script! You sir are a legend.

#3
Xianb

Xianb
  • Members
  • 6971 posts
  • Joined 25 August 11
Google is Your Best Friend. It keeps me from posting topics that i could just Google.

#4
trDna

trDna
  • Scholars
  • 1713 posts
  • Joined 18 June 12
  • LocationCanada

Google is Your Best Friend.

I've mentioned that in the thread :)
I just left this thread to help people out a little more than Google does.

#5
Linear

Linear
  • Members
  • 2543 posts
  • Joined 18 November 10
  • LocationSout-West UK
I will read this later; looks like a nice tutorial though.

I may ask, shall we be expecting client work by yourself? (sorry if you do have your own project and i just don't know! :-P)

#6
A Template

A Template
  • Scholars
  • 3858 posts
  • Joined 16 June 12
  • LocationNetherlands
That's not the only and probably also not the easiest way to make a bot, but it's a nice tut. Though this wasn't necessary because all this information can be found on RS-Hacking.com

#7
Webjoch

Webjoch
  • Members
  • 13 posts
  • Joined 11 August 11
Thank you for this tutorial. Exactly where I was looking for!

#8
trDna

trDna
  • Scholars
  • 1713 posts
  • Joined 18 June 12
  • LocationCanada

I will read this later; looks like a nice tutorial though.

I may ask, shall we be expecting client work by yourself? (sorry if you do have your own project and i just don't know! :-P)

Not exactly sure what you mean specifically, but I'm not planning to create a bot client of my own. I did start on one, but I chose to leave it unfinished. Posted Image

That's not the only and probably also not the easiest way to make a bot, but it's a nice tut. Though this wasn't necessary because all this information can be found on RS-Hacking.com

1) As I mentioned in the original post, there are better ways of doing it, but this thread outlines what most people do.
2) Thanks :)
3) Not all of it, getting data from the accessor methods are not explained there, which is why I created my own examples to help people out.

Thank you for this tutorial. Exactly where I was looking for!

You're welcome! Glad I could help Posted Image

Edited by 0, 04 July 2012 - 09:00 PM.


#9
Naux

Naux
  • Sponsors

  • 20423 posts
  • Joined 01 July 10
  • LocationDaemonheim

a mini tutorial for making a bot while scripters need a whole page for a yak script! You sir are a legend.

Dafuq.

#10
llaver

llaver
  • Members
  • 565 posts
  • Joined 21 March 09
I have been working on my own sort of custom client but I was having trouble getting data from accessor methods because they were never explained well on rs-hacking. Your example was very easy to follow and was explained well. Thank you very much. :)


#11
Cake

Cake
  • Restricted
  • 2341 posts
  • Joined 04 May 11
  • LocationNorway / Sweden

Dafuq.

Dafuq.

^



#12
trDna

trDna
  • Scholars
  • 1713 posts
  • Joined 18 June 12
  • LocationCanada

I have been working on my own sort of custom client but I was having trouble getting data from accessor methods because they were never explained well on rs-hacking. Your example was very easy to follow and was explained well. Thank you very much. http://powerbot-gold4rs.netdna-ssl.com/c...

You're welcome. Glad to see that you understand my example Posted Image

Edited by 0, 05 July 2012 - 03:03 AM.


#13
Blood_Rush20

Blood_Rush20
  • Script Writers
  • 659 posts
  • Joined 05 September 11
  • LocationEverywhere..
Damn I sweep through alittle, plan on fully reading later, but this is great! I was planning on trying alittle bit just to get a grasp on it for future references and better understanding of the bots. Thank you sir!

#14
Hydra901

Hydra901
  • Restricted
  • 232 posts
  • Joined 05 July 12
Took a quick look, just looks like the updater didn't pay to much attention to it. Great tutorial.

#15
Cake

Cake
  • Restricted
  • 2341 posts
  • Joined 04 May 11
  • LocationNorway / Sweden
Btw "First off, I do not recommend hacking into the official RS client. It's hard enough to deobfuscate their client, but also to keep up with the updates."
1. They made it open source.
2. They haven't updated it for a really really really long time.
3. -.-

#16
USR032

USR032
  • Members
  • 132 posts
  • Joined 11 June 12
  • LocationSydney

Btw "First off, I do not recommend hacking into the official RS client. It's hard enough to deobfuscate their client, but also to keep up with the updates."
1. They made it open source.
2. They haven't updated it for a really really really long time.
3. -.-

How are you a contributor? Read the second point dud.

#17
trDna

trDna
  • Scholars
  • 1713 posts
  • Joined 18 June 12
  • LocationCanada

Btw "First off, I do not recommend hacking into the official RS client. It's hard enough to deobfuscate their client, but also to keep up with the updates."
1. They made it open source.
2. They haven't updated it for a really really really long time.
3. -.-

1. Edited.
2. ?
3. Ouch.. negativity much :(

#18
llaver

llaver
  • Members
  • 565 posts
  • Joined 21 March 09

Btw "First off, I do not recommend hacking into the official RS client. It's hard enough to deobfuscate their client, but also to keep up with the updates."
1. They made it open source.
2. They haven't updated it for a really really really long time.
3. -.-

Whaaaaat? When was the rsclient made open source? And where can I find it?

#19
Cake

Cake
  • Restricted
  • 2341 posts
  • Joined 04 May 11
  • LocationNorway / Sweden

Whaaaaat? When was the rsclient made open source? And where can I find it?

Always been,
And are you so fucking stupid that you can't even go look for 3 sec?
Posted Image


#20
trDna

trDna
  • Scholars
  • 1713 posts
  • Joined 18 June 12
  • LocationCanada

Always been,
And are you so fucking stupid that you can't even go look for 3 sec?
http://i.imm.io/voVw.png...

Just a question, isn't that only for the launcher, not the game code?