NationalSecurityAgency / ghidra

Ghidra is a software reverse engineering (SRE) framework
https://www.nsa.gov/ghidra
Apache License 2.0
52.21k stars 5.91k forks source link

Windows build doesn't find Visual Studio build tools without full IDE #1733

Closed shoaniki closed 2 years ago

shoaniki commented 4 years ago

Describe the bug gradle buildGhidra on Windows requires the complete Visual Studio IDE to be installed, even though everything it actually needs is present in the standalone Visual Studio build tools package, and the build works fine with a minor change to vsconfig.gradle.

To Reproduce Steps to reproduce the behavior:

  1. Install Visual Studio build tools, Windows SDK, and ATL, but not the Visual Studio IDE.
  2. Run gradle buildGhidra.

Expected behavior Ghidra should build successfully, since all the tools and headers it needs are present.

Environment (please complete the following information):

Additional context vsconfig.gradle uses vswhere to locate Visual Studio. By default this tool only reports full IDE installations. If the option -products Microsoft.VisualStudio.Product.BuildTools is added to the vswhere command line, the build succeeds and native code portions such as the decompiler appear to work normally.

Since I don't have the full IDE installed, I don't know whether adding that option breaks things in that situation; if it does, it should be straightforward to try both forms before failing.

astrelsky commented 4 years ago

I'll add this later and check if it breaks anything or not. You should probably submit a pull request for this though.

Unfortunately adding that option caused it to fail.

Edit specifying more than one products works ok.

While it is a bit ugly I don't know of another way since including all the products may result in one which doesn't have build tools. Changing the line to def vswhereOutput = "${vswherePath} -latest -products Microsoft.VisualStudio.Product.Enterprise Microsoft.VisualStudio.Product.Professional Microsoft.VisualStudio.Product.Community Microsoft.VisualStudio.Product.BuildTools -format json".execute().text.trim() should work in all cases.

endrin commented 2 years ago

While it is a bit ugly I don't know of another way since including all the products may result in one which doesn't have build tools.

${vswherePath} -products * -latest -format json worked for me for a long time.

endrin commented 2 years ago

I have to clarify my previous comment, while this works it's not enough for build to succeed. Turns out, currently Ghidra build scripts are not using results of vsconfig.gradle execution to build natives, instead the VisualCpp plugin is used, which does not detect BuildTools. I had to use modified Gradle build with VisualCpp's vswhere call changed in order to locate the compiler correctly.