Skip to content

Commit

Permalink
print version info
Browse files Browse the repository at this point in the history
  • Loading branch information
LordNoteworthy committed Feb 10, 2024
1 parent 76e3d72 commit 493a9e1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 36 deletions.
62 changes: 30 additions & 32 deletions cmd/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func loopFilesWorker(cfg config) error {
for _, file := range files {
if !file.IsDir() {
fullpath := filepath.Join(path, file.Name())
parse(fullpath, cfg)
parsePE(fullpath, cfg)
}
}
wg.Done()
Expand All @@ -53,26 +53,25 @@ func LoopDirsFiles(path string) error {
if err != nil {
return err
}
//Add this path as a job to the workers
//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.

go func() {
wg.Add(1)

Check failure on line 58 in cmd/dump.go

View workflow job for this annotation

GitHub Actions / Build & Test (1.19.x, windows-latest)

should call wg.Add(1) before starting the goroutine to avoid a race (SA2000)
jobs <- path
}()
for _, file := range files {
if file.IsDir() {
//Recursively go further in the tree
LoopDirsFiles(filepath.Join(path, file.Name()))
}
}
return nil
}

func prettyPrint(buff []byte) string {
func prettyPrint(iface interface{}) string {
var prettyJSON bytes.Buffer
error := json.Indent(&prettyJSON, buff, "", "\t")
if error != nil {
log.Info("JSON parse error: ", error)
buff, _ := json.Marshal(iface)
err := json.Indent(&prettyJSON, buff, "", "\t")
if err != nil {
log.Errorf("JSON parse error: %v", err)
return string(buff)
}

Expand Down Expand Up @@ -245,30 +244,12 @@ func parsePE(filename string, cfg config) {
}

// Dump all results to disk in JSON format.
// b, _ := json.Marshal(pe)
// f, err := os.Create("out.json")
// if err != nil {
// return
// }
// defer f.Close()
// f.WriteString(prettyPrint(b))

// Calculate the PE authentihash.
pe.Authentihash()

// Calculate the PE checksum.
pe.Checksum()

// Get file type.
if pe.IsEXE() {
log.Debug("File is Exe")
}
if pe.IsDLL() {
log.Debug("File is DLL")
}
if pe.IsDriver() {
log.Debug("File is Driver")
}
// f.WriteString(prettyPrint(pe))

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

r, err := pe.ParseVersionResources()
if err == nil {
fmt.Print(r)
versionInfo, err := pe.ParseVersionResources()
if err != nil {
log.Errorf("failed to parse version resources: %v", err)
} else {
fmt.Printf("\nVersion Info: %v", prettyPrint(versionInfo))
}
fmt.Print()
}

if cfg.wantException && pe.FileInfo.HasException {
Expand Down Expand Up @@ -601,6 +583,9 @@ func parsePE(filename string, cfg config) {
fmt.Fprintf(w, "Signature Algorithm:\t %s\n", cert.Info.SignatureAlgorithm.String())
fmt.Fprintf(w, "PublicKey Algorithm:\t %s\n", cert.Info.PublicKeyAlgorithm.String())
w.Flush()

// Calculate the PE authentihash.
pe.Authentihash()
}

if cfg.wantReloc && pe.FileInfo.HasReloc {
Expand Down Expand Up @@ -698,7 +683,6 @@ func parsePE(filename string, cfg config) {
fpoData.Reserved, fpoData.FrameType, fpoData.FrameType.String())
}
}

}
}

Expand Down Expand Up @@ -881,5 +865,19 @@ func parsePE(filename string, cfg config) {
}
}

// Get file type.
if pe.IsEXE() {
log.Debug("File is Exe")
}
if pe.IsDLL() {
log.Debug("File is DLL")
}
if pe.IsDriver() {
log.Debug("File is Driver")
}

// Calculate the PE checksum.
pe.Checksum()

fmt.Print("\n")
}
14 changes: 10 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,20 @@ func main() {
wantCLR: *dumpCLR,
}

//Start as many workers you want, now 10 workers
// Start as many workers you want, now 10 workers
numWorkers := runtime.GOMAXPROCS(runtime.NumCPU() - 1)
for w := 1; w <= numWorkers; w++ {
go loopFilesWorker(cfg)
}
//Start the recursion
LoopDirsFiles(os.Args[2])
wg.Wait()

if !isDirectory(os.Args[2]) {
// Input path in a single file.
parsePE(os.Args[2], cfg)
} else {
// Input path in a directory.
LoopDirsFiles(os.Args[2])
wg.Wait()
}

case "version":
verCmd.Parse(os.Args[2:])
Expand Down

0 comments on commit 493a9e1

Please sign in to comment.