Description
Unformatted Attachment Preview
Purchase answer to see full attachment
Explanation & Answer
Hello, here is the file bro
Student Name:
Assignment Name:
Submission Date:
1. A detailed list of the steps you took converting the binary file to C
a. Using gdb, we check the functions available in the binary file, info functions.
The above command display the functions given below. We have two functions to
consider, the main and the DisplayMenu function.
b. Disassembling the main function.
Using disassemble /m main command in gdb, we get the assembly statements of the
binary file.
The above image just show part of the disassembled main function.In gdb we can
move step by step in the assembly file, to check the result of the statements when
executed. Creating breakpoints allow us to check the statements part by part.
Lets put a break point at
0x00000000004006f2 :
mov
$0x4008c9,%edi
This can be achieved by this command in gdb
b *0x00000000004006f2
Then running the code, print the four lines as shown below
---------------- 1)Add
-
- 2)Subtract - 3)Multiply - 4)Exit
-
----------------
The above lines can only be printed on the screen using printf statement in c. We can
also see in the disassembled main that, the first statements call 0x4004e0 six
times, which is the print statements. Therefore writing this in c, becomes
printf ("----------------\n");
printf ("- 1)Add -\n");
printf ("- 2)Subtract -\n");
printf ("- 3)Multiply -\n");
printf ("- 4)Exit -\n");
printf ("----------------\n");
Putting our next breakpoint at 0x0000000000400709
b * 0x0000000000400709
Putting a break point a line after the call for scanf, the program displays the menu, allow one to
choose a choice then in stops at the breakpoint.
Therefore we can confirm that our next statements calls for a scanf statement, to take in a value
or the choice, the choice of the user per the menu given.
This can be performed by scanf statement in c
scanf ("%d", &choice);
0x00000000004006fc : callq 0x400520
0x0000000000400701 : mov -0x1c(%rbp),%eax
The value entered is stored in a variable choice, which has been defined before as seen below
0x00000000004006a3 :
movl $0x0,-0x1c(%rbp), with an initial value of zero
After the scanf statement, the following comparison can also bee seen in the disassembled main
First condition check.
The value entered by the user is stored in a memory location,
mov -0x1c(%rbp),%eax
Immediately after the value is moved to %eax, as seen above we see a CMP statement, as seen in
the above image, the value is compared to 1
0x0000000000400704 : cmp $0x1,%eax
This statement is followed by jne instruction, which is a conditional jump. The condition will
jump to +175 in the main function as seen below
0x0000000000400707 : jne 0x400749
Therefore the instructions before are performed only when the condition posed is
met, that is comparing the choice if it’s equal to 1.
This is the same as the below code in c
If(choice == 1){
Block of code
}
Code between the condition block
Sample code 1
0x0000000000400707 : jne 0x400749
0x0000000000400709 : lea -0x14(%rbp),%rdx
0x000000000040070d : lea -0x18(%rbp),%rax
0x0000000000400711 : mov %rax,%rsi
0x0000000000400714 : mov $0x4008cc,%edi
0x0000000000400719 : mov $0x0,%eax
0x000000000040071e : callq 0x400520
0x0000000000400723 : mov -0x18(%rbp),%edx
0x0000000000400726 : mov -0x14(%rbp),%eax
0x0000000000400729 : mov %edx,%ecx
0x000000000040072b : sub %eax,%ecx
0x000000000040072d : mov -0x14(%rbp),%edx
0x0000000000400730 : mov -0x18(%rbp),%eax
0x0000000000400733 : mov %eax,%esi
0x0000000000400735 : mov $0x4008d2,%edi
0x000000000040073a : mov $0x0,%eax
0x000000000040073f : callq 0x4004f0
0x0000000000400744 : jmpq 0x4007d1
Creating a breakpoint at
0x0000000000400744 : jmpq 0x4007d1
Then we execute the program to check the function of this block.
Breakpoint 4 at 0x400744
(gdb) run
The program being debugged has been started already.
Start it from the beg...