Self Checksum

From AntiHax

WARNING: This page is a work in progress
This page is a stub and needs expanding. Feel free to contribute to the article.


This is Windows specific and needs cleaning up.

static inline bool SelfHash(unsigned char *hash) {
	
	char 	file[MAX_PATH];
	int	n, handle;
	MD5	md5;
	byte	buf[16384];

    	GetModuleFileName(NULL, file, MAX_PATH);

	if ((handle = open (file, O_RDONLY|O_BINARY)) == -1)
	{ 
		return false;
	}

	memset(hash,0,16);
	for (;;)
	{
		n = read(handle,buf,sizeof(buf));
		if (n<=0) break;
		md5.update(buf,n);
	}
	md5.final(hash);
	close(handle);
	
	return true;
}