@@ -40,7 +40,7 @@ func loopFilesWorker(cfg config) error {
40
40
for _ , file := range files {
41
41
if ! file .IsDir () {
42
42
fullpath := filepath .Join (path , file .Name ())
43
- parse (fullpath , cfg )
43
+ parsePE (fullpath , cfg )
44
44
}
45
45
}
46
46
wg .Done ()
@@ -53,26 +53,25 @@ func LoopDirsFiles(path string) error {
53
53
if err != nil {
54
54
return err
55
55
}
56
- //Add this path as a job to the workers
57
- //You must call it in a go routine, since if every worker is busy, then you have to wait for the channel to be free.
56
+
58
57
go func () {
59
58
wg .Add (1 )
60
59
jobs <- path
61
60
}()
62
61
for _ , file := range files {
63
62
if file .IsDir () {
64
- //Recursively go further in the tree
65
63
LoopDirsFiles (filepath .Join (path , file .Name ()))
66
64
}
67
65
}
68
66
return nil
69
67
}
70
68
71
- func prettyPrint (buff [] byte ) string {
69
+ func prettyPrint (iface interface {} ) string {
72
70
var prettyJSON bytes.Buffer
73
- error := json .Indent (& prettyJSON , buff , "" , "\t " )
74
- if error != nil {
75
- log .Info ("JSON parse error: " , error )
71
+ buff , _ := json .Marshal (iface )
72
+ err := json .Indent (& prettyJSON , buff , "" , "\t " )
73
+ if err != nil {
74
+ log .Errorf ("JSON parse error: %v" , err )
76
75
return string (buff )
77
76
}
78
77
@@ -245,30 +244,12 @@ func parsePE(filename string, cfg config) {
245
244
}
246
245
247
246
// Dump all results to disk in JSON format.
248
- // b, _ := json.Marshal(pe)
249
247
// f, err := os.Create("out.json")
250
248
// if err != nil {
251
249
// return
252
250
// }
253
251
// defer f.Close()
254
- // f.WriteString(prettyPrint(b))
255
-
256
- // Calculate the PE authentihash.
257
- pe .Authentihash ()
258
-
259
- // Calculate the PE checksum.
260
- pe .Checksum ()
261
-
262
- // Get file type.
263
- if pe .IsEXE () {
264
- log .Debug ("File is Exe" )
265
- }
266
- if pe .IsDLL () {
267
- log .Debug ("File is DLL" )
268
- }
269
- if pe .IsDriver () {
270
- log .Debug ("File is Driver" )
271
- }
252
+ // f.WriteString(prettyPrint(pe))
272
253
273
254
if cfg .wantDOSHeader {
274
255
DOSHeader := pe .DOSHeader
@@ -546,11 +527,12 @@ func parsePE(filename string, cfg config) {
546
527
fmt .Printf ("\n RESOURCES\n **********\n " )
547
528
printRsrcDir (pe .Resources )
548
529
549
- r , err := pe .ParseVersionResources ()
550
- if err == nil {
551
- fmt .Print (r )
530
+ versionInfo , err := pe .ParseVersionResources ()
531
+ if err != nil {
532
+ log .Errorf ("failed to parse version resources: %v" , err )
533
+ } else {
534
+ fmt .Printf ("\n Version Info: %v" , prettyPrint (versionInfo ))
552
535
}
553
- fmt .Print ()
554
536
}
555
537
556
538
if cfg .wantException && pe .FileInfo .HasException {
@@ -601,6 +583,9 @@ func parsePE(filename string, cfg config) {
601
583
fmt .Fprintf (w , "Signature Algorithm:\t %s\n " , cert .Info .SignatureAlgorithm .String ())
602
584
fmt .Fprintf (w , "PublicKey Algorithm:\t %s\n " , cert .Info .PublicKeyAlgorithm .String ())
603
585
w .Flush ()
586
+
587
+ // Calculate the PE authentihash.
588
+ pe .Authentihash ()
604
589
}
605
590
606
591
if cfg .wantReloc && pe .FileInfo .HasReloc {
@@ -698,7 +683,6 @@ func parsePE(filename string, cfg config) {
698
683
fpoData .Reserved , fpoData .FrameType , fpoData .FrameType .String ())
699
684
}
700
685
}
701
-
702
686
}
703
687
}
704
688
@@ -881,5 +865,19 @@ func parsePE(filename string, cfg config) {
881
865
}
882
866
}
883
867
868
+ // Get file type.
869
+ if pe .IsEXE () {
870
+ log .Debug ("File is Exe" )
871
+ }
872
+ if pe .IsDLL () {
873
+ log .Debug ("File is DLL" )
874
+ }
875
+ if pe .IsDriver () {
876
+ log .Debug ("File is Driver" )
877
+ }
878
+
879
+ // Calculate the PE checksum.
880
+ pe .Checksum ()
881
+
884
882
fmt .Print ("\n " )
885
883
}
0 commit comments