C++嵌套汇编------ 加密文件

#include <iostream>
#include <fstream>

using namespace std;

void TranslateBuffer (char *buf, unsigned count, unsigned char eChar);

int main(int argc, char * argv[])
{
	// Read input and output files from the command line
	if ( argc < 3){
		cout << "Usage: encode infile outfile" << endl;
		return -1;
	}
	const int BUFSIZE = 2000;
	char buffer[BUFSIZE];
	unsigned int count;		 // character count

	unsigned char encryptCode;
	cout << "Encryption code [0-255]? ";
	cin >> encryptCode;

	ifstream infile( argv[1], ios::binary );
	ofstream outfile( argv[2], ios::binary );

	cout << "Reading " << argv[1] << " and creating "
		 << argv[2] << endl;

	while (!infile.eof())
	{
		infile.read(buffer, BUFSIZE);
		count = infile.gcount();
		TranslateBuffer(buffer,count,encryptCode);
		outfile.write(buffer,count);
	}
	return 0;
}

void TranslateBuffer ( char *buf, unsigned count, unsigned char eChar) 
{
	__asm {
		mov esi,buf
		mov ecx,count
		mov al,eChar

L1: 
		xor [esi],al
		inc esi
		loop L1
	}
}

猜你喜欢

转载自blog.csdn.net/lyx2007825/article/details/18839847