Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building on Windows #7

Closed
hillu opened this issue Dec 25, 2020 · 5 comments
Closed

Building on Windows #7

hillu opened this issue Dec 25, 2020 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@hillu
Copy link

hillu commented Dec 25, 2020

Hi, I'm the author of go-yara and I recently spent some time figuring out how to build libyara on Winows using MSYS2. Perhaps you'll find hillu/go-yara#78 (the issue that pointed me into the right direction) and https://github.com/hillu/go-yara/blob/master/README.cross-building.md#example-building-on-windows-using-msys2 (the resulting condensed description) useful.

@targodan
Copy link
Collaborator

Thank you for the pointer! 👍

I'll have a look at those resources and try to get it working on windows.

@targodan targodan added the enhancement New feature or request label Dec 30, 2020
@targodan targodan self-assigned this Dec 30, 2020
@targodan
Copy link
Collaborator

targodan commented Jan 7, 2021

Thanks again @hillu! Thanks to your notes I got it working. The automation part was a bit fiddly, but I got it working in the end.

Here are some of my findings/results you might also find interesting:

  • Adding the line // #cgo yara_static LDFLAGS: -static to my yara.go allowed me to build a true-static binary without having to fiddle with the CGO_LDFLAGS environment variable. (although I still had to fiddle with the library path 🙄 )
  • I wrote a powershell (and some bash) scripts to have as close to a one-click solution as I was comfortable with. The user still has to install Golang, MSYS2 and some build-dependencies via pacman, but then cicd/buildOnWindows.ps1 takes care of the rest. It optionally calls msys64, to execute the script cicd/buildAndInstallDependencies.sh and once that's done it compiles yapscan.exe

Some reasoning for my decisions/further explanation of what you might stumble across:

  • I went the powershell route, since I didn't like the idea of trying to get the go toolchain working within msys.
  • In addition to yara, I have OpenSSL as a dependency because the PE-plugin of yara requires something in libcrypto

Feel free to make use of what you might find useful in my scripts. :)

EDIT: Any changes are, so far, only available in the develop branch. Once I merge into master, I'll close this issue. But we can still use it as a discussion platform, if you have further questions. :)

@hillu
Copy link
Author

hillu commented Jan 8, 2021

Glad you made progress. OpenSSL on Windows is only needed for Authenticode signature (pe.signatures[*].* support in YARA rules. Anything related to hash functions will use the Windows CryptoAPI functions instead if OpenSSL is not available. (And if I ever get a variant of VirusTotal/yara#1423 merged, the requirement may go away altogether.)

If I can be of further help, feel free to ask.

@targodan
Copy link
Collaborator

targodan commented Jan 8, 2021

Thanks for the clarification, all I saw was that some rule didn't work and google told me the PE module needs openssl. Would be cool if that could be merged! I left a +1 on that merge request.

@targodan
Copy link
Collaborator

Thanks again for you help. The build process for windows is described in the README. It uses mingw64 and I have provided powershell build scripts in the cicd/ folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants