-
Notifications
You must be signed in to change notification settings - Fork 0
/
gopkgr.go
123 lines (118 loc) · 3.32 KB
/
gopkgr.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package main
import (
"fmt"
"io/ioutil"
"os"
"os/signal"
"path/filepath"
"regexp"
"strings"
"syscall"
"time"
. "github.com/cipheras/gohelper"
)
func main() {
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
fmt.Println("\nExiting...")
os.Exit(0)
}()
Flog()
Cwindows()
pkr()
fmt.Printf("\nPress any key to exit...")
fmt.Scanf("enter")
}
func pkr() {
f, err := os.OpenFile("pkg.go", os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0644)
Try(err, true, "Creating \"pkg.go\" file")
fmt.Fprintln(f, p)
var bytstr []string
fmt.Fprintf(f, "pth := []string{") //open pth
ignore := map[string]bool{
"log.txt": true,
"pkg.go": true,
"go.mod": true,
"go.sum": true,
"LICENSE": true,
"README.md": true,
"CHANGELOG": true,
strings.ReplaceAll(os.Args[0], "./", ""): true,
}
Cprint(N, "Reading dir structure")
time.Sleep(1 * time.Second)
err = filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
exe, _ := regexp.MatchString("^(.*\\.exe)$", info.Name())
if info.Mode().IsRegular() && !ignore[info.Name()] && !exe && !strings.Contains(path, ".git") {
filebyt, err := ioutil.ReadFile(path)
Try(err, false, "Reading file \""+path+"\"")
fmt.Println(path)
fmt.Fprintf(f, "\"%v\",", path)
replacer := strings.NewReplacer("[", "{", "]", "}", " ", ",")
bytstr = append(bytstr, replacer.Replace(fmt.Sprint(filebyt)))
}
return nil
})
Try(err, false)
fmt.Fprintln(f, "}") //close pth
fmt.Fprintf(f, "file := [][]byte{") //open byt
Cprint(N, "Starting packing")
time.Sleep(1 * time.Second)
// replacer := strings.NewReplacer("[", "", "]", "", " ", "")
for i, v := range bytstr {
// var ss []string
// for i, c := range v {
// if i%1000 == 0 && i > 0 && string(c) != "," && string(c) != "0" && string(c) != "{" && string(c) != "}" {
// ss = append(ss, "+ \n")
// }
// ss = append(ss, string(c))
// }
// fmt.Fprintf(f, "%v,", replacer.Replace(fmt.Sprint(ss)))
fmt.Fprintf(f, "%v,", v)
fmt.Printf("\033[100D \033[48;5;22m:Packing [%v/%v]\033[0m [%v%v]", i+1, len(bytstr), strings.Repeat("#", i+1), strings.Repeat(".", len(bytstr)-i-1))
}
fmt.Fprintln(f, "}") //close byt
fmt.Fprintln(f, "return pth, file") //return all paths
fmt.Fprintln(f, "}") //end main
fmt.Fprintln(f, u)
f.Close()
fmt.Printf("\n")
Cprint(N, "Packing complete")
}
var p string = `
package main
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
)
func pkg() ([]string, [][]byte) {
`
var u string = `
func unpkr(unpdir string) error{
pth, file := pkg()
for i, p := range pth {
fd := strings.SplitAfter(p, "/")
var fp string
for _, v := range fd[:len(fd)-1] {
fp = fp + v
}
err := os.MkdirAll(filepath.Join(unpdir, fp), os.ModePerm)
if err != nil {
return err
}
err = ioutil.WriteFile(filepath.Join(unpdir, p), file[i], os.ModePerm)
if err != nil {
return err
}
// defer os.RemoveAll(unpdir)
fmt.Printf("\033[1000D \033[48;5;22m:Unpacking [%v/%v]\033[0m [%v%v]", i+1, len(pth), strings.Repeat("#", i+1), strings.Repeat(".", len(pth)-i-1))
}
fmt.Printf("\n")
return nil
}
`