ne_viens
Advanced Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору // cl /Ox /GF /GS- patcher.c kernel32.lib user32.lib advapi32.lib #include <windows.h> #pragma comment(linker, "/SUBSYSTEM:WINDOWS /NODEFAULTLIB /ENTRY:WinMain /MERGE:.rdata=.text") //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// patch() { HKEY hKey; int x, i; HANDLE hFile; FILETIME at, bt, ct; char buf[MAX_PATH]; if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MyProg 5.2_is1", 0, KEY_QUERY_VALUE, &hKey)) { x = sizeof(buf); i = RegQueryValueEx(hKey, "InstallLocation", NULL, NULL, buf, &x); RegCloseKey(hKey); if(ERROR_SUCCESS == i) { lstrcat(buf, "MyProg 5.exe"); hFile = CreateFile(buf, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if(INVALID_HANDLE_VALUE != hFile) { GetFileTime(hFile, &at, &bt, &ct); SetFilePointer(hFile, 0x130, NULL, FILE_BEGIN); ReadFile(hFile, buf, 4, &x, 0); if(*(int*)buf == 0x4FBA4BBB) //14:05:47 2012.05.21 { SetFilePointer(hFile, 0x28b470, NULL, FILE_BEGIN); *(int*)buf = 0x04c201b0; buf[4] = 0; WriteFile(hFile, buf, 5, &x, 0); SetFileTime(hFile, &at, &bt, &ct); CloseHandle(hFile); MessageBox(NULL, "File patched successfully", "OK", 0); return 0; } CloseHandle(hFile); MessageBox(NULL, "Wrong file version!", NULL, 0); return -1; } MessageBox(NULL, "Can not open a file for patching.", NULL, 0); return -1; } } MessageBox(NULL, "Program not found, install it first!", NULL, 0); return -1; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// int WinMain(HINSTANCE h, HINSTANCE h2, char* cmdl, int i) { return patch(); } |