assembly - 将 CDECL 调用约定采用到仅复制/粘贴当前参数的函数中
问题描述
好的,我的讲师编写了一个加密程序,他希望我实现一个 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 }
被叫
__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
}
解决方案
推荐阅读
- eclipse - Robot Framework - 如何在 Eclipse 中导入 SeleniumLibrary 关键字实现/文档
- python - 是否可以让程序等到变量从 1 变为 0 或从 0 变为 1 才能执行某些操作?
- r - 如何使用 lapply 和 dplyr::filter 函数遍历列表?
- javascript - 如果单击按钮,如何删除输入字段?
- django - 使用两个提交按钮将 django inlineformset 保存为草稿
- vb.net - 在 VB.Net 的 Listview 中更改下载百分比
- ios - 当wifi和移动数据之间发生切换时,有没有办法使用NE Packet Tunnel Provider重置iOS中的隧道?
- batch-file - 从 vs 2019 运行 bat 文件时找不到文件
- php - Symfony / Ajax:成功响应时调用函数
- java - 如何在 JSP 文件中运行 Java 8 lambda