PS转换二进制编码问题


PowerShell交流中心分类: 文件和注册表PS转换二进制编码问题
0
wb8504 asked 6 年 ago

网上找的代码可以将二进制程序生成base64的字符串并存储在b64.txt中,执行了代码没有报错但是也不见生成b64.txt,代码如下

function Convert-BinaryToString {
[CmdletBinding()] param (
[string] $FilePath
)
try {
$ByteArray = [System.IO.File]::ReadAllBytes($FilePath);
}
catch {
throw "Failed to read file. Ensure that you have permission to the file, and that the file path is correct.";
}
if ($ByteArray) {
$Base64String = [System.Convert]::ToBase64String($ByteArray);
}
else {
throw '$ByteArray is $null.';
}
$Base64String | set-content ("b64.txt")
}
2 Answers
0
Best Answer
Mooser Lee 管理员 answered 6 年 ago
"b64.txt"用绝对路径"d:\abc\b64.txt"
wb8504 replied 6 年 ago

绝对路径试了也不能生成txt,执行PS的命令格式如下有问题吗?
.\Convert-BinaryToString -FilePath .\svchost.exe

0
woyaozhuce01 answered 6 年 ago

测试过,这脚本使用绝对路径输出没问题。或者用powershell ise 下设置断点查看一下执行过程的数据出传递是否正确。