-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
67 lines (58 loc) · 1.63 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"io"
"io/fs"
"log"
"os"
"path/filepath"
"github.com/jessevdk/go-flags"
"github.com/yardenlaif/balagan/obfuscator"
)
func main() {
var opts struct {
Source string `short:"s" long:"source" description:"Directory with code to obfuscate" required:"true"`
Target string `short:"t" long:"target" description:"Directory to write obfuscated code to" required:"true"`
Ignore []string `short:"i" long:"ignore" description:"Directory to ignore"`
}
_, err := flags.Parse(&opts)
if err != nil {
return
}
opts.Source, err = filepath.Abs(opts.Source)
if err != nil {
log.Fatalf("Unable to get absolute source path %s: %v", opts.Source, err)
}
opts.Target, err = filepath.Abs(opts.Target)
if err != nil {
log.Fatalf("Unable to get absolute target path %s: %v", opts.Target, err)
}
for i, ignore := range opts.Ignore {
opts.Ignore[i], err = filepath.Abs(ignore)
if err != nil {
log.Fatalf("Unable to get absolute ignore path %s: %v", ignore, err)
}
}
// Make sure target directory is empty (if it exists at all)
if _, err := os.Stat(opts.Target); !os.IsNotExist(err) {
dir, err := os.Open(opts.Target)
defer func() { _ = dir.Close() }()
if err == nil {
_, err := dir.Readdirnames(1)
if err != io.EOF {
log.Fatalf("Target directory %s is not empty!", opts.Target)
}
}
}
err = os.MkdirAll(opts.Target, fs.ModePerm)
if err != nil {
log.Fatalf("Unable to create target directory %s: %v", opts.Target, err)
}
obf, err := obfuscator.NewObfuscator(opts.Source, opts.Target, opts.Ignore)
if err != nil {
log.Fatal(err)
}
err = obf.Obfuscate()
if err != nil {
log.Fatal(err)
}
}