Iam having only one main class and I've hardcoded the values like password in the main class file.Then we are giving the option of changing password for the user.
The obvious way is to change the value of password variable ,but it works for that instance of running program. There are ways like configuaration files,Serialization .But they create one more extra file. Is it possible to do with one and only one main class.
In theory, you could find the .class file and change the data in the class file itself. There are several different ways you might accomplish this, but all of them are pretty silly.
If you package your application in a jar file, then you might consider storing the data in a file in the jar file, and then having the program update the jar file. This is still silly, but maybe a little less so.
And of course, both of these schemes assume your .class or .jar file is writeable; what if it's stored on a CD?
1. Storing the password in the class isn't just dangerous, but stupidly dangerous. If you rely on the obscurity of burying the password into the class, you're just welcoming disaster. There are too many better places to store it that I almost wish to just leave this topic alone.
2. If you really must use this, the only sane solution is to use ASM (http://asm.objectweb.org/) to re-engineer the class to which will contain the new password (not even close to simple thats for sure) then use JRE 1.5+'s java.lang.instrument package to redefine the runtime instance of the class so that you know it worked. Once re-engineered and redefined successfully, you can then attempt to write the byte array over the original class file if you can find it. Hint: start with MyReallyBadIdea.class.getClassLoader().getResource(MyReallyBadIdea.class.getName().replace(".", "/") + ".class").
3. Finally, this is the worst solution to any problem you could possibly have and you're in for a world of hurt trying, even if its just for fun.
I've taken password as an example for changing code...it may look stupid .
I've seen win32 applications like this which doesn't store passwords anywhere ( Registry,property pages,configuration files....etc).I think its possible because a win32 valid executable can contain resource files.
At machine level , a program is combination of code i.e instructions and DATA,so can't we change the data i.e state of the program
Reverse Engineering the class file and changing resources like text strings are certainly possible.But,what i am looking is programatical change....
Anyway thanks for your suggestions.... [ March 01, 2008: Message edited by: ramya sri ]
mooooooo ..... tiny ad ....
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth