Researched by Ed Ort
January 4, 2002
Question
How can I use an obfuscator with the J2ME Wireless Toolkit?
Tip
At this time, it is not possible to incorporate obfuscation into the build
or package process performed by the J2ME Wireless Toolkit release 1.0.3.
Therefore, if you want to obfuscate your MIDlet suite, you need to do it manually.
The main difference in obfuscating a J2ME application is the need to manually
rerun the preverifier after the obfuscation is finished. You need to do this
because obfuscators usually remove the necessary additional data added by the preverifier to the class files. In addition, obfuscators usually load all classes referenced by your MIDlet suite's class files. Some of these classes might be the ones in the MIDP API (that is, the file midapi.zip in the lib subdirectory of the Wireless Toolkit's installation directory). However, some of the MIDP API classes have native methods that cause the obfuscators to stop. To avoid this problem, you can use an "emptied out" MIDP API, that is, a MIDP API without the native methods. An emptied out MIDP API is available in a ZIP file created by the Wireless Toolkit Engineering Team.
Following are step-by-step instructions on how to obfuscate a MIDlet suite using the
RetroGuard obfuscator version 1.1. The instructions assume the use of the UIDemo example provided with the J2ME Wireless Toolkit. The instructions also assume:
- The J2ME Wireless Toolkit is installed in
c:\j2mewtk
- The RetroGuard JAR file is in the
bin subdirectory of the Wireless Toolkit's installation directory, that is, c:\j2mewtk\bin
- The "emptied out" MIDP API is in the
wtklib subdirectory of the Wireless Toolkit's installation directory.
- The JDK's
bin subdirectory is in the PATH variable setting (this is
required by the preverifier).
To obfuscate a MIDlet suite using the RetroGuard obfuscator:
- Package a MIDlet suite, that is, create the appropriate JAR and JAD files.
You can do this by selecting Project->Package from the Wireless Toolkit's KToolbar. If you're using the Forte for Java IDE, right-click a MIDlet suite and select Update JAR from the Popup menu.
- Rename the generated JAR file, for example,
UIDemo.jar to UIDemo-orig.jar.
- Create a script file that tells the obfuscator which classes not to obfuscate. These classes should be the MIDlets specified in the JAD file, (that is, the classes that subclass
javax.microedition.MIDlet), and any classes that are dynamically loaded using Class.forName(). Place the file in the same directory as the JAR and JAD files. The example script file (ignore.rgs) is in RetroGuard format and was created for the UIDemo suite.
- Run the following command (all on the same line) from the command line:
java -classpath c:\j2mewtk\bin\retroguard.jar;
c:\j2mewtk\wtklib\emptyapi.zip
RetroGuard UIDemo-orig.jar UIDemo-obf.jar ignore.rgs
- Run the preverifier on the newly obfuscated JAR file (enter the command on one line):
c:\j2mewtk\bin\preverify.exe -classpath
c:\j2mewtk\lib\midpapi.zip UIDemo-obf.jar
- Copy the preverified JAR from the
output subdirectory that was created by the preverifier, and rename it to the original JAR file:
copy .\output\UIDemo-obf.jar UIDemo.jar
- Run the MIDlet suite:
c:\j2mewtk\bin\emulator.exe -Xdescriptor:UIDemo.jad
Acknowledgments
Thank you to member Ariel Levin for the solution to this question.
Back To Top
|
|