package tools import ( "fmt" "os" "regexp" "b612.me/starainrt" "b612.me/starlog" "github.com/spf13/cobra" ) var viccmd = &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") if len(args) != 2 || args[1] != "sakura" { starlog.StdPrintln(0, starlog.RED, "ヴィクトリカだけが使えるよ") return } shell := func(pect float64) { if pect == 100 { fmt.Println("已处理:100.000000%") } else { fmt.Printf("已处理:%f%%\r", pect) } } cry := new(starainrt.StarCrypto) if ok { path, _ := this.Flags().GetString("path") if !de { err = cry.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 = cry.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 := cry.VicqueEncodeV1([]byte(args[0]), pwd) fmt.Println(data) fmt.Println(cry.Base64Encode(data)) } else { var data []byte src, _ := cry.Base64Decode(args[0]) data = cry.VicqueDecodeV1(src, pwd) fmt.Println(string(data)) } } if err != nil { starlog.StdPrintln(0, starlog.RED, err) return } }, } func init() { viccmd.Flags().BoolP("file", "f", false, "VICQUE处理文件") viccmd.Flags().StringP("path", "p", "./v64.encode", "指定处理地址,默认为./v64.encode") viccmd.Flags().BoolP("decode", "d", false, "VICQUE解码") viccmd.Flags().StringP("key", "k", "", "密钥") viccmd.Flags().BoolP("replace", "r", false, "覆盖原文件") viccmd.Flags().BoolP("extension", "e", false, "添加/取消.victorique后缀") viccmd.MarkFlagRequired("key") Maincmd.AddCommand(viccmd) }