instructions for test_function

7
Instructions for test_function Instructions for main Text Segment void test_function(int a) { int flag = a*a; } int main( ) { int num = 8; test_function(num); } Source Code gcc, gdb ~ ~

Upload: uzuri

Post on 04-Jan-2016

21 views

Category:

Documents


0 download

DESCRIPTION

Text Segment. Source Code. void test_function ( int a) { int flag = a*a; } int main( ) { int num = 8; test_function ( num ); }. Instructions for test_function. gcc , gdb. Instructions for main. ~. ~. Text Segment. Source Code. void test_function ( int a) { - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Instructions for  test_function

Instructions for test_function

Instructions for main

Text Segment

void test_function(int a){ int flag = a*a;}int main( ){ int num = 8; test_function(num);}

Source Code

gcc, gdb

~ ~

Page 2: Instructions for  test_function

Instructions for test_function

Instructions for main

Text Segment

void test_function(int a){ int flag = a*a;}int main( ){ int num = 8; test_function(num);}

Source Code

eip

eip 0x08048366

esp 0xbffff800

ebp 0xbffff808

Registers

ADDRESS Contents Description0xbffff7f4 Garbage0xbffff7f5 Garbage0xbffff7f6 Garbage0xbffff7f7 Garbage0xbffff7f8 Garbage0xbffff7f9 Garbage0xbffff7fa Garbage0xbffff7fb Garbage0xbffff7fc Garbage0xbffff7fd Garbage0xbffff7fe Garbage0xbffff7ff Garbage0xbffff800 Garbage0xbffff801 Garbage0xbffff802 Garbage0xbffff803 Garbage0xbffff804 Garbage0xbffff805 Garbage0xbffff806 Garbage0xbffff807 Garbage0xbffff808 Garbage

Stack

esp

ebp

~ ~

~ ~

Stack frame for main

Page 3: Instructions for  test_function

Instructions for test_function

Instructions for main

Text Segment

void test_function(int a){ int flag = a*a;}int main( ){ int num = 8; test_function(num);}

Source Code

eip

eip 0x0804836d

esp 0xbffff800

ebp 0xbffff808

Registers

~ ~ADDRESS Contents Description0xbffff7f4 Garbage0xbffff7f5 Garbage0xbffff7f6 Garbage0xbffff7f7 Garbage0xbffff7f8 Garbage0xbffff7f9 Garbage0xbffff7fa Garbage0xbffff7fb Garbage0xbffff7fc Garbage0xbffff7fd Garbage0xbffff7fe Garbage0xbffff7ff Garbage0xbffff800 Garbage0xbffff801 Garbage0xbffff802 Garbage0xbffff803 Garbage0xbffff804 08 main variable num0xbffff805 000xbffff806 000xbffff807 000xbffff808 Garbage

Stack

esp

ebp

~ ~

Stack frame for main

Page 4: Instructions for  test_function

Instructions for test_function

Instructions for main

Text Segment

void test_function(int a){ int flag = a*a;}int main( ){ int num = 8; test_function(num);}

Source Code

eip

eip 0x0804836d

esp 0xbffff800

ebp 0xbffff808

Registers

~ ~ADDRESS Contents Description0xbffff7f4 Garbage0xbffff7f5 Garbage0xbffff7f6 Garbage0xbffff7f7 Garbage0xbffff7f8 Garbage0xbffff7f9 Garbage0xbffff7fa Garbage0xbffff7fb Garbage0xbffff7fc Garbage0xbffff7fd Garbage0xbffff7fe Garbage0xbffff7ff Garbage0xbffff800 08 function argument0xbffff801 000xbffff802 000xbffff803 000xbffff804 08 main variable num0xbffff805 000xbffff806 000xbffff807 000xbffff808 Garbage

Stack

esp

ebp

~ ~

Stack frame for main

Note: this is the address we want to return to after the function call (i.e. the return address)

Page 5: Instructions for  test_function

Instructions for test_function

Instructions for main

Text Segment

void test_function(int a){ int flag = a*a;}int main( ){ int num = 8; test_function(num);}

Source Code

eip

eip 0x0804834a

esp 0xbffff7f4

ebp 0xbffff7f8

Registers

~ ~ADDRESS Contents Description0xbffff7f4 Garbage0xbffff7f5 Garbage0xbffff7f6 Garbage0xbffff7f7 Garbage0xbffff7f8 08 old ebp0xbffff7f9 f8 (i.e., 0xbffff808)0xbffff7fa ff0xbffff7fb bf0xbffff7fc 78 return address0xbffff7fd 83 (i.e., 0x08048378)0xbffff7fe 040xbffff7ff 080xbffff800 08 function argument0xbffff801 000xbffff802 000xbffff803 000xbffff804 08 main variable num0xbffff805 000xbffff806 000xbffff807 000xbffff808 Garbage

Stackesp

ebp~ ~

Stack frame for main

Stack frame for test_function

Page 6: Instructions for  test_function

Instructions for test_function

Instructions for main

Text Segment

void test_function(int a){ int flag = a*a;}int main( ){ int num = 8; test_function(num);}

Source Code

eip

eip 0x08048354

esp 0xbffff7f4

ebp 0xbffff7f8

Registers

~ ~ADDRESS Contents Description0xbffff7f4 40 funct. variable flag0xbffff7f5 00 (i.e.,8^2=64=0x40)0xbffff7f6 000xbffff7f7 000xbffff7f8 08 old ebp0xbffff7f9 f8 (i.e., 0xbffff808)0xbffff7fa ff0xbffff7fb bf0xbffff7fc 78 return address0xbffff7fd 83 (i.e., 0x08048378)0xbffff7fe 040xbffff7ff 080xbffff800 08 function argument0xbffff801 000xbffff802 000xbffff803 000xbffff804 08 main variable num0xbffff805 000xbffff806 000xbffff807 000xbffff808 Garbage

Stackesp

ebp~ ~

Stack frame for main

Stack frame for test_function

Page 7: Instructions for  test_function

Instructions for test_function

Instructions for main

Text Segment

void test_function(int a){ int flag = a*a;}int main( ){ int num = 8; test_function(num);}

Source Code

eip

eip 0x08048378

esp 0xbffff800

ebp 0xbffff808

Registers

~ ~ADDRESS Contents Description0xbffff7f4 400xbffff7f5 000xbffff7f6 000xbffff7f7 000xbffff7f8 080xbffff7f9 f80xbffff7fa ff0xbffff7fb bf0xbffff7fc 780xbffff7fd 830xbffff7fe 040xbffff7ff 080xbffff800 080xbffff801 000xbffff802 000xbffff803 000xbffff804 08 main variable num0xbffff805 000xbffff806 000xbffff807 000xbffff808 Garbage

Stack

esp

ebp

~ ~

Stack frame for main