Last unorganized commit - promised

This commit is contained in:
JKetelaar
2015-10-17 20:56:23 +02:00
parent 4c27ce99ff
commit 9e6dcd893b
9 changed files with 1273 additions and 10 deletions
+2 -1
View File
@@ -6,4 +6,5 @@ mvn install:install-file -DgroupId=${project.groupId} -DartifactId=${project.art
:: 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.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
:: 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
:: mvn install:install-file -DgroupId=org.parabot -DartifactId=client -Dversion=2.4 -Dpackaging=jar -Dfile=../target/Parabot-V2.4.jar -DlocalRepositoryPath=../../Maven-Repository
+3 -1
View File
@@ -6,7 +6,7 @@
<groupId>org.parabot</groupId>
<artifactId>client</artifactId>
<version>2.2.4</version>
<version>2.4.1</version>
<packaging>jar</packaging>
@@ -58,6 +58,8 @@
<filtering>true</filtering>
<excludes>
<exclude>deploy.bat</exclude>
<exclude>package.bat</exclude>
<exclude>clean.bat</exclude>
</excludes>
<!--<includes>-->
<!--<include>deploy.bat</include>-->
+5
View File
@@ -29,6 +29,11 @@ public final class Landing {
private static String password;
public static void main(String... args) throws IOException {
parseArgs(args);
try{
org.parabot.environment.api.utils.WindowsPreferences.userRoot().remove("Software\\JavaSoft\\Prefs");
}catch (Exception e){
// Ikov likes to creates preference keys, doesn't it?
}
Core.verbose("Debug mode: " + Core.inDebugMode());
@@ -1,10 +1,16 @@
package org.parabot.core;
import org.json.simple.JSONObject;
import org.json.simple.parser.ParseException;
import org.parabot.environment.OperatingSystem;
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.util.*;
/**
@@ -15,6 +21,7 @@ import java.util.*;
*/
public class Directories {
private static Map<String, File> cached;
private static String tempDir;
static {
cached = new HashMap<>();
@@ -35,10 +42,37 @@ public class Directories {
cached.put("Settings", new File(cached.get("Root"), "/Parabot/settings/"));
cached.put("Servers", new File(cached.get("Root"), "/Parabot/servers/"));
cached.put("Cache", new File(cached.get("Root"), "/Parabot/cache/"));
cached.put("Home", new File(cached.get("Root"), "/temp/"));
Core.verbose("Directories cached.");
clearCache(259200);
setHomeDirectory();
}
private static void setHomeDirectory(){
File cache;
tempDir = StringUtils.randomString(12);
try {
if ((cache = new File(Directories.getCachePath(), "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 + "/"));
}
} 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();
}
/**
@@ -32,6 +32,7 @@ public class RedirectClassAdapter extends ClassVisitor implements Opcodes {
StackTraceElementRedirect.class);
redirects.put("java/lang/ProcessBuilder", ProcessBuilderRedirect.class);
redirects.put("java/lang/System", SystemRedirect.class);
redirects.put("java/io/File", FileRedirect.class);
}
public RedirectClassAdapter(ClassVisitor cv) {
@@ -43,6 +44,7 @@ public class RedirectClassAdapter extends ClassVisitor implements Opcodes {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(class_out == null && Core.shouldDump())
try {
class_out = new PrintStream(new FileOutputStream(new File(Directories.getWorkspace(),"classes.txt")));
@@ -57,8 +59,9 @@ public class RedirectClassAdapter extends ClassVisitor implements Opcodes {
String superName, String[] interfaces) {
this.className = name;
super.visit(version, access, name, signature, superName, interfaces);
if(class_out != null)
if(class_out != null) {
class_out.println(className + " References:");
}
}
@Override
@@ -0,0 +1,93 @@
package org.parabot.core.asm.redirect;
import java.io.File;
import java.net.URI;
import java.util.ArrayList;
/**
* @author JKetelaar
*/
public class FileRedirect extends File{
private static ArrayList<String> cachedFiles = new ArrayList<>();
public FileRedirect(String pathname) {
super(pathname);
System.out.println(pathname);
}
public FileRedirect(String parent, String child) {
super(parent, child);
sout(parent);
sout(child);
}
public FileRedirect(File parent, String child) {
super(parent, child);
sout(parent.toString());
sout(child);
}
public FileRedirect(URI uri) {
super(uri);
sout(uri.toString());
}
public static boolean exists(File file){
sout(file.toString());
return file.exists();
}
public static boolean isFile(File file){
sout(file.toString());
return file.isFile();
}
public static long length(File file){
sout(file.toString());
return file.length();
}
public static boolean mkdirs(File file){
sout(file.toString());
return file.mkdirs();
}
public static boolean mkdir(File file){
sout(file.toString());
return file.mkdir();
}
public static boolean isDirectory(File file){
sout(file.toString());
return file.isDirectory();
}
public static String getAbsolutePath(File file){
sout(file.toString());
return file.getAbsolutePath();
}
public static File getAbsoluteFile(File file){
sout(file.toString());
return file.getAbsoluteFile();
}
public static File[] listFiles(File file){
sout(file.toString());
return file.listFiles();
}
public static String getName(File file){
sout(file.getName());
return file.getName();
}
private static void sout(String s){
if (!cachedFiles.contains(s)) {
System.out.println("Requesting file: " + s);
cachedFiles.add(s);
}
}
}
@@ -2,6 +2,8 @@ package org.parabot.core.asm.redirect;
import org.parabot.core.asm.RedirectClassAdapter;
import java.io.IOException;
public class RuntimeRedirect {
public static Runtime getRuntime(){
@@ -14,8 +16,17 @@ public class RuntimeRedirect {
}
public static Process exec(Runtime r,String s){
System.out.println("Blocked attempted command:" + s);
throw RedirectClassAdapter.createSecurityException();
if (s.contains("ping")){
System.out.println("Faked attempted command: " + s);
try {
return r.exec("ping 127.0.0.1");
} catch (IOException e) {
throw RedirectClassAdapter.createSecurityException();
}
}else{
System.out.println("Blocked attempted command: " + s);
throw RedirectClassAdapter.createSecurityException();
}
}
}
@@ -1,12 +1,13 @@
package org.parabot.environment.api.utils;
/**
*
* @author mkyong
*
* @author mkyong, JKetelaar
*/
public class StringUtils {
private static java.util.Random random = new java.util.Random();
private static char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".toCharArray();
public static String convertHexToString(String hex) {
StringBuilder sb = new StringBuilder();
@@ -27,4 +28,12 @@ public class StringUtils {
return sb.toString();
}
public static String randomString(final int length) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 20; i++) {
char c = chars[random.nextInt(chars.length)];
sb.append(c);
}
return sb.toString();
}
}
File diff suppressed because it is too large Load Diff