Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for inputting a text file #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
BSD 3-Clause License

Copyright (c) 2019, Jérôme Renard
Copyright (c) 2022, Mohammad-Mohsen Aseman-Manzar
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ problem by obfuscating the string so it is no longer searchable with
You can install mumbojumbo by running:

go get github.com/jeromer/mumbojumbo/...
go install github.com/jeromer/mumbojumbo

## Usage

Expand Down Expand Up @@ -94,6 +95,10 @@ see "some secret"

Run `mumbojumbo --help` to get help

You can also use a text file as input:

mumbojumbo -sf=/path/to/file -p=foo | goimports > foo.go

## License

This project is licensed under the BSD 3-Clause License - see the [LICENSE](LICENSE) file for details
Expand Down
26 changes: 18 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ const (
)

var (
s = flag.String("s", "", "string to obfuscate")
p = flag.String("p", "", "pkg name for the generated code")
s = flag.String("s", "", "string to obfuscate")
sf = flag.String("sf", "", "string file to obfuscate")
p = flag.String("p", "", "pkg name for the generated code")
)

var (
tpl = `// CODE GENERATED BY mumbojumbo {{ .Version }} (https://github.com/jeromer/mumbojumbo) DO NOT EDIT !!!!
var tpl = `// CODE GENERATED BY mumbojumbo {{ .Version }} (https://github.com/jeromer/mumbojumbo) DO NOT EDIT !!!!

package {{ .Pkg }}

Expand All @@ -38,13 +38,24 @@ func Get() string {
{{ .Obfuscated }}
}
`
)

func main() {
flag.Parse()

var text string

if *s == "" {
quit("no string provided")
if *sf != "" {
b, err := os.ReadFile(*sf)
if err != nil {
quit(err.Error())
}
text = string(b)
} else {
quit("no string provided")
}
} else {
text = *s
}

if *p == "" {
Expand All @@ -56,7 +67,7 @@ func main() {
tplData{
Version: VERSION,
Pkg: *p,
Obfuscated: obfuscate(*s),
Obfuscated: obfuscate(text),
},
),
)
Expand All @@ -77,7 +88,6 @@ func generateGoCode(data tplData) string {

w := new(bytes.Buffer)
err := tmpl.Execute(w, data)

if err != nil {
panic(err)
}
Expand Down