Open dio opened 3 years ago
I dont think we need to do this optimization like this until there's a lot of motivation as we already try hard to keep deps low.
let's optimize for KISS (keep it simple and stupid)
thanks for the idea though.
ps I am glad you mentioned how to do this as if I ever need we can look at this issue again (here or any project!)
Seems like we can rely on something similar (the approach, by scanning the bytes) https://github.com/ArthurHlt/go-isexecutable/blob/v1.0.0/isexecutable.go, whilst it is very raw and naive, it has no external deps.
good find and go for it, but please don't copy/paste that code for citation and otherwise reasons.
As our only use case at the moment is a binary executable, I think the minimum logic can be used for the windows code (scanning header for magic bytes) and leave the other operating systems as-is (based on chmod info).
make sure you make a nice comment about the magic bytes in the windows impl!
Currently, on Windows, we only check the binary suffix to infer whether a file is executable or not (
strings.HasSuffix(f.Name(), ".exe")
). We can have a more sophisticated check for this if it is desired. However, we need to pull ingithub.com/Velocidex/go-pe
or write a small package to accommodate our needs.The steps that can be done are as follows: