Skip to content

Instantly share code, notes, and snippets.

@STashakkori
Created October 7, 2023 04:25
Show Gist options
  • Save STashakkori/2075999954abd44e8ebbbf0b439dd6f1 to your computer and use it in GitHub Desktop.
Save STashakkori/2075999954abd44e8ebbbf0b439dd6f1 to your computer and use it in GitHub Desktop.
Poor human's hexdump in ps. Works but stupid slow
$filePath = "D:\test_binary.exe"
$bytes = [System.IO.File]::ReadAllBytes($filePath)
$hexLines = @()
$asciiLines = @()
for ($i = 0; $i -lt $bytes.Length; $i += 8) {
$lineBytes = $bytes[$i..($i + 7)]
$hexLine = -join ($lineBytes | ForEach-Object { " {0:x2}" -f $_ })
$asciiLine = [System.Text.Encoding]::ASCII.GetString($lineBytes)
$hexLines += $hexLine
$asciiLines += $asciiLine
}
for ($i = 0; $i -lt $hexLines.Count; $i++) {
Write-Host "$hexLines[$i]|$asciiLines[$i]"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment