2 Replies Latest reply: Jan 18, 2011 2:46 AM by 831998 RSS

    Modifying and re-preverifying classes in existing JAR file

    843849
      Suppose I have an existing JAR file that was developed using an SDK like the Motorola SDK. In other words, it was compiled and preverified using the Motorola MIDP/CLDC libraries and preverfier tools. I am just using Motorola as an example - it could be a JAR from any number of SDKs that are not the Sun WTK.

      From the JAD file, I know the name of the class that extends MIDlet, ie the main class that the JVM will launch.

      Now suppose that I want to add a new class that extends the original MIDlet class. In other words, if the original MIDlet class was OrigMIDlet, I want to create a class called MyNewMIDlet that extends OrigMIDlet and list this class in the JAD instead of OrigMIDlet. Assume that OrigMIDlet is not final so this can be done.

      The problem is this. I do not have the source code for the classes in the original JAR, and these classes are probably obfuscated anyway. Even more importantly, I may not actually know which exact SDK was used to build the JAR in the first place. But my new class MyNewMIDlet just needs to call the standard MIDlet methods startApp(), pauseApp() etc and does NOT need to access any other classes in the original JAR.

      So is it possible for me to add my MyNewMIDlet class to the JAR file if I compile and preverify using the standard preverify tool and library in the Sun WTK? In other words, will the JVM on the phone allow an app to run if one of the classes used the Sun preverify tool and libraries rather than say the Motorola preverify tool used by the rest of the classes? If this doesn't work, please tell me why not. What exactly is the difference between the different preverify tools in the different SDKs? Under which situations can we preverify different classes with different preverify tools?

      And yes, I will have permission from the JAD/JAR vendor to do all this. There are a number of publishers who are willing to have their games/apps modified in a certain way as long as they themselves don't have to do any recoding, ie as long as I can operate directly on the JAR file. So all legal/ethical issues have been resolved. This is purely a technical question to see if this is possible and what sorts of snags can result.

      Another possibility is to use the javassist library to modify the JAR bytecode directly. I could leave the OrigMIDlet class as the main class called by the JVM, but I could use javassist to modify startApp() to run some of my code in my new classes before doing whatever was originally inside startApp(). But the question remains: must I recompile and preverify using whatever libraries and SDKs were used to create the original JAR? Or is it possible to compile and preverify my new classes with the basic Sun WTK MIDP1.0 libraries/classfiles and preverify tool and then insert these into the existing JAR file? And if I modify the OrigMIDlet class with javassist, then will I need to preverify that all over again before re-inserting into the JAR file? And can I use the Sun preverifier on that?

      I realize this is a big list of questions, but any help or insight would be appreciated.
        • 1. Re: Modifying and re-preverifying classes in existing JAR file
          843849
          this shouldn't be a problem, I actually recall doing something like this a few years ago so i could generically wrap jars with a custom midlet that made the 'production' jar into a 'demo' jar (by limiting the amount of times it could be launched).
          • 2. Re: Modifying and re-preverifying classes in existing JAR file
            831998
            Hello,

            I would like to use javassist library to modify the JAR bytecode. If you have obtained the answers to your initial questions related to javassist, please post the anwers here.
            Many thanks!

            Note - Here are the questions (taken from the first post) that I am interested in
            1) Must I recompile and preverify using whatever libraries and SDKs were used to create the original JAR?
            2) Or is it possible to compile and preverify my new classes with the basic Sun WTK MIDP1.0 libraries/classfiles and preverify tool and then insert these into the existing JAR file?
            3) And if I modify the OrigMIDlet class with javassist, then will I need to preverify that all over again before re-inserting into the JAR file? And can I use the Sun preverifier on that?