This commit is contained in:
Misaki
2026-06-08 18:02:54 +08:00
commit e565b80bc2
19 changed files with 1152 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
package utils
import (
"crypto/aes"
)
func AesEcbDecrypt(key []byte, src []byte) ([]byte, error) {
block, err := aes.NewCipher(key)
if err != nil {
return nil, err
}
dst := make([]byte, 0, len(src))
tmp := make([]byte, aes.BlockSize)
for i := 0; i < len(src); i += aes.BlockSize {
block.Decrypt(tmp, src[i:i+aes.BlockSize])
if i == len(src)-aes.BlockSize {
pad := int(tmp[len(tmp)-1])
if pad > aes.BlockSize {
pad = 0
}
dst = append(dst, tmp[:aes.BlockSize-pad]...)
} else {
dst = append(dst, tmp...)
}
}
return dst, nil
}
+48
View File
@@ -0,0 +1,48 @@
package utils
import (
"os"
"path/filepath"
"strings"
)
func ReplaceExtension(filepathStr, newExt string) string {
ext := filepath.Ext(filepathStr)
return strings.TrimSuffix(filepathStr, ext) + newExt
}
func PathExists(path string) bool {
_, err := os.Stat(path)
if err == nil {
return true
}
if os.IsNotExist(err) {
return false
}
return false
}
func IsDir(path string) bool {
s, err := os.Stat(path)
if err != nil {
return false
}
return s.IsDir()
}
func GetRelativePath(from, to string) string {
rel, err := filepath.Rel(from, to)
if err != nil {
return ""
}
return rel
}
func IsRegularFile(path string) bool {
s, err := os.Stat(path)
if err != nil {
return false
}
return s.Mode().IsRegular()
}
+22
View File
@@ -0,0 +1,22 @@
package utils
import (
"fmt"
"github.com/TwiN/go-color"
)
func DonePrintfln(format string, a ...interface{}) {
fmt.Printf(color.InBold(color.InGreen("[Done] "))+format+"\n", a...)
}
func InfoPrintfln(format string, a ...interface{}) {
fmt.Printf(color.InBold(color.InBlue("[Info] "))+format+"\n", a...)
}
func WarningPrintfln(format string, a ...interface{}) {
fmt.Printf(color.InBold(color.InYellow("[Warning] "))+format+"\n", a...)
}
func ErrorPrintfln(format string, a ...interface{}) {
fmt.Printf(color.InBold(color.InRed("[Error] "))+format+"\n", a...)
}