Skip to content

Commit 0202366

Browse files
committed
add md5 for file check
1 parent 74140a3 commit 0202366

File tree

7 files changed

+397
-16
lines changed

7 files changed

+397
-16
lines changed

Win10WubiShiftPatch.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,11 @@
144144
</ItemDefinitionGroup>
145145
<ItemGroup>
146146
<ClCompile Include="main.cpp" />
147+
<ClCompile Include="md5.cpp" />
147148
<ClCompile Include="utils.cpp" />
148149
</ItemGroup>
149150
<ItemGroup>
151+
<ClInclude Include="md5.h" />
150152
<ClInclude Include="utils.h" />
151153
</ItemGroup>
152154
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

Win10WubiShiftPatch.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,16 @@
2121
<ClCompile Include="utils.cpp">
2222
<Filter>源文件</Filter>
2323
</ClCompile>
24+
<ClCompile Include="md5.cpp">
25+
<Filter>源文件</Filter>
26+
</ClCompile>
2427
</ItemGroup>
2528
<ItemGroup>
2629
<ClInclude Include="utils.h">
2730
<Filter>源文件</Filter>
2831
</ClInclude>
32+
<ClInclude Include="md5.h">
33+
<Filter>源文件</Filter>
34+
</ClInclude>
2935
</ItemGroup>
3036
</Project>

main.cpp

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,18 @@
77
#include <string>
88
#include <thread>
99
#include <chrono>
10-
#include <algorithm>
1110

1211
#include <Windows.h>
1312
#include <TlHelp32.h>
1413

1514
#include "utils.h"
15+
#include "md5.h"
1616

1717
using namespace std;
1818

1919
static void sys_sleep(uint32_t nMilliseconds)
2020
{
2121
std::this_thread::sleep_for(std::chrono::milliseconds(nMilliseconds));
22-
}
23-
24-
static std::wstring LowerCase(const std::wstring& text)
25-
{
26-
std::wstring ret = text;
27-
std::transform(ret.begin(), ret.end(), ret.begin(), tolower);
28-
return ret;
2922
}
3023

3124
static uint64_t GetDLLBaseAddress(std::wstring needDllName, int32_t pid)
@@ -45,8 +38,8 @@ static uint64_t GetDLLBaseAddress(std::wstring needDllName, int32_t pid)
4538
int loaded_count = 0;
4639
while (bMore) {
4740
std::wstring dll_name = module.szModule;
48-
dll_name = LowerCase(dll_name);
49-
needDllName = LowerCase(needDllName);
41+
dll_name = lower_case(dll_name);
42+
needDllName = lower_case(needDllName);
5043
if (dll_name == needDllName) {
5144
ret = (uint64_t)module.modBaseAddr;
5245
break;
@@ -74,11 +67,11 @@ static std::vector<DWORD> GetPidByProcessName(wstring process_name)
7467
if (!::Process32FirstW(hSnapshot, &lppe))
7568
return ret;
7669

77-
process_name = LowerCase(process_name);
70+
process_name = lower_case(process_name);
7871

7972
do {
8073
wstring exeName = lppe.szExeFile;
81-
exeName = LowerCase(exeName);
74+
exeName = lower_case(exeName);
8275
if(exeName == process_name) {
8376
ret.push_back(lppe.th32ProcessID);
8477
}
@@ -120,7 +113,7 @@ class win10_wubi_patch
120113
uint32_t count = 0;
121114
while (!_exit) {
122115

123-
sys_sleep(5000);
116+
sys_sleep(2500);
124117

125118
std::vector<DWORD> pids = GetPidByProcessName(s_target_process_name);
126119
for (auto pid : pids) {
@@ -133,7 +126,7 @@ class win10_wubi_patch
133126
} else {
134127
s_bok = "failed";
135128
}
136-
printf("---- do patch, pid = %d, times = %d, result = %s\n", pid, count, s_bok.c_str());
129+
printf("-- do patch, pid = %d, times = %d, result = %s\n", pid, count, s_bok.c_str());
137130
}
138131
}
139132
}
@@ -178,8 +171,37 @@ class win10_wubi_patch
178171
std::thread _thread;
179172
};
180173

174+
bool check_support_version()
175+
{
176+
std::string chs_ime_path = get_system_winodws_path();
177+
chs_ime_path += "System32\\InputMethod\\CHS\\ChsIME.exe";
178+
bool bSupport = false;
179+
do
180+
{
181+
std::string file_md5 = md5file(chs_ime_path.c_str());
182+
if (file_md5.empty()) {
183+
break;
184+
}
185+
186+
file_md5 = lower_case(file_md5);
187+
if (file_md5 == "b3448bf077665f2e1ca67094bcf2a7c5") {
188+
bSupport = true;
189+
}
190+
191+
} while (0);
192+
return bSupport;
193+
}
194+
181195
int main()
182196
{
197+
printf("---Widows 10 Disable English Switch Key(Shift) For Wubi InputMethod---\n");
198+
printf("==key press [Q] to exit==\n");
199+
printf("\n");
200+
201+
if (!check_support_version()) {
202+
printf("file(ChsIME.exe) not support.\n");
203+
return -1;
204+
}
183205

184206
if (!set_debug_privilege()) {
185207
printf("admin privileges are required.\n");
@@ -190,7 +212,6 @@ int main()
190212

191213
win10_wubi_patch wubi_patch;
192214
wubi_patch.RunThread();
193-
printf("---Widows 10 Disable English Switch Key(Shift) For Wubi InputMethod--- =key press [Q] to exit=\n");
194215
do {
195216
if (read_key() == 'q') {
196217
printf("exit\n");

0 commit comments

Comments
 (0)