0

我编写了一个使用 ASM x86 混淆字符串的简单程序。用户必须输入他们想要的字符串,然后Ekey为要混淆的字符串选择一个键 ( )。(我知道您可以使用移位运算符或表格查找来模拟左右位旋转,我只是想让自己熟悉 ASM)

我正在尝试更改程序,以便它采用可接受的 C++ 标准调用过程,例如Cdecl将参数 ( EKey& tempChar) 传递到子例程obfuscate中。

尽管进行了数小时的研究,但我一直没有成功,所以我来到这里希望有更多经验的人能够提供一些指导。

这是相关的功能:

void obfusc_chars (int length, char EKey)
{   char tempChar;                      // char temporary store

    for (int i = 0; i < length; i++)    // encrypt characters one at a time
    {
        tempChar = OChars [i];          //
        __asm {                         //
            push   eax                  // save register values on stack to be safe
            push   ecx                  // pushes first string on stack
                                        //
            movzx  ecx,tempChar         // set up registers (Nb this isn't StdCall or Cdecl)
            lea    eax,EKey             //
            call   obfuscate            // obfuscate the character
            mov    tempChar,al          //
                                        //
            pop    ecx                  // restore original register values from stack
            pop    eax                  //
        }
        EChars [i] = tempChar;          // Store encrypted char in the encrypted chars array
    }
   return;

obfuscate子程序:

// 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 {

     obfuscate: push    esi
                push    ecx
                mov     esi, eax
      and dword ptr     [esi], 0xFF
      ror byte ptr      [esi], 1
      ror byte ptr      [esi], 1
      add byte ptr      [esi], 0x01
                mov     ecx, [esi]
                pop     edx
            x17:ror     dl, 1
                dec     ecx
                jnz     x17
                mov     eax, edx
                add eax, 0x20
                xor eax, 0xAA
                pop esi
                ret
        }

提前感谢您花时间阅读。

4

0 回答 0