droid
droid copied to clipboard
Simple CLI invocation with "default" options
Hi,
Simple CLI commands like droid file.jpg
or droid directory/
fail with the error "Incorrect command line syntax: No command line options specified" because some options are not optional at all. Is it just me or wouldn't one expect that this just works by identifying the given files/directories (recursively) with the latest available (container) signature file? To me this seems like the "default" behavior for quick command line usage.
Personally, I work around this by tweaking your droid.sh file a little so that it accepts a CLI invocation like this. Would you possibly like to add this feature to DROID? In this case I will open a pull request.
Have a nice weekend, Martin
Hi Martin, That sounds like a good suggestion. I think, instead of doing it in the .bat or .sh file, it would be much more elegant to do this in the commandline.
Droid CLI can run in a "no-profile" mode as well, and your suggestion sounds like a better fit in that mode. It could be a shortcut into a command line of this nature:
-Nr "/path/to/the/data/file/samples.7z" -Ns "/path/to/signature/DROID_SignatureFile_V96.xml" -A
Is your suggestion about altering the .bat or .sh file or making it part of the droid CLI?
Thanks,
--Saurabh
Hi Saurabh,
You mean in the DROID Java code for command line argument parsing? Yes, that would indeed be much better.
At the moment I simply replaced this piece of code at the end of the droid.sh file ...
# Run the command-line or user interface version with the options:
if [ $# -gt 0 ]; then
java $OPTIONS -jar "$DROID_HOME/droid-command-line-6.5.jar" "$@"
else
java $OPTIONS -jar "$DROID_HOME/droid-ui-6.5.jar"
fi
... with this:
# Run the command-line or user interface version with the options:
# Arguments given, start CLI.
if [ $# -gt 0 ]; then
case $1 in
# First argument is an option, let DROID parse arguments.
-*)
java $OPTIONS -jar "$DROID_HOME/droid-command-line-6.5.jar" "$@"
;;
# First argument is not an option, assume only files given, start with
# default configuration.
*)
java $OPTIONS -jar "$DROID_HOME/droid-command-line-6.5.jar" \
-R -Ns $(latest_sigfile) -Nc $(latest_container_sigfile) \
-Nr "$@"
;;
esac
# No arguments given, start GUI.
else
java $OPTIONS -jar "$DROID_HOME/droid-ui-6.5.jar"
fi
Where latest_sigfile
and latest_container_sigfile
are Bash functions that retrieve the name of the latest (container) signature files in the ~/.droid6 directory:
latest_sigfile() {
find ~/.droid6/signature_files/ -type f | sort -n | tail -n 1
}
latest_container_sigfile() {
find ~/.droid6/container_sigs/ -type f | sort -n | tail -n 1
}
But of course this whole approach is a little fragile and if implemented properly would require duplicated code in the .sh and .bat files. So I greatly prefer your idea of making this a part of the Java code! I could still see what I can do in terms of a pull request, but I'd have to look into the Java code first which may take a while. So maybe you're faster just implementing it yourself. What do you think?
Edit: I see there is currently some major work in progress regarding the CLI (like e.g. #470). I suppose it's better if I don't mess with that but you just sneak the improvements discussed in this issue in where/when it fits?
Best, Martin
Thanks Martin. My preference would be to do it in the command line and also assess the impact on existing.
You are quite right about being cautious.
Thanks once again for identifying this, we would take it up as per the priorities of existing issues.
Regards, --Saurabh
Note - I'm working on getting better CSV output from the command line (and essentially replacing the -Nr option (or to be more precise, aliasing it to the new code, so it will still work). But the -Nr option produces very little output, just two columns. The new code will be more like performing an export from a profile (but without having to produce the profile first and then export).
But I agree, having a simple shortcut that just identifies the resources and writes the CSV output to the console by default would be nice.
I've now added this to my new command line code. If you don't specify any other top level arguments, it will default to just identifying files, and output the results to the console by default as CSV:
droid {file1} {file2} etc...
You can still specify other standard options to recurse into folder as normal, or to output to a file:
droid {file1} {folder1} -R -o "/home/user/scans/results.csv"
I guess recursion should be the default....? However, DROID itself doesn't have a "no recursion" option - it's off by default. So if we wanted to default to recursive scanning, we'd also want a "no recursion" option if that's not actually want you wanted...
Seems simpler to keep recursion as an explicit option. Most other command line utils default to no recursion, and you have to specify recursion explicitly.
Sounds awesome, thanks for your work!
Regarding recursion, I think it's OK to stay with the explicit option and keep "no recursion" the default. As you say, most tools do it that way.
Hey, I just updated from 6.5 to 6.7 and the new CLI is such an improvement, you really made my day! Commands like droid file.jpg
or droid directory/
now work as expected, and the new CSV output is also nice, btw. So I think we can close this issue.