Repository

Looks good to me!

User Tools

Site Tools


kb:intranet:software:powershell

Copied shamelessly from SO on dumping hex values from binary file, and back. Thought VSCode could do the job, but the official hex editor does not quite support copy-paste.

perform_hexdump.ps1
# read the binary data as byte array
[byte[]]$data = [System.IO.File]::ReadAllBytes('D:\Test\blah.exe')
 
# write to new file as string of hex encoded characters
[System.IO.File]::WriteAllText('D:\Test\blah.hex',[System.BitConverter]::ToString($data).Replace('-',''), [System.Text.Encoding]::ASCII)
restore_hexdump.ps1
# read the textfile as single ASCII string
$hex = [System.IO.File]::ReadAllText('D:\Test\blah.hex', [System.Text.Encoding]::ASCII)
 
# convert to bytes and write these as new binary file
[System.IO.File]::WriteAllBytes('D:\Test\blahblah.exe', ($hex -split '(.{2})' -ne '' -replace '^', '0X'))
kb/intranet/software/powershell.txt · Last modified: 19 months ago ( 2 May 2023) by 127.0.0.1