From 45b591d8eb924d05e7452c9c409e15a0a0b7775b Mon Sep 17 00:00:00 2001 From: pagran Date: Tue, 29 Aug 2023 17:08:13 +0200 Subject: [PATCH] refact --- internal/ctrlflow/ctrlflow.go | 6 ++++-- internal/ctrlflow/hardening.go | 4 ---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/internal/ctrlflow/ctrlflow.go b/internal/ctrlflow/ctrlflow.go index c880e193..d40b08eb 100644 --- a/internal/ctrlflow/ctrlflow.go +++ b/internal/ctrlflow/ctrlflow.go @@ -182,7 +182,7 @@ func Obfuscate(fset *token.FileSet, ssaPkg *ssa.Package, files []*ast.File, obfR if passes == 0 { fmt.Fprintf(os.Stderr, "control flow obfuscation for %q function has no effect on the resulting binary, to fix this flatten_passes must be greater than zero", ssaFunc) } - hardening := newDispatcherHardening(params.StringSlice("flatten_hardening")) + flattenHardening := params.StringSlice("flatten_hardening") applyObfuscation := func(ssaFunc *ssa.Function) []dispatcherInfo { for i := 0; i < split; i++ { @@ -211,7 +211,9 @@ func Obfuscate(fset *token.FileSet, ssaPkg *ssa.Package, files []*ast.File, obfR // Because of ssa package api limitations, implementation of hardening for control flow flattening dispatcher // is implemented during converting by replacing key values with obfuscated ast expressions var prologues []ast.Stmt - if len(dispatchers) > 0 && hardening != nil { + if len(flattenHardening) > 0 && len(dispatchers) > 0 { + hardening := newDispatcherHardening(flattenHardening) + ssaRemap := make(map[ssa.Value]ast.Expr) for _, dispatcher := range dispatchers { decl, stmt := hardening.Apply(dispatcher, ssaRemap, obfRand) diff --git a/internal/ctrlflow/hardening.go b/internal/ctrlflow/hardening.go index 87c54a09..b6681ff0 100644 --- a/internal/ctrlflow/hardening.go +++ b/internal/ctrlflow/hardening.go @@ -19,10 +19,6 @@ var hardeningMap = map[string]dispatcherHardening{ } func newDispatcherHardening(names []string) dispatcherHardening { - if len(names) == 0 { - return nil - } - hardenings := make([]dispatcherHardening, len(names)) for i, name := range names { h, ok := hardeningMap[name]