Skip to content

Commit

Permalink
refact
Browse files Browse the repository at this point in the history
  • Loading branch information
pagran authored and lu4p committed Oct 9, 2023
1 parent 8df617e commit 45b591d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 4 additions & 2 deletions internal/ctrlflow/ctrlflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++ {
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions internal/ctrlflow/hardening.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 45b591d

Please sign in to comment.