You are not logged in.
I'm doing some analysing of some code written in bash.
Now I must know all the "things" that are executed (or can be executed) from inside the script, without executing the script.
So basically the script must be parsed and all the occurrences of executions of programs and sh functions must be listed.
Does anyone know if there is a tool/script for this somewhere?
Thanks.
Last edited by Dieter@be (2008-11-08 15:12:07)
< Daenyth> and he works prolifically
4 8 15 16 23 42
Offline
First you should know that it's impossible to get a guaranteed-correct answer without executing the script. Scripts can call programs/functions whose names are found/generated at runtime. The most common example is opening a text file using the program whose name is stored in $EDITOR.
That said, you can get an approximation by writing a parser. Parsers are hard. Smart programmers use a parser generator like bison or ANTLR to abstract away much of the complexity, but it's still sort of a pain in the butt the first time or two.
If you don't want to write a parser, a very approximate answer can be found by splitting each line by whitespace and returning the first word. Then finding other places commands can hide, like after semicolons, backticks, "$(", etc, but not when quoted. At this point, you will have written a very shoddy parser and taken longer at it than you would have if you'd bothered to learn bison or ANTLR.
Last edited by skymt (2008-11-08 15:34:36)
Offline
Yeah, this is totally impossible to do for most programming languages. If you're just trying to find out dependencies you can do something workable, but for security purposes, for example, it's totally inadequate. Especially in a language that can produce entirely new programs to run.
Offline
Well, in this specific case we can luckily ignore the fact that the script can dynamically generate executable/function names. I know the code a bit, and I know I have enough with the executables/functions that are hard coded
< Daenyth> and he works prolifically
4 8 15 16 23 42
Offline
run the script, see what processes are started with ps?
Offline
Run the script in an isolated environment ? A virtual machine ?
I mean, if you're concerned about whether it is safe to execute...
Last edited by moljac024 (2008-11-09 13:18:20)
The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...
Offline
run the script, see what processes are started with ps?
Run the script in an isolated environment ? A virtual machine ?
carlocci & moljac024:
Not an option. The script can take many different routes according to a variety of parameters. Checking the processes is not good either because a process can finish really fast, some things are just sh *functions* etc. I need to do this because I'm refactoring some code ;-)
Last edited by Dieter@be (2008-11-09 13:20:07)
< Daenyth> and he works prolifically
4 8 15 16 23 42
Offline
Try set -x
Offline
for word in $(cat filename); do
[ -f $word -o -f /bin/$word and so on ] && echo $word
done
you might want to sanitize a little bit removing ",(,`,; and so on from word
you might want to check for execution instead of existance (-f)
Offline