PSH*_*r12 1 windows powershell encoding character-encoding
我正在尝试使用 Powershell 的 -EncodedCommand 标志弹出一个简单的消息框,但它一直失败。在过去的几个小时里,我试过谷歌搜索,但似乎无法正常工作。它几乎看起来像是编码错误,但我使用的是带有标准 ASCII 向后兼容字符的常规 UTF-8。
不断失败的命令:
Powershell.exe -EncodedCommand QWRkLVR5cGUgLUFzc2VtYmx5TmFtZSBQcmVzZW50YXRpb25Db3JlLFByZXNlbnRhdGlvbkZyYW1ld29yaztbU3lzdGVtLldpbmRvd3MuTWVzc2FnZUJveF06OlNob3coJ3dvcmtpbmcnKTs=
Run Code Online (Sandbox Code Playgroud)
b64解码后的命令是:
Add-Type -AssemblyName PresentationCore,PresentationFramework;[System.Windows.MessageBox]::Show('working');
Run Code Online (Sandbox Code Playgroud)
我错过了什么?感谢您帮助解决我的菜鸟问题
传递给的 Base64 编码字符串-EncodedCommand必须对UTF-16LE(“Unicode”)字符串的字节表示进行编码-不支持UTF-8 :
$cmd = 'Add-Type -AssemblyName PresentationCore,PresentationFramework;[System.Windows.MessageBox]::Show(''working'')'
$encodedCmd = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($cmd))
powershell.exe -EncodedCommand $encodedCmd
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2735 次 |
| 最近记录: |