-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Swap over to yara-x; improve performance and readability
Signed-off-by: egibs <[email protected]>
- Loading branch information
Showing
56 changed files
with
2,349 additions
and
1,939 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package action | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/chainguard-dev/clog" | ||
) | ||
|
||
// findFilesRecursively returns a list of files found recursively within a path. | ||
func findFilesRecursively(ctx context.Context, rootPath string) ([]string, error) { | ||
logger := clog.FromContext(ctx) | ||
var files []string | ||
|
||
// Follow symlink if provided at the root | ||
root, err := filepath.EvalSymlinks(rootPath) | ||
if err != nil { | ||
// If the target does not exist, log the error but return gracefully | ||
// This is useful when scanning -compat packages | ||
if os.IsNotExist(err) { | ||
logger.Debugf("symlink target does not exist: %s", err.Error()) | ||
return nil, nil | ||
} | ||
// Allow /proc/XXX/exe to be scanned even if symlink is not resolveable | ||
if strings.HasPrefix(rootPath, "/proc/") { | ||
root = rootPath | ||
} else { | ||
return nil, fmt.Errorf("eval %q: %w", rootPath, err) | ||
} | ||
} | ||
|
||
err = filepath.WalkDir(root, | ||
func(path string, info os.DirEntry, err error) error { | ||
if err != nil { | ||
logger.Errorf("error: %s: %s", path, err) | ||
return nil | ||
} | ||
if info.IsDir() || strings.Contains(path, "/.git/") { | ||
return nil | ||
} | ||
|
||
files = append(files, path) | ||
return nil | ||
}) | ||
return files, err | ||
} | ||
|
||
// cleanPath removes the temporary directory prefix from the path. | ||
func cleanPath(path string, prefix string) string { | ||
return strings.TrimPrefix(path, prefix) | ||
} | ||
|
||
// formatPath formats the path for display. | ||
func formatPath(path string) string { | ||
if strings.Contains(path, "\\") { | ||
path = strings.ReplaceAll(path, "\\", "/") | ||
} | ||
return path | ||
} |
Oops, something went wrong.