#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tlhelp32.h>
#define USAGE "./%s path"
long NomProcessusToPid(char* process);


int main(int argc,char* argv[])
{
    printf("Keygen pour le defi 1 de gutte par 0vercl0k.\n\n");
    if(!argv[1]){printf(USAGE,argv[0]); return 0;}
    long pid = NomProcessusToPid(argv[1]);
    printf("[+] PID : %ld\n",pid);
    if(pid == 0){return 0;}

    DWORD recup,recup2,taille;

    HANDLE handleProcess = OpenProcess(PROCESS_ALL_ACCESS , FALSE , pid);
    ReadProcessMemory(handleProcess,(LPCVOID)0x0022FF70,&recup,sizeof(DWORD),&taille);
    printf("[+]Pass : %ld\n",recup);
    getchar();
    ReadProcessMemory(handleProcess,(LPCVOID)0x0022FF60,&recup2,sizeof(DWORD),&taille);
    printf("[+]Pass2 : %ld\n",recup2);
    CloseHandle(handleProcess);
    return 0;
}

long NomProcessusToPid(char* process)
{
    HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
    PROCESSENTRY32 structprocsnapshot = {0};

    structprocsnapshot.dwSize = sizeof(PROCESSENTRY32);

    if(snapshot == INVALID_HANDLE_VALUE)return 0;
    if(Process32First(snapshot,&structprocsnapshot) == FALSE)return 0;

    while(Process32Next(snapshot,&structprocsnapshot) )
    {
       if(!strcmp(structprocsnapshot.szExeFile,process))
       {
            CloseHandle(snapshot);
            return structprocsnapshot.th32ProcessID;
       }
    }
    CloseHandle(snapshot);
    return 0;
}