Linux and assembly code

In this section, we will read about the assembly language. The objective is to take a C code, translate it to an assembly, and see the proceedings. The sample C code that we will be loading and using is as follows:

Let's now run this program from the command line as ./buff and try to attach this executable program to the Evans debugger as follows:

We now attach our running code to the launched Evans debugger from the GUI by going to the File | Attach option. We attach the executable as follows:

When we click on OK, the object file will be attached to the debugger and we will be able to see the associated assembly level code with it as shown:

The top-right section of the window displays the assembly code of the application under test. The top-left section represents the registers and their corresponding contents. The section just below the assembly code displays the method that will be invoked when the user inputs the data on the console, which is our read-system call. The section at the bottom of the screen represents the memory dump, wherein the contents of the memory is displayed both in Hexadecimal and ASCII format. Let's see how the application cleanly exists when we specify a value that is less than 400 characters:

Now, let's input a value that is greater than 400 bytes and see what happens to our registers:

When we pass this input, we arrive at the following state:

It can be seen in the preceding screenshot that the value we passed gets written in the register RSP. For a 64-bit architecture, the register RSP holds the address of the next instruction to be executed and, as the value overflowed from the arr buffer, some was written to the register RSP. The program fetched the contents of RSP to go to the next instruction that it was meant to execute and since it arrived to aaaaaaaaaa, it crashed, as this is an invalid address. It should be noted that 0X6161616161, as shown in the previous screenshot, is the hexadecimal equivalent of aaaaaaaaaa.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.6.77