X86 сборка cdecl путаница

Утро, я внедрил метод вызова cdecl в следующую процедуру шифрования. Однако, хотя мой метод работает, он не следует точно рекомендованным (уни и другим источникам).

Советуюсь с благодарностью (некоторые комментарии могут быть «неправильными» для функций, связанных с 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 dataror 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 resultpop ebp //cdecl ,pop ebp
ret //cdecl

//----

}

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector