You are on page 1of 16

CRNS 19IT066

Task-1

Code:
Create program in c with vi editer.

Run program using below command and create 32-bit object code for above code.
CRNS 19IT066

Now, run GDB with pro1-32 file.


CRNS 19IT066

1) Compile code with options as discussed in class.


Disassemble the function main() and add().
main()
CRNS 19IT066

add()

2) Identify the instruction represent prelaud in main().

It is 0x00001218 to 0x00001227 is executed prior to the any other instruction execution of


main().
CRNS 19IT066

3) Show the contents of the stack before the call to add(). Specifically show the content
of IP and SP registers. Identify the instructions executed before the prelude to the
function add() and those that are part of prelude of the cell.

So, here 0x0000123c and 0x00001235 are making parameters which we are passing as part of
function call for add.

BP, SP and IP details as shown before calling function add().


CRNS 19IT066

4) Show the address of the instruction executed after function returns to main().

0x5655627b as it return address shown in front of call instruction to add.

5) Show how the space of the local variables is created in the prelude to the function
call.

Here as part of function call once call will start it will push old value of base pointer (ebp) on
first instruction and then it will make space for all the local variables in function call by next
2 instructions and then function body will start execution.
CRNS 19IT066

6) Show the contents of the stack during add() Call. Note that the stack grows and
shrinks as a result of function calls made by add(). Specifically show the contents of
the IP and SP registers.

Here, print ebp, esp, eip value before of function call and then executed steps.
CRNS 19IT066

Task -2
Code:
Write the program using vi editor.

Run the program using below command and create 32-bit object code for the file.

Now run gdb with object file as prog1_32


CRNS 19IT066

Now run with GDB

1) Compile the code with the options as discussed during the class. Disassemble the
function main() and the function IsPasswordOK().

Disassemble main()
CRNS 19IT066

Disassemble IsPasswordOk()
CRNS 19IT066

2) Identify the instructions that represent the prelude in the main() function call.
CRNS 19IT066

Here instruction prior to address 0x00001291 are part of prelude of main function.
CRNS 19IT066

3) Show the contents of the stack before the Call to IsPasswordOK(). Specifically show
the contents of the IP and SP registers. Identify the instructions executed before the
prelude to the functions IsPasswordOK() and those that are part of the prelude of the
call.

0x128e and 0x1291 shows instruction executed before prelude IsPasswordOk().


4) Show the address of the instruction executed after the function returns to the main().
CRNS 19IT066

5) Show how the space of the local variables is created in the prelude to the function call

6) Show the contents of the stack before the Call to IsPasswordOK(). Specifically show
the contents of the IP and SP registers.
CRNS 19IT066

7) Show the contents of the stack during IsPasswordOK() Call. Note that the stack grows
and shrinks as a result of function calls made by IsPasswordOK(void). Specifically
show the contents of the IP and SP registers.
CRNS 19IT066

You might also like