Skip to content

Instantly share code, notes, and snippets.

@khr0x40sh
Last active November 5, 2019 15:05
Show Gist options
  • Save khr0x40sh/8633d9623d457a0cc32d96cead95fb93 to your computer and use it in GitHub Desktop.
Save khr0x40sh/8633d9623d457a0cc32d96cead95fb93 to your computer and use it in GitHub Desktop.
hexdump output in powershell
Param($byteArray);
function print_prettystring($value)
{
$final = ""
for($i=0; $i -lt $value.Count; $i++)
{
if($value[$i] -gt 31 -and $value[$i] -lt 127)
{
$final += [char]$value[$i]
}
else
{
$final += "."
}
}
$final
}
function print_hexdump($value)
{
$x = 0
$h = ""
for($i = 0; $i -lt $value.Count; $i++)
{
if ($i % 16 -eq 0)
{
if ($i -gt 0)
{
$h +=" |"
$h += print_prettystring $value[($i -16) .. ($i-1)]
$h +="|`n"
}
$h += "{0:x8}" -f $i
$h += " "
}
$h +="{0:X2}" -f $value[$i]
$h += " "
}
if ($value.Count % 16 -gt 0)
{
for ($j=($i % 16); $j -lt 16; $j++)
{
$h += " "
}
$h +=" |"
$h += print_prettystring $value[($i - ($i % 16)) .. ($i-1)]
$h +="|`n"
}
if ($value.Count % 16 -eq 0)
{
$h += " |"
$h += print_prettystring $value[($value.Count - 16) .. ($value.Count -1)]
$h += "|`n"
}
$h += "{0:x8}" -f $value.Count
$h
}
#Example:
print_hexdump $byteArray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment