我有一个instructions.txt
包含以下内容的文件:
00000000000000000000000000010011
00000010110100010010000010000011
00000000011100110000001010110011
00000000011100110000010000110011
00000000011100110110010010110011
00000000000000000000000000010011
Run Code Online (Sandbox Code Playgroud)
如何创建instructions.bin
与instructions.txt
. 换句话说,.bin
文件应该与文件中的 192 位相同.txt
,每行 32 位。我在 Ubuntu Linux 上使用 bash。我试图使用,xxd -b instructions.txt
但输出比 192 位长得多。
如何很容易地转换到/从普通的机器可读的十六进制数据(无任何填补处理/偏移/字符视图)与xdd
或hexdump
?
我厌倦了挖掘一些特殊格式的字符串(并发现它突然开始在 N 个字符后换行或跳过行)或每次编写 Perl 单行。
为什么不像base64
/那样简单base64 -d
?
我正在寻找如何进行反向十六进制转储并发现提到了 xxd。但是,它似乎不能简单地使用:
xxd -r hexdumpfile > binaryfile
Run Code Online (Sandbox Code Playgroud)
然后我比较了xxd infile
和 的输出之间的差异hexdump infile
,发现了三个差异:
5a42
在 hexdump 输出中变成425a
在 xxd 输出中)我在服务器上只有某些文件的 hexdumped 版本。如何使用 xxd 正确取回二进制数据?
我一直在xxd
用来创建文件的六进制表示(任何文件,如 .jpg、.docx、.zip 等),像这样,..
$ xxd -p original_file.zip > hexa_format.txt
Run Code Online (Sandbox Code Playgroud)
并扭转
$ xxd -r -p hexa_format.txt > original_file.zip
Run Code Online (Sandbox Code Playgroud)
如果有人觉得这不是正确的方法,请纠正我。无论如何这不是我的问题。现在我必须将它们转换为二进制而不是六进制。所以命令是这样的,如果我是正确的。
$ xxd -p -b original_file.zip > binary_format.txt
Run Code Online (Sandbox Code Playgroud)
我的问题是,
如何将其从上述命令创建的二进制文件 (binary_format.txt) 反转回原始文件。xxd 的手册页说它不能完成(在最后一行)。
-b | -bits
Switch to bits (binary digits) dump, rather than hexdump. This
option writes octets as eight digits "1"s and "0"s instead of a
normal hexadecimal dump. Each line is preceded by a line number
in hexadecimal and followed by an ascii (or ebcdic) representa?
tion. …
Run Code Online (Sandbox Code Playgroud) 如何转储“纯”和纯二进制位序列?
例如,我有这个:
0000000: 10001001 01010000 01001110 01000111 00001101 00001010 .PNG..
0000006: 00011010 00001010 00000000 00000000 00000000 00001101 ......
000000c: 01001001 01001000 01000100 01010010 00000000 00000000 IHDR..
0000012: 00000010 01011000 00000000 00000000 00000001 10010000 .X....
0000018: 00001000 00000010 00000000 00000000 00000000 11111101 ......
000001e: 01010111 10001001 11001111 00000000 00000000 00000000 W.....
0000024: 00000111 01110100 01001001 01001101 01000101 00000111 .tIME.
Run Code Online (Sandbox Code Playgroud)
左边的那些行号和右边的 ASCII 对我来说是个问题。我确实尝试过将其删除:
xxd -b /root/Desktop/image.png | sed -r "s/\d32{3,}.*//g" | sed "s/.*://" | sed "s/\d32//g"
Run Code Online (Sandbox Code Playgroud)
但是,我没有成功:
100010010101000001001110010001110000110100001010.PNG..
000110100000101000000000000000000000000000001101......
010010010100100001000100010100100000000000000000IHDR..
000000100101100000000000000000000000000110010000.X....
000010000000001000000000000000000000000011111101...... …
Run Code Online (Sandbox Code Playgroud) 我使用的是 Mac OS X 10.8.2,运行xxd
v1.10 的编译副本(源代码)以及xxd
OS X 上预安装的副本。
我正在尝试通过终端中的一系列管道命令生成 Base64 编码的 SHA1 签名。
通常我会做类似以下的事情:
$ echo "foo" | openssl sha1 | xxd -p -r | base64 - > foo_sha1_signature
Run Code Online (Sandbox Code Playgroud)
该文件foo_sha1_signature
通常包含字符串 的 Base64 编码的 SHA1 哈希值foo
。
问题是xxd -p -r
不返回任何数据,因此文件foo_sha1_signature
是空的。
如果我将命令分开来查看 的输出xxd -r
,我会得到一个结果(如下所示):
$ echo "foo" | openssl sha1 | xxd -p | xxd -r
7b36c94bcdf32bee$
Run Code Online (Sandbox Code Playgroud)
但是,如果我将标准输出通过管道传输到文件,则该文件为空:
$ echo "foo" | openssl sha1 | xxd -p …
Run Code Online (Sandbox Code Playgroud) xxd ×6
linux ×5
hexdump ×3
binary-files ×2
command-line ×2
bash ×1
conversion ×1
macos ×1
sha1 ×1