Methods to hex edit binary files via Powershell

前端 未结 4 439
醉梦人生
醉梦人生 2020-11-30 09:37

Am trying to perform binary hex edit from the command line using only powershell. Have had partial success performing a hex replace with this snip. Problem springs up when

4条回答
  •  醉话见心
    2020-11-30 09:50

    You already have a byte array, so you could simply modify the bytes at any given offset.

    $bytes  = [System.IO.File]::ReadAllBytes("C:\OldFile.exe")
    $offset = 23
    
    $bytes[$offset]   = 0xFF
    $bytes[$offset+1] = 0xFF
    $bytes[$offset+2] = 0xFF
    
    [System.IO.File]::WriteAllBytes("C:\NewFile.exe", $bytes)
    

提交回复
热议问题