Fixed issue with reflection

This commit is contained in:
JKetelaar
2015-09-15 20:29:46 +02:00
parent e5348444b6
commit 4c27ce99ff
7 changed files with 211 additions and 119 deletions
+2 -2
View File
@@ -5,5 +5,5 @@ mvn install:install-file -DgroupId=${project.groupId} -DartifactId=${project.art
:: mvn install:install-file -DgroupId=org.parabot -DartifactId=client -Dversion=2.2.33 -Dpackaging=jar -Dfile=../target/Parabot-V2.2.33.jar -DlocalRepositoryPath=../../Maven-Repository :: mvn install:install-file -DgroupId=org.parabot -DartifactId=client -Dversion=2.2.33 -Dpackaging=jar -Dfile=../target/Parabot-V2.2.33.jar -DlocalRepositoryPath=../../Maven-Repository
:: mvn install:install-file -DgroupId=org.parabot -DartifactId=client -Dversion=2.2.34 -Dpackaging=jar -Dfile=../target/Parabot-V2.2.34.jar -DlocalRepositoryPath=../../Maven-Repository :: mvn install:install-file -DgroupId=org.parabot -DartifactId=client -Dversion=2.2.34 -Dpackaging=jar -Dfile=../target/Parabot-V2.2.34.jar -DlocalRepositoryPath=../../Maven-Repository
:: mvn install:install-file -DgroupId=org.parabot -DartifactId=client -Dversion=2.2.35 -Dpackaging=jar -Dfile=../target/Parabot-V2.2.35.jar -DlocalRepositoryPath=../../Maven-Repository :: mvn install:install-file -DgroupId=org.parabot -DartifactId=client -Dversion=2.2.35 -Dpackaging=jar -Dfile=../target/Parabot-V2.2.35.jar -DlocalRepositoryPath=../../Maven-Repository
:: mvn install:install-file -DgroupId=org.parabot -DartifactId=client -Dversion=2.2.35 -Dpackaging=jar -Dfile=../target/Parabot-V2.2.35.jar -DlocalRepositoryPath=../../Maven-Repository :: mvn install:install-file -DgroupId=org.parabot -DartifactId=client -Dversion=2.2.36 -Dpackaging=jar -Dfile=../target/Parabot-V2.2.36.jar -DlocalRepositoryPath=../../Maven-Repository
:: mvn install:install-file -DgroupId=org.parabot -DartifactId=client -Dversion=2.2.36 -Dpackaging=jar -Dfile=../target/Parabot-V2.2.36.jar -DlocalRepositoryPath=../../Maven-Repository :: mvn install:install-file -DgroupId=org.parabot -DartifactId=client -Dversion=2.2.4 -Dpackaging=jar -Dfile=../target/Parabot-V2.2.4.jar -DlocalRepositoryPath=../../Maven-Repository
+1 -5
View File
@@ -6,7 +6,7 @@
<groupId>org.parabot</groupId> <groupId>org.parabot</groupId>
<artifactId>client</artifactId> <artifactId>client</artifactId>
<version>2.2.36</version> <version>2.2.4</version>
<packaging>jar</packaging> <packaging>jar</packaging>
@@ -58,13 +58,9 @@
<filtering>true</filtering> <filtering>true</filtering>
<excludes> <excludes>
<exclude>deploy.bat</exclude> <exclude>deploy.bat</exclude>
<exclude>package.bat</exclude>
<exclude>clean.bat</exclude>
</excludes> </excludes>
<!--<includes>--> <!--<includes>-->
<!--<include>deploy.bat</include>--> <!--<include>deploy.bat</include>-->
<!--<include>package.bat</include>-->
<!--<include>clean.bat</include>-->
<!--</includes>--> <!--</includes>-->
</resource> </resource>
</resources> </resources>
+74 -72
View File
@@ -40,7 +40,7 @@ public final class Landing {
t.printStackTrace(); t.printStackTrace();
} }
if (!Core.inDebugMode() && !Core.isValid()) { if (!Core.inDebugMode() && !Core.isValid() && Core.hasValidation()) {
UILog.log("Updates", UILog.log("Updates",
"Please download the newest version of Parabot at " "Please download the newest version of Parabot at "
+ Configuration.DOWNLOAD_BOT, + Configuration.DOWNLOAD_BOT,
@@ -76,81 +76,83 @@ public final class Landing {
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
final String arg = args[i].toLowerCase(); final String arg = args[i].toLowerCase();
switch (arg.toLowerCase()) { switch (arg.toLowerCase()) {
case "-createdirs": case "-createdirs":
Directories.validate(); Directories.validate();
System.out System.out
.println("Directories created, you can now run parabot."); .println("Directories created, you can now run parabot.");
System.exit(0); System.exit(0);
break; break;
case "-debug": case "-debug":
Core.setDebug(true); Core.setDebug(true);
break; break;
case "-v": case "-v":
case "-verbose": case "-verbose":
Core.setVerbose(true); Core.setVerbose(true);
break; break;
case "-server": case "-server":
ServerSelector.initServer = args[++i]; ServerSelector.initServer = args[++i];
break; break;
case "-login": case "-login":
username = args[++i]; username = args[++i];
password = args[++i]; password = args[++i];
break; break;
case "-loadlocal": case "-loadlocal":
Core.setLoadLocal(true); Core.setLoadLocal(true);
break; break;
case "-dump": case "-dump":
Core.setDump(true); Core.setDump(true);
break; break;
case "-scriptsbin": case "-scriptsbin":
Directories.setScriptCompiledDirectory(new File(args[++i])); Directories.setScriptCompiledDirectory(new File(args[++i]));
break; break;
case "-serversbin": case "-serversbin":
Directories.setServerCompiledDirectory(new File(args[++i])); Directories.setServerCompiledDirectory(new File(args[++i]));
break; break;
case "-clearcache": case "-clearcache":
File[] cache = Directories.getCachePath().listFiles(); File[] cache = Directories.getCachePath().listFiles();
if (cache != null) { if (cache != null) {
for (File f : cache) { for (File f : cache) {
if (f.exists() && f.canWrite()) { if (f.exists() && f.canWrite()) {
f.delete(); f.delete();
}
} }
} }
} break;
break; case "-mac":
case "-mac": byte[] mac = new byte[6];
byte[] mac = new byte[6]; String str = args[++i];
String str = args[++i]; if (str.toLowerCase().equals("random")) {
if (str.toLowerCase().equals("random")) { new java.util.Random().nextBytes(mac);
new java.util.Random().nextBytes(mac); } else {
} else { i--;
i--; for (int j = 0; j < 6; j++) {
for (int j = 0; j < 6; j++) { mac[j] = Byte.parseByte(args[++i], 16); // parses a hex
mac[j] = Byte.parseByte(args[++i], 16); // parses a hex // number
// number }
} }
} NetworkInterface.setMac(mac);
NetworkInterface.setMac(mac); break;
break; case "-proxy":
case "-proxy": ProxyType type = ProxyType.valueOf(args[++i].toUpperCase());
ProxyType type = ProxyType.valueOf(args[++i].toUpperCase()); if (type == null) {
if (type == null) { System.err.println("Invalid proxy type:" + args[i]);
System.err.println("Invalid proxy type:" + args[i]); System.exit(1);
System.exit(1); return;
return; }
} ProxySocket.setProxy(type, args[++i],
ProxySocket.setProxy(type, args[++i], Integer.parseInt(args[++i]));
Integer.parseInt(args[++i])); break;
break; case "-auth":
case "-auth": ProxySocket.auth = true;
ProxySocket.auth = true; ProxySocket.setLogin(args[++i], args[++i]);
ProxySocket.setLogin(args[++i], args[++i]); break;
break; case "-no_sec":
case "-no_sec": Core.disableSec();
Core.disableSec(); break;
break; case "-no_validation":
Core.disableValidation();
break;
} }
} }
} }
} }
+10 -2
View File
@@ -28,8 +28,17 @@ public class Core {
private static boolean dump; private static boolean dump;
private static boolean loadLocal; //Loads both local and public scripts/servers private static boolean loadLocal; //Loads both local and public scripts/servers
private static boolean validate = true;
private static boolean secure = true; private static boolean secure = true;
public static void disableValidation() {
Core.validate = false;
}
public static boolean hasValidation() {
return validate;
}
/** /**
* Enabled loadLocal mode * Enabled loadLocal mode
* *
@@ -118,7 +127,6 @@ public class Core {
* Checks the version of the bot using a checksum of the jar comparison against checksum given by the website * Checks the version of the bot using a checksum of the jar comparison against checksum given by the website
* @return <b>true</b> if no new version is found, otherwise <b>false</b>. * @return <b>true</b> if no new version is found, otherwise <b>false</b>.
*/ */
@SuppressWarnings("unused")
private static boolean checksumValid(){ private static boolean checksumValid(){
File f = new File(Landing.class.getProtectionDomain().getCodeSource().getLocation().getFile()); File f = new File(Landing.class.getProtectionDomain().getCodeSource().getLocation().getFile());
if (f.isFile()) { if (f.isFile()) {
@@ -107,6 +107,7 @@ public class RedirectClassAdapter extends ClassVisitor implements Opcodes {
if(class_out != null) if(class_out != null)
class_out.println(owner); class_out.println(owner);
super.visitMethodInsn(opcode, owner, name, desc); super.visitMethodInsn(opcode, owner, name, desc);
} }
@@ -1,47 +1,127 @@
package org.parabot.core.asm.redirect; package org.parabot.core.asm.redirect;
import org.parabot.core.asm.RedirectClassAdapter;
import org.parabot.environment.scripts.Script;
import java.io.InputStream; import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import org.parabot.core.asm.RedirectClassAdapter;
public class ClassRedirect { public class ClassRedirect {
public static Object newInstance(Class<?>c){
throw RedirectClassAdapter.createSecurityException();
}
public static Field getDeclaredField(Class<?> c, String s) throws NoSuchFieldException, SecurityException{
System.out.println(c.getName() + "." + c.getDeclaredField(s) + " Blocked.");
throw RedirectClassAdapter.createSecurityException();
}
public static Method getDeclaredMethod(Class<?>c,String name,Class<?>... params) throws NoSuchMethodException, SecurityException{
System.out.println(c.getName() + "#" + c.getDeclaredMethod(name,params) + " Blocked.");
throw RedirectClassAdapter.createSecurityException();
}
public static Class<?> forName(String name) throws ClassNotFoundException{
if(name.contains("parabot"))
throw new ClassNotFoundException();
return Class.forName(name);
}
public static ClassLoader getClassLoader(Class<?>c){
throw RedirectClassAdapter.createSecurityException();
}
public static String getName(Class<?>c){
if(c.getName().contains("parabot"))
return "java.lang.String";
return c.getName();
}
public static InputStream getResourceAsStream(Class<?>c, String res){
if(res.contains(".class"))
throw RedirectClassAdapter.createSecurityException();
return c.getResourceAsStream(res);
}
public static Object newInstance(Class<?> c) throws IllegalAccessException, InstantiationException {
if (validStack()){
return c.newInstance();
}
throw RedirectClassAdapter.createSecurityException();
}
public static Field getDeclaredField(Class<?> c, String s) throws NoSuchFieldException, SecurityException {
if (validStack()) {
return c.getDeclaredField(s);
}
System.out.println(c.getName() + "." + c.getDeclaredField(s) + " Blocked.");
throw RedirectClassAdapter.createSecurityException();
}
public static Method getDeclaredMethod(Class<?> c, String name, Class<?>... params) throws NoSuchMethodException, SecurityException {
if (validStack()) {
return c.getDeclaredMethod(name, params);
}
System.out.println(c.getName() + "#" + c.getDeclaredMethod(name, params) + " Blocked.");
throw RedirectClassAdapter.createSecurityException();
}
public static Class<?> forName(String name) throws ClassNotFoundException {
if (name.contains("parabot"))
throw new ClassNotFoundException();
return Class.forName(name);
}
public static ClassLoader getClassLoader(Class<?> c) {
throw RedirectClassAdapter.createSecurityException();
}
public static Field[] getDeclaredFields(Class<?> c) {
if (validStack()) {
return c.getDeclaredFields();
}
System.out.println(c.getName() + "#getDeclaredFields()" + " Blocked.");
throw RedirectClassAdapter.createSecurityException();
}
public static Method[] getDeclaredMethods(Class<?> c) {
if (validStack()) {
return c.getDeclaredMethods();
}
System.out.println(c.getName() + "#getDeclaredMethods()" + " Blocked.");
throw RedirectClassAdapter.createSecurityException();
}
public static Field[] getFields(Class<?> c){
if (validStack()) {
return c.getFields();
}
System.out.println(c.getName() + "#getFields()" + " Blocked.");
throw RedirectClassAdapter.createSecurityException();
}
public static Annotation[] getAnnotations(Class<?> c){
if (validStack()){
return c.getAnnotations();
}
System.out.println(c.getName() + "#getFields()" + " Blocked.");
throw RedirectClassAdapter.createSecurityException();
}
public static Method[] getMethods(Class<?> c){
if (validStack()) {
return c.getMethods();
}
System.out.println(c.getName() + "#getMethods()" + " Blocked.");
throw RedirectClassAdapter.createSecurityException();
}
public static Method getMethod(Class<?> c, String name, Class<?>... params) throws NoSuchMethodException, SecurityException {
if (validStack()) {
return c.getMethod(name, params);
}
System.out.println(c.getName() + "#getMethod()" + " Blocked.");
throw RedirectClassAdapter.createSecurityException();
}
public static Field getField(Class<?> c, String name)
throws NoSuchFieldException, SecurityException {
if (validStack()) {
return c.getField(name);
}
System.out.println(c.getName() + "#getField()" + " Blocked.");
throw RedirectClassAdapter.createSecurityException();
}
public static String getName(Class<?> c) {
if (c.getName().contains("parabot"))
return "java.lang.String";
return c.getName();
}
public static InputStream getResourceAsStream(Class<?> c, String res) {
if (validStack()) {
return c.getResourceAsStream(res);
}
if (res.contains(".class")) {
throw RedirectClassAdapter.createSecurityException();
}
return c.getResourceAsStream(res);
}
private static boolean validStack() {
Exception e = new Exception();
for (StackTraceElement elem : e.getStackTrace()) {
if (elem.getClassName().equals(Script.class.getName()))
return true;
}
return false;
}
} }
@@ -1,5 +1,6 @@
package org.parabot.core.reflect; package org.parabot.core.reflect;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@@ -85,6 +86,10 @@ public class RefClass extends RefModifiers {
return this.clazz.getCanonicalName(); return this.clazz.getCanonicalName();
} }
public Annotation[] getAnnotations(){
return this.clazz.getAnnotations();
}
/** /**
* Gets the type of this class * Gets the type of this class
* *