有没有办法检测sed中的空字节(?,NUL,\ 0)?

l0b*_*0b0 20 bash sed

另一个问题相关,为了模糊检测二进制文件,有没有办法检测?字节在sed?

jip*_*pie 22

例子:

证明我正在发送一个 NUL 字节,后跟一个换行符:

$ echo -e \\0 | hexdump -C
00000000  00 0a                                             |..|
00000002
Run Code Online (Sandbox Code Playgroud)

现在我将 NUL 字节更改为!感叹号:

$ echo -e \\0 | sed 's/\x00/!/' | hexdump -C
00000000  21 0a                                             |!.|
Run Code Online (Sandbox Code Playgroud)

所以诀窍是使用\x00NUL 字节。

  • 应该提到的是,`\x` 是一个非标准的 `sed` 扩展,但是 [GNU `sed`](http://www.gnu.org/software/sed/manual/html_node/Escapes.html#index -g_t_0040acronym_007bGNU_007d-extensions_002c-special-escapes-222) 确实提供了它。 (7认同)
  • 还应该提到的是,`echo -e` 是一种 [bashism](http://mywiki.wooledge.org/Bashism)。`printf` 更加兼容。 (6认同)
  • 你可以`echo -ne \\0` 来避免换行。 (3认同)

jof*_*fel 8

是的,模式\x00匹配空字节。

例子:

$ printf "\0\n\0\n" > file
$ sed -e 's/\x00/test/' -i file
$ cat file
test
test
$  
Run Code Online (Sandbox Code Playgroud)