I have a executable linux file called "Fyserver". I want to open it with this arg
./Fyserver --pass 2849
If I don't enter this --pass
arg to ELF, then it should exit itself without even running. Is there a way to do this?
NOTE: I don't have the source code of this ELF. I want to do it in bash.
CodePudding user response:
There is no sane way to do what you are asking. You can't add new behavior to a binary without access to the source code or some serious reverse engineering skills.
The usual solution is to create a simple wrapper, i.e. move ./Fyserver
to ./Fyserver.real
and create a script like
#!/bin/sh
[ "$1" = "--pass" ] || { echo "Syntax: $0 --pass <pass>" >&2; exit 127; }
exec ./Fyserver.real "$@"
The argument checking could arguably be more sophisticated, but this should at least give you an idea of how this is usually handled.
If you really wanted to, I suppose you could write this logic in a compiled language, and embed the original binary within it somehow.