smart solutions for small devices
[ start | index | login ]
start > J2ME > Reading files from J2ME on a 6600

Reading files from J2ME on a 6600

Created by bjoernQ. Last edited by bjoernQ, 10 years and 46 days ago. Viewed 4,955 times. #2
[diff] [history] [edit] [rdf]
labels
attachments

Not possible?

Well it's not that easy. But it can be done.
First of all we need everybody's darling - >>FExplorer.

Playing around with it we will find the midp20.exe. Beaming this via bluetooth to the PC and looking at it with an hex-editor … and we will find something like "com.symbian.midp.runtime.NativeFile". Wonder what this class could do …

Well there's a "open(String s)" and an "getBytes(byte buffer, int len)" and certainly a "close()". Cool.

Unfortunately these methods are not accessible from outside the package "com.symbian.midp.runtime". And if you try to add a class in that package to your jar file will result in a midlet that won't be installable.

But wait. You can create a dummy midlet. Install it and then change your code to include a Class that can call the wanted methods of NativeFile.

e.g.

package com.symbian.midp.runtime;

public class HackTest {

public static String testIt() throws Exception{ NativeFile nf = new NativeFile(); nf.open("c:\\SmallFile"); byte[] buffer = new byte[512]; int l = nf.getBytes(buffer,512); nf.close(); StringBuffer sb = new StringBuffer(); for(int i=0;i<l;i++){ sb.append( (char)(buffer[i])); }

return sb.toString();

}

}

(To compile the that class you will need the "kmidp20.zip" from the Nokia Series_60_MIDP_SDK_2_1 (I guess an other version will do also) in your classpath.)

Now transfer the resulting jar-file but don't install it! Locate the installed midlet (e.g. "E:\System\MIDlets\[12345678]\" and overwrite the contained jar with the newly created one.
Now launch the midlet and .... we're done. We can read a file from J2ME.


Conclusion

We can read a well known file. We have to tinker around with FExplorer since this hack cannot be installed easily. This method is not end-user friendly. But it's also not a security risk since the AMS hinders those midlets from being installed.
Unfortunately I haven't figured out a way to list files in a directory or write to a file. But it's more something like a proof of concept.
In the future we will have the PIM and File API in J2ME which makes something like this obsolete. (Although the access will be limited to files in some safe directories like "pictures" and "sound files").

no comments | post comment
www.mobile-j.de | Bjoern Quentin