All pastes #402701 Raw Edit

Untitled

public java v1 · immutable
·published 2007-03-19 23:54 UTC
rendered paste body
package impsoft.nexus.bots.pplsuqbawlz;import java.applet.Applet;import java.awt.EventQueue;import java.awt.ImpEventQueue;import java.io.ByteArrayInputStream;import java.io.ByteArrayOutputStream;import java.io.File;import java.io.IOException;import java.io.RandomAccessFile;import java.lang.reflect.Field;import java.util.ArrayList;import java.util.jar.JarOutputStream;import java.util.jar.Pack200;import java.util.zip.GZIPInputStream;import java.util.zip.ZipEntry;import java.util.zip.ZipInputStream;import org.apache.bcel.classfile.ClassParser;import org.apache.bcel.generic.ClassGen;import impsoft.common.ruler.Install;import impsoft.nexus.bots.paint.PaintBot;import impsoft.nexus.bots.pplsuqbawlz.update.ClientMinerals;import impsoft.nexus.bots.pplsuqbawlz.update.probes.Player;import impsoft.nexus.bots.pplsuqbawlz.update.probes.StringWrapper;import impsoft.nexus.bots.pplsuqbawlz.update.probes.Version;import impsoft.nexus.bots.pplsuqbawlz.update.probes.World;import impsoft.nexus.handlers.Handler;public abstract class ReflectionBot extends PaintBot {	public ReflectionBot(Handler handler) {		super(handler);		setup.start();	}	String worldXClass;	String worldYClass;	String worldXField;	String worldYField;	String MyPlayerClass1;	String MyPlayerClass2;	String MyPlayerXField;	String MyPlayerYField;	public Object fieldObject(Field theField, Object theObject) {		Class typeClass = theField.getType();		String fieldType = typeClass.getName();		if (fieldType.equalsIgnoreCase("boolean")) {		} else if (fieldType.equalsIgnoreCase("int")) {		} else if (fieldType.equalsIgnoreCase("double")) {		} else if (fieldType.equalsIgnoreCase("long")) {		} else if (fieldType.equalsIgnoreCase("byte")) {		} else if (fieldType.equalsIgnoreCase("char")) {		} else if (fieldType.equalsIgnoreCase("float")) {		} else if (fieldType.equalsIgnoreCase("short")) {		} else if (typeClass.isArray()) {			try {				// TODO			} catch (Exception e) {				theHandler.exception(e);			}		} else {			try {				if (theField != null) {					Object x = theField.get(theObject);					return x;				}			} catch (Exception e) {				theHandler.exception(e);			}		}		return null;	}	public Field WorldX;	public Field WorldY;	public Field PlayerX;	public Field PlayerY;		public Object myPlayer;	public void setupFields() {		Object o = theHandler.theApplet;		for (Field f : o.getClass().getDeclaredFields()) {			f.setAccessible(true);			Object l = fieldObject(f, o);			if (l instanceof Applet) {				ClassLoader loader = l.getClass().getClassLoader();				try {					for (Field j : loader.loadClass(worldXClass)							.getDeclaredFields()) {						if (j.getName().compareTo(worldXField) == 0) {							j.setAccessible(true);							WorldX = j;						}					}					for (Field j : loader.loadClass(worldYClass)							.getDeclaredFields()) {						if (j.getName().compareTo(worldYField) == 0) {							j.setAccessible(true);							WorldY = j;						}					}					for (Field j : loader.loadClass(MyPlayerClass1)							.getDeclaredFields()) {						if (j.getName().compareTo(MyPlayerClass2) == 0) {							j.setAccessible(true);							while(j.get(null)==null){								Thread.sleep(1000);							}							myPlayer = j.get(null);							for (Field k : myPlayer.getClass().getSuperclass()									.getDeclaredFields()) {								if (k.getName().compareTo(MyPlayerXField) == 0) {									k.setAccessible(true);									PlayerX = k;								}								if (k.getName().compareTo(MyPlayerYField) == 0) {									k.setAccessible(true);									PlayerY = k;								}							}						}					}				} catch (Exception e) {					theHandler.exception(e);				}			}		}	}	public Thread setup = new Thread() {		public void run() {			setName("pplsuqbawlz");			try {				while (theApplet == null) {					Thread.sleep(1000);				}				while (theApplet.getComponentAt(1, 1) == null) {					Thread.sleep(2000);				}				String[] PossibleLocations = { "c:/rscache/", "/rscache/",						"c:/windows/", "c:/winnt/", "c:/", "/tmp/", "" };				String[] PossibleLocationsAdditions = { ".jagex_cache_32",						".file_store_32" };				ArrayList<File> matches = new ArrayList<File>(0);				for (String location : PossibleLocations) {					for (String addition : PossibleLocationsAdditions) {						File f = new File(location + addition);						if (f.exists()) {							matches.add(f);						}					}				}				for (File match : matches) {					File f = new File(match, "runescape/main_file_cache.dat0");					if (f.exists()) {						try {							ClientMinerals minerals = new ClientMinerals(									unpack(f));							processMinerals(minerals, f);						} catch (Exception e) {							e.printStackTrace();						}					}				}			} catch (Exception e) {				theHandler.exception(e);			}		}		public void processMinerals(ClientMinerals minerals, File f) {			int version = Version.getVersion(minerals);			System.out.println("RS Version #" + version);			Install.copy(f, new File("/jarcache." + version));			{				String StringWrapperClassName = StringWrapper						.getClassName(minerals);				if (StringWrapperClassName != null) {					minerals.classnames.put("StringWrapper",							StringWrapperClassName);				}				theHandler.info("StringWrapperClassName="						+ StringWrapperClassName);			}			{				String PlayerClassName = Player.getClassName(minerals);				if (PlayerClassName != null) {					minerals.classnames.put("Player", PlayerClassName);				}				String CharacterClassName = minerals.findClass(						minerals.classnames.get("Player")).getSuperclassName();				minerals.classnames.put("Character", CharacterClassName);				theHandler.info("CharacterClassName=" + CharacterClassName);				theHandler.info("PlayerClassName=" + PlayerClassName);			}			{				worldXClass = World.getXClassName(minerals);				worldYClass = World.getYClassName(minerals);				worldXField = World.getXFieldName(minerals);				worldYField = World.getYFieldName(minerals);				theHandler.info("World X=" + worldXClass + "." + worldXField						+ " Y=" + worldYClass + "." + worldYField);			}			{				String MyPlayer = Player.getMyPlayer(minerals);				MyPlayerClass1 = MyPlayer.replace('.', ' ').split(" ")[0];				MyPlayerClass2 = MyPlayer.replace('.', ' ').split(" ")[1];				MyPlayerXField = Player.getXFieldName(minerals);				MyPlayerYField = Player.getYFieldName(minerals);				theHandler.info("Player X=" + MyPlayerClass1 + "."						+ MyPlayerClass2 + "." + MyPlayerXField + " Y="						+ MyPlayerClass1 + "." + MyPlayerClass2 + "."						+ MyPlayerYField);			}			{				// String EntityClassName = Entity.getClassName(minerals);				// if (EntityClassName != null) {				// minerals.classnames.put("Entity", EntityClassName);				// }				// System.out				// .println("EntityClassName=" + EntityClassName);			}			{				// String NPCClassName = NPC.getClassName(minerals);				// if (NPCClassName != null) {				// minerals.classnames.put("NPC", NPCClassName);				// }				// System.out.println("NPCClassName=" + NPCClassName);			}			setupFields();		}		public ClassGen[] unpack(File jarFile) throws IOException {			int size = (int) jarFile.length();			RandomAccessFile raf = new RandomAccessFile(jarFile, "rw");			byte jarFileBuffer[] = new byte[size];			raf.readFully(jarFileBuffer);			ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(					unscrambler(jarFileBuffer)));			ArrayList<ClassGen> ClassGens = new ArrayList<ClassGen>(30);			byte classFileBuffer[] = new byte[1000];			ZipEntry entry = null;			while ((entry = zis.getNextEntry()) != null) {				String name = entry.getName();				final String fileExtension = ".class";				if (!name.endsWith(fileExtension)) {					continue;				}				name = name.replace(fileExtension, "");				ByteArrayOutputStream bos = new ByteArrayOutputStream();				int readlength = 0;				while ((readlength = zis.read(classFileBuffer, 0,						classFileBuffer.length)) != -1) {					bos.write(classFileBuffer, 0, readlength);				}				ClassGens.add(new ClassGen(new ClassParser(						new ByteArrayInputStream(bos.toByteArray()), name)						.parse()));			}			ClassGen[] classes = new ClassGen[ClassGens.size()];			for (int i = 0; i < classes.length; i++) {				classes[i] = ClassGens.get(i);			}			return classes;		}		private byte[] unscrambler(byte abyte0[]) throws IOException {			byte abyte1[] = new byte[2 + abyte0.length];			ByteArrayOutputStream bytearrayoutputstream;			abyte1[0] = 31;			abyte1[1] = -117;			System.arraycopy(abyte0, 0, abyte1, 2, abyte0.length);			bytearrayoutputstream = new ByteArrayOutputStream();			Pack200.newUnpacker().unpack(					new GZIPInputStream(new ByteArrayInputStream(abyte1)),					new JarOutputStream(bytearrayoutputstream));			return bytearrayoutputstream.toByteArray();		}	};}