- Joined
- Nov 3, 2013
- Messages
- 609
- Thread Author
- #1
I've got a fun little hack here that I have been working on. I plan to use this for my player owned port script if I ever get around to writing it. The hack an exploit in Java's Class system that allows access to a the script Classloader and from there with a bit of Reflection the other classes that have been loaded by that loader. As it stands, this is a sort of Beta to the hack and I plan to actually make it work with a gui and implement some sample logic for future use. The main idea here is not steal data or other scripts, but to allow for scripts that have some sort of long wait time in between actions to better use their idle time. A good example of this is farming trees where it might take several hours for a single tree to grow, and those hours could be spent crafting nature runes. So here it is.
Here is the first class you will need (or any local script, this one is just easy and simple):
This is just to test the system out, here is the real meat of the hack:
Read the comments in the code, but feel free to post any questions.
Theoretically this should work with store scripts if run from the store since store scripts aren't loaded in sdk mode. I'll have to wait for a comment from @Cloud since this would obviously be a security risk if put on the store, but I would be curious enough just to try it.
DISCLAIMER: Use this at your own risk.
Here is the first class you will need (or any local script, this one is just easy and simple):
Code:
import com.runemate.game.api.script.framework.LoopingScript;
public class TestScript extends LoopingScript {
@Override
public void onLoop() {
System.out.println("Hello World!");
}
}
Code:
import java.lang.reflect.Field;
import java.util.Scanner;
import java.util.Vector;
import com.runemate.game.api.script.framework.AbstractScript;
import com.runemate.game.api.script.framework.LoopingScript;
public class BatHacker extends LoopingScript{
private AbstractScript scriptInstance;
@Override
public void onStart(String... args){
try {
//First grab the ClassLoader for the script
ClassLoader loader = this.getClass().getClassLoader();
//Now grab the loader's class
Class<?> loaderClass = loader.getClass().getSuperclass();
//Grab the Field object from that class via reflection
Field classesField = loaderClass.getDeclaredField("classes");
//Change the Field from private to public (roughly)
classesField.setAccessible(true);
//Grab that "classes" field from out specific ClassLoader object
//At this point we should have all of the script that the client sees
Vector<?> scripts = (Vector<?>) classesField.get(loader);
//This part prompts the user to choose a script from the list
//Note that this uses the class names, not the script names
//TODO: implement as a GUI
System.out.println("Select the script you wish to start by choosing the number: ");
for (int i = 0; i < scripts.size(); i++) {
System.out.println(i + ". " + ((Class<?>)scripts.get(i)).getSimpleName());
}
//Grab the number that the user chose
@SuppressWarnings("resource")
Scanner in = new Scanner(System.in);
int scriptIndex = in.nextInt();
//in.close(); DO NOT CLOSE THIS SCANNER SINCE IT WILL CLOSE System.in AS WELL
//Make sure that class is actually a script
Object scriptOb = scripts.get(scriptIndex);
if(scriptOb instanceof Class){
//Create a new instance of the script
Class<?> script = (Class<?>)scriptOb;
scriptInstance = (AbstractScript)script.newInstance();
}
if(scriptInstance == null){
System.out.println("Failed to load scriprt!");
}else{
//TODO: maybe prompt for arguments
scriptInstance.onStart("");
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onLoop() {
//This is how you would access the loop of the script
//If the script is a TaskScript, simply cast to that instead
if(scriptInstance != null){
LoopingScript loopInstance = (LoopingScript)scriptInstance;
loopInstance.onLoop();
}
}
}
Read the comments in the code, but feel free to post any questions.
Theoretically this should work with store scripts if run from the store since store scripts aren't loaded in sdk mode. I'll have to wait for a comment from @Cloud since this would obviously be a security risk if put on the store, but I would be curious enough just to try it.
DISCLAIMER: Use this at your own risk.