Inside Paulo Abrantes' head
[ start | index | login or register ]
start > 2006-06-04 > 1

Reverse Engineering: cheating on your favorite J2ME game

Created by pabrantes. Last edited by pabrantes, 2 years and 78 days ago. Viewed 1,620 times. #1
[edit] [rdf]
labels
attachments

Reverse Engineering: cheating on your favorite J2ME game

Nowadays it'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.

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'm a computer science guy.. I love to watch "inside the box" to see how things are working.

I'm not really into java reverse engineering, but I know two java decompilers, one written in java called >>Mocha and other written in C++ called >>HomeBrew. It's true they have been around for many years but, most of the time they do the job, specially if we're talking about simple j2me applications. Even if these decompilers are nice applications you have to keep in mind two things:

  1. Sometimes they are not able to decompile the entire bytecode resulting in a incomplete and probably non functional source code file.
  2. They do not work with class files compiled with javac from java 5 SDK.
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't needed, so I just discarded it.

My main objectives were:

  1. Understand what kind of interface a J2ME application uses, I know that there are tutorials, but I preferred to this in this way.
  2. Change the number of initial lives, I already have ended the game but is always fun to do this kind of cheats!
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().

The 2nd objective also didn'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.
There was a funny thing while doing procedure, even if I'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't add to your life counter. I just found that looking at grep's output, when I read:

if (mCanvas.numLives < 5) { mCanvas.numLives++; mCanvas.mPaintUIFlag = true; }

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.
I killed myself (obivously in the game) and the number of lives wasn't affected.
I think I can call a success!

This was only a simple and fun trick to show you the power of reverse engineering. But do your own experiences, you'll see that you'll find it interesting.

What you do need:

  • Moche, HomeBrew or any other java decompiler
  • >> J2ME SDK
  • Patience
  • Knowledge about java
Hope this post made you want to try to reverse engineer one of the java games you have.
Have fun!
Please login to www.pabrantes.net.
Who am I?
paulo-roca2My name is Paulo Abrantes AKA pabrantes and I'm a software developer. I'm currently employed at >>CIIST working as a Java developer in >>FenixEDU.

This blog is mostly about Java programming, domain driven design and snipsnap bliki developing. Everything written in this blog is my personal opinion and it may not reflect the opinions of my employer and co-workers.


Blog subscription
subscribe by rss subscribe by email

Links
>> Home
>> Paulo's Profile
>> Post History
>> Add to Technorati Favorites
>> Paulo's Photo Gallery
>> WishList
>> Posting without Login

Search Blog
Fellow Bloggers

Recent Posts

Java Programming: Bytecode Injection
Intermission: Sorry For Downtime
Software Developing: Studying The Bliki Domain Model
SnipSnap Developing: Trying to settle a roadmap
System Administration: Load Balancing with Apache
Blogging: Two years have passed
Software Developing: The SnipSnap Saga
Java Programming: Getting your code spicy with Groovy
Software Developing: Fluent Interfaces
Software Developing: Implementing a ShoutBox on SnipsSnip
Software Developing: SnipSnap, SnipIt and SnipSnip
Java Programming: Proxies and Access Control
Java Programming: Proxies and References
Java Programming: References' Package
YALM: Yet Another Layout Modification

For older posts, please refer to post-history for a complete Post History

Logged in Users: (0)
… and 5 Guests.
This is a modified version of snipsnap.org created by >>Paulo Abrantes