Problem 1 – Compilation Process XXXXXXXXXX___/15 1. Write a C program that prints a small message on the terminal call it message.c 2. ( 2 marks) Use gcc manual or any other resource and research the...

1 answer below »
Instructions in word document



Problem 1 – Compilation Process ___/15 1. Write a C program that prints a small message on the terminal call it message.c 2. ( 2 marks) Use gcc manual or any other resource and research the following gcc options. Provide a brief description or purpose of the option a. S b. O c. c d. v 3. Use the respective gcc option to generate assembly code and call the file mesg.s 4. Use nano or any editor to edit mesg.s file. Observe the results and different sections created and identify the section that contains the strings 5. ( 2 mark) Generate mesg.s optimized by adding the -O2 (capital O) option. Edit the results and compare with previous result without optimization. What is the main difference? 6. ( 1 mark) Use Linux manual and learn about as program. What is the purpose of as ? 7. ( 3 marks) Use as or any other assembler program to convert the assembly code created before into an object and call it mesg.o a. Why shouldn’t the .o file be read with a text editor? b. What is the size of mesg.o file? c. What program can be used to view this type of file. Name at least 2 program(s) 8. ( 2 marks) Use the linker ld to generate an executable. Check notes or slides to verify libraries required 9. ( 5 marks) Provide screen captures that demo the following: a. C code created b. msg.s and command used to generate it c. optimized mesg.s and command used to generate it d. msg.o and command used to generat it e. executable and command used to generated it Problem 2 Debugger ___/20 1. Use the following web sites to download peda and gef debuggers https://infosecwriteups.com/pwndbg-gef-peda-one-for-all-and-all-for-one-714d71bf36b8 or https://github.com/hugsy/gef a. Create the following c code and save it as buff.c b. ( 1 mark) Compile it and use gdb-gef to debug the code c. Create a point in main d. This program requires input ( values to copy into the buffer). Run the program with 15 strings e.g run aaaaaaaaaaaaaaa e. ( 1 mark) Explore the different gef debugger sections. Based on registers output and code section what is the next instruction to be executed? f. ( 1 mark) Based on Source section what is the next line of the source code to be executed? g. ( 1 mark) Use next instruction (n) to move to the next line and observe the registers content. What registers are storing the string a? h. ( 1 mark) What is the hex of character a? i. Now in the registers section identify and copy the address pointed by the rsi register. Use the command x to display the content of this memory address. e.g. x 0x00007fffffffe452 j. To display more memory address space use x/4x 0x00007fffffffe452 k. To display more memory content use x/40x $rsp. In the output identify the following: · The addresses that store the string a · Under trace section identify the arguments of main() function. What addresses in memory contain argc and argv respectively? l. ( 5 marks) Attach the screen captures that demo the following: · C code created buffer.c · The debugger that demo registers that contain string a · The debugger with the memory results after using x command. Underline the addresses that store the string a and the arguments of main() function m. Now you can use c (continue) command to end the program 2. Create the following assembly. a. Use the debugger and respective commands to step into the program. Explore, registers, code and source sections and analyze instruction(s) that affected eflags b. ( 2 marks) Provide the screen capture that demo the eflags (set) affected. c. ( 2 marks) Explain why these flags were set. d. ( 1 mark) What was the final value of rax register before the program exited ? e. ( 5 marks) Modify the assembly code a comment or delete the syscall instruction. Use the debugger with respective commands to analyze the results. Provide a screen capture that demo the final result. Was the result affected? why? (explain) Problem 3 System calls ___/10 1. Use Linux man to identify parameters passed to write() system call 2. Use the respective unistd_64.h to identify write() system call number 3. Write assembly code that implements the write() system call to display your name on STDOUT 4. Modify the code by introducing the following errors: a. Store system call number in rcx register instead of rax b. Pass the second parameter into rdi register and the first parameter into rsi 5. Provide the screen captures that demo: a. Assembly code created b. Run the executable and display your name on terminal c. Modified code with errors d. Debugged code with results after introducing errors Problem 4 Conditional Jump and Loops __10 1. Write assembly code that compare two different integer numbers in a loop. Increment the lowest number till they are equal. If the numbers are equal exit. Implement conditional and unconditional jump instructions 2. Use the debugger to test the code 3. Provide screen captures that demo a. Assembly code created b. Debugged code (register with final results)
Answered 4 days AfterFeb 07, 2022

Answer To: Problem 1 – Compilation Process XXXXXXXXXX___/15 1. Write a C program that prints a small message on...

Swapnil answered on Feb 12 2022
116 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here