-
Notifications
You must be signed in to change notification settings - Fork 1
/
eudic.cpp
121 lines (97 loc) · 3.44 KB
/
eudic.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <Windows.h>
#include <tchar.h>
#include <cstdio>
#include <TlHelp32.h>
#include <string>
LONG set_reg(DWORD time_left){
HKEY hKey;
DWORD dwDisposition;
LONG lError = RegCreateKeyEx(HKEY_CURRENT_USER,
_T("SOFTWARE\\Francophonie\\Eudic\\Customer Info"),
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&hKey,
&dwDisposition);
if (lError != ERROR_SUCCESS)
{
// Handle error
return false;
}
// Define the value data
LPCTSTR lpSerialCode = _T("Welcome back to eudic");
DWORD dwTimesLeft3 = time_left;
LPCTSTR lpRegDate = _T("2020/4/20 0000");
LPCTSTR lpLicenseCode = _T("Welcome back to eudic");
// Set the value data
RegSetValueEx(hKey, _T("SerialCode"), 0, REG_SZ, (LPBYTE)lpSerialCode, sizeof(TCHAR) * (_tcslen(lpSerialCode) + 1));
RegSetValueEx(hKey, _T("TimesLeft3"), 0, REG_DWORD, (LPBYTE)&dwTimesLeft3, sizeof(DWORD));
RegSetValueEx(hKey, _T("regDate"), 0, REG_SZ, (LPBYTE)lpRegDate, sizeof(TCHAR) * (_tcslen(lpRegDate) + 1));
RegSetValueEx(hKey, _T("LicenseCode"), 0, REG_SZ, (LPBYTE)lpLicenseCode, sizeof(TCHAR) * (_tcslen(lpLicenseCode) + 1));
// Close the key
RegCloseKey(hKey);
return 0;
}
bool IsProcessRunning(const std::wstring& processName) {
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnapshot == INVALID_HANDLE_VALUE) {
return false;
}
PROCESSENTRY32 pe;
pe.dwSize = sizeof(PROCESSENTRY32);
if (!Process32First(hSnapshot, &pe)) {
CloseHandle(hSnapshot);
return false;
}
bool found = false;
do {
if (wcscmp(pe.szExeFile, processName.c_str()) == 0) {
found = true;
break;
}
} while (Process32Next(hSnapshot, &pe));
CloseHandle(hSnapshot);
return found;
}
int main()
{
ShowWindow(GetConsoleWindow(), SW_HIDE);
HWND hwnd = FindWindow(NULL, _T("欧路词典"));
if (hwnd) {
ShowWindow(hwnd, SW_SHOW);
SetForegroundWindow(hwnd);
return 0;
}
//bool is_running = IsProcessRunning(L"eudic.exe");
DWORD systemLocale = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL);
HLOCAL hLocal = NULL;
DWORD dwRet;
if (dwRet = set_reg(0x000c85e7)) {
dwRet = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
dwRet, systemLocale, (PTSTR)&hLocal, 0, NULL);
_tprintf(_T("Fail to open registry: %s"), (PTSTR)hLocal);
LocalFree(hLocal);
return -1;
}
TCHAR current_path[MAX_PATH];
GetCurrentDirectory(MAX_PATH, current_path);
_tcscat_s(current_path, _T("\\eudic.exe"));
HINSTANCE result = ShellExecute(NULL, _T("open"), current_path, NULL, NULL, SW_SHOWNORMAL);
if ((int)result <= 32)
{
_tprintf(_T("Error: %d\n"), (int)result);
return 1;
}
Sleep(5000);
if (dwRet = set_reg(1)) {
dwRet = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
dwRet, systemLocale, (PTSTR)&hLocal, 0, NULL);
_tprintf(_T("Fail to open registry: %s"), (PTSTR)hLocal);
LocalFree(hLocal);
return -1;
};
_tprintf(_T("Software Upgraded Successfully!"));
return 0;
}