早上,我在下面的“加密”例程中实现了一个 cdecl 调用方法。然而,虽然我的方法有效,但它并没有完全遵循推荐的(uni 和其他来源)。
建议赞赏(某些评论可能是“错误”的 cdecl 相关功能已标记为)
我的困惑是,我被告知对于每个推送的参数(在本例中为 2)我必须在调用之前推送,在函数内部再次推送,然后为每次额外推送执行 mov [ebp+n] - 在主体之前.
但是,如果我遵循以下逻辑:为每次推送执行 mov ebp 移位 - 不添加额外的推送,一切正常。但这很可能是一个错误。
如果需要,我可以发布一些参考文档。
代码提取:
void encrypt_chars (int length, char EKey)
{char temp_char; // Character temporary store
for (int i = 0; i < length; i++) // Encrypt characters one at a time
{
temp_char = OChars [i]; // Get the next char from Original Chars array
// Note the lamentable lack of comments below!
__asm { //
push eax //making a copy of char to be encrypted index
push ecx //making a copy of the char to be encrypted
//
movzx ecx,temp_char //padding out temp_char
lea eax,EKey //moving Ekey adress to eax, for function to use, eax contents acting as perameter
call encrypt6 //Doing the encryption
add esp, 8 //cdecl added stack pointer baxk
mov temp_char,al //Move the encrypted result into temp_char
pop ecx //resetting registers to before call
pop eax //
}
EChars [i] = temp_char; // Store encrypted char in the Encrypted Chars array
}
return;
// Encrypt subroutine. You should paste in the encryption routine you've been allocated from Bb and
// overwrite this initial, simple, version. Ensure you change the ‘call’ above to use the
// correct 'encryptnn' label where nn is your encryption routine number.
// Inputs: register EAX = 32-bit address of Ekey,
// ECX = the character to be encrypted (in the low 8-bit field, CL).
// Output: register EAX = the encrypted value of the source character (in the low 8-bit field, AL).
__asm {
encrypt6:
push ebp //cdecl Making a copy of base pointer
mov ebp, esp //cdecl storing the point at which the base pointer has shifted the stack
// push ecx //cdecl
// push eax //cdecl
// mov ecx, [ebp + 12] // cdecl storing Ekey adress
// mov eax, [ebp + 8] //cdecl storing temp_char data
ror byte ptr[eax], 1 //Rotating the EKey data right 6 times
ror byte ptr[eax], 1 //
ror byte ptr[eax], 1 //
ror byte ptr[eax], 1 //
ror byte ptr[eax], 1 //
push ecx //Making a copy of ecx
mov ecx, [ebp + 8] // cdecl ,
not byte ptr[eax] //Inverting the Ekey data
movzx edx, byte ptr[eax] //making a copy of the ekey data with leading zero's
pop eax //restoring register to thet temp_char ascii value
xor eax, edx //XORing original temp_char with encrypted temp_Char
ror al, 1 //Rotating the Ekey adreses 8 bit component right twice (To edit)
ror al, 1 //
not al // Inverting the result
add eax, 0x20 // adding a space (32) to result
pop ebp //cdecl ,pop ebp
ret //cdecl
//----
}