Lab 2
Lab 2
First type “$ gdb -h” to get all the available options. Out of all that the only option
use is “-q” which is quit start. It just suppresses licensing info. Another option
which can be helpful is “-p” which is used for attaching already running process to
GDB.
- “info” (i) command is used for extracting information of various kind. Just type
“(gdb) help info” to get every available option. Some useful options are:
2. info registers — List of integer registers and their contents
3. info symbol — Describe what symbol is at location ADDR
4. info breakpoints — Status of specified breakpoints (all user-
settable breakpoints if no argument)
5. info files — Names of targets and files being debugged
- “break” (b) command is used for setting a break point. This breakpoint can be set
against “address”, “function” etc. GDB also offers facility of conditional
breakpoints, which we will be using multiple times
- “run” (r) command will run the loaded executable inside GDB.
- “disassemble” (disas) is the command to disassemble the pointed instruction.
- “stepi” command will help to execute step by step execution.
break
break [addr] sets a breakpoint
*_start+5
print/d
print/d $ecx print expression in decimal
[expr]
print/x
print/x $ecx print expression in hex
[expr]
x/NFU x/12xw
Examine contents of memory in given format
[addr] &msg
- Type following command to get details about list of symbols in the executable.
As we can see since program is not running register values are mostly zero. Mind
you that these values are relative.
- Lets disassemble the code. Note that disas command can disassemble address,
function or register value. In our case we have disassembled EIP register value,
which is address of next instruction
Here I have defined very simple hook. It will disassemble $eip and next 10
instructions, then display value of EAX, EBX, ECX, EDX respectively. On
running program, you’ll get following output:
We can observe the step by step changes in the value of registers. So after couple
of “stepi”s it will be something like below.
- Gõ liên tiếp một số lần lệnh stepi
- Kết quả sẽ như hình vẽ
- Finally just type “c” to continue execution. It will execute the program to the
end, if no other breakpoint present.
global _start
section .text
_start:
mov eax, 1
mov ebx, 0
int 80h
section .data
- (Executable Loaded in GDB with Breakpoint set to “_start” symbol. “r” for
starting execution of code)
- First, we will list out all the variables present in the code with “info
variables” command.