Archive for the ‘debugger’ Category

What is a debugger?
Debugger is a program that used to test, explore or find a bug (error) in other program. Using debugger you can run the program step by step. You can analyze why a program crash. You can stop a program with a specific conditions. If you’ve ever worked with Debug, on old MS-DOS program, you can even create a simply new program.

There are few debugger available for Linux:
-GDB (gnu debugger)
-Radare (reverse engineering and analyzing binaries)
-DDD (data display debugger)
-Nemiver (debugger for GNOME)
-Valgrind (memory debugger)
-Electric Fence (Malloc debugger)

What is Gnu Debugger?
GDB is a free software, protected by GPL (General Public License). GPL is a software license, globally used, which guarantees end users the freedom to run, study, share and modify the software.

GDB is part of Gnu Project, first annouched on 27 September 1983 by Richard Stallman at MIT to develop a complete Unix-Like operating system which is free software. Gnu Debugger (GDB), Gnu Assembler (GAS) and Gnu C Compiler (GCC) are part of it.

GDB can be used to debug programs written C, C++, Assembly, ADA, D, Fortran, Go, Objective-C, OpenCL, Modula-2, Rust and Pascal (some still not work with pascal syntax). Richard Stallman was the original author of GDB.

Read Full Post »

In this article, I will show you assembly command for arithmetic function.

It’s increase ‘operand’ by 1 (one).

INC destination

Type the codes below and save it to ‘inc.asm’. It’s a very simple program. It will increase the value in variable num by 1 from 2 to 3.

1 section .text
2 global _start
3 _start:
5 ;put number in num
6 mov eax,2
7 mov [num],eax
8 inc byte [num]
10 ;exit
11 mov eax,1
12 mov ebx,[num]
13 int 0x80
15 section .data
16 num db 0

Compile and run the program.

$ nasm -f elf32 inc.asm -o inc.o
$ ld inc.o -o inc
$ echo $?
$ ./inc
$ echo $?


Read Full Post »

In assembly, register only know ASCII (American Standard Code for Information Interchange) characters. It mean, If you are working with number and need to display the result by calling syscall number 4 (32 bit x86), you can’t just put the result address into ecx register. Because, the ecx register will assume that your result in Hex number.
For example, your result is 7. ecx will assume that it’s 7hexadesimal not 7decimal meanwhile 7 is 37hexadesimal in ASCII table.

Let’s try in coding to see how it works.
It’s very simple program. I just do simple math, 4+2=6. I add 4 into eax register and 2 into ebx register. Then add ebx register to eax register, so the result will be:
eax = eax + ebx.
= 4 + 2
= 6

1 section .text
2 global _start
3 _start:
5 mov eax,4
6 mov ebx,2
8 add eax,ebx
9 mov [result],eax
11 mov eax,4
12 mov ebx,1
13 mov ecx,result
14 mov edx,1
15 int 0x80
17 mov eax,4
18 mov ebx,1
19 mov ecx,newline
20 mov edx,1
21 int 0x80
23 mov eax,1
24 int 0x80
26 section .data
27 newline db 0xA
29 section .bss
30 result resb 1

$ nasm -f elf32 add.asm -o add.o
$ ld add.o -o add
$ ./add


Read Full Post »

What is stack register?
Stack is a group of memory which is use for storage informations during the execution of program. It’s temporary area in CPU.
How it work?
The First data that goes into the stack is the Last data that come out from the stack.

In this article I will show you how it works using gdb (gnu debugger).
First, I create a program named stack in assembly language. I name the file stack.asm.

section .text
 global _start

 push 0xBBBBBBBB
 push 0xCCCCCCCC
 push 0xDDDDDDDD

pop eax
 pop ebx
 pop ecx
 pop edx

 mov eax,1
 mov ebx,0
 int 0x80

Then I compile with “nasm” and link with “ld”. I add option -gstabs+ to tell nasm to save debugging information that I will use in gdb to print the line of assembler code that correspond to each assembler instruction. Since my processor is 32 bit, the format will be elf32.

$ nasm -f elf32 -gstabs+ stack.asm -o stack.o
$ ld stack.o - stack

Now, let start using gdb.
Type “gdb” followed by the program “stack”.

$ gdb stack
GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08 
Copyright (C) 2011 Free Software Foundation, Inc. 
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it. 
There is NO WARRANTY, to the extent permitted by law. Type "show copying" 
and "show warranty" for details. 
This GDB was configured as "i686-linux-gnu". 
For bug reporting instructions, please see: 
Reading symbols from /home/darklinux/assembly/stack...done. 


Read Full Post »