Unverified Commit 5c607b11 by Enkelmann Committed by GitHub

Version number (#57)

Add "--version" to command line options.
parent ee048cbc
...@@ -96,6 +96,10 @@ let check_for_help (flags: string list) : bool = ...@@ -96,6 +96,10 @@ let check_for_help (flags: string list) : bool =
print_help_message (); true print_help_message (); true
) else false ) else false
let check_for_version (flags:string list) : bool =
if (Stdlib.List.mem "-v" flags) || (Stdlib.List.mem "-version" flags) || (Stdlib.List.mem "--version" flags) then (
print_version (); true
) else false
let check_for_module_versions (flags: string list) : bool = let check_for_module_versions (flags: string list) : bool =
if Stdlib.List.mem "-module-versions" flags then if Stdlib.List.mem "-module-versions" flags then
...@@ -134,6 +138,7 @@ let process_input () : string * string list = ...@@ -134,6 +138,7 @@ let process_input () : string * string list =
| [] -> raise (NoBinaryPathException ("No binary path was provided. If you need help, please call the cwe_checker with the --help or -h flag")) | [] -> raise (NoBinaryPathException ("No binary path was provided. If you need help, please call the cwe_checker with the --help or -h flag"))
| input -> ( | input -> (
if check_for_help input then exit 0; if check_for_help input then exit 0;
if check_for_version input then exit 0;
if check_for_module_versions input then exit 0; if check_for_module_versions input then exit 0;
check_for_no_logging input; check_for_no_logging input;
let binary_path = check_for_binary_path input in let binary_path = check_for_binary_path input in
......
...@@ -42,6 +42,7 @@ If you want to print the output to a file with [--cwe-checker-out], you also nee ...@@ -42,6 +42,7 @@ If you want to print the output to a file with [--cwe-checker-out], you also nee
If you run the {i cwe_checker} as a BAP plugin, all command line options have to be prefixed with [--cwe-checker] (so that BAP knows to forward them to the {i cwe_checker} plugin). If you run the {i cwe_checker} as a BAP plugin, all command line options have to be prefixed with [--cwe-checker] (so that BAP knows to forward them to the {i cwe_checker} plugin).
If you run the {i cwe_checker} directly, do not prefix the command line options. If you run the {i cwe_checker} directly, do not prefix the command line options.
The available command line options are: The available command line options are:
- [-version] Print the version number of the {i cwe_checker} and exit.
- [-check-path] Find paths between input functions (configurable in the configuration file) and CWE hits. - [-check-path] Find paths between input functions (configurable in the configuration file) and CWE hits.
Should be used together with the [-partial] command line option if you are only interested in paths to specific CWEs. Should be used together with the [-partial] command line option if you are only interested in paths to specific CWEs.
- [-config=[FILE]] Use [[FILE]] as the configuration file. - [-config=[FILE]] Use [[FILE]] as the configuration file.
......
...@@ -2,6 +2,7 @@ open Core_kernel ...@@ -2,6 +2,7 @@ open Core_kernel
open Bap.Std open Bap.Std
open Format open Format
let version = "0.3-dev"
type cwe_module = { type cwe_module = {
cwe_func : Bap.Std.program Bap.Std.term -> Bap.Std.project -> Bap.Std.word Bap.Std.Tid.Map.t -> string list list -> string list -> unit; cwe_func : Bap.Std.program Bap.Std.term -> Bap.Std.project -> Bap.Std.word Bap.Std.Tid.Map.t -> string list list -> string list -> unit;
...@@ -27,6 +28,7 @@ let known_modules = [{cwe_func = Cwe_190.check_cwe; name = Cwe_190.name; version ...@@ -27,6 +28,7 @@ let known_modules = [{cwe_func = Cwe_190.check_cwe; name = Cwe_190.name; version
let cmdline_flags = [ let cmdline_flags = [
("version", "Print the version number of the cwe_checker and quit");
("module-versions", "Prints out the version numbers of all known modules."); ("module-versions", "Prints out the version numbers of all known modules.");
("json", "Outputs the result as JSON."); ("json", "Outputs the result as JSON.");
("no-logging", "Outputs no logging (info, error, warning). This does not pollute STDOUT when output json to it."); ("no-logging", "Outputs no logging (info, error, warning). This does not pollute STDOUT when output json to it.");
...@@ -46,6 +48,9 @@ let build_version_sexp () = ...@@ -46,6 +48,9 @@ let build_version_sexp () =
let print_module_versions () = let print_module_versions () =
Log_utils.info (sprintf "[cwe_checker] module_versions: {%s}" (build_version_sexp ())) Log_utils.info (sprintf "[cwe_checker] module_versions: {%s}" (build_version_sexp ()))
let print_version () =
print_endline version
let print_help_message ((): unit) : unit = let print_help_message ((): unit) : unit =
let flags = cmdline_flags in let flags = cmdline_flags in
let params = cmdline_params in let params = cmdline_params in
...@@ -117,7 +122,11 @@ let main flags params project = ...@@ -117,7 +122,11 @@ let main flags params project =
let json_output = String.Map.find_exn flags "json" in let json_output = String.Map.find_exn flags "json" in
let file_output = String.Map.find_exn params "out" in let file_output = String.Map.find_exn params "out" in
let no_logging = String.Map.find_exn flags "no-logging" in let no_logging = String.Map.find_exn flags "no-logging" in
let print_version_flag = String.Map.find_exn flags "version" in
if print_version_flag then
print_version ()
else
if module_versions then if module_versions then
print_module_versions () print_module_versions ()
else else
......
...@@ -12,6 +12,11 @@ type cwe_module = { ...@@ -12,6 +12,11 @@ type cwe_module = {
has_parameters : bool; has_parameters : bool;
} }
val version: String.t
(** prints the version number *)
val print_version: unit -> unit
val known_modules: cwe_module List.t val known_modules: cwe_module List.t
val cmdline_flags: (String.t * String.t) List.t val cmdline_flags: (String.t * String.t) List.t
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment