all: drop x/exp in favor of std

x/exp/rand was being used for no apparent reason; use math/rand.

x/exp/maps and x/exp/slices can be replaced with maps and slices
respectively now that we require Go 1.23 or later.
Note that the APIs are slightly different due to iterators.
This commit is contained in:
Daniel Martí
2024-11-18 23:45:40 +00:00
committed by Paul Scheduikat
parent 30357af923
commit 4963af3311
7 changed files with 11 additions and 14 deletions
-1
View File
@@ -7,7 +7,6 @@ require (
github.com/go-quicktest/qt v1.101.0
github.com/google/go-cmp v0.6.0
github.com/rogpeppe/go-internal v1.13.1
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c
golang.org/x/mod v0.21.0
golang.org/x/tools v0.26.0
)
-2
View File
@@ -13,8 +13,6 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsK
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c h1:7dEasQXItcW1xKJ2+gg5VOiBnqWrJc+rq0DPKyvvdbY=
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c/go.mod h1:NQtJDoLvd6faHhE7m4T/1IY708gDefGGjR/iUW8yQQ8=
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
+2 -3
View File
@@ -7,7 +7,6 @@ import (
mathrand "math/rand"
"strconv"
"golang.org/x/exp/rand"
"golang.org/x/tools/go/ssa"
ah "mvdan.cc/garble/internal/asthelper"
"mvdan.cc/garble/internal/literals"
@@ -76,7 +75,7 @@ func (xorHardening) Apply(dispatcher []cfgInfo, ssaRemap map[ssa.Value]ast.Expr,
globalKeyName, localKeyName := getRandomName(rnd), getRandomName(rnd)
firstKey := int(rnd.Int31())
secondKey := make([]byte, literals.MinSize+rand.Intn(literals.MinSize)) // make second part of key literals obfuscation friendly
secondKey := make([]byte, literals.MinSize+mathrand.Intn(literals.MinSize)) // make second part of key literals obfuscation friendly
if _, err := rnd.Read(secondKey); err != nil {
panic(err)
}
@@ -150,7 +149,7 @@ func (xorHardening) Apply(dispatcher []cfgInfo, ssaRemap map[ssa.Value]ast.Expr,
type delegateTableHardening struct{}
func (delegateTableHardening) Apply(dispatcher []cfgInfo, ssaRemap map[ssa.Value]ast.Expr, rnd *mathrand.Rand) (ast.Decl, ast.Stmt) {
keySize := literals.MinSize + rand.Intn(literals.MinSize)
keySize := literals.MinSize + mathrand.Intn(literals.MinSize)
delegateCount := keySize
// Reusing multiple times one decryption function is fine,
+3 -2
View File
@@ -8,12 +8,13 @@ import (
"go/ast"
"go/token"
"go/types"
"maps"
"math"
mathrand "math/rand"
"slices"
"strconv"
"strings"
"golang.org/x/exp/maps"
"golang.org/x/tools/go/ssa"
ah "mvdan.cc/garble/internal/asthelper"
"mvdan.cc/garble/internal/ssa2ast"
@@ -395,7 +396,7 @@ func (t *trashGenerator) chooseRandomMethod(vars map[string]*definedVar) (string
return "", nil
}
candidateTypes := maps.Keys(groupedCandidates)
candidateTypes := slices.Collect(maps.Keys(groupedCandidates))
candidateType := candidateTypes[t.rand.Intn(len(candidateTypes))]
candidates := groupedCandidates[candidateType]
+1 -1
View File
@@ -6,11 +6,11 @@ import (
"go/ast"
"go/token"
"go/types"
"slices"
"sort"
"strconv"
"strings"
"golang.org/x/exp/slices"
"golang.org/x/tools/go/ssa"
ah "mvdan.cc/garble/internal/asthelper"
)
+2 -2
View File
@@ -25,6 +25,7 @@ import (
"io"
"io/fs"
"log"
"maps"
mathrand "math/rand"
"os"
"os/exec"
@@ -32,6 +33,7 @@ import (
"regexp"
"runtime"
"runtime/debug"
"slices"
"strconv"
"strings"
"time"
@@ -39,8 +41,6 @@ import (
"unicode/utf8"
"github.com/rogpeppe/go-internal/cache"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
"golang.org/x/mod/module"
"golang.org/x/tools/go/ast/astutil"
"golang.org/x/tools/go/ssa"
+3 -3
View File
@@ -3,10 +3,10 @@ package main
import (
"fmt"
"go/types"
"maps"
"path/filepath"
"slices"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
"golang.org/x/tools/go/ssa"
)
@@ -30,7 +30,7 @@ func (ri *reflectInspector) recordReflection(ssaPkg *ssa.Package) {
// find all unchecked APIs to add them to checkedAPIs after the pass
notCheckedAPIs := make(map[string]bool)
for _, knownAPI := range maps.Keys(ri.result.ReflectAPIs) {
for knownAPI := range maps.Keys(ri.result.ReflectAPIs) {
if !ri.checkedAPIs[knownAPI] {
notCheckedAPIs[knownAPI] = true
}