diff options
| author | Shulhan <ms@kilabit.info> | 2023-04-05 00:58:51 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-04-05 00:58:51 +0700 |
| commit | 144ceef8e29f8780c84bc5ae2589dab3895c5ee6 (patch) | |
| tree | ee490791ca58df366ee313c3990cce0264f0a127 /lib/bytes/testdata | |
| parent | 981e42af5d17f632546a6247c59a753b579c8882 (diff) | |
| download | pakakeh.go-144ceef8e29f8780c84bc5ae2589dab3895c5ee6.tar.xz | |
lib/bytes: implement function ParseHexDump
The ParseHexDump parse the default output of [hexdump](1) utility from
parameter in back into stream of byte.
An example of default output of hexdump is
0000000 7865 5f70 6964 2f72 0000 0000 0000 0000
0000010 0000 0000 0000 0000 0000 0000 0000 0000
*
0000060 0000 0000 3030 3030 3537 0035 3030 3130
The first column is the address and the rest of the column is the data.
Each data column is 16-bit words in big-endian order, so in the above
example, the first byte would be 65, second byte is 78 and so on.
The asterisk "*" means that the address from 0000020 to 0000050 is equal to
the previous line, 0000010.
[hexdump]: https://man.archlinux.org/man/hexdump.1
Diffstat (limited to 'lib/bytes/testdata')
| -rw-r--r-- | lib/bytes/testdata/ParseHexDump_exp_dir_tar_test.txt | 68 | ||||
| -rw-r--r-- | lib/bytes/testdata/ParseHexDump_test.txt | 48 | ||||
| -rw-r--r-- | lib/bytes/testdata/exp_dir.tar | bin | 0 -> 10240 bytes |
3 files changed, 116 insertions, 0 deletions
diff --git a/lib/bytes/testdata/ParseHexDump_exp_dir_tar_test.txt b/lib/bytes/testdata/ParseHexDump_exp_dir_tar_test.txt new file mode 100644 index 00000000..dceff86f --- /dev/null +++ b/lib/bytes/testdata/ParseHexDump_exp_dir_tar_test.txt @@ -0,0 +1,68 @@ +>>> exp_dir.tar +0000000 7865 5f70 6964 2f72 0000 0000 0000 0000 +0000010 0000 0000 0000 0000 0000 0000 0000 0000 +* +0000060 0000 0000 3030 3030 3537 0035 3030 3130 +0000070 3537 0030 3030 3130 3537 0030 3030 3030 +0000080 3030 3030 3030 0030 3431 3731 3236 3532 +0000090 3635 0035 3130 3330 3534 2000 0035 0000 +00000a0 0000 0000 0000 0000 0000 0000 0000 0000 +* +0000100 7500 7473 7261 2020 6d00 0073 0000 0000 +0000110 0000 0000 0000 0000 0000 0000 0000 0000 +0000120 0000 0000 0000 0000 6d00 0073 0000 0000 +0000130 0000 0000 0000 0000 0000 0000 0000 0000 +* +0000200 7865 5f70 6964 2f72 6964 5f72 2f78 0000 +0000210 0000 0000 0000 0000 0000 0000 0000 0000 +* +0000260 0000 0000 3030 3030 3537 0035 3030 3130 +0000270 3537 0030 3030 3130 3537 0030 3030 3030 +0000280 3030 3030 3030 0030 3431 3731 3236 3532 +0000290 3535 0030 3130 3431 3434 2000 0035 0000 +00002a0 0000 0000 0000 0000 0000 0000 0000 0000 +* +0000300 7500 7473 7261 2020 6d00 0073 0000 0000 +0000310 0000 0000 0000 0000 0000 0000 0000 0000 +0000320 0000 0000 0000 0000 6d00 0073 0000 0000 +0000330 0000 0000 0000 0000 0000 0000 0000 0000 +* +0000400 7865 5f70 6964 2f72 6964 5f72 2f78 6966 +0000410 656c 785f 0000 0000 0000 0000 0000 0000 +0000420 0000 0000 0000 0000 0000 0000 0000 0000 +* +0000460 0000 0000 3030 3030 3436 0034 3030 3130 +0000470 3537 0030 3030 3130 3537 0030 3030 3030 +0000480 3030 3030 3430 0031 3431 3731 3236 3532 +0000490 3535 0030 3130 3632 3033 2000 0030 0000 +00004a0 0000 0000 0000 0000 0000 0000 0000 0000 +* +0000500 7500 7473 7261 2020 6d00 0073 0000 0000 +0000510 0000 0000 0000 0000 0000 0000 0000 0000 +0000520 0000 0000 0000 0000 6d00 0073 0000 0000 +0000530 0000 0000 0000 0000 0000 0000 0000 0000 +* +0000600 6f43 746e 6e65 2074 666f 6520 7078 645f +0000610 7269 642f 7269 785f 662f 6c69 5f65 2e78 +0000620 000a 0000 0000 0000 0000 0000 0000 0000 +0000630 0000 0000 0000 0000 0000 0000 0000 0000 +* +0000800 7865 5f70 6964 2f72 6966 656c 795f 0000 +0000810 0000 0000 0000 0000 0000 0000 0000 0000 +* +0000860 0000 0000 3030 3030 3436 0034 3030 3130 +0000870 3537 0030 3030 3130 3537 0030 3030 3030 +0000880 3030 3030 3330 0033 3431 3731 3236 3532 +0000890 3635 0035 3130 3531 3333 2000 0030 0000 +00008a0 0000 0000 0000 0000 0000 0000 0000 0000 +* +0000900 7500 7473 7261 2020 6d00 0073 0000 0000 +0000910 0000 0000 0000 0000 0000 0000 0000 0000 +0000920 0000 0000 0000 0000 6d00 0073 0000 0000 +0000930 0000 0000 0000 0000 0000 0000 0000 0000 +* +0000a00 6f43 746e 6e65 2074 666f 6520 7078 645f +0000a10 7269 662f 6c69 5f65 2e79 000a 0000 0000 +0000a20 0000 0000 0000 0000 0000 0000 0000 0000 +* +0002800 diff --git a/lib/bytes/testdata/ParseHexDump_test.txt b/lib/bytes/testdata/ParseHexDump_test.txt new file mode 100644 index 00000000..e326072d --- /dev/null +++ b/lib/bytes/testdata/ParseHexDump_test.txt @@ -0,0 +1,48 @@ +>>> trailing new line +0000000 6548 6c6c 2c6f 7720 726f 646c 0a21 + + +<<< trailing new line +Hello, world! + + +>>> invalid address +000000x 6548 6c6c 2c6f 7720 726f 646c 0a21 + +<<< invalid address +ParseHexDump: strconv.ParseInt: parsing "000000x": invalid syntax + +>>> start with asterisk +* +0000000 6548 6c6c 2c6f 7720 726f 646c 0a21 + +<<< start with asterisk +Hello, world! + + +>>> first row < 16 +0000000 6548 6c6c 2c6f 7720 726f 646c 0a21 +* +0000020 6548 6c6c 2c6f 7720 726f 646c 0a21 + +<<< first row < 16 +Hello, world! +Hello, world! +Hello, world! + + +>>> invalid hex +0000000 654x 6c6c 2c6f 7720 726f 646c 0a21 + +<<< invalid hex +ParseHexDump: strconv.ParseInt: parsing "654x": invalid syntax + +>>> invalid character on new line +0000000 6548 6c6c 2c6f 7720 726f 646c 0a21 +- + +<<< invalid character on new line +Hello, world! + + +<<< DONE. diff --git a/lib/bytes/testdata/exp_dir.tar b/lib/bytes/testdata/exp_dir.tar Binary files differnew file mode 100644 index 00000000..465deda2 --- /dev/null +++ b/lib/bytes/testdata/exp_dir.tar |
