Skip to content
Snippets Groups Projects
Commit 1790a17f authored by Virgile Prevosto's avatar Virgile Prevosto
Browse files

[obfuscator] more linting

parent c8c254fe
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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\
......
......@@ -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:
......
......@@ -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
......
......@@ -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 ]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment