SI202: Week 1

advertisement
EC312 Homework 4
Name: _________________
Read: (1) Lecture 4 Notes
(2) Hacking, the Art of Exploitation, pages 37-41
1.
Consider the section of main memory shown below. The address of one of the individual bytes is also
shown on the figure.
00003D14
00003D15
00003D16
00003D17
0x96
00003D19
0x00
00003D1a
0x00
00003D1b
0x00
00003D1c
The decimal (base-10) integer value of 150 is stored at address 00003D18.
(a)
(b)
(c)
2.
On the picture above, show how the value of 150 (0x00000096) would be stored in main
memory. Use hexadecimal notation.
Annotate the diagram above to show the addresses for each byte in memory that is depicted on
the figure (so that all nine bytes have an address label on the left).
What would be displayed on the monitor by the command: x/xb 00003D18 ?
0x96
(d)
What would be displayed on the monitor by the command: x/xh
0x0096
00003D18 ?
(e)
What would be displayed on the monitor by the command: x/xw
0x00000096
00003D18 ?
Compile the program char_array2.c which already exists in the booksrc directory. Run the
executable code with the debugger, list the code and show the assembly code. Insert a breakpoint at line
6 (which should correspond to the blank line in the code listing. Then run the program up to the
breakpoint.
(a)
In words (a sentence or two), what does this program do?
It initializes a string of 20 characters, then uses string copy to define it as ‘Hello World!’ and
prints it
(b)
At the breakpoint (where your program stops), what is the value of the instruction pointer?
0x80483c4
(c)
At the breakpoint, what is the value of $eip expressed as an assembly language instruction?
mov DWORD PTR [esp+4],0x80484c4
1
3.
Consider the picture below:
(a)
In words: what is held in the eip register, i.e., what is the purpose of this register? (Your
answer should not be: "804838d".)
The address of the next instruction to be executed
(b)
What would be displayed on the monitor by the command: i r eip ?
0x0804838d
(c)
What would be displayed on the monitor by the command: x/xb $eip ?
0x9b
(d)
What would be displayed on the monitor by the command: i r esp ?
0xbffff810
(e)
What would be displayed on the monitor by the command: x/xw $esp ?
0x08048475
(f)
What would be displayed on the monitor by the command: x/xb
0x59
(g)
What would be displayed on the monitor by the command: x/s
Yes
0x08048475 ?
0x08048475 ?
4.
Let’s pretend there are 5 students in EC312. Write a C program that declares an array named
EC312midterm that will hold the midterm grades for the class. Your program should allow the user to enter
the midterm grades at runtime, and should then print out the average of the midterm grades. Turn in a copy of
your source code and a screen capture of your program successfully running.
2
Program 4.
#include <stdio.h>
int main()
{
int students = 5;
float EC312midterm[ students ];
int number;
float sum = 0, average;
for ( number = 0 ; number < 5 ; number = number + 1 )
{
printf( "Enter score for student %d : " , number + 1);
scanf( "%f" , &EC312midterm[ number ] );
sum = sum + EC312midterm[ number ];
}
average = sum / students;
printf( "Class midterm average: %.3f \n" , average );
return 0;
}
3
Download