Skip to content

Commit

Permalink
chore(pe): Route saferwall/pe log messages to logrus
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitstack committed Oct 16, 2024
1 parent e819404 commit c161273
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/pe/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"github.com/rabbitstack/fibratus/pkg/util/format"
"github.com/rabbitstack/fibratus/pkg/util/va"
peparser "github.com/saferwall/pe"
peparserlog "github.com/saferwall/pe/log"
log "github.com/sirupsen/logrus"
"golang.org/x/sys/windows"
"os"
"path/filepath"
Expand Down Expand Up @@ -220,9 +222,29 @@ func newParserOpts(opts opts) *peparser.Options {
OmitLoadConfigDirectory: true,
OmitGlobalPtrDirectory: true,
SectionEntropy: opts.sectionEntropy,
Logger: &Logger{},
}
}

// Logger is the adapter for routing PE package logs to logrus.
type Logger struct{}

func (l Logger) Log(level peparserlog.Level, keyvals ...interface{}) error {
switch level {
case peparserlog.LevelDebug:
log.Debug(keyvals[1:]...)
case peparserlog.LevelInfo:
log.Info(keyvals[1:]...)
case peparserlog.LevelWarn:
log.Warn(keyvals[1:]...)
case peparserlog.LevelError, peparserlog.LevelFatal:
log.Error(keyvals[1:]...)
default:
log.Info(keyvals[1:]...)
}
return nil
}

func parse(path string, data []byte, options ...Option) (*PE, error) {
var opts opts
for _, opt := range options {
Expand Down

0 comments on commit c161273

Please sign in to comment.