如何在Linux上判断对boost有依赖的文件
2023-11-04 20:48:44
标签: shell find xargs readelf for
项目需要Scan一下哪个库对Boost有符号依赖,在Linux上,所以想用python或shell来完成。
为了做到这个效果,决定还是用shell,因为一些查找需要find和readelf等命令。
#!/bin/bash
# Directory to search in
directory="/home/client-delivery/.neutron_3p"
# Find all folders in the specified directory
folder_paths=$(find $directory -name
'RuntimeRoots')
# Iterate over each folder path
for folder_path in $folder_paths; do
updated_folder_path="$folder_path/Release"
files_pathes=$(find $updated_folder_path -print0
-name "*.so" | xargs -0 -L1 file | grep "ELF
" | cut -d ":" -f1)
for file_path in $files_pathes; do
#echo "Checking $file_path"
sizes=$(readelf -s $file_path | grep boost | wc
-l)
if [ $sizes -gt 0 ]; then
echo "$file_path has boost reference"
fi
done
done
结合人工智能的代码输出,在VSCode中直接输入注释,稍等会产生代码,然后再修改一下,就可以了。
$(find $updated_folder_path -print0 -name "*.so" |
xargs -0 -L1 file | grep "ELF " | cut -d
":" -f1)
这句是最关键的,找所有so文件,并且去掉其中不是ELF的文件,后面加空格是为了去掉某些。ELFV.png类的文件。
$(readelf -s $file_path | grep boost | wc -l)
来得到有多少个boost相关的符号。
当符号数大于0的时候,报告这个so的文件名称。
最后根据结果可以得到一堆依赖库的包名。
如何在Linux上判断对boost有依赖的文件
项目需要Scan一下哪个库对Boost有符号依赖,在Linux上,所以想用python或shell来完成。
为了做到这个效果,决定还是用shell,因为一些查找需要find和readelf等命令。
#!/bin/bash
# Directory to search in
directory="/home/client-delivery/.neutron_3p"
# Find all folders in the specified directory
folder_paths=$(find $directory -name 'RuntimeRoots')
# Iterate over each folder path
for folder_path in $folder_paths; do
updated_folder_path="$folder_path/Release"
files_pathes=$(find $updated_folder_path -print0 -name "*.so" | xargs -0 -L1 file | grep "ELF " | cut -d ":" -f1)
for file_path in $files_pathes; do
#echo "Checking $file_path"
sizes=$(readelf -s $file_path | grep boost | wc -l)
if [ $sizes -gt 0 ]; then
echo "$file_path has boost reference"
fi
done
done
结合人工智能的代码输出,在VSCode中直接输入注释,稍等会产生代码,然后再修改一下,就可以了。
$(find $updated_folder_path -print0 -name "*.so" | xargs -0 -L1 file | grep "ELF " | cut -d ":" -f1)
这句是最关键的,找所有so文件,并且去掉其中不是ELF的文件,后面加空格是为了去掉某些。ELFV.png类的文件。
$(readelf -s $file_path | grep boost | wc -l) 来得到有多少个boost相关的符号。
当符号数大于0的时候,报告这个so的文件名称。
最后根据结果可以得到一堆依赖库的包名。