I've written a simple program that obfuscates a string using ASM x86. User must input their desired string, and then choose a key (Ekey
) for the string to be obfuscated. (I know you can emulate left and right bit rotations with shift operators or table lookups, I'm just trying to familiarize myself with ASM)
I'm trying to alter the program so that it adopts an accepted C++ standard calling procedure such as Cdecl
for passing parameters (EKey
& tempChar
) into the sub-routine obfuscate
.
Despite numerous hours of research I've been unsuccessful so I have come here in hope that somebody with a little more experience would be kind enough to offer some guidance.
Here's the relevant function:
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;
And the obfuscate
subroutine:
// 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
}
Thanks in advance for taking the time to read.