C Language Inline compilation
void Main ()
{
Char ps[20] = "aaaaaaaaaa\n";
Char *p1 =ps;
Rewrite the following 2 lines of code with assembly statements
Ps[3]= ' B ';
printf (PS);
}
//equivalent notation 1:
Void Main ()
{
Char ps[20] = "aaaaaaaaaa\n";
Char *p1 =ps;
Hmodule hmod =getmodulehandle ("Msvcr90. DLL ");
if (hmod)
{
PVOID pfun =getprocaddress (hmod, "printf");
if (Pfun)
{
__asm
{
//&P1 is the memory that holds the pointer P1, [P1] means the value of the P1 is taken.
//a bit around, here P1 is the pointer entity, not the value to understand for it
mov eax, DWORD ptr [P1]
//[eax] means to take the contents of EAX storage. Now EAX is the value of P1
mov byte ptr [eax+3],0x62
push DWORD Ptr[p1]
Call Pfun
mov eax, 1
Add esp,4
}
}< Br>freelibrary (HMOD);
}
}
Equivalent notation 2:
void Main ()
{
Char ps[20] = "aaaaaaaaaa\n";
Char *p1 =ps;
Hmodule hmod =getmodulehandle ("Msvcr90. DLL ");
if (hmod)
{
PVOID pfun =getprocaddress (hmod, "printf");
if (Pfun)
{
__asm
{
[ps+3] means to take the 3rd element, although the C language inside the array name is a pointer, the assembly can not be directly written as equivalent
mov byte ptr [ps+3],0x62
Push DWORD Ptr[p1]
Call Pfun
mov eax, 1
Pop EBX//equivalent to esp+=4
}
}
FreeLibrary (HMOD);
}
}
Notation 3:
void Main ()
{
Char ps[20] = "aaaaaaaaaa\n";
Char *p1 =ps;
Hmodule hmod =getmodulehandle ("Msvcr90. DLL ");
if (hmod)
{
PVOID pfun =getprocaddress (hmod, "printf");
if (Pfun)
{
__asm
{
MOV ecx,10
mov ebx, 0
Replace PS to BBBBBBBB
S:mov byte ptr [ps+ebx],0x62
Inc EBX
Loop s
Push DWORD Ptr[p1]
Call Pfun
mov eax, 1
Pop ebx
}
}
FreeLibrary (HMOD);
}
}
Assembly Language 9 inline assembly