But I will show you how to correct our mistakes without using the compiler.
Let's start:
I have written a program in Delphi. Let's see my mistake.
I have created a form like this.
[attachment=1170:000.JPG]
After this I wrote the codes in the Compare Button click as below.
CODE
1. procedure TForm1.ComparebuttonClick(Sender: TObject);
2. var
3. a,b:integer;
4. begin
5. a := StrToInt(EditA.Text);
6. b := StrToInt(EditB.Text);
7.
8. if a<b then // Look at here carefully. We have made a mistake. We should have written a>b
9. ShowMessage('A is greater than B')
10. else
11. ShowMessage('A is not greater than B');
12. end;
As you can see, I wrote wrong at line 8.2. var
3. a,b:integer;
4. begin
5. a := StrToInt(EditA.Text);
6. b := StrToInt(EditB.Text);
7.
8. if a<b then // Look at here carefully. We have made a mistake. We should have written a>b
9. ShowMessage('A is greater than B')
10. else
11. ShowMessage('A is not greater than B');
12. end;
Let's run the program.
[attachment=1171:first_screen.JPG]
Enter 13 in the first editbox
Enter 7 in the second editbox, and click Compare
13 is greater than 7, but the message saying A is not greater than B because of our mistake at line 8.
Now let's correct our mistake by Debugging. You need a debugger, All debuggers can do our work. I will use Olly Debugger here.
Open the Olly Debugger and open our exe by clicking File -> Open. And go to the related directory and open our project file, Project1.exe.
We opened our exe with Olly Debugger. Now you can see there are lots of ASM codes.
Right click on any ASM codes in the windows which has the tabs Address, Hex dump, Disassembly, Comments.
Select Search For -> All Referenced Text Strings , like in the picture below.
[attachment=1172:second.JPG]
A new window will come which's caption is Text strings referenced in Project:CODE.
In this window press Home key to go to the top. Right Click and select Search for Text, like in the picture below.
[attachment=1173:third.JPG]
A new messagebox will come which's caption is Enter text to search for.
Remember that in our exe when we press Compare the message is coming and saying A is not greater than B. So let's search the word greater than.
Write greater than and press OK like this picture below.
[attachment=1174:forth.JPG]
The text will be found, like this picture below.
[attachment=1175:fifth.JPG]
Double click the selected line. This will get you back to the ASM codes. As this picture below.
[attachment=1176:sixth.JPG]
In Delphi, C++, PHP,... we are using if statement, but in Assembly the if statement is different and there are lots of codes about if statements. For example:
if (a<=b ) can be written as JLE.
JLE means Jump if Less or Equal. JG :Jumg if greater. JNZ :Jump if not zero. .... etc.
As you can see in the picture above there is a JLE one line upside. Double click on the JLE line and there will come a new message box, like this picture below.
[attachment=1177:seventh.JPG]
In textbox replace JLE to JG . The last text is JG SHORT 0045384F
Press Assemble button. JLE will be replaced to JG in the Assembly codes section. Now you can close the message box.
Now right click on any ASM codes and select Copy to executable -> All Modifications, like this picture below.
[attachment=1178:nineth.JPG]
A message box is asking us "Copy selection to executable file?". Click Copy All.
A new window will come which is showing the difference we made. Looks like this picture below.
[attachment=1179:tenth.JPG]
Right click on the selected line and select Save File.
A Save As dialog box will appear. Save your file as new.exe
Now you can close Olly Debugger.
Congratulations. You have debugged your exe file. Now let's check it if it is working properly.
Run new.exe , And type 13 and 7 again. Press Compare.
[attachment=1180:eleventh.JPG]
The message box is saying A is greater than B which means 13 is greater than 7.
As you can see our program is working properly.
We have corrected our mistake in code without using compiler. We debugged.
By the way do not try to debug any copyrighted application.


