diff --git a/.gitattributes b/.gitattributes index 4754b74..c63c54e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1 @@ -utils/resourcepack-ace.go filter=git-crypt diff=git-crypt \ No newline at end of file +subcommands/resourcepack-d/resourcepack-d.go filter=git-crypt diff=git-crypt \ No newline at end of file diff --git a/build.py b/build.py index a09229d..fc70b05 100644 --- a/build.py +++ b/build.py @@ -12,8 +12,8 @@ VER = VER_RE.match(TAG).group(1) CI = not not os.getenv("GITLAB_CI") -with open("./utils/resourcepack-ace.go", "rb") as f: - PACK_SUPPORT = f.read(7) == b"package" +with open("./subcommands/resourcepack-d/resourcepack-d.go", "rb") as f: + PACK_SUPPORT = f.read(100).count(b"package ") > 0 print(f"Pack Support: {PACK_SUPPORT}") @@ -21,7 +21,7 @@ LDFLAGS = f"-s -w -X github.com/bedrock-tool/bedrocktool/utils.Version={TAG}" PLATFORMS = [ ("windows", ["386", "amd64"], ".exe"), - ("linux", ["386", "amd64", "arm", "arm64"], ""), + ("linux", ["386", "amd64", "arm64"], ""), #("darwin", ["amd64", "arm64"], ""), ("android", ["arm64"], ".apk") ] @@ -60,21 +60,19 @@ for (platform_name, archs, ext) in PLATFORMS: SUB1 = '-gui' if GUI else '' name = f"{NAME}{SUB1}" + tags = [] env = ["GOVCS=*:off"] - GOFLAGS = [] if not PACK_SUPPORT: - GOFLAGS.append("-overlay=overlay.json") + tags.append("nopacks") if GUI: - if len(GOFLAGS): - env.append(f"GOFLAGS={' '.join(GOFLAGS)}") args = [ "fyne-cross", platform_name, "-app-version", VER, "-arch", ",".join(archs), "-ldflags", LDFLAGS + f" -X github.com/bedrock-tool/bedrocktool/utils.CmdName=bedrocktool-gui", "-name", name, - "-tags", "gui", + "-tags", ",".join(["gui"] + tags), "-debug" ] for e in env: @@ -96,10 +94,10 @@ for (platform_name, archs, ext) in PLATFORMS: "go", "build", "-ldflags", LDFLAGS, "-trimpath", + "-tags", ",".join(tags), "-v", "-o", out_path, ] - args.extend(GOFLAGS) args.append("./cmd/bedrocktool") print(args) out = subprocess.run(args) diff --git a/cmd/bedrocktool/main.go b/cmd/bedrocktool/main.go index e064495..760b3d8 100644 --- a/cmd/bedrocktool/main.go +++ b/cmd/bedrocktool/main.go @@ -232,14 +232,6 @@ func (c *CreateCustomDataCMD) Execute(_ context.Context, f *flag.FlagSet, _ ...i return 0 } -func (c *TransCMD) MainWindow() error { - return nil -} - -func (c *CreateCustomDataCMD) MainWindow() error { - return nil -} - func init() { utils.RegisterCommand(&TransCMD{}) utils.RegisterCommand(&CreateCustomDataCMD{}) diff --git a/overlay.json b/overlay.json deleted file mode 100644 index c139207..0000000 --- a/overlay.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "Replace": { - "utils/resourcepack-ace.go": "utils/dummy" - } -} \ No newline at end of file diff --git a/subcommands/chat_log.go b/subcommands/chat_log.go index 65a8e4f..1a284e6 100644 --- a/subcommands/chat_log.go +++ b/subcommands/chat_log.go @@ -7,8 +7,6 @@ import ( "os" "time" - "fyne.io/fyne/v2/data/binding" - "fyne.io/fyne/v2/widget" "github.com/bedrock-tool/bedrocktool/locale" "github.com/bedrock-tool/bedrocktool/utils" @@ -30,19 +28,6 @@ func (c *ChatLogCMD) SetFlags(f *flag.FlagSet) { f.BoolVar(&c.Verbose, "v", false, "verbose") } -func (c *ChatLogCMD) SettingsUI() *widget.Form { - return widget.NewForm( - widget.NewFormItem( - "serverAddress", widget.NewEntryWithData(binding.BindString(&c.ServerAddress)), - ), widget.NewFormItem( - "", widget.NewCheckWithData("verbose", binding.BindBool(&c.Verbose)), - ), - ) -} -func (c *ChatLogCMD) MainWindow() error { - return nil -} - func (c *ChatLogCMD) Usage() string { return c.Name() + ": " + c.Synopsis() + "\n" + locale.Loc("server_address_help", nil) } diff --git a/subcommands/resourcepack-d.go b/subcommands/resourcepack-d.go new file mode 100644 index 0000000..8b3f00d --- /dev/null +++ b/subcommands/resourcepack-d.go @@ -0,0 +1,49 @@ +//go:build !nopacks + +package subcommands + +import ( + "context" + "flag" + + "github.com/bedrock-tool/bedrocktool/locale" + resourcepackd "github.com/bedrock-tool/bedrocktool/subcommands/resourcepack-d" + "github.com/bedrock-tool/bedrocktool/utils" + "github.com/google/subcommands" + "github.com/sirupsen/logrus" +) + +// decrypt using cfb with segmentsize = 1 + +type ResourcePackCMD struct { + ServerAddress string + SaveEncrypted bool + OnlyKeys bool +} + +func (*ResourcePackCMD) Name() string { return "packs" } +func (*ResourcePackCMD) Synopsis() string { return locale.Loc("pack_synopsis", nil) } + +func (c *ResourcePackCMD) SetFlags(f *flag.FlagSet) { + f.StringVar(&c.ServerAddress, "address", "", locale.Loc("remote_address", nil)) + f.BoolVar(&c.SaveEncrypted, "save-encrypted", false, locale.Loc("save_encrypted", nil)) + f.BoolVar(&c.OnlyKeys, "only-keys", false, locale.Loc("only_keys", nil)) +} + +func (c *ResourcePackCMD) Usage() string { + return c.Name() + ": " + c.Synopsis() + "\n" + locale.Loc("server_address_help", nil) +} + +func (c *ResourcePackCMD) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus { + err := resourcepackd.Execute_cmd(ctx, c.ServerAddress, c.OnlyKeys, c.SaveEncrypted) + if err != nil { + logrus.Error(err) + return 1 + } + return 0 +} + +func init() { + utils.RegisterCommand(&ResourcePackCMD{}) + +} diff --git a/subcommands/resourcepack-d/resourcepack-d.go b/subcommands/resourcepack-d/resourcepack-d.go new file mode 100644 index 0000000..674462c Binary files /dev/null and b/subcommands/resourcepack-d/resourcepack-d.go differ diff --git a/subcommands/resourcepack-stub.go b/subcommands/resourcepack-stub.go new file mode 100644 index 0000000..893b6a8 --- /dev/null +++ b/subcommands/resourcepack-stub.go @@ -0,0 +1,36 @@ +//go:build nopacks + +package subcommands + +import ( + "context" + "flag" + + "github.com/bedrock-tool/bedrocktool/utils" + "github.com/google/subcommands" + "github.com/sirupsen/logrus" +) + +type ResourcePackCMD struct { + ServerAddress string + SaveEncrypted bool + OnlyKeys bool +} + +func (*ResourcePackCMD) Name() string { return "packs" } +func (*ResourcePackCMD) Synopsis() string { return "NOT COMPILED" } + +func (c *ResourcePackCMD) SetFlags(f *flag.FlagSet) {} + +func (c *ResourcePackCMD) Usage() string { + return c.Name() + ": " + c.Synopsis() +} + +func (c *ResourcePackCMD) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus { + logrus.Error("not compiled") + return 1 +} + +func init() { + utils.RegisterCommand(&ResourcePackCMD{}) +} diff --git a/ui/gui/gui.go b/ui/gui/gui.go index 1937569..6dc3ad2 100644 --- a/ui/gui/gui.go +++ b/ui/gui/gui.go @@ -1,4 +1,4 @@ -//go:build gui || android +//go:build gui || android || true package gui @@ -16,7 +16,7 @@ import ( ) var settings = map[string]func(utils.Command) *widget.Form{ - "world": func(cc utils.Command) *widget.Form { + "worlds": func(cc utils.Command) *widget.Form { c := cc.(*world.WorldCMD) return widget.NewForm( widget.NewFormItem( @@ -71,6 +71,18 @@ var settings = map[string]func(utils.Command) *widget.Form{ ), ) }, + "packs": func(cc utils.Command) *widget.Form { + c := cc.(*subcommands.ResourcePackCMD) + return widget.NewForm( + widget.NewFormItem( + "serverAddress", widget.NewEntryWithData(binding.BindString(&c.ServerAddress)), + ), widget.NewFormItem( + "", widget.NewCheckWithData("saveEncrypted", binding.BindBool(&c.SaveEncrypted)), + ), widget.NewFormItem( + "", widget.NewCheckWithData("only-keys", binding.BindBool(&c.OnlyKeys)), + ), + ) + }, } type GUI struct { diff --git a/utils/realms.go b/utils/realms.go index 7deb883..6021899 100644 --- a/utils/realms.go +++ b/utils/realms.go @@ -6,7 +6,6 @@ import ( "fmt" "strings" - "fyne.io/fyne/v2/widget" "github.com/bedrock-tool/bedrocktool/locale" "github.com/google/subcommands" "github.com/sirupsen/logrus" @@ -40,14 +39,6 @@ func (*RealmListCMD) Synopsis() string { return locale.Loc("list_realms_synopsis func (c *RealmListCMD) SetFlags(f *flag.FlagSet) {} -func (c *RealmListCMD) SettingsUI() *widget.Form { - return nil -} - -func (c *RealmListCMD) MainWindow() error { - return nil -} - func (c *RealmListCMD) Usage() string { return c.Name() + ": " + c.Synopsis() + "\n" } diff --git a/utils/resourcepack-ace.go b/utils/resourcepack-ace.go deleted file mode 100644 index 9960ac9..0000000 Binary files a/utils/resourcepack-ace.go and /dev/null differ diff --git a/utils/utils.go b/utils/utils.go index 0574d97..e32aac1 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -4,6 +4,7 @@ package utils import ( "bytes" "context" + "crypto/aes" "crypto/sha256" "encoding/json" "errors" @@ -177,3 +178,20 @@ func WriteManifest(manifest *resource.Manifest, fpath string) error { } return nil } + +func CfbDecrypt(data []byte, key []byte) ([]byte, error) { + cipher, err := aes.NewCipher([]byte(key)) + if err != nil { + return nil, err + } + + shiftRegister := append(key[:16], data...) + iv := make([]byte, 16) + off := 0 + for ; off < len(data); off += 1 { + cipher.Encrypt(iv, shiftRegister) + data[off] ^= iv[0] + shiftRegister = shiftRegister[1:] + } + return data, nil +}