Next release. Worked more on SecurityManager, it is finally getting there.

This commit is contained in:
Travis Burtrum 2010-03-31 02:46:07 -04:00 committed by moparisthebest
parent 70a4c73f10
commit b9a6fef0e4
5 changed files with 47 additions and 28 deletions

View File

@ -8,8 +8,8 @@ import java.io.PrintStream;
public class Main { public class Main {
public static final String folderName = "/home/mopar/htdocs/508/"; public static final String folderName = "/home/mopar/htdocs/508/";
// some (crappy) filesystems can handle more than this many files in any given folder, so we have to handle it (suffer) // some (crappy) filesystems can't handle more than this many files in any given folder, so we have to handle it (suffer)
public static final int maxFilesInFolder = 33000; public static final int maxFilesInFolder = 33005;
public static PrintStream log; public static PrintStream log;
public Main() { public Main() {
@ -77,10 +77,16 @@ public class Main {
maxIds[10] = 1; maxIds[10] = 1;
dumpFile(cache, 10,1431655766); dumpFile(cache, 10,1431655766);
for (short index = 0; index <= 255 && index >= 0; ++index) int idCount;
for (int id = 0; id <= maxId && id >= 0; ++id) for (short index = 0; index <= 255 && index >= 0; ++index){
idCount = 0;
for (int id = 0; id <= maxId && id >= 0; ++id){
//for (int id = 0; id <= maxIds[index] && id >= 0; ++id) //for (int id = 0; id <= maxIds[index] && id >= 0; ++id)
dumpFile(cache, index, id); if(!dumpFile(cache, index, id))
++idCount;
}
System.out.println("total files for index '"+index+"' is '"+idCount+"'");
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -172,14 +178,18 @@ public class Main {
} }
public static File checkFile(int index, int id) throws Exception { public static File checkFile(int index, int id) throws Exception {
File file = new File(folderName + index); String folder = folderName + index;
// handle crappy filesystems
if(id >= maxFilesInFolder)
folder += "/a";
File file = new File(folder);
if (!file.exists()) if (!file.exists())
if (!file.mkdir()) { if (!file.mkdirs()) {
println("can't create dir"); println("can't create dir");
System.exit(1); System.exit(1);
} }
file = new File(folderName + index + "/" + id); file = new File(folder + "/" + id);
if (file.exists()) { if (file.exists()) {
println("oh shit, collision!!!!!!"); println("oh shit, collision!!!!!!");
System.exit(1); System.exit(1);

View File

@ -94,9 +94,10 @@ public class Class20
is[i_3_] = (byte) -1; is[i_3_] = (byte) -1;
} }
} }
for(byte b : is) //xxx moparisthebest added
System.out.print(b + ", "); //for(byte b : is)
System.out.println(); // System.out.print(b + ", ");
//System.out.println();
class68_sub14.writeBytes(24, 0, is); class68_sub14.writeBytes(24, 0, is);
} }

View File

@ -7,6 +7,7 @@ package org.moparscape.classloader;
import org.moparscape.Update; import org.moparscape.Update;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.security.ProtectionDomain; import java.security.ProtectionDomain;
@ -22,7 +23,7 @@ import java.util.zip.CRC32;
*/ */
public class CRCClassLoader extends ClassLoader { public class CRCClassLoader extends ClassLoader {
private Map<String, byte[]> classes; private Map<String, byte[]> classes = new HashMap<String, byte[]>();
private long crcVal; private long crcVal;
private ClassLoader parent = null; private ClassLoader parent = null;
private ProtectionDomain pd = null; private ProtectionDomain pd = null;
@ -102,10 +103,16 @@ public class CRCClassLoader extends ClassLoader {
} }
private void setup(String jarFileLoc, boolean updateCRC) throws IOException { private void setup(String jarFileLoc, boolean updateCRC) throws IOException {
File f = new File(jarFileLoc);
if (!f.exists()) {
System.out.println("Jar file doesn't exist: " + jarFileLoc);
return;
}
JarFile jf = new JarFile(jarFileLoc); JarFile jf = new JarFile(f);
Enumeration entries = jf.entries(); Enumeration entries = jf.entries();
if(updateCRC)
classes = new HashMap<String, byte[]>(); classes = new HashMap<String, byte[]>();
CRC32 crc = null; CRC32 crc = null;
@ -119,7 +126,6 @@ public class CRCClassLoader extends ClassLoader {
while (entries.hasMoreElements()) { while (entries.hasMoreElements()) {
JarEntry entry = (JarEntry) entries.nextElement(); JarEntry entry = (JarEntry) entries.nextElement();
if (entry.getName().endsWith(".class")) { if (entry.getName().endsWith(".class")) {
//System.out.println("class name: " + entry.getName());
InputStream in = jf.getInputStream(entry); InputStream in = jf.getInputStream(entry);
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
int len; int len;
@ -135,6 +141,7 @@ public class CRCClassLoader extends ClassLoader {
crc.update(classArr); crc.update(classArr);
String className = entry.getName().substring(0, entry.getName().lastIndexOf(".")).replaceAll("/", "."); String className = entry.getName().substring(0, entry.getName().lastIndexOf(".")).replaceAll("/", ".");
//if (updateCRC) System.out.println("class name: " + className);
// save class // save class
classes.put(className, classArr); classes.put(className, classArr);
} }
@ -152,17 +159,17 @@ public class CRCClassLoader extends ClassLoader {
/** /**
* Is called by the ClassLoader when the requested class * Is called by the ClassLoader when the requested class
* is not found in its cache. The parent is only used when * is not found in its cache. The parent is only used when
* this is ran as an applet strangely. * this is ran as an applet, strangely.
* *
* @param name The name of the class * @param name The name of the class
*/ */
public Class<?> findClass(String name) throws ClassNotFoundException { public Class<?> findClass(String name) throws ClassNotFoundException {
// System.out.println("CRCClassLoader: Requesting class " + name); //System.out.println("CRCClassLoader: Requesting class '" + name + "'");
byte[] classBytes = classes.get(name); byte[] classBytes = classes.get(name);
if (classBytes == null) { if (classBytes == null) {
if (parent == null) if (parent == null)
throw new ClassNotFoundException("Couldn't find class " + name); throw new ClassNotFoundException("Couldn't find class " + name);
//System.out.println("Couldn't find class " + name + " trying parent class loader."); System.out.println("Couldn't find class '" + name + "' trying parent class loader.");
return parent.loadClass(name); return parent.loadClass(name);
} }
Class foundClass = defineClass(name, classBytes, 0, classBytes.length, pd); Class foundClass = defineClass(name, classBytes, 0, classBytes.length, pd);

View File

@ -120,7 +120,7 @@ public abstract class Server extends Thread {
public HttpURLConnection getHttpURLConnection(String request) { public HttpURLConnection getHttpURLConnection(String request) {
HttpURLConnection ret; HttpURLConnection ret;
String urlStr = customLocation + request; String urlStr = customLocation + request;
System.out.println("getHttpURLConnection urlStr: "+urlStr); //System.out.println("getHttpURLConnection urlStr: "+urlStr);
try { try {
ret = (HttpURLConnection) new URL(urlStr).openConnection(); ret = (HttpURLConnection) new URL(urlStr).openConnection();
// if response code is not 200 // if response code is not 200
@ -153,8 +153,7 @@ public abstract class Server extends Thread {
public void handleException(Exception e) { public void handleException(Exception e) {
if (MainPanel.debug()) { if (MainPanel.debug()) {
String myName = this.getClass().getName(); String myName = this.getClass().getName();
if (myName.equals("org.moparscape.userver.v508.OndemandServer443")) //if (myName.equals("org.moparscape.userver.v508.OndemandServer443")) return;
return;
System.err.print("Server error: "); System.err.print("Server error: ");
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -17,8 +17,10 @@ import java.net.URLConnection;
*/ */
public class OndemandServer extends Server { public class OndemandServer extends Server {
public static final String odsPath = "508/%d/%d"; public static final String odsPath = "508/%d%s/%d";
public static final int clientVersion = 508; public static final int clientVersion = 508;
// some (crappy) filesystems can't handle more than this many files in any given folder, so we have to handle it (suffer)
public static final int maxFilesInFolder = 33005;
public byte[] buffer = new byte[1024]; public byte[] buffer = new byte[1024];
public int len; public int len;
@ -113,9 +115,9 @@ public class OndemandServer extends Server {
//long hash = (long) ((index << 16) + id); //long hash = (long) ((index << 16) + id);
//System.out.println("request " + hash); //System.out.println("request " + hash);
//System.out.println(String.format(odsPath, index, id)); //System.out.println(String.format(odsPath, index, id >= maxFilesInFolder ? "/a" : "", id));
URLConnection url = getHttpURLConnection(String.format(odsPath, index, id)); URLConnection url = getHttpURLConnection(String.format(odsPath, index, id >= maxFilesInFolder ? "/a" : "", id));
// if url is null, custom and default cannot be reached, continue // if url is null, custom and default cannot be reached, continue
if (url == null) { if (url == null) {
// unless we want the update keys and may not be connected to the internet // unless we want the update keys and may not be connected to the internet
@ -163,16 +165,16 @@ public class OndemandServer extends Server {
// if size == -1 it doesn't exist // if size == -1 it doesn't exist
// however this cannot be counted on as a 404 will still send html // however this cannot be counted on as a 404 will still send html
//System.out.println("size: " + size); //System.out.println("size: " + size);
System.out.println("opening stream"); //System.out.println("opening stream");
InputStream data1 = url.getInputStream(); InputStream data1 = url.getInputStream();
System.out.println("InputStream Open!"); //System.out.println("InputStream Open!");
// buffer and len are static // buffer and len are static
while ((len = data1.read(buffer)) >= 0){ while ((len = data1.read(buffer)) >= 0){
System.out.println("len read:"+len); //System.out.println("len read:"+len);
out.write(buffer, 0, len); out.write(buffer, 0, len);
} }
System.out.println("Data Written! len:"+len); //System.out.println("Data Written! len:"+len);
out.flush(); out.flush();
data1.close(); data1.close();
} }