【发布时间】:2014-01-22 23:52:03
【问题描述】:
我正在尝试仅使用 powershell 从命令行执行二进制十六进制编辑。使用此剪辑执行十六进制替换已部分成功。当 123456 多次出现并且替换应该只发生在特定位置时,就会出现问题。
注意:剪辑需要在此处找到的 Convert-ByteArrayToHexString 和 Convert-HexStringToByteArray 函数。
http://www.sans.org/windows-security/2010/02/11/powershell-byte-array-hex-convert
$readin = [System.IO.File]::ReadAllBytes("C:\OldFile.exe");
$hx = Convert-ByteArrayToHexString $readin -width 40 -delimiter "";
$hx = $hx -replace "123456","FFFFFF";
$hx = "0x" + $hx;
$writeout = Convert-HexStringToByteArray $hx;
set-content -value $writeout -encoding byte -path "C:\NewFile.exe";
我们如何在 powershell 中指定一个偏移位置来替换这个粗略的 -replace 命令。
【问题讨论】:
-
这里有很多好的答案,但很少有人能上门。很高兴看到一个函数需要:(1)一个文件名,(2)一个 hex-string 来搜索,或(3)一个偏移量, (4) 一个要替换的十六进制字符串,作为某些 powershell 函数的输入。我想我们将不得不等待......
标签: powershell binary hex powershell-2.0 patch