2020-05-11 01:14:05 +00:00
|
|
|
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
|
|
|
Start-Process PowerShell -Verb RunAs "-NoProfile -ExecutionPolicy Bypass -Command `"cd '$pwd'; & '$PSCommandPath';`"";
|
|
|
|
exit;
|
|
|
|
}
|
2020-05-10 16:00:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
$Supported = @{
|
|
|
|
"B3448BF077665F2E1CA67094BCF2A7C5" = 0x14DE1;
|
|
|
|
"DE5FA392A825332AB3E348EF0316B514" = 0x16A61;
|
|
|
|
"F653C99D4A0C61D4B2C64358B8213BD8" = 0x15C11;
|
|
|
|
"C8BC76C87563E78C9BC85EE9F4F96760" = 0x15C11;
|
|
|
|
}
|
|
|
|
$ChsIME = "ChsIME"
|
|
|
|
$ChsIMEExe = "${ChsIME}.exe"
|
|
|
|
|
|
|
|
# make sure CheIme.exe is the right version
|
|
|
|
$ChsImeExePath = "$env:windir\System32\InputMethod\CHS\$ChsIMEExe"
|
|
|
|
$ChsIMEHash = (Get-FileHash $ChsImeExePath -Algorithm MD5).Hash
|
|
|
|
$offsetAddr = $Supported[$ChsIMEHash]
|
|
|
|
if (-not $offsetAddr) {
|
|
|
|
throw [System.Exception] "Unsupported ChsIme.exe"
|
|
|
|
}
|
|
|
|
|
2020-05-11 01:14:05 +00:00
|
|
|
Add-Type -MemberDefinition @'
|
|
|
|
[DllImport("kernel32.dll", SetLastError = true)]
|
|
|
|
public static extern bool WriteProcessMemory(
|
|
|
|
IntPtr hProcess,
|
|
|
|
IntPtr lpBaseAddress,
|
|
|
|
byte[] lpBuffer,
|
|
|
|
Int32 nSize,
|
|
|
|
out IntPtr lpNumberOfBytesWritten);
|
|
|
|
'@ -Name Kernel32 -Namespace Pinvoke
|
2020-05-10 16:00:42 +00:00
|
|
|
|
|
|
|
|
2020-05-11 04:56:25 +00:00
|
|
|
$i = 0
|
|
|
|
while ($i++ -lt 10) {
|
|
|
|
|
|
|
|
$ps = Get-Process -Name $ChsIME
|
|
|
|
foreach ($p in $ps) {
|
|
|
|
$hModule = $p.Modules | Where-Object {$_.ModuleName -eq $ChsIMEExe}
|
|
|
|
if (!$hModule) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
$hModule = $hModule[0]
|
|
|
|
$addr = [IntPtr]::Add($hModule.BaseAddress, $offsetAddr)
|
|
|
|
[Int32]$n = 0
|
|
|
|
$pidd = $p.id
|
|
|
|
if ([Pinvoke.Kernel32]::WriteProcessMemory($p.Handle[0], $addr, @(0x31, 0xc0), 2, [ref]$n)) {
|
|
|
|
echo "$pidd is patched"
|
|
|
|
} else {
|
|
|
|
throw [System.Exception] "Failed to patch $pidd"
|
|
|
|
}
|
2020-05-10 16:00:42 +00:00
|
|
|
}
|
2020-05-11 04:56:25 +00:00
|
|
|
if ($ps) {
|
|
|
|
break
|
2020-05-11 01:14:05 +00:00
|
|
|
}
|
2020-05-11 04:56:25 +00:00
|
|
|
Start-Sleep -Milliseconds 100
|
2020-05-10 16:00:42 +00:00
|
|
|
}
|