Proj 18: C Constructs in Assembly (15 pts)

What You Need

Purpose

You compile several C programs and disassemble them with IDA Pro.

Downloading and Installing IDA Pro Free

Open this page:

https://www.hex-rays.com/products/ida/support/download_freeware.shtml

Click the "IDA Freeware for Windows" link, as shown below.

Install the software with the default options.

Compiling "Print"

In the Developer Command Prompt window, execute these commands:
mkdir c:\decomp
cd c:\decomp
notepad print.cpp
Enter this code:
#include <iostream>  
using namespace std;  
void main()  
{  
    printf("%d %s\n", 2, "HELLO");  
}  

In Notepad, click File, Save.

In the Developer Command Prompt window, execute these commands:

cl /EHsc print.cpp
print
The program runs, and prints out

2 HELLO

as shown below.

Disassembling the printf Function Call

Open IDA Pro Free.

In the "IDA Quick start" box, click the New button, as shown below.

In the "Select file" box, navigate to C:\decomp and double-click print.

In the "Load a new file" box, click OK.

IDA opens, showing some of the code that launches print, as shown below.

From the IDA manu bar, click View, "Open subviews", Strings. In the Strings pane, double-click HELLO, as shown below.

The address in the rdata section where that string is stored appears, as shown below. On the right side, point to the address labelled "DATA XREF". The code that uses this string appears in a pop-up box, as shown below.

Double-click the address labelled "DATA XREF". The assembly code appears, as shown below.

The assembly code in the green box performs this C command:

    printf("%d %s\n", 2, "HELLO");  
The three argument are pushed onto the stack in reverse order, and then the function is called.

as shown below.

Global and Local Variables

In the Developer Command Prompt window, execute these commands:
cd c:\decomp
notepad glob.cpp
Enter this code:
#include <iostream>  
using namespace std;  

int g=2; // GLOBAL VARIABLE

void main()  
{  
    int l = 3; // LOCAL VARIABLE
    printf("%d %d\n", g, l);  
}  

In Notepad, click File, Save.

In the Developer Command Prompt window, execute these commands:

cl /EHsc glob.cpp
glob
The program runs, and prints out

2 3

as shown below.

Disassembling glob

In IDA Pro, from the menu bar, click File, Open.

In the "Save database" box, check "DON'T SAVE the database" and click OK.

In the "Select file" box, navigate to C:\decomp and double-click glob.

In the "Load a new file" box, click OK.

IDA opens, showing the launcher.

From the IDA manu bar, click View, "Open subviews", Strings.

In the Strings pane, double-click "%d %d\n", as shown below.

On the right side, point to the address labelled "DATA XREF". The code that uses this string appears in a pop-up box, as shown below.

Double-click the address labelled "DATA XREF". The assembly code appears, as shown below. Notice these features:

Analyzing an Unknown Binary

Download this file:

arith.exe

Disassemble it in IDA Pro. Find the code shown below.

Find the value covered by a green box in the image below.


18. Recording Your Success (15 pts)

Use the form below to record your score in Canvas.

If you don't have a Canvas account, see the instructions here.

Name or Email:
Value (redacted in the image above):


Posted: 10-2-18