123456
出现多次时,我的问题就出现了,因为替换只应该发生在特定位置。
注意:这段代码需要使用这里显示的
Convert-ByteArrayToHexString
和Convert-HexStringToByteArray
函数。
$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命令?