From 1790a17fe88f6ecabe7e7519cd9f3c4d61c1311d Mon Sep 17 00:00:00 2001 From: Virgile Prevosto <virgile.prevosto@m4x.org> Date: Mon, 8 Apr 2019 12:25:54 +0200 Subject: [PATCH] [obfuscator] more linting --- .Makefile.lint | 4 --- src/plugins/obfuscator/dictionary.ml | 22 +++++++------- src/plugins/obfuscator/obfuscator_kind.ml | 30 +++++++++---------- src/plugins/obfuscator/obfuscator_register.ml | 16 +++++----- src/plugins/obfuscator/options.ml | 24 +++++++-------- 5 files changed, 46 insertions(+), 50 deletions(-) diff --git a/.Makefile.lint b/.Makefile.lint index a46b10f034d..435f216117e 100644 --- a/.Makefile.lint +++ b/.Makefile.lint @@ -324,10 +324,6 @@ ML_LINT_KO+=src/plugins/metrics/metrics_gui.ml ML_LINT_KO+=src/plugins/metrics/metrics_parameters.ml ML_LINT_KO+=src/plugins/metrics/register.ml ML_LINT_KO+=src/plugins/metrics/register_gui.ml -ML_LINT_KO+=src/plugins/obfuscator/dictionary.ml -ML_LINT_KO+=src/plugins/obfuscator/obfuscator_kind.ml -ML_LINT_KO+=src/plugins/obfuscator/obfuscator_register.ml -ML_LINT_KO+=src/plugins/obfuscator/options.ml ML_LINT_KO+=src/plugins/occurrence/Occurrence.mli ML_LINT_KO+=src/plugins/occurrence/options.ml ML_LINT_KO+=src/plugins/occurrence/register.ml diff --git a/src/plugins/obfuscator/dictionary.ml b/src/plugins/obfuscator/dictionary.ml index 1ae55c07c0c..aae72b82af2 100644 --- a/src/plugins/obfuscator/dictionary.ml +++ b/src/plugins/obfuscator/dictionary.ml @@ -28,7 +28,7 @@ module Dictionary = let name = "Obfuscator.Dictionary" let size = 97 let dependencies = [ Ast.self ] - end) + end) module Literal_strings = State_builder.Hashtbl @@ -38,14 +38,14 @@ module Literal_strings = let name = "Obfuscator.Literal_strings" let size = 17 let dependencies = [ Dictionary.self ] - end) + end) let fresh kind name = let h = Dictionary.memo (fun _ -> Datatype.String.Hashtbl.create 17) kind in let idx = Datatype.String.Hashtbl.length h + 1 in let fresh = Obfuscator_kind.prefix kind ^ string_of_int idx in Datatype.String.Hashtbl.add h fresh name; - if kind = Obfuscator_kind.Literal_string && not (Literal_strings.mem name) + if kind = Obfuscator_kind.Literal_string && not (Literal_strings.mem name) then Literal_strings.add name fresh; fresh @@ -56,8 +56,8 @@ let iter_sorted_kind f k h = let f = f k in Datatype.String.Hashtbl.iter_sorted f h -let iter_sorted f = - let cmp k1 k2 = +let iter_sorted f = + let cmp k1 k2 = Datatype.String.compare (Obfuscator_kind.prefix k1) (Obfuscator_kind.prefix k2) @@ -67,7 +67,7 @@ let iter_sorted f = let pretty_entry fmt k = Format.fprintf fmt "// %as@\n" Obfuscator_kind.pretty k; let quote = k = Obfuscator_kind.Literal_string in - fun new_ old -> + fun new_ old -> if quote then Format.fprintf fmt "#define %s %S@\n" new_ old else Format.fprintf fmt "#define %s %s@\n" new_ old @@ -75,18 +75,18 @@ let pretty_kind fmt k = try let h = Dictionary.find k in iter_sorted_kind (pretty_entry fmt) k h - with Not_found -> + with Not_found -> () let pretty fmt = - Format.fprintf fmt "\ + Format.fprintf fmt "\ /* *********************************** */@\n\ /* start of dictionary for obfuscation */@\n\ /* *********************************** */@\n"; iter_sorted - (fun k -> - if k = Obfuscator_kind.Literal_string then fun _ _ -> () - else pretty_entry fmt k); + (fun k -> + if k = Obfuscator_kind.Literal_string then fun _ _ -> () + else pretty_entry fmt k); Format.fprintf fmt "\ /*********************************** */@\n\ /* end of dictionary for obfuscation */@\n\ diff --git a/src/plugins/obfuscator/obfuscator_kind.ml b/src/plugins/obfuscator/obfuscator_kind.ml index 80ba427b2ba..404e7c51084 100644 --- a/src/plugins/obfuscator/obfuscator_kind.ml +++ b/src/plugins/obfuscator/obfuscator_kind.ml @@ -72,21 +72,21 @@ let prefix = function | Logic_constructor -> "LC" include Datatype.Make_with_collections -(struct - type t = k - let name = "Obfuscator.kind" - let reprs = [ Global_var ] - let hash (k:k) = Hashtbl.hash k - let equal (k1:k) k2 = k1 = k2 - let compare (k1:k) k2 = Transitioning.Stdlib.compare k1 k2 - let varname _ = "k" - let internal_pretty_code = Datatype.undefined - let copy = Datatype.identity - let structural_descr = Structural_descr.t_abstract - let rehash = Datatype.identity - let mem_project = Datatype.never_any_project - let pretty fmt k = Format.fprintf fmt "%s" (name_of_kind k) - end) + (struct + type t = k + let name = "Obfuscator.kind" + let reprs = [ Global_var ] + let hash (k:k) = Hashtbl.hash k + let equal (k1:k) k2 = k1 = k2 + let compare (k1:k) k2 = Transitioning.Stdlib.compare k1 k2 + let varname _ = "k" + let internal_pretty_code = Datatype.undefined + let copy = Datatype.identity + let structural_descr = Structural_descr.t_abstract + let rehash = Datatype.identity + let mem_project = Datatype.never_any_project + let pretty fmt k = Format.fprintf fmt "%s" (name_of_kind k) + end) (* Local Variables: diff --git a/src/plugins/obfuscator/obfuscator_register.ml b/src/plugins/obfuscator/obfuscator_register.ml index 0674063a9bf..c7828f790a4 100644 --- a/src/plugins/obfuscator/obfuscator_register.ml +++ b/src/plugins/obfuscator/obfuscator_register.ml @@ -27,7 +27,7 @@ let disable_other_analyzers () = (Parameter_state.get_selection ()) (State_selection.Static.union (State_selection.of_list - (Kernel.CodeOutput.self :: Options.states)) + (Kernel.CodeOutput.self :: Options.states)) (* The command-line options that govern the creation of the AST must be preserved *) (State_selection.Static.with_codependencies Ast.self)) @@ -44,14 +44,14 @@ let force_run () = else begin let file = Options.Dictionary.get () in try - let cout = open_out file in - let fmt = Format.formatter_of_out_channel cout in - Dictionary.pretty fmt + let cout = open_out file in + let fmt = Format.formatter_of_out_channel cout in + Dictionary.pretty fmt with Sys_error _ as exn -> - Options.error - "@[cannot generate the dictionary into file `%s':@ %s@]" - file - (Printexc.to_string exn) + Options.error + "@[cannot generate the dictionary into file `%s':@ %s@]" + file + (Printexc.to_string exn) end; File.pretty_ast (); Printer.set_printer old_printer diff --git a/src/plugins/obfuscator/options.ml b/src/plugins/obfuscator/options.ml index 71c15870307..66278a7015f 100644 --- a/src/plugins/obfuscator/options.ml +++ b/src/plugins/obfuscator/options.ml @@ -21,19 +21,19 @@ (**************************************************************************) include Plugin.Register - (struct - let name = "obfuscator" - let shortname = "obfuscator" - let help = "obfuscator for confidential code" - end) + (struct + let name = "obfuscator" + let shortname = "obfuscator" + let help = "obfuscator for confidential code" + end) module Run = False (struct - let option_name = "-obfuscate" - let help = "print an obfuscated version of the input files and exit.\n\ -Disable any other Frama-C analysis." - end) + let option_name = "-obfuscate" + let help = "print an obfuscated version of the input files and exit.\n\ + Disable any other Frama-C analysis." + end) module Dictionary = Empty_string @@ -41,7 +41,7 @@ module Dictionary = let option_name = "-obfuscator-dictionary" let arg_name = "f" let help = "generate the dictionary into file <f> (on stdout by default)" - end) + end) module Literal_string = Empty_string @@ -49,8 +49,8 @@ module Literal_string = let option_name = "-obfuscator-string-dictionary" let arg_name = "f" let help = "generate the dictionary of literal strings into file <f> \ -(in the same place than the code by default)" - end) + (in the same place than the code by default)" + end) let states = [ Run.self; Dictionary.self; Literal_string.self ] -- GitLab