HellPot/internal/extra/banner.go

94 lines
2.7 KiB
Go
Raw Normal View History

2021-09-15 19:17:32 +00:00
package extra
import (
crip "crypto/rand"
"encoding/binary"
"fmt"
"os"
"runtime"
2021-09-15 19:17:32 +00:00
"strings"
2022-04-06 11:41:40 +00:00
"time"
"git.tcp.direct/kayos/common/squish"
2021-09-16 07:51:16 +00:00
"github.com/yunginnanet/HellPot/internal/config"
2021-09-15 19:17:32 +00:00
)
2022-04-06 11:41:40 +00:00
const hellpot = "H4sIAAAAAAACA8VXvW7bQAze9QpZOGQUZNXntBD6Ahm7Gx1cx0jdRnKRKAUCdPDgQavOgB/QTxLZ1P3oRJ5Obo0CtnE5feSR30fylOhmfjv9PEtzwIXIj4dds/xw2jsequNB2gizXd3Mxad2O81PX7AAe+UNGneuR8aUOuTsqQUDXAMv1cJE5Tfbn6GaKz45kpid+lQc3zoNY5zmEUEt+jCGNZUjeYr0StZYmbwtwNavuCaUFWA8MjxVIImjNas6TPQT9Tnq4MnYJF0zkhVU4rLvqflscU/ox0Lg45qKTjoSmiLQPA+ZuTT7BbrckpfWKMkUquTErIPEYbPoKjamy6SjR0feGssPUMYTCDWEnrR8c0m7hJ2B4jekK2KUsBfa7bpTD0ftnmKPE9nN2IzcLc99vxhIUbszlwqrJoklpQWlI6AeQh9nDHXj2ldOvyat/vZdDxVfzZdbSuspRUe/+IKZtxq2GWlbZzS6jnrnDEXGCkXUGnahuTgAA+DY9HU8FUoYH3ji/q84HetDWmT/Y3ml6oX21/eCNzB46+6UuVTSQHXgGmzUTJT/zeNQ3zCvysEBuH3hER9CbhNa6FoLHSBfT2gmK/rFKCj/K1nTfcBduKHVwgjo+Y+HilXBEAqhKg1X6lQzMaIF6ZK6ipVILR0Awh16SWy9KsxvZXWbL34oGpNmMcPNdYFmiE40+qV9cg4Logjm2uXjukzK5a/kYf28WpaTn4u3zcvkfvX09GVTnuFfEYzBNujvr9+S5SafvL0Wj+uiWBSrsov/I6axmMXiLhYf40zE2TTOZnF2F2fNn2n0DpcvBxhQEAAA"
2021-10-17 17:09:28 +00:00
2021-09-15 19:17:32 +00:00
func rc(s []string) string {
return strings.TrimSpace(s[ru()%uint32(len(s))])
}
2021-10-17 17:09:28 +00:00
2021-09-15 19:17:32 +00:00
func process(in string) (s string) {
2021-09-16 07:51:16 +00:00
var v = strings.Split(config.Version, "")
maj := v[0]
min := v[2]
2022-07-26 05:46:04 +00:00
smin := v[4]
defl8, _ := squish.UnpackStr(in)
sp := strings.Split(defl8, "|")
2021-09-15 19:17:32 +00:00
s = sp[0]
if smin == "" || len(config.Version) == 7 {
s = strings.ReplaceAll(s, "$1;40m.", "$1;40m")
if len(config.Version) == 7 {
s = strings.ReplaceAll(s, "$3;40m.", "$3;40m")
}
}
2021-09-15 19:17:32 +00:00
c := strings.Split(sp[1], ",")
cproc := func(in, num string) (inr string) {
inr = in
tor := fmt.Sprintf("$%s", num)
for n := strings.Count(inr, tor); n > 0; n-- {
inr = strings.Replace(inr, tor, rc(c), 1)
}
return
}
for n := 1; n < 5; n++ {
s = cproc(s, fmt.Sprintf("%d", n))
}
if len(config.Version) == 7 {
maj = "[" + config.Version + "]"
min = ""
smin = ""
}
2021-11-14 22:06:15 +00:00
s = strings.ReplaceAll(s, "$maj", maj)
s = strings.ReplaceAll(s, "$min", min)
2022-04-06 11:41:40 +00:00
s = strings.ReplaceAll(s, "$smin", smin)
2021-09-15 19:17:32 +00:00
return
}
2021-10-17 17:09:28 +00:00
2021-09-15 19:17:32 +00:00
func ru() uint32 {
b := make([]byte, 8192)
2021-10-17 17:09:28 +00:00
if _, err := crip.Read(b); err != nil {
bannerFail(err)
}
2021-09-15 19:17:32 +00:00
return binary.LittleEndian.Uint32(b)
}
// printBanner prints our entropic banner
func printBanner() {
2022-04-06 11:41:40 +00:00
time.Sleep(5 * time.Millisecond)
2021-09-15 19:17:32 +00:00
println("\n" + process(hellpot) + "\n\n")
time.Sleep(5 * time.Millisecond)
}
func bannerFail(errs ...error) {
println("failed printing banner, consider using --nocolor")
for _, err := range errs {
if err != nil {
println(err.Error())
}
}
os.Exit(1)
}
// Banner prints out our banner (using spooky magic)
func Banner() {
//goland:noinspection GoBoolExpressions
if runtime.GOOS == "windows" || config.NoColor {
println(config.Title + " " + config.Version)
return
}
printBanner()
2021-09-15 19:17:32 +00:00
}