[misc] improve ime process detection logic

This commit is contained in:
Klesh Wong 2020-05-11 12:56:25 +08:00
parent 9ee9afb76e
commit d51340686f
2 changed files with 21 additions and 14 deletions

View File

@ -20,5 +20,4 @@ if (Test-Path $sshconf -PathType Leaf) {
$wubiAction = New-ScheduledTaskAction -Execute 'Powershell.exe' ` $wubiAction = New-ScheduledTaskAction -Execute 'Powershell.exe' `
-Argument "-NoProfile -WindowStyle Hidden -File $PSScriptRoot\wubi-no-shift.ps1" -Argument "-NoProfile -WindowStyle Hidden -File $PSScriptRoot\wubi-no-shift.ps1"
$wubiTrigger = New-ScheduledTaskTrigger -AtLogOn $wubiTrigger = New-ScheduledTaskTrigger -AtLogOn
$wubiTrigger.Delay = 'PT3S'
Register-ScheduledTask -Action $wubiAction -Trigger $wubiTrigger -TaskName "Wubi No Shift" -Description "Disable Shift key toggling CN/EN" -RunLevel Highest Register-ScheduledTask -Action $wubiAction -Trigger $wubiTrigger -TaskName "Wubi No Shift" -Description "Disable Shift key toggling CN/EN" -RunLevel Highest

View File

@ -32,19 +32,27 @@ Add-Type -MemberDefinition @'
'@ -Name Kernel32 -Namespace Pinvoke '@ -Name Kernel32 -Namespace Pinvoke
$ps = Get-Process -Name $ChsIME $i = 0
foreach ($p in $ps) { while ($i++ -lt 10) {
$hModule = $p.Modules | Where-Object {$_.ModuleName -eq $ChsIMEExe}
if (!$hModule) { $ps = Get-Process -Name $ChsIME
continue 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"
}
} }
$hModule = $hModule[0] if ($ps) {
$addr = [IntPtr]::Add($hModule.BaseAddress, $offsetAddr) break
[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"
} }
Start-Sleep -Milliseconds 100
} }