Modification of the games on the example of Arcanoid

Good day!

Introduction


For some time I have been watching the blog Assembler habré in view of the fact that there began to appear more than articles on the analysis of various keygen's and "reverse engineering". I've been wanting to do something similar and modify some game on J2ME. I roamed the Internet in search of a good, but at the same time easy to understand (in terms of analysis) of the game. One day, I was digging on the website of my friend the programmer (by the way, he also writes programs for J2ME. Who used ProPaintMobile — he knows who I'm talking about. And I found it — it was a simple Arkanoid. Apparently, this was someone's homework, or he had just written "just for fun", but nevertheless this game was exactly what you needed.


What we need


In order to make a modification we need the following components:

    the Decompiler that would give us the source code, to make it easier to navigate the change process byte code. I personally use for these purposes, Java Decompiler that you can pull here; the

  1. Disassembler of byte code virtual machine us this the byte code will issue JavaByte, which can be downloaded here;
  2. the
  3. Itself experimental — Arcanoid;
  4. the
  5. and still it would be nice to see a specification, which contains virtual machine instructions, which you can read here.

Perhaps all. In fact, the choice of software is an individual matter, and I would say intimate. So you can easily use, for example, Jasmin is a Java Decompiler.

What do we do now


Step one

First we need to open enemy car this game and see what you can modify. Since the original jar file we have, but there are preverification classes and MANIFEST.MF, let's pack our game. No sooner said than done.


The structure of our file should look exactly as shown above. You only have to change the extension from zip to jar.

Step two

And run our game. Let's have a little play.


Continue to play...


Oops. Okay, two more lives left. Play on.


All finished badly. Need something to do.

Step three

Do something with it, namely Decompiler. No problem. Digging in the source code and understand what is most interesting is stored in the file GCanvas.java. Let's take a closer look at what's what:



Here we see the constructor, variables and methods.

It is worth Recalling that we are looking for you where we diminish life. Look for the reference to live or lives. We got lucky here. Since the game is not obfuscated, we can see the variables and methods with a more or less real names. And then our eyes catches on the following line at the beginning of the source file:

the
 
int m_m_LivesII; 


No comment. This is counter of our lives. It only remains to find where this variable is reduced. And that's where, as indicated by the Decompiler, it's line 170:

the
 
this.m_m_LivesII -= 1; 


Let's examine this piece of code:

the
 
while (this.m_m_goGameZZ) 
{ 
if (!this.m_m_playGameZZ) 
{ 
if (this.m_m_boomZZ) 
{ 
this.m_m_ballcBallcBall.setVisible(false); 
_AnimateBoomcGraphicsV(g); 
this.platform.setVisible(false); 
this.m_m_LivesII -= 1; 


Then, we can say, we are given a complete manual: if a variable is m_m_goGameZZ, which is Boolean is the value true, the game is. The collision, is also a Boolean variable called m_m_playGameZZ becomes the value false, then animates the explosion of the platform (_AnimateBoomGraphics), then the platform becomes invisible (platform.setVisible(false)), and then we take life that you can see in the code that is above. Of course, the first thing that comes to mind is instead of a variable m_m_LivesII subtract unit, it is necessary to modify code to add. But it is not on Feng Shui somehow. Then it just equate a variable to unit. And precompiledweb? It need to be recompiled, preferibilmente classes, and then reassemble all the files. No, I'm too lazy. But there is a way just to modify the byte code of the class and then we will not need to perform the first two steps. Moving on...
What's the step? Oh yeah, the fourth

In order to edit byte code we have a JavaBite. What would make use of it.
Let's open our class (Classes -> Add a Java Class and see this picture:



I hope you remember where the piece of code that called interested? Similarly, this method run. Take a look at it:



Let's run through the eyes of the user from the beginning. Stop! Nothing like?



Yes, that's exactly what we need. Through the manual down you'll notice the isub — this is it!
Generally, speaking the Russian language, this statement means that we subtract from the variable m_m_LivesII. We need to make this variable was always equal to one. It is very easy to achieve. Let's change the isub on nop. Click the right mouse button and select Edit Instructions. There's even screenshots do not. In the end, the user would look like this:



Let down our already stereotyped class with the replacement of the old and try to open our game, but instead of it we get to play here is the error message:



Debriefing

From this message we can understand that the class contains an error. Yes, cap!
But what is it? The thing is that the nop in this case, will cause the imbalance of the of the stomach the stack and to us to solve the problem we need for thenopit and the iconst_1. Why? I'll leave as homework. This statement is on the arm's length immediately after our nop. By the way, here she is:



In fact, doing the things that had to do with her yesterday. Voila!



Now personarum our game. And finally it will play.




Now, when we miss our ball outside of the platform, we will always see:



We are not afraid of the gray wolf. Now you can safely play the game before losing momentum (although it will bore you after a minute because there are only two levels) and are not afraid of death!

Opinion


In fact, I did this experience at the time was new and the only master in all of these statements. Once for me they, and the assembler was a bad dream. However, time passes views change, we change. Hope this lesson was useful for you.

See you soon!

PS During this experience, no one arkanoid gets hurt!
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

March Habrameeting in Kiev

PostgreSQL load testing using JMeter, Yandex.Tank and Overload

Monitoring PostgreSQL with Zabbix