From c8c254febbe66b94c350b947ea99afb5f8c47bb0 Mon Sep 17 00:00:00 2001 From: Virgile Prevosto <virgile.prevosto@m4x.org> Date: Mon, 8 Apr 2019 11:56:17 +0200 Subject: [PATCH] [obfuscator] Renames parameters in function pointers Fixes external issue 2433 --- src/plugins/obfuscator/obfuscate.ml | 17 ++++++++++++++++- src/plugins/obfuscator/obfuscator_kind.ml | 3 +++ src/plugins/obfuscator/obfuscator_kind.mli | 1 + tests/misc/oracle/long_ident.res.oracle | 4 ++++ tests/misc/oracle/obfuscate.res.oracle | 11 ++++++++++- 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/plugins/obfuscator/obfuscate.ml b/src/plugins/obfuscator/obfuscate.ml index 5b6799903ac..4b48f22da13 100644 --- a/src/plugins/obfuscator/obfuscate.ml +++ b/src/plugins/obfuscator/obfuscate.ml @@ -36,12 +36,27 @@ class visitor = object val logic_vars_visited = Logic_var.Hashtbl.create 7 val id_pred_visited = Identified_predicate.Hashtbl.create 7 + method! vtype = function + | TFun(t, args, variadic, attrs) -> + let args' = + match args with + | None -> None + | Some l -> + Some + (List.map + (fun (s,t,a) -> + (Dictionary.fresh Obfuscator_kind.Formal_in_type s, t, a)) l) + in + Cil.ChangeDoChildrenPost(TFun(t,args',variadic,attrs), Extlib.id) + | _ -> Cil.DoChildren + method! vglob_aux = function | GType (ty,_) -> if not (Cil.typeHasAttribute "fc_stdlib" ty.ttype) then ty.tname <- Dictionary.fresh Obfuscator_kind.Type ty.tname; Cil.DoChildren - | GVarDecl (v, _) | GVar (v, _, _) | GFun ({svar = v}, _) | GFunDecl (_, v, _) + | GVarDecl (v, _) | GVar (v, _, _) + | GFun ({svar = v}, _) | GFunDecl (_, v, _) when Cil.is_unused_builtin v -> Cil.SkipChildren | _ -> diff --git a/src/plugins/obfuscator/obfuscator_kind.ml b/src/plugins/obfuscator/obfuscator_kind.ml index 47633a9a28a..80ba427b2ba 100644 --- a/src/plugins/obfuscator/obfuscator_kind.ml +++ b/src/plugins/obfuscator/obfuscator_kind.ml @@ -25,6 +25,7 @@ type k = | Enum | Field | Formal_var + | Formal_in_type | Function | Global_var | Label @@ -41,6 +42,7 @@ let name_of_kind = function | Enum -> "enum" | Field -> "field" | Formal_var -> "formal variable" + | Formal_in_type -> "formal variable in fun type" | Function -> "function" | Global_var -> "global variable" | Label -> "label" @@ -57,6 +59,7 @@ let prefix = function | Enum -> "E" | Field -> "M" | Formal_var -> "f" + | Formal_in_type -> "ft" | Function -> "F" | Global_var -> "G" | Label -> "L" diff --git a/src/plugins/obfuscator/obfuscator_kind.mli b/src/plugins/obfuscator/obfuscator_kind.mli index 25685566b88..ac5fc7d8384 100644 --- a/src/plugins/obfuscator/obfuscator_kind.mli +++ b/src/plugins/obfuscator/obfuscator_kind.mli @@ -25,6 +25,7 @@ type k = | Enum | Field | Formal_var + | Formal_in_type | Function | Global_var | Label diff --git a/tests/misc/oracle/long_ident.res.oracle b/tests/misc/oracle/long_ident.res.oracle index 5b634422ab1..bfe69779d74 100644 --- a/tests/misc/oracle/long_ident.res.oracle +++ b/tests/misc/oracle/long_ident.res.oracle @@ -18,6 +18,10 @@ #define f1 q #define f2 X_9999999999999999999999999999999999999999999999999999_0 #define f3 p +// formal variable in fun types +#define ft1 q +#define ft2 X_9999999999999999999999999999999999999999999999999999_0 +#define ft3 p /*********************************** */ /* end of dictionary for obfuscation */ /*********************************** */ diff --git a/tests/misc/oracle/obfuscate.res.oracle b/tests/misc/oracle/obfuscate.res.oracle index 0618abc8f7a..124447020ca 100644 --- a/tests/misc/oracle/obfuscate.res.oracle +++ b/tests/misc/oracle/obfuscate.res.oracle @@ -53,6 +53,15 @@ #define f4 c #define f5 d #define f6 s +// formal variable in fun types +#define ft1 x +#define ft2 y +#define ft3 p +#define ft4 f1 +#define ft5 p +#define ft6 c +#define ft7 d +#define ft8 s /*********************************** */ /* end of dictionary for obfuscation */ /*********************************** */ @@ -74,7 +83,7 @@ enum T1 { E3 = 4 }; struct T2 { - void (*M1)(int x, int y) ; + void (*M1)(int ft1, int ft2) ; }; int G1 = 0; /*@ global invariant LV1: G1 ≥ 0; -- GitLab