覆盖可执行文件中的硬编码路径

ead*_*ter 2 executable sandbox portability

我想覆盖预编译可执行文件中存储的一些硬编码路径,例如“/usr/share/nmap/”,并将它们重定向到另一个目录。

我理想的解决方案不应该需要 root 权限,因此创建符号链接是不行的。

(也不能重新编译)

Sté*_*las 5

perl -pe 's:/usr/share/nmap/:/other/dir/nmap/:g
  ' /path/to/executable > new-executable
Run Code Online (Sandbox Code Playgroud)

/other/dir/nmap应与 的长度相同/usr/share/nmap/如果没有,您可以用字符填充:

perl -pe 's:/usr/share/nmap/:/other//////dir/:g
  ' /path/to/executable > new-executable
Run Code Online (Sandbox Code Playgroud)

新的路不能再长了。/tmp如果这是一个问题,您始终可以选择创建符号链接。