Skip to content

Commit

Permalink
append lib exts (#202)
Browse files Browse the repository at this point in the history
* append lib exts

* use osutils
  • Loading branch information
dogancanbakir authored Oct 10, 2023
1 parent 01fb120 commit 593fd8f
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/projectdiscovery/pdtm/pkg/types"
"github.com/projectdiscovery/pdtm/pkg/utils"
errorutil "github.com/projectdiscovery/utils/errors"
osutils "github.com/projectdiscovery/utils/os"
stringsutil "github.com/projectdiscovery/utils/strings"
"github.com/projectdiscovery/utils/syscallutil"
)
Expand Down Expand Up @@ -264,7 +265,29 @@ func getTool(toolName string, tools []types.Tool) *types.Tool {
}

func requirementSatisfied(requirementName string) bool {
if strings.HasPrefix(requirementName, "lib") {
libNames := appendLibExtensionForOS(requirementName)
for _, libName := range libNames {
_, sysErr := syscallutil.LoadLibrary(libName)
if sysErr == nil {
return true
}
}
return false
}
_, execErr := exec.LookPath(requirementName)
_, sysErr := syscallutil.LoadLibrary(requirementName)
return sysErr == nil || execErr == nil
return execErr == nil
}

func appendLibExtensionForOS(lib string) []string {
switch {
case osutils.IsWindows():
return []string{fmt.Sprintf("%s.dll", lib), lib}
case osutils.IsLinux():
return []string{fmt.Sprintf("%s.so", lib), lib}
case osutils.IsOSX():
return []string{fmt.Sprintf("%s.dylib", lib), lib}
default:
return []string{lib}
}
}

0 comments on commit 593fd8f

Please sign in to comment.