Skip to content

Commit

Permalink
feat(cli): support both long and shorthand flags, set output director…
Browse files Browse the repository at this point in the history
…y manually

Closes: #18
  • Loading branch information
ssut committed Jun 23, 2021
1 parent d8d68fa commit 412e5a9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:x
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.1 h1:ZFgWrT+bLgsYPirOnRfKLYJLvssAegOj/hgyMFdJZe0=
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
Expand All @@ -36,7 +35,6 @@ github.com/spencercw/go-xz v0.0.0-20181128201811-c82a2123b492 h1:8J9q7E8tGpVB84c
github.com/spencercw/go-xz v0.0.0-20181128201811-c82a2123b492/go.mod h1:EvRrgz1GcjNV5yfN+ISxA4sxn255MimeGQ/ROJnQPtQ=
github.com/vbauerster/mpb/v5 v5.3.0 h1:vgrEJjUzHaSZKDRRxul5Oh4C72Yy/5VEMb0em+9M0mQ=
github.com/vbauerster/mpb/v5 v5.3.0/go.mod h1:4yTkvAb8Cm4eylAp6t0JRq6pXDkFJ4krUlDqWYkakAs=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down
39 changes: 31 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,21 @@ func extractPayloadBin(filename string) string {
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())

list := flag.Bool("l", false, "Show list of partitions in payload.bin")
partitions := flag.String("p", "", "Dump only selected partitions")
var (
list bool
partitions string
outputDirectory string
concurrency int
)

flag.BoolVar(&list, "list", false, "Show list of partitions in payload.bin")
flag.BoolVar(&list, "l", false, "Show list of partitions in payload.bin (shorthand)")
flag.StringVar(&partitions, "partitions", "", "Dump only selected partitions (comma-separated)")
flag.StringVar(&partitions, "p", "", "Dump only selected partitions (comma-separated) (shorthand)")
flag.StringVar(&outputDirectory, "output", "", "Set output directory")
flag.StringVar(&outputDirectory, "o", "", "Set output directory (shorthand)")
flag.IntVar(&concurrency, "concurrency", 4, "Number of multiple workers to extract")
flag.IntVar(&concurrency, "c", 4, "Number of multiple workers to extract (shorthand)")
flag.Parse()

if flag.NArg() == 0 {
Expand Down Expand Up @@ -79,17 +92,27 @@ func main() {
}
payload.Init()

if *list {
if list {
return
}

now := time.Now()
targetDirectory := fmt.Sprintf("extracted_%d%02d%02d_%02d%02d%02d", now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second())
if err := os.Mkdir(targetDirectory, 0755); err != nil {
log.Fatal("Failed to create target directory")

var targetDirectory = outputDirectory
if targetDirectory == "" {
targetDirectory = fmt.Sprintf("extracted_%d%02d%02d_%02d%02d%02d", now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second())
}
if _, err := os.Stat(targetDirectory); os.IsNotExist(err) {
if err := os.Mkdir(targetDirectory, 0755); err != nil {
log.Fatal("Failed to create target directory")
}
}
if *partitions != "" {
if err := payload.ExtractSelected(targetDirectory, strings.Split(*partitions, ",")); err != nil {

payload.SetConcurrency(concurrency)
fmt.Printf("Number of workers: %d\n", payload.GetConcurrency())

if partitions != "" {
if err := payload.ExtractSelected(targetDirectory, strings.Split(partitions, ",")); err != nil {
log.Fatal(err)
}
} else {
Expand Down

0 comments on commit 412e5a9

Please sign in to comment.