Created
May 5, 2025 22:10
-
-
Save jqntn/36680f4cb96592d8ef06f7bd703d3015 to your computer and use it in GitHub Desktop.
Fast xxd -i implementation in Windows PowerShell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $file_name = ($args[0] -replace '\W', '_').ToLower() | |
| $file_bytes = [System.IO.File]::ReadAllBytes($args[0]) | |
| $hex_array = New-Object string[] $file_bytes.Length | |
| for ($i = 0; $i -lt $file_bytes.Length; $i++) { | |
| $hex_array[$i] = '0x{0:x2}' -f $file_bytes[$i] | |
| } | |
| $hex_string = [string]::Join(', ', $hex_array) | |
| "unsigned char $file_name[] = { $hex_string };" | |
| "unsigned int ${file_name}_len = $($file_bytes.Length);" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment