Call/Ret in x86 assembly embedded in C++ -


This is probably trivial, but for some reason I can not do this work. This is considered as a simple task that changes the last byte of a den on 'AA' (10101010), but when I call the function, nothing happens. It just gives my original DWORD.

__ declspec (nude) long function (unsigned long inputDord, unsigned long * outputDWord) {_asm {mov EBX, DWORD ptr [esp 4] push EBX call SET_AA pop EBX mov eax, DWORD ptr [Esp + 8] mov DWORD ptr [eax], EBX}} __declspec (naked) unsigned long SET_AA (unsigned long inputDWord) {__ss {mov eax, [esp 4] mov al, 0xAA / / 10101010 or again Do not work}}

You have a value and an out variable.

here:

  push ebux call SET_AA pop ebx  

You are working as EBX An outside variable is here

and:.

  mov eax, [esp 4] mov al, 0xAA // 10101010 either did not work retired  

you just eax (Once with the parameter, then you overwrite with your 0xAA). eax is traditionally a return value register

If you want it to be an out variable, you have to do something for it:

  __ declspec (naked) long function (unsigned long inputDWord, unsigned long * outputDWord) {_asm {mov EBX, DWORD ptr [esp 4] push EBX call SET_AA pop EBX mov eax, DWORD ptr [esp + 8] MOV DWORD ptr [eax], EBX}} __declspec (naked) zero SET_AA (unsigned long inputDWord) {0 {0 __SEAM MOV [esp 4], 0xAA // variable pile passed on retired}} 0xAA  

you get a refund Want something, you can do something like this:

  __ declspec (naked) long function (unsigned long inputDord, unsigned long * outputDWord) {_asm {mov ebx, dword Ptr [esp + 4] call SET_AA mov ebx, eax mov eax, dword ptr [esp + 8] mov dword ptr [eax], ebx}} __declspec (naked) unsigned long SET_AA (/ * Input paragraph M is not required, We are just returning a value * /) {__asm ​​{mov eax, 0xAA // return 0xAA ex through register register}}  

Comments