26.07.2018 Views

hacking-the-art-of-exploitation

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The display format also uses a single-letter shorthand, which is optionally<br />

preceded by a count <strong>of</strong> how many items to examine. Some common format<br />

letters are as follows:<br />

o<br />

x<br />

u<br />

t<br />

Display in octal.<br />

Display in hexadecimal.<br />

Display in unsigned, standard base-10 decimal.<br />

Display in binary.<br />

These can be used with <strong>the</strong> examine command to examine a certain<br />

memory address. In <strong>the</strong> following example, <strong>the</strong> current address <strong>of</strong> <strong>the</strong> EIP<br />

register is used. Shorthand commands are <strong>of</strong>ten used with GDB, and even<br />

info register eip can be shortened to just i r eip.<br />

(gdb) i r eip<br />

eip 0x8048384 0x8048384 <br />

(gdb) x/o 0x8048384<br />

0x8048384 : 077042707<br />

(gdb) x/x $eip<br />

0x8048384 : 0x00fc45c7<br />

(gdb) x/u $eip<br />

0x8048384 : 16532935<br />

(gdb) x/t $eip<br />

0x8048384 : 00000000111111000100010111000111<br />

(gdb)<br />

The memory <strong>the</strong> EIP register is pointing to can be examined by using <strong>the</strong><br />

address stored in EIP. The debugger lets you reference registers directly, so $eip<br />

is equivalent to <strong>the</strong> value EIP contains at that moment. The value 077042707 in<br />

octal is <strong>the</strong> same as 0x00fc45c7 in hexadecimal, which is <strong>the</strong> same as 16532935 in<br />

base-10 decimal, which in turn is <strong>the</strong> same as 00000000111111000100010111000111<br />

in binary. A number can also be prepended to <strong>the</strong> format <strong>of</strong> <strong>the</strong> examine command<br />

to examine multiple units at <strong>the</strong> target address.<br />

(gdb) x/2x $eip<br />

0x8048384 : 0x00fc45c7 0x83000000<br />

(gdb) x/12x $eip<br />

0x8048384 : 0x00fc45c7 0x83000000 0x7e09fc7d 0xc713eb02<br />

0x8048394 : 0x84842404 0x01e80804 0x8dffffff 0x00fffc45<br />

0x80483a4 : 0xc3c9e5eb 0x90909090 0x90909090 0x5de58955<br />

(gdb)<br />

The default size <strong>of</strong> a single unit is a four-byte unit called a word. The size<br />

<strong>of</strong> <strong>the</strong> display units for <strong>the</strong> examine command can be changed by adding a<br />

size letter to <strong>the</strong> end <strong>of</strong> <strong>the</strong> format letter. The valid size letters are as follows:<br />

b<br />

h<br />

w<br />

g<br />

A single byte<br />

A halfword, which is two bytes in size<br />

A word, which is four bytes in size<br />

A giant, which is eight bytes in size<br />

28 0x200

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!