Practical - C Constructs in Assembly
Practical - C Constructs in Assembly
C Constructs in Assembly
Purpose
To compile several C programs and disassemble them with IDA Pro.
https://www.bowneconsultingcontent.com/pub/EH/proj/cloud/ED301c_tkp/ED301c_
tkp.htm
https://www.hex-rays.com/products/ida/support/download_freeware.shtml
Compiling "Print"
Click Start. Scroll to the V section and expand "Visual Studio 2019". Click "Developer
Command Prompt for VS 2019".
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");
}
cl print.cpp
print
The program runs, and prints out
2 HELLO
as shown below.
In the "IDA Quick start" box, click the New button, as shown below.
Click on New, In the "Select file" box, navigate to C:\decomp and double-click print.
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 three argument are pushed onto the stack in reverse order, and then the function is
called.
void main()
{
int l = 3; // LOCAL VARIABLE
printf("%d %d\n", g, l);
}
cl glob.cpp
glob
The program runs, and prints out
23
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.
From the IDA manu bar, click View, "Open subviews", Strings.
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: