Skip to content

Commit 493a9e1

Browse files
committed
print version info
1 parent 76e3d72 commit 493a9e1

File tree

2 files changed

+40
-36
lines changed

2 files changed

+40
-36
lines changed

cmd/dump.go

+30-32
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func loopFilesWorker(cfg config) error {
4040
for _, file := range files {
4141
if !file.IsDir() {
4242
fullpath := filepath.Join(path, file.Name())
43-
parse(fullpath, cfg)
43+
parsePE(fullpath, cfg)
4444
}
4545
}
4646
wg.Done()
@@ -53,26 +53,25 @@ func LoopDirsFiles(path string) error {
5353
if err != nil {
5454
return err
5555
}
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+
5857
go func() {
5958
wg.Add(1)
6059
jobs <- path
6160
}()
6261
for _, file := range files {
6362
if file.IsDir() {
64-
//Recursively go further in the tree
6563
LoopDirsFiles(filepath.Join(path, file.Name()))
6664
}
6765
}
6866
return nil
6967
}
7068

71-
func prettyPrint(buff []byte) string {
69+
func prettyPrint(iface interface{}) string {
7270
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)
7675
return string(buff)
7776
}
7877

@@ -245,30 +244,12 @@ func parsePE(filename string, cfg config) {
245244
}
246245

247246
// Dump all results to disk in JSON format.
248-
// b, _ := json.Marshal(pe)
249247
// f, err := os.Create("out.json")
250248
// if err != nil {
251249
// return
252250
// }
253251
// 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))
272253

273254
if cfg.wantDOSHeader {
274255
DOSHeader := pe.DOSHeader
@@ -546,11 +527,12 @@ func parsePE(filename string, cfg config) {
546527
fmt.Printf("\nRESOURCES\n**********\n")
547528
printRsrcDir(pe.Resources)
548529

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("\nVersion Info: %v", prettyPrint(versionInfo))
552535
}
553-
fmt.Print()
554536
}
555537

556538
if cfg.wantException && pe.FileInfo.HasException {
@@ -601,6 +583,9 @@ func parsePE(filename string, cfg config) {
601583
fmt.Fprintf(w, "Signature Algorithm:\t %s\n", cert.Info.SignatureAlgorithm.String())
602584
fmt.Fprintf(w, "PublicKey Algorithm:\t %s\n", cert.Info.PublicKeyAlgorithm.String())
603585
w.Flush()
586+
587+
// Calculate the PE authentihash.
588+
pe.Authentihash()
604589
}
605590

606591
if cfg.wantReloc && pe.FileInfo.HasReloc {
@@ -698,7 +683,6 @@ func parsePE(filename string, cfg config) {
698683
fpoData.Reserved, fpoData.FrameType, fpoData.FrameType.String())
699684
}
700685
}
701-
702686
}
703687
}
704688

@@ -881,5 +865,19 @@ func parsePE(filename string, cfg config) {
881865
}
882866
}
883867

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+
884882
fmt.Print("\n")
885883
}

cmd/main.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,20 @@ func main() {
8989
wantCLR: *dumpCLR,
9090
}
9191

92-
//Start as many workers you want, now 10 workers
92+
// Start as many workers you want, now 10 workers
9393
numWorkers := runtime.GOMAXPROCS(runtime.NumCPU() - 1)
9494
for w := 1; w <= numWorkers; w++ {
9595
go loopFilesWorker(cfg)
9696
}
97-
//Start the recursion
98-
LoopDirsFiles(os.Args[2])
99-
wg.Wait()
97+
98+
if !isDirectory(os.Args[2]) {
99+
// Input path in a single file.
100+
parsePE(os.Args[2], cfg)
101+
} else {
102+
// Input path in a directory.
103+
LoopDirsFiles(os.Args[2])
104+
wg.Wait()
105+
}
100106

101107
case "version":
102108
verCmd.Parse(os.Args[2:])

0 commit comments

Comments
 (0)