Skip to content

Commit

Permalink
do not mark as seen twice (#499)
Browse files Browse the repository at this point in the history
  • Loading branch information
dogancanbakir authored Jun 24, 2024
1 parent 510bb25 commit b1d5252
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions runner/output_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,29 @@ func (o *OutputWriter) Write(data []byte) {
}
}

func (o *OutputWriter) findDuplicate(data string) bool {
func (o *OutputWriter) findDuplicate(data string, markAsSeen bool) bool {
// check if we've already printed this data
itemHash := sha1.Sum([]byte(data))
if o.cache.Contains(itemHash) {
return true
}
o.cache.Add(itemHash, struct{}{})
if markAsSeen {
o.cache.Add(itemHash, struct{}{})
}
return false
}

// WriteString writes the string taken as input using only
func (o *OutputWriter) WriteString(data string) {
if o.findDuplicate(data) {
if o.findDuplicate(data, true) {
return
}
o.Write([]byte(data))
}

// WriteJsonData writes the result taken as input in JSON format
func (o *OutputWriter) WriteJsonData(data sources.Result) {
if o.findDuplicate(fmt.Sprintf("%s:%d", data.IP, data.Port)) {
if o.findDuplicate(fmt.Sprintf("%s:%d", data.IP, data.Port), true) {
return
}
o.Write([]byte(data.JSON()))
Expand Down
2 changes: 1 addition & 1 deletion runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (r *Runner) Run(ctx context.Context) error {
if result.Host != "" || r.options.OutputFile != "" {
searchFor = append(searchFor, result.Host)
}
if stringsutil.ContainsAny(outData, searchFor...) && !r.outputWriter.findDuplicate(outData) {
if stringsutil.ContainsAny(outData, searchFor...) && !r.outputWriter.findDuplicate(outData, false) {
if r.options.Verbose {
// if output is verbose include source name
gologger.Info().Label(result.Source).Msg(outData)
Expand Down

0 comments on commit b1d5252

Please sign in to comment.