Linux查找二进制文件(Linux Find Binary File)
我试图在Linux系统中使用类似下面的方法找到二进制文件:
if [ -f `which $1` ] then
echo "File Found"
else
echo "File not Found"
fi
虽然代码工作正常,但问题是“哪个”将返回一个空操作符,BASH将其解释为存在的某个文件,以便始终找到文件。 任何建议都会很棒。
谢谢
I am attempting to find a binary file in a Linux system using something like this:
if [ -f `which $1` ] then
echo "File Found"
else
echo "File not Found"
fi
while the code works fine the problem is "which" will return a null operator which BASH interprets as something existing so a file always comes back found. Any suggestions would be great.
Thanks
原文:https://stackoverflow.com/questions/9014262
更新时间:2019-10-12 09:53
最满意答案
if [ `which "$1"` != "" ]; then
当它找到二进制时它不会返回"" 。
if [ `which "$1"` != "" ]; then
which won't return "" when it finds the binary.
2012-01-26
相关问答
Unix在文本和二进制文件之间没有区别,这就是为什么你可以将它们放在一起: cat file1 file2 > target_file
Unix has no distinction between text and binary files, which is why you can just cat them together: cat file1 file2 > target_file
建议使用@ user786653,使用xxd(1)程序: xxd -r -p input.txt output.bin
As @user786653 suggested, use the xxd(1) program: xxd -r -p input.txt output.bin
您可以使用readelf来浏览ELF头。 readelf -d将直接依赖关系列为“ NEEDED部分。 $ readelf -d elfbin
Dynamic section at offset 0xe30 contains 22 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libssl.so.1.0
...
你用过吗? cmake .. -DJSONCPP_WITH_CMAKE_PACKAGE=ON -DJSONCPP_LIB_BUILD_SHARED=OFF -DCMAKE_CXX_FLAGS=-fPIC 因为这就是本教程中用来构建项目的内容,并且CMakaList.txt将处理所有路径。 I managed to get it to work. I reinstalled libfunctionality in my ~/src directory. Then I removed the gith
...
您想要在流中搜索一个神奇的单词(而不是字符串)。 这是个主意: 从这个文件中读取一个char(使用file.read(1))使用你的魔术字的队列长度,检查每次读取的队列 MAGIC_WORD = r'JPEG' # it's example... just example
l = list(c for c in f.read(len(MAGIC_WORD)))
offset = 0
while True:
if ''.join(l) == MAGIC_WORD:
retu
...
尝试ls -l /proc/"proess id"/exe 。 来自GNU coreutils的ls实用程序显示带-l选项的链接,但我没有关于来自busybox ls确切信息。 Try ls -l /proc/"proess id"/exe. ls utility from GNU coreutils shows links with -l option, but I don't have exact information about ls from busybox.
nm 会告诉你哪些符号被定义,更重要的是,这些符号被给定的二进制使用。 您可以通过检查输出中列出哪个poll或select来获得保守的猜测。 您可能会发现您的应用程序与两者都有关联。 在这种情况下,它可能会作出运行时间决定,哪一个要调用,如果你运行它,你将无法轻易地知道它实际使用哪一个。 根据构建二进制文件的方式,您可能必须使用-D标志运行nm ; 或者你可能需要确保你没有指定-D 。 尝试两种方式。 如果程序使用共享库,实际的poll或select调用可能在它正在使用的库中。 在
...
if [ `which "$1"` != "" ]; then
当它找到二进制时它不会返回"" 。 if [ `which "$1"` != "" ]; then
which won't return "" when it finds the binary.