Just to have this make more sense, the code:
This is the way I am not supposed to open my file.
Works like a charm, but it should not when accessing the file system.
code:
public void init()
{
java.net.URLConnection Conn = null;
java.net.URL myUrl = null;
java.io.InputStream fpointer = null;
try{
myUrl = new java.net.URL(this.getCodeBase().toString()+"/Kinkimono.ttf");
fpointer = myUrl.openStream();
}
catch(Exception e){
System.out.println("Bad url");
}
In theory, I should use fpointer as a fileinputstream, and pass it a vaild file handle.
But the following code won't work.
code:
try{
fpointer = new FileInputStream("Kinkimono.ttf");
}
catch(Exception e){
System.out.println("shoot, can't find the file:: " + " because::" + e.getMessage());
}
Practically, this is just "applied Java coding experience", I wanted to do something the Java engineers did not expect and had blocked.
I managed to do it by abusing a feature they had expected... but didn't expect to be used this way.
It really all comes down to onions. Find the mismatch, and there you go.
Btw, as I said, I "suspect", but have not tested ways to use this from a remote applet.
Currently, the applet when run locally can bypass the Java security manager and read local files without any prompt, the user just has to open the web page which includes it.
This is convenient to geeks like me for demo purposes, and that's about it, but beware, do not open .html+.class attachments from untrusted sources.
If what I suspect is true, the trick could be extended to make it possible to load local content from a remote java applet.
I can hardly believe it works to that extent, but my little finger keeps saying "yo, they didn't even consider it would ever work locally".
...And they had no reason to consider it, theyre specs said "users will use urlinputstreams for content from the web, fileinputstreams for local files, the security manager takes care
of wether or not resources can be accessed" I love the concept.