Encryption at runtime

Posts 1–2 of 2 · Page 1 of 1
Encryption at runtime
Recently I tried to make a xor encryptor which encrypts a strings memory at runtime.
code:
Code:
#include <iostream>
#include <Windows.h>

using namespace std;

void XorEncrypt(DWORD orig, DWORD size)
{
	__asm
	{
		push eax
		push ecx

		mov eax, orig
		mov ecx, orig
		add ecx, size
		enryption_loop:
		xor byte ptr [eax], 0x9A
		inc eax
		cmp eax, ecx
		jl enryption_loop

		pop eax
		pop ecx
	}
}

int main()
{
	string orig = "Hello World";
	DWORD size = orig.size();
	
	XorEncrypt((DWORD)&orig, size);

	system("pause");
	return 0;
}
It seems to give error "inline assembler syntax error in 'second operand'; found 'newline'" at line 15. Does anyone know why this is happening?
1.) You're using a std::string yet passing a pointer of it and treating it like a `char*` ? That'll turn out well. Pass the `orig.c_str()` if you want an actual pointer to the raw string.
2.) Were we supposed to count all 15 lines to find out where the error was?
3.) Append your assembly instructions with a 'comment' ( semi-colon. ) Sure the assembly doesn't need it except for comments but using labels will confuse your compiler.
Posts 1–2 of 2 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us