create an ascii hexdump from binary or text files, to take a look into format details like line endings, with the sfk hexdump command on windows and linux.
- download the free swiss file knife base from sourceforge.
- unpack the tool using winzip or unzip.
- open the Windows Command Line or a Linux shell.
sfk ... +hextobin outfile
convert lines of text containing hexdump to binary.
chain-only command.
hextobin can be used only after another command,
typically filter, which reads and prepares the input data.
examples:
sfk filter dump.txt +hextobin out.dat
requires dump.txt to contain pure hex data, e.g.
7466696C 65732F46 6F726D61 74732F31
blanks and some chars like <> are skipped automatically.
sfk filter dump.txt "-+ >" -rep "_<*__" +hextobin out.dat
takes a verbose hexdump produced by "sfk hexump":
>73746669 6C65732F 42617365 4C69622F< stfiles/BaseLib/ 00000020
using only lines starting with " >" (skipping a possible
filename line), stripping the ascii and offset infos after "< ",
extracting and converting pure hex data.
sfk fromclip +hextobin %TEMP%\tmp1.dat +hexdump
takes a hex sequence like 22737769 73732066 from clipboard,
printing it's text via a temporary file and hexdump.
example: write a list of bytes into a binary file
let's say we want to write the binary data
0x01 0x02 0x03 0x04 0x05
into a binary file "target.exe" at offset 0x9876,
then this can be achieved by these steps:
sfk echo "01 02 03 04 05" +hextobin tmp1.dat
writes the byte sequence into a temporary file.
sfk partcopy tmp1.dat 0 5 target.exe 0x9876 -yes
copies these bytes from tmp1.dat into target.exe,
which must exist, at the offset 0x9876 (39030 decimal).
finally, you may
sfk hexdump target.exe -offlen 0x9870 20
to check the result by dumping the bytes around that area:
:file target.exe
>28C80000 10C20102 03040500 00000000< (............... 00009870
>00000000 06C90000 44C20000 00000000< ........D....... 00009880
see also:
sfk hexdump - creating hexdumps from binary data.
sfk partcopy - copy parts of a binary file.
sfk hexdump [-showle] [-wide] [...] dir .ext1 .ext2 .ext3 create human-readable hexdump of binary file(s). options:
-showle highlights line ending characters CR and LF.
-wide dumps 32 input bytes per line.
-lean dumps 16 input bytes per line.
-nofile or -nofilenames does not list the filename(s).
-pure lists flat hex characters:
53464B2D544553540D0A
-hexsrc lists hex comma separated values:
0x53,0x46,0x4B,0x2D,0x54,0x45,0x53,0x54,0x0D,0x0A,
-decsrc lists decimal comma separated values:
83,70,75,45,84,69,83,84,13,10,
-offlen n1 n2 dump from offset n1 only n2 bytes.
examples:
sfk hexdump -offlen 4221566976 96 part1.avi
dumps 96 bytes from offset 4221566976 within part1.avi
sfk hexdump -offlen 0xFBA00000 0x60 part1.avi
the same as above, but using hexadecimal numbers
example:
check if a script file contains just UNIX LF line endings,
or DOS CR/LF format:
sfk hexdump -showle thescript.bat
>6364202E 2E0A726D 202D7266 20746D70< cd ...rm -rf tmp 00000000
>2D73656C 66746573 740A6D6B 64697220< -selftest.mkdir 00000010
>746D702D 73656C66 74657374 0A636420< tmp-selftest.cd 00000020
>746D702D 73656C66 74657374 0A637020< tmp-selftest.cp 00000030
>2D52202E 2E2F7465 73746669 6C657320< -R ../testfiles 00000040
>74657374 66696C65 730A0A65 78706F72< testfiles..expor 00000050
>74205443 4D443D22 636D7020 2E2E2F73< t TCMD="cmp ../s 00000060
>63726970 74732F31 302D7366 6B2D7365< cripts/10-sfk-se 00000070
>6C667465 73742D64 622E7478 74220A0A< lftest-db.txt".. 00000080
>2E202E2E 2F736372 69707473 2F31322D< . ../scripts/12- 00000090
>7375622D 74657374 2D75782E 6261740A< sub-test-ux.bat. 000000a0
>0A636420 2E2E2F73 63726970 74730A< .cd ../scripts. 000000b0
the result shows that the script is in UNIX format (just LF 0x0A,
no CR/LF 0x0D0A).
see also:
sfk hextobin - converting hex text to binary.