Name:

 

Date:

 

Lab 5 – Finding Function Arguments on the X86 Stack



Introduction 

Due

 

Lab Steps

Part 1 – Function Arguments

  1. Log into your Unix account on felix or helix (not on tanner, since we will need a Linux machine for this lab), then change your current directory to csc2400/x86.
  2. Copy the executable x86stack1 from the /mnt/a/mdamian/courses/x86 directory into your csc2400/x86 directory. Invoke gdb with x86stack1 as an argument:
             gdb ./x86stack1
  1. Set the disassembly language to Intel:
             set disassembly-flavor intel
4.          Disassemble the main function, then answer the questions listed below. 
 
5.          Write down the names of the two functions invoked by the main function:  ________________________________________________
 
6.          Focus on the 2nd invoked function. Write down the instructions that place the function arguments onto the stack (just before the function is invoked with call):
__________________________________________________
__________________________________________________
7.          Write down the number of arguments for the 2nd invoked function: _________________
8.          Write down the values of the arguments passed to the 2nd invoked function: _________________
There are two ways to answer this question (do it both ways please, the result should be the same). 
 
Method 1: 
a)           Set a breakpoint at the second function call (identified in part a)
          
          break *(main+???)
 
b)           Check the values that just got placed onto the stack
          
          x /d $esp
          x /d $esp+4
 
 
 
 
Method 2: 
 
a)           Disassemble the 2nd function invoked by main. Set a breakpoint at the first instruction following the common prolog
          push ebp
          mov  ebp, esp
 
b)           Check the values stored at addresses $ebp+8, $ebp+12, etc
          
          x /d $ebp+8
          x /d $ebp+12
 
9.          Write down the value returned by the 2nd invoked function: _________________ (To do so, check the contents of eax before the function returns.)
10.       Write down the value returned by the main function: _________________ 

Part 2 – Repeat the Activities of Part 1 on a Different Piece of Code

  1. Copy the executable x86stack2 from the /mnt/a/mdamian/courses/x86 directory into your csc2400/x86 directory. Invoke gdb with x86stack2 as an argument.
  2. Set the disassembly language to Intel. Disassemble the main function, then answer the questions listed below.
  3. Write down the names of the two functions invoked by the main function:  ________________________________________________
  4. Focus on the 2nd invoked function. Write down the instructions that place the function arguments onto the stack (just before the function is invoked with call):
_______________________________________________
 
__________________________________________________
  1. Write down the number of arguments for the 2nd invoked function: _________________
  2. Write down the values of the arguments passed to the 2nd invoked function: _________________
  3. Write down the value returned by the 2nd invoked function: _________________
  4. Write down the value returned by the main function: _________________