Finding Function Arguments on the Stack

Introduction

Lab Steps

Part 1 – Function Arguments

  1. Log into your Unix account on felix, helix or matrix (not on tanner, since we need a Linux machine for this lab). Change your current working directory to systems/x86.

  2. Copy the executable x86stack1 from /mnt/a/mdamian/x86 into your systems/x86 directory. Invoke gdb with x86stack1 as an argument:
        gdb ./x86stack1
    

  3. Set the disassembly language to Intel:
        set disassembly-flavor intel
    

  4. Disassemble the main function:
        disas main
    

  5. What are the two functions invoked by main? Write down their names:

    __________________________________________________________________________

    __________________________________________________________________________

  6. Focus on the 2nd invoked function. How many arguments does this function take? You can tell that by looking at what gets placed on the stack just before the function is invoked.

  7. Find out the values of the arguments passed to the 2nd invoked function. There are two ways to do this (do it both ways, please).

    Method 1 (from the main function):

    Method 2 (from the invoked function)

    Write down the values of the arguments found using the two methods outline above (they should produce the same result):

    __________________________________________________________________________

  8. Write down the value returned by the main function. You can find it by setting a breakpoint to the ret instruction in main>, executing the program up to that breakpoint, and inspecting the value of the register EAX (which always contains the return value).

    __________________________________________________________________________

Part 2 – Repeat the activities of Part 1 on a different piece of code

  1. Copy the executable x86stack2 from /mnt/a/mdamian/x86 into your systems/x86 directory. Invoke gdb with x86stack2 as an argument.

  2. Set the disassembly language to Intel. Disassemble the main function, the answer the questions listed below.

  3. What are the two functions invoked by main? Write down their names:

    __________________________________________________________________________

    __________________________________________________________________________

  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):

    __________________________________________________________________________

    __________________________________________________________________________

    __________________________________________________________________________

  5. Write down the number of arguments for the 2nd function invoked by main:

    __________________________________________________________________________

    Write down the values of the arguments passed to the 2nd function invoked by main:

    __________________________________________________________________________

    Write down the value returned by the 2nd function invoked by main:

    __________________________________________________________________________

    Write down the value returned by the main function:

    __________________________________________________________________________