|
|
|
|
package vic
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"b612.me/starcrypto"
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"regexp"
|
|
|
|
|
|
|
|
|
|
"b612.me/starlog"
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var Cmd = &cobra.Command{
|
|
|
|
|
Use: "vicque",
|
|
|
|
|
Short: "嵐を乗り越えて",
|
|
|
|
|
Long: "あの子の未来を照らし出せ",
|
|
|
|
|
Run: func(this *cobra.Command, args []string) {
|
|
|
|
|
var err error
|
|
|
|
|
ok, _ := this.Flags().GetBool("file")
|
|
|
|
|
de, _ := this.Flags().GetBool("decode")
|
|
|
|
|
pwd, _ := this.Flags().GetString("key")
|
|
|
|
|
rep, _ := this.Flags().GetBool("replace")
|
|
|
|
|
ext, _ := this.Flags().GetBool("extension")
|
|
|
|
|
shell := func(pect float64) {
|
|
|
|
|
if pect == 100 {
|
|
|
|
|
fmt.Println("已处理:100.000000%")
|
|
|
|
|
} else {
|
|
|
|
|
fmt.Printf("已处理:%f%%\r", pect)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ok {
|
|
|
|
|
path, _ := this.Flags().GetString("path")
|
|
|
|
|
if !de {
|
|
|
|
|
err = starcrypto.VicqueEncodeV1File(args[0], path, pwd, shell)
|
|
|
|
|
if err == nil {
|
|
|
|
|
if rep {
|
|
|
|
|
os.Remove(args[0])
|
|
|
|
|
os.Rename(path, args[0])
|
|
|
|
|
path = args[0]
|
|
|
|
|
}
|
|
|
|
|
if ext {
|
|
|
|
|
os.Rename(path, path+".victorique")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
err = starcrypto.VicqueDecodeV1File(args[0], path, pwd, shell)
|
|
|
|
|
if err == nil {
|
|
|
|
|
if rep {
|
|
|
|
|
os.Remove(args[0])
|
|
|
|
|
os.Rename(path, args[0])
|
|
|
|
|
path = args[0]
|
|
|
|
|
}
|
|
|
|
|
if ext {
|
|
|
|
|
reg := regexp.MustCompile(`(.*?)\.victorique$`)
|
|
|
|
|
if reg.MatchString(path) {
|
|
|
|
|
paths := reg.FindStringSubmatch(path)
|
|
|
|
|
os.Rename(path, paths[1])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if !de {
|
|
|
|
|
data := starcrypto.VicqueEncodeV1([]byte(args[0]), pwd)
|
|
|
|
|
fmt.Println(data)
|
|
|
|
|
fmt.Println(starcrypto.Base64Encode(data))
|
|
|
|
|
} else {
|
|
|
|
|
var data []byte
|
|
|
|
|
src, _ := starcrypto.Base64Decode(args[0])
|
|
|
|
|
data = starcrypto.VicqueDecodeV1(src, pwd)
|
|
|
|
|
fmt.Println(string(data))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if err != nil {
|
|
|
|
|
starlog.Errorln(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
Cmd.Flags().BoolP("file", "f", false, "VICQUE处理文件")
|
|
|
|
|
Cmd.Flags().StringP("path", "p", "./v64.encode", "指定处理地址,默认为./v64.encode")
|
|
|
|
|
Cmd.Flags().BoolP("decode", "d", false, "VICQUE解码")
|
|
|
|
|
Cmd.Flags().StringP("key", "k", "", "密钥")
|
|
|
|
|
Cmd.Flags().BoolP("replace", "r", false, "覆盖原文件")
|
|
|
|
|
Cmd.Flags().BoolP("extension", "e", false, "添加/取消.victorique后缀")
|
|
|
|
|
Cmd.MarkFlagRequired("key")
|
|
|
|
|
}
|