-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathutils.go
61 lines (51 loc) · 1.38 KB
/
utils.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
package main
import (
"fmt"
"math/rand"
"time"
)
func check(e error) {
// Reading files requires checking most calls for errors.
// This helper will streamline our error checks below.
if e != nil {
panic(e)
}
}
func userInput(stubCfg *stubConfig) (string, string) {
var srcFilePath string
fmt.Print("[?] Path of file to be encrypted: ")
fmt.Scanln(&srcFilePath)
var dstFilePath string
fmt.Print("[?] Path of output (encrypted) file: ")
fmt.Scanln(&dstFilePath)
fmt.Print("[?] Name of the target process: ")
fmt.Scanln(&stubCfg.ProcName)
fmt.Print("[?] Encryption key (32 bits - random if empty): ")
fmt.Scanln(&stubCfg.EncryptionIV)
fmt.Print("[?] Encryption IV (16 bits - random if empty): ")
fmt.Scanln(&stubCfg.EncryptionIV)
if stubCfg.EncryptionKey == "" {
stubCfg.EncryptionKey = randKey(modeKey)
stubCfg.EncryptionIV = randKey(modeIV)
}
fmt.Println()
fmt.Printf("[!] Random encryption key (used in stub): %s\n", stubCfg.EncryptionKey)
fmt.Printf("[!] Random encryption IV (used in stub): %s\n", stubCfg.EncryptionIV)
return srcFilePath, dstFilePath
}
func randKey(mode int) string {
var keySize int
if mode == modeIV {
keySize = 16
} else if mode == modeKey {
keySize = 32
}
key := make([]byte, keySize)
for i := range key {
key[i] = allowedChars[rand.Intn(len(allowedChars))]
}
return string(key)
}
func init() {
rand.Seed(time.Now().UTC().UnixNano())
}