<rdf:RDF
    xmlns:s='http://snipsnap.org/rdf/snip-schema#'
    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
    xml:base='http://pabrantes.net/blog/rdf'>
    <s:Snip rdf:about='http://pabrantes.net/blog/rdf#start/2006-06-04/1'
         s:name='start/2006-06-04/1'
         s:cUser='pabrantes'
         s:oUser='pabrantes'
         s:mUser='pabrantes'>
        <s:content>1 Reverse Engineering: cheating on your favorite J2ME game {anchor:Reverse Engineering: cheating on your favorite J2ME game}&#xA;Nowadays it&apos;s normal to own a cellphone that has a java virtual machine that can run J2ME applications.\\ Most of the time, your cellphone already comes with some games, but you can buy or download hundred of others all over the internet. &#xD;&#xA;&#xD;&#xA;But have you ever thought on how they are programmed? Or how you can cheat on them? Well I have, and since it they were written in java my first thought was on to reverse engineer the games, just for fun and being able to mess with their code. I know that cheating is bad, but I&apos;m a computer science guy.. I love to watch &quot;inside the box&quot; to see how things are working.&#xD;&#xA;&#xD;&#xA;I&apos;m not really into java reverse engineering, but I know two java decompilers, one written in java called {link:Mocha|url=http://www.brouhaha.com/~eric/software/mocha/|newWindow=true} and other written in C++ called {link:HomeBrew|url=http://www.pdr.cx/projects/hbd/|newWindow=true}. It&apos;s true they have been around for many years but, most of the time they do the job, specially if we&apos;re talking about simple j2me applications. Even if these decompilers are nice applications you have to keep in mind two things:&#xD;&#xA;&#xD;&#xA;1. Sometimes they are not able to decompile the entire bytecode resulting in a incomplete and probably non functional source code file.&#xD;&#xA;&#xD;&#xA;1. They do not work with class files compiled with javac from java 5 SDK.&#xD;&#xA;&#xD;&#xA;Anyway I grabbed the jar file from one of my favorite games, called Bounce, unziped it and fired Mocha against the bytecode files. There were 9 classes, mocha was able to decompile 8 of them. Using HomeBrew I managed to partially decompile the last class, although for my main purpose such class wasn&apos;t needed, so I just discarded it. &#xD;&#xA;&#xD;&#xA;My main objectives were:&#xD;&#xA;&#xD;&#xA;1. Understand what kind of interface a J2ME application uses, I know that there are tutorials, but I preferred to this in this way.&#xD;&#xA;&#xD;&#xA;1. Change the number of initial lives, I already have ended the game but is always fun to do this kind of cheats! &#xD;&#xA;&#xD;&#xA;The main interface was easy to find, just had to check the MANIFEST.MF file. The interface is pretty simple, the class has to extend __MIDlet__ which is an abstract class and makes you implement three methods, destroyApp(), pauseApp() and startApp().&#xD;&#xA;&#xD;&#xA;The 2nd objective also didn&apos;t took much to finish, I just ~~grepped~~ the source files for live and found a couple of statements referring to a variable called \ ~~numLives~~.\\&#xD;&#xA;There was a funny thing while doing procedure, even if I&apos;m fond of this game and play it for ages, I never had realized that if we have 5 lives and pick up an extra one, it doesn&apos;t add to your life counter. I just found that looking at grep&apos;s output, when I read:&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;if (mCanvas.numLives &lt; 5)&#xD;&#xA;{&#xD;&#xA;  mCanvas.numLives++;&#xD;&#xA;  mCanvas.mPaintUIFlag = true;&#xD;&#xA;}&#xD;&#xA;&#xD;&#xA;{code} &#xD;&#xA;&#xD;&#xA;Anyway instead of giving an higher value as inicial value I commented the line where it decreases the number of lives and ~~voila~~ immortality for this game! I then recompiled the code - keep in mind that to realize this last steps you need to have the j2me sdk installed - generated a new jar file, uploaded to my cellphone and gave it a try. &#xD;&#xA;\\I killed myself (obivously in the game) and the number of lives wasn&apos;t affected. \\&#xD;&#xA;I think I can call a success! &#xD;&#xA;&#xD;&#xA;This was only a simple and fun trick to show you the power of reverse engineering. But do your own experiences, you&apos;ll see that you&apos;ll find  it interesting. &#xD;&#xA;&#xD;&#xA;What you do need:&#xD;&#xA;&#xD;&#xA;* Moche, HomeBrew or any other java decompiler&#xD;&#xA;* {link: J2ME SDK|url=http://java.sun.com/javame/|newWindow=true}&#xD;&#xA;* Patience&#xD;&#xA;* Knowledge about java&#xD;&#xA;&#xD;&#xA;Hope this post made you want to try to reverse engineer one of the java games you have.&#xD;&#xA;\\Have fun!</s:content>
        <s:mTime>2006-06-04 02:52:03.579</s:mTime>
        <s:cTime>2006-06-04 02:52:03.579</s:cTime>
        <s:comments
             rdf:type='http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag'/>
        <s:snipLinks>
            <rdf:Bag>
                <rdf:li rdf:resource='http://pabrantes.net/blog/rdf#pabrantes/post-history'/>
                <rdf:li rdf:resource='#snipsnap-notfound'/>
                <rdf:li rdf:resource='#pabrantes'/>
                <rdf:li rdf:resource='http://pabrantes.net/blog/rdf#start/2006-05-01/1'/>
            </rdf:Bag>
        </s:snipLinks>
        <s:attachments
             rdf:type='http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag'/>
    </s:Snip>
</rdf:RDF>
