好的,所以我有一个由讲师编写的加密程序,他希望我实现cdecl调用约定。我了解堆栈,推送和弹出的基本概念,但发现在此处难以实现。
问题: 如何在此CALLER / CALEE函数中实现CDECL?
以下电话
__asm
{ //
push eax // Push the eax register onto the call stack, it will preserve value when we pop the register
push ecx // Pushes the ecx value on stack, it currently contains the value of first character entered by the user
push edx // push the edx register onto the call stack, preserve value of edx register when we pop it.
movzx ecx, temp_char // copy the value of variable temp_char(ascii of first character of user input) in ECX register, movzx is used to
// specify that higher-order "unused" bits in the int value are zeroes.
lea eax, EKey // copy the value of variable EKey(which is the ascii of encryption key 'S') into the EAX register
call encrypt_18 // run the encryption routine 18 which will encrypt the characters, one by one
mov temp_char, dl // copy the contents of dl register which contains the encryped value of char into the temp_char variable
pop edx // return the value in edx register
pop ecx // return the value in ecx register
pop eax // return the value in eax register
}
EChars[i] = temp_char; // Store encrypted char in the Encrypted }
CALLEE
__asm
{
encrypt_18:
push ecx // pushes the ecx register on stack with the ascii value to be encrypted
mov esi, eax // copies the value of EAX which contains the Encryption Key ascii value of 'S' character into ESI register
xchg eax, [eax] // load char Ekey into the AL(8 bit register), replace old key with pointer to the new key
and eax, 0x79 //
ror al, 1 //
ror al, 1 //
ror al, 1 //
add eax, 0x03 // These 5 instructions do the encryption, it adds rol(key & 0x79, 3) + 5 to the char,
// it also rotates it left by 1
mov edx, eax // copies the value of EAX which is the new key into the EDX register
pop ecx // return the value of ECX
add ecx, 0x02 // add 2 to the value in ECX which is currently the first char entered by user, it becomes
//equal to a char that is value of original char + 2.
add ecx, edx // adds the value of edx with the value of ecx
ror cl, 1 // shift the right hand side bit to the left side in the ECX register
mov[esi], eax // copy the content of EAX register into the ESI register address pointer
mov edx, ecx // copy the value of ECX register into the EDX register
ret // return back to the function
}