summaryrefslogtreecommitdiff
path: root/enc_file/source.cpp
blob: 9056764b8f0e53644d4fb43661a98b22e7faa629 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <Windows.h>

int main( ) {
	uint8_t key{ };
	std::cin >> key;
	printf( "key: %d", key );

	auto file = CreateFileA( "./enc.dll", GENERIC_READ, 0, 0, OPEN_ALWAYS, 0, 0 );
	if( !file ) return 0;

	auto size = GetFileSize( file, 0 );
	if( !size ) {
		CloseHandle( file );
		return 0;
	}

	uint8_t* data = ( uint8_t* )( malloc( size ) );
	if( !ReadFile( file, data, size, 0, 0 ) ) {
		CloseHandle( file );
		free( data );
		return 0;
	}

	CloseHandle( file );

	for( size_t i{ }; i < size; ++i ) {
		data[ i ] ^= key;
	}

	data[ 0 ] = 'c';
	data[ 1 ] = 'd';

	FILE* f;
	fopen_s( &f, "./out.dll", "wb" );
	fwrite( data, 1, size, f );
	fclose( f );

	return 0;
}