Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need someone to help me explain how to get the solution to this question. It is a practice problem so I do not need

I need someone to help me explain how to get the solution to this question. It is a practice problem so I do not need just the answer, but a brief solution on HOW to get to the answer.

This problem tests your understanding of how procedures and the stack work, arrays, and byte ordering. Here are some notes to help you work the problem: gets(char *dst) copies bytes from the input to the string at address dest until a return (newline) is detected (it does not copy the return but does null terminate the string with \0 character). It does not check the size of the destination buffer. Note that Linux/x86 64 machines are Little Endian, i.e. the lowest (highest) order byte of a multi-byte integer is stored in the lowest memory address. You will need to know the hex values of the following characters: a - z are the contiguous values from 0x61 to 0x7a inclusively and null is 0x00. Now consider what happens on a Linux/x86 64 machine when main calls foo and the user enters the input string abcdefghijklmnopqrstuvwxyz followed by a return. (a) List the contents of the following memory locations immediately after gets returns to foo. Each answer should be an unsigned 4-byte integer expressed as 8 hex digits.

a[0] = 0x____________________

a[1] = 0x____________________

a[2] = 0x____________________

a[3] = 0x____________________

a[4] = 0x____________________

a[5] = 0x____________________

a[6] = 0x____________________

(b) Immediately after the add instruction at address 0x00000000004005b0 executes, what is the 8 byte value at the stop of the stack?

VALUE AT THE TOP OF THE STACK = 0x________________________________________

(c) Immediately after the retq instruction at address 0x00000000004005b4 executes, what is the value of the program counter register %rip? %rip = 0x________________________________________

void foo(int x) { i

nt a[2];

a[0] = 0xF0F1F2F3;

a[1] = x;

gets((char *)a);

printf("a=0x%016x a[0] = 0x%x, a[1] = 0x%x ", a, a[0], a[1]); }

int main(int argc, char **argv) {

foo(0xdeadbeef);

return 0;

}

Dump of assembler code for function foo:

0x0000000000400580 <+0>: sub $0x18,%rsp

0x0000000000400584 <+4>: movl $0xf0f1f2f3,(%rsp)

0x000000000040058b <+11>: mov %edi,0x4(%rsp)

0x000000000040058f <+15>: mov %rsp,%rdi

0x0000000000400592 <+18>: callq 0x400480

0x0000000000400597 <+23>: mov 0x4(%rsp),%ecx

0x000000000040059b <+27>: mov (%rsp),%edx

0x000000000040059e <+30>: mov %rsp,%rsi

0x00000000004005a1 <+33>: mov $0x400660,%edi

0x00000000004005a6 <+38>: mov $0x0,%eax

0x00000000004005ab <+43>: callq 0x400450

0x00000000004005b0 <+48>: add $0x18,%rsp

0x00000000004005b4 <+52>: retq Dump of assembler code for function main:

0x00000000004005b5 <+0>: sub $0x8,%rsp

0x00000000004005b9 <+4>: mov $0xdeadbeef,%edi

0x00000000004005be <+9>: callq 0x400580

0x00000000004005c3 <+14>: mov $0x0,%eax

0x00000000004005c8 <+19>: add $0x8,%rsp

0x00000000004005cc <+23>: retq

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Datacasting How To Stream Databases Over The Internet

Authors: Jessica Keyes

1st Edition

007034678X, 978-0070346789

More Books

Students also viewed these Databases questions