mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-03 00:37:55 +00:00
[TASK] Redid the caching system
This commit is contained in:
@@ -112,7 +112,7 @@
|
||||
<version>2.4.1</version>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>fat</descriptorRef>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
<archive>
|
||||
<manifest>
|
||||
|
||||
@@ -112,14 +112,7 @@ public final class Landing {
|
||||
Directories.setServerCompiledDirectory(new File(args[++i]));
|
||||
break;
|
||||
case "-clearcache":
|
||||
File[] cache = Directories.getCachePath().listFiles();
|
||||
if (cache != null) {
|
||||
for (File f : cache) {
|
||||
if (f.exists() && f.canWrite()) {
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
Directories.clearCache();
|
||||
break;
|
||||
case "-mac":
|
||||
byte[] mac = new byte[6];
|
||||
|
||||
@@ -0,0 +1,243 @@
|
||||
package org.parabot;
|
||||
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.parabot.core.Context;
|
||||
import org.parabot.core.reflect.RefClass;
|
||||
import org.parabot.core.reflect.RefMethod;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Created by jeroen on 01/01/16.
|
||||
*/
|
||||
public class Test {
|
||||
|
||||
private static Class noparams[] = {};
|
||||
private static Class[] paramShort = new Class[3];
|
||||
private static Class[] paramShort2 = new Class[2];
|
||||
|
||||
static {
|
||||
paramShort[0] = int.class;
|
||||
paramShort2[0] = int.class;
|
||||
paramShort[1] = int.class;
|
||||
paramShort2[1] = long.class;
|
||||
paramShort[2] = int.class;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(C5("_aUm\u0017{\\xXzX|Vz"));
|
||||
}
|
||||
|
||||
public static String C5(final String a) {
|
||||
final int n = 1 << 3;
|
||||
final int n2 = (0x2 ^ 0x5) << 3 ^ 0x1;
|
||||
final int length = a.length();
|
||||
final char[] array = new char[length];
|
||||
int n3;
|
||||
int i = n3 = length - 1;
|
||||
final char[] array2 = array;
|
||||
final char c = (char)n2;
|
||||
final int n4 = n;
|
||||
while (i >= 0) {
|
||||
final char[] array3 = array2;
|
||||
final int n5 = n3;
|
||||
final char char1 = a.charAt(n5);
|
||||
--n3;
|
||||
array3[n5] = (char)(char1 ^ n4);
|
||||
if (n3 < 0) {
|
||||
break;
|
||||
}
|
||||
final char[] array4 = array2;
|
||||
final int n6 = n3--;
|
||||
array4[n6] = (char)(a.charAt(n6) ^ c);
|
||||
i = n3;
|
||||
}
|
||||
return new String(array2);
|
||||
}
|
||||
|
||||
public static String C4(final String a) {
|
||||
final int n = 5 << 4 ^ 3 << 1;
|
||||
final int n2 = (0x2 ^ 0x5) << 3 ^ (0x2 ^ 0x5);
|
||||
final int length = a.length();
|
||||
final char[] array = new char[length];
|
||||
int n3;
|
||||
int i = n3 = length - 1;
|
||||
final char[] array2 = array;
|
||||
final char c = (char)n2;
|
||||
final int n4 = n;
|
||||
while (i >= 0) {
|
||||
final char[] array3 = array2;
|
||||
final int n5 = n3;
|
||||
final char char1 = a.charAt(n5);
|
||||
--n3;
|
||||
array3[n5] = (char)(char1 ^ n4);
|
||||
if (n3 < 0) {
|
||||
break;
|
||||
}
|
||||
final char[] array4 = array2;
|
||||
final int n6 = n3--;
|
||||
array4[n6] = (char)(a.charAt(n6) ^ c);
|
||||
i = n3;
|
||||
}
|
||||
return new String(array2);
|
||||
}
|
||||
|
||||
public static String C2(final String a) {
|
||||
final int n = 4;
|
||||
final int n2 = n << n ^ 2 << 1;
|
||||
final int n3 = 3;
|
||||
final int n4 = n3 << n3 ^ 0x3;
|
||||
final int length = a.length();
|
||||
final char[] array = new char[length];
|
||||
int n5;
|
||||
int i = n5 = length - 1;
|
||||
final char[] array2 = array;
|
||||
final char c = (char)n4;
|
||||
final int n6 = n2;
|
||||
while (i >= 0) {
|
||||
final char[] array3 = array2;
|
||||
final int n7 = n5;
|
||||
final char char1 = a.charAt(n7);
|
||||
--n5;
|
||||
array3[n7] = (char)(char1 ^ n6);
|
||||
if (n5 < 0) {
|
||||
break;
|
||||
}
|
||||
final char[] array4 = array2;
|
||||
final int n8 = n5--;
|
||||
array4[n8] = (char)(a.charAt(n8) ^ c);
|
||||
i = n5;
|
||||
}
|
||||
return new String(array2);
|
||||
}
|
||||
|
||||
public static String C(final String a) {
|
||||
final int n = 2 << 3 ^ (0x2 ^ 0x5);
|
||||
final int n2 = (0x2 ^ 0x5) << 4;
|
||||
final int n3 = 2;
|
||||
final int n4 = n2 ^ (n3 << n3 ^ 0x1);
|
||||
final int length = a.length();
|
||||
final char[] array = new char[length];
|
||||
int n5;
|
||||
int i = n5 = length - 1;
|
||||
final char[] array2 = array;
|
||||
final char c = (char)n4;
|
||||
final int n6 = n;
|
||||
while (i >= 0) {
|
||||
final char[] array3 = array2;
|
||||
final int n7 = n5;
|
||||
final char char1 = a.charAt(n7);
|
||||
--n5;
|
||||
array3[n7] = (char)(char1 ^ n6);
|
||||
if (n5 < 0) {
|
||||
break;
|
||||
}
|
||||
final char[] array4 = array2;
|
||||
final int n8 = n5--;
|
||||
array4[n8] = (char)(a.charAt(n8) ^ c);
|
||||
i = n5;
|
||||
}
|
||||
return new String(array2);
|
||||
}
|
||||
|
||||
public static String C3(final String a) {
|
||||
final int n = (0x3 ^ 0x5) << 4 ^ (0x2 ^ 0x5);
|
||||
final int n2 = (0x3 ^ 0x5) << 4 ^ 3 << 1;
|
||||
final int length = a.length();
|
||||
final char[] array = new char[length];
|
||||
int n3;
|
||||
int i = n3 = length - 1;
|
||||
final char[] array2 = array;
|
||||
final char c = (char)n2;
|
||||
final int n4 = n;
|
||||
while (i >= 0) {
|
||||
final char[] array3 = array2;
|
||||
final int n5 = n3;
|
||||
final char char1 = a.charAt(n5);
|
||||
--n3;
|
||||
array3[n5] = (char)(char1 ^ n4);
|
||||
if (n3 < 0) {
|
||||
break;
|
||||
}
|
||||
final char[] array4 = array2;
|
||||
final int n6 = n3--;
|
||||
array4[n6] = (char)(a.charAt(n6) ^ c);
|
||||
i = n3;
|
||||
}
|
||||
return new String(array2);
|
||||
}
|
||||
|
||||
public static void invokeD(Class clazz, Object client) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException {
|
||||
Class<?> c = Context.getInstance().getASMClassLoader()
|
||||
.loadClass("a/a/c/q");
|
||||
Method method = c.getDeclaredMethod("d", noparams);
|
||||
if(method != null){
|
||||
method.invoke(c, null);
|
||||
}
|
||||
|
||||
System.out.println("InvokeD");
|
||||
}
|
||||
|
||||
public static void invokeQC(Class clazz, Object client) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException {
|
||||
Class<?> c = Context.getInstance().getASMClassLoader()
|
||||
.loadClass("a/a/c/q");
|
||||
Method method = c.getDeclaredMethod("C", noparams);
|
||||
if(method != null){
|
||||
method.invoke(c, null);
|
||||
}
|
||||
|
||||
System.out.println("InvokeD");
|
||||
}
|
||||
|
||||
public static void invokeU(Class clazz, Object client) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException, NoSuchFieldException {
|
||||
Method method = Context.getInstance().getClient().getClass().getDeclaredMethod("f", noparams);
|
||||
if(method != null){
|
||||
method.setAccessible(true);
|
||||
method.invoke(Context.getInstance().getClient(), null);
|
||||
}
|
||||
|
||||
Field fieldEF = Context.getInstance().getClient().getClass().getDeclaredField("eF");
|
||||
Field fieldRC = Context.getInstance().getClient().getClass().getDeclaredField("Rc");
|
||||
Field fieldCD = Context.getInstance().getClient().getClass().getDeclaredField("cd");
|
||||
|
||||
fieldEF.set(Context.getInstance().getClient(), 0);
|
||||
fieldRC.set(Context.getInstance().getClient(), 765);
|
||||
fieldCD.set(Context.getInstance().getClient(), 503);
|
||||
|
||||
System.out.println("invokeU");
|
||||
}
|
||||
|
||||
public static void invokeXD(Class clazz, Object client) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException {
|
||||
Class<?> c = Context.getInstance().getASMClassLoader()
|
||||
.loadClass("a/a/l/x");
|
||||
Method method = c.getDeclaredMethod("d", noparams);
|
||||
if(method != null){
|
||||
method.invoke(c, null);
|
||||
}
|
||||
|
||||
|
||||
System.out.println("invokeXD");
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings the size of the client
|
||||
* @param clazz
|
||||
* @param client
|
||||
* @throws NoSuchMethodException
|
||||
* @throws InvocationTargetException
|
||||
* @throws IllegalAccessException
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
public static void invokeTB(Class clazz, Object client) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException {
|
||||
Method method = Context.getInstance().getClient().getClass().getDeclaredMethod("d", paramShort);
|
||||
|
||||
if(method != null){
|
||||
method.setAccessible(true);
|
||||
method.invoke(Context.getInstance().getClient(), 0, 765, 503);
|
||||
}
|
||||
|
||||
System.out.println("invokeTB");
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.parabot.core;
|
||||
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.parabot.Test;
|
||||
import org.parabot.core.asm.ASMClassLoader;
|
||||
import org.parabot.core.classpath.ClassPath;
|
||||
import org.parabot.core.desc.ServerProviderInfo;
|
||||
@@ -229,6 +230,16 @@ public class Context {
|
||||
|
||||
BotDialog.getInstance().validate();
|
||||
|
||||
try {
|
||||
Test.invokeQC(getClient().getClass(), getClient());
|
||||
Test.invokeD(getClient().getClass(), getClient());
|
||||
Test.invokeU(getClient().getClass(), getClient());
|
||||
Test.invokeXD(getClient().getClass(), getClient());
|
||||
Test.invokeTB(getClient().getClass(), getClient());
|
||||
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | ClassNotFoundException | NoSuchFieldException e) {
|
||||
// e.printStackTrace(); // This is just for testing purpose
|
||||
}
|
||||
|
||||
System.setOut(this.defaultOut);
|
||||
System.setErr(this.defaultErr);
|
||||
}
|
||||
|
||||
@@ -7,10 +7,7 @@ import org.parabot.environment.api.utils.StringUtils;
|
||||
import org.parabot.environment.api.utils.WebUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@@ -54,27 +51,39 @@ public class Directories {
|
||||
File cache;
|
||||
tempDir = StringUtils.randomString(12);
|
||||
try {
|
||||
if ((cache = new File(Directories.getCachePath(), "cache.json")).exists()){
|
||||
if ((cache = new File(Directories.getSettingsPath(), "cache.json")).exists()){
|
||||
JSONObject object = (JSONObject) WebUtil.getJsonParser().parse(new FileReader(cache));
|
||||
String temp;
|
||||
if ((temp = (String) object.get("homedir")) != null){
|
||||
cached.put("Home", new File(cached.get("Root"), "/" + temp + "/"));
|
||||
}
|
||||
}else{
|
||||
cache.createNewFile();
|
||||
JSONObject object = new JSONObject();
|
||||
object.put("homedir", tempDir);
|
||||
FileWriter file = new FileWriter(cache);
|
||||
file.write(object.toJSONString());
|
||||
file.flush();
|
||||
file.close();
|
||||
cached.put("Home", new File(cached.get("Root"), "/" + tempDir + "/"));
|
||||
cached.put("Home", createCacheDirectory(cache));
|
||||
}
|
||||
} catch (IOException | ParseException ignored) {
|
||||
cached.put("Home", new File(cached.get("Root"), "/" + tempDir + "/"));
|
||||
}
|
||||
System.out.println("Setting server cache directory to: " + cached.get("Home"));
|
||||
cached.get("Home").mkdirs();
|
||||
if (!cached.get("Home").exists()) {
|
||||
cached.get("Home").mkdirs();
|
||||
}
|
||||
System.out.println("Set temporary cache directory to: " + cached.get("Home"));
|
||||
}
|
||||
|
||||
private static File createCacheDirectory(File cacheFile) throws IOException {
|
||||
cacheFile.createNewFile();
|
||||
JSONObject object = new JSONObject();
|
||||
object.put("homedir", tempDir);
|
||||
FileWriter file = new FileWriter(cacheFile);
|
||||
file.write(object.toJSONString());
|
||||
file.flush();
|
||||
file.close();
|
||||
|
||||
File cacheDir = new File(cached.get("Root"), "/" + tempDir + "/");
|
||||
if (!cacheDir.exists()) {
|
||||
cacheDir.mkdirs();
|
||||
}
|
||||
|
||||
return cacheDir;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -221,8 +230,9 @@ public class Directories {
|
||||
* Clears the cache based on the latest modification
|
||||
*
|
||||
* @param remove A long that represents the amount of seconds that a file may have since the latest modification
|
||||
* @param force Defines if the cache folder, within user.home, should also be removed
|
||||
*/
|
||||
private static void clearCache(int remove) {
|
||||
public static void clearCache(int remove, boolean force){
|
||||
File[] cache = getCachePath().listFiles();
|
||||
if (cache != null) {
|
||||
for (File f : cache) {
|
||||
@@ -232,14 +242,59 @@ public class Directories {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (force){
|
||||
File cacheFile;
|
||||
|
||||
if ((cacheFile = new File(Directories.getSettingsPath(), "cache.json")).exists()){
|
||||
try {
|
||||
JSONObject jsonObject = (JSONObject) WebUtil.getJsonParser().parse(new FileReader(cacheFile));
|
||||
if (jsonObject != null){
|
||||
Object dirObject;
|
||||
if ((dirObject = jsonObject.get("homedir")) != null) {
|
||||
String dir = (String) dirObject;
|
||||
if (dir.length() > 0) {
|
||||
File cacheDir = new File(cached.get("Root"), "/" + dir + "/");
|
||||
removeDirectory(cacheDir);
|
||||
createCacheDirectory(cacheFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IOException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void clearCache(int remove) {
|
||||
clearCache(remove, false);
|
||||
}
|
||||
|
||||
public static void clearCache() {
|
||||
File[] cache = getCachePath().listFiles();
|
||||
if (cache != null) {
|
||||
for (File f : cache) {
|
||||
Core.verbose("Clearing " + f.getName() + " from cache...");
|
||||
f.delete();
|
||||
clearCache(0, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Solve this
|
||||
*
|
||||
* @param file Directory to be removed
|
||||
*/
|
||||
private static void removeDirectory(File file){
|
||||
File[] files;
|
||||
if ((files = file.listFiles()) != null){
|
||||
for(File f : files){
|
||||
if (f != null){
|
||||
File[] dirFiles;
|
||||
if (f.isDirectory() && (dirFiles = f.listFiles()) != null && dirFiles.length > 0){
|
||||
System.out.println(dirFiles.length);
|
||||
removeDirectory(f);
|
||||
}else{
|
||||
System.out.println("Deleting " + f.getAbsolutePath());
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.parabot.core.asm;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.parabot.Test;
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.Directories;
|
||||
import org.parabot.core.asm.redirect.*;
|
||||
@@ -20,7 +21,7 @@ public class RedirectClassAdapter extends ClassVisitor implements Opcodes {
|
||||
|
||||
private String className;
|
||||
|
||||
private static PrintStream str_out, class_out;
|
||||
private static PrintStream str_out, class_out, dec_out;
|
||||
|
||||
static {
|
||||
redirects.put("java/awt/Toolkit", ToolkitRedirect.class);
|
||||
@@ -40,6 +41,7 @@ public class RedirectClassAdapter extends ClassVisitor implements Opcodes {
|
||||
if (str_out == null && Core.shouldDump())
|
||||
try {
|
||||
str_out = new PrintStream(new FileOutputStream(new File(Directories.getWorkspace(),"strings.txt")));
|
||||
dec_out = new PrintStream(new FileOutputStream(new File(Directories.getWorkspace(),"decrypted_strings.txt")));
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
@@ -89,8 +91,15 @@ public class RedirectClassAdapter extends ClassVisitor implements Opcodes {
|
||||
|
||||
@Override
|
||||
public void visitLdcInsn(Object o) {
|
||||
if (o instanceof String && str_out != null)
|
||||
if (o instanceof String && str_out != null) {
|
||||
str_out.println(className + " " + o);
|
||||
if (!className.toLowerCase().contains("parabot")) {
|
||||
dec_out.println(o + ":");
|
||||
dec_out.println("\t" + Test.C((String) o));
|
||||
dec_out.println("\t" + Test.C2((String) o));
|
||||
dec_out.println();
|
||||
}
|
||||
}
|
||||
super.visitLdcInsn(o);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user