@@ -48,8 +48,21 @@ func extractPayloadBin(filename string) string {
4848func main () {
4949 runtime .GOMAXPROCS (runtime .NumCPU ())
5050
51- list := flag .Bool ("l" , false , "Show list of partitions in payload.bin" )
52- partitions := flag .String ("p" , "" , "Dump only selected partitions" )
51+ var (
52+ list bool
53+ partitions string
54+ outputDirectory string
55+ concurrency int
56+ )
57+
58+ flag .BoolVar (& list , "list" , false , "Show list of partitions in payload.bin" )
59+ flag .BoolVar (& list , "l" , false , "Show list of partitions in payload.bin (shorthand)" )
60+ flag .StringVar (& partitions , "partitions" , "" , "Dump only selected partitions (comma-separated)" )
61+ flag .StringVar (& partitions , "p" , "" , "Dump only selected partitions (comma-separated) (shorthand)" )
62+ flag .StringVar (& outputDirectory , "output" , "" , "Set output directory" )
63+ flag .StringVar (& outputDirectory , "o" , "" , "Set output directory (shorthand)" )
64+ flag .IntVar (& concurrency , "concurrency" , 4 , "Number of multiple workers to extract" )
65+ flag .IntVar (& concurrency , "c" , 4 , "Number of multiple workers to extract (shorthand)" )
5366 flag .Parse ()
5467
5568 if flag .NArg () == 0 {
@@ -79,17 +92,27 @@ func main() {
7992 }
8093 payload .Init ()
8194
82- if * list {
95+ if list {
8396 return
8497 }
8598
8699 now := time .Now ()
87- targetDirectory := fmt .Sprintf ("extracted_%d%02d%02d_%02d%02d%02d" , now .Year (), now .Month (), now .Day (), now .Hour (), now .Minute (), now .Second ())
88- if err := os .Mkdir (targetDirectory , 0755 ); err != nil {
89- log .Fatal ("Failed to create target directory" )
100+
101+ var targetDirectory = outputDirectory
102+ if targetDirectory == "" {
103+ targetDirectory = fmt .Sprintf ("extracted_%d%02d%02d_%02d%02d%02d" , now .Year (), now .Month (), now .Day (), now .Hour (), now .Minute (), now .Second ())
104+ }
105+ if _ , err := os .Stat (targetDirectory ); os .IsNotExist (err ) {
106+ if err := os .Mkdir (targetDirectory , 0755 ); err != nil {
107+ log .Fatal ("Failed to create target directory" )
108+ }
90109 }
91- if * partitions != "" {
92- if err := payload .ExtractSelected (targetDirectory , strings .Split (* partitions , "," )); err != nil {
110+
111+ payload .SetConcurrency (concurrency )
112+ fmt .Printf ("Number of workers: %d\n " , payload .GetConcurrency ())
113+
114+ if partitions != "" {
115+ if err := payload .ExtractSelected (targetDirectory , strings .Split (partitions , "," )); err != nil {
93116 log .Fatal (err )
94117 }
95118 } else {
0 commit comments