Search Tool using a Shell Script
My requirement is to write a tool which takes as input a list of system calls and then searches for the occurrences of these system calls in a list of files. Right now, we have identified a list of 227 system calls. The number of files can be huge. The algorithm that I have employed right now is a simple nested for loop. And understandably the program is taking a very very long time to process. I am using shell scr开发者_开发百科ipts to achieve this.
Can anybody please suggest a better/efficient algorithm to do this?
Thank You, Aditya.
What type of files? Source code? Executables? Also, a syscall can be constructed at runtime with self modifying code, and in many cases the syscall is a generic kernel entry with the syscall number being potentially dynamic "data", so is the degree to which an analysis of static files may be incomplete even useful?
If you can identify something that distinguishes a system call in general from the other contents of a file, you could check for that first and then figure out which one it is, either by a brute force comparison or by some kind of tree search.
Another idea might be to see if you could use grep to identify system calls in general, and output the call with its file name and line number or whatever you like, then see if you could simply use sort on that by system call.
You might also want to look at using a language like perl which has some nice hash-related capabilities.
Your system calls will be in a file named calls
, one per line. Your list of files is in a file called list_of_files
, one per line.
cat list_of_files | xargs grep -f calls
精彩评论