[feature] ms-wubi-no-shift

This commit is contained in:
Klesh Wong 2020-05-11 09:14:05 +08:00
parent 7829c4d789
commit 9ee9afb76e
2 changed files with 31 additions and 42 deletions

View File

@ -1,3 +1,8 @@
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;
}
Set-ExecutionPolicy RemoteSigned
# link config files
@ -11,5 +16,9 @@ if (Test-Path $sshconf -PathType Leaf) {
New-Item -ItemType SymbolicLink -Target $sshconf -Path $home\.ssh\config -Force
}
# disable Shift key toggling CN/EN
Install-Module -Name PSReflect-Functions
# fix Shift key toggling Cn/En fro MS wubi
$wubiAction = New-ScheduledTaskAction -Execute 'Powershell.exe' `
-Argument "-NoProfile -WindowStyle Hidden -File $PSScriptRoot\wubi-no-shift.ps1"
$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

View File

@ -1,6 +1,8 @@
#Requires -RunAsAdministrator
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;
}
Import-Module PSReflect-Functions
$Supported = @{
"B3448BF077665F2E1CA67094BCF2A7C5" = 0x14DE1;
@ -18,53 +20,31 @@ $offsetAddr = $Supported[$ChsIMEHash]
if (-not $offsetAddr) {
throw [System.Exception] "Unsupported ChsIme.exe"
}
echo "Offset Address: $offsetAddr"
# reference
<#
public enum ProcessAccessFlags : uint
{
All = 0x001F0FFF,
Terminate = 0x00000001,
CreateThread = 0x00000002,
VirtualMemoryOperation = 0x00000008,
VirtualMemoryRead = 0x00000010,
VirtualMemoryWrite = 0x00000020,
DuplicateHandle = 0x00000040,
CreateProcess = 0x000000080,
SetQuota = 0x00000100,
SetInformation = 0x00000200,
QueryInformation = 0x00000400,
QueryLimitedInformation = 0x00001000,
Synchronize = 0x00100000
}
public enum SnapshotFlags : uint
{
HeapList = 0x00000001,
Process = 0x00000002,
Thread = 0x00000004,
Module = 0x00000008,
Module32 = 0x00000010,
All = (HeapList | Process | Thread | Module),
Inherit = 0x80000000,
NoHeaps = 0x40000000
}
#>
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
$ps = Get-Process -Name $ChsIME
foreach ($p in $ps) {
$hProcess = Get-Process -Name $ChsIme
if (!$hProcess) {
throw [System.Exception] "Unable to open process $pid";
}
$hModule = $hProcess.Modules | Where-Object {$_.ModuleName -eq $ChsIMEExe}
$hModule = $p.Modules | Where-Object {$_.ModuleName -eq $ChsIMEExe}
if (!$hModule) {
continue
}
$hModule = $hModule[0]
$addr = [IntPtr]::Add($hModule.BaseAddress, $offsetAddr)
[Int32]$n = 0
[PSReflectFunctions.kernel32]::WriteProcessMemory($hProcess.Handle[0], $addr, @(0x31, 0xc0), 2, [ref]$n)
$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"
}
}