pe-util icon indicating copy to clipboard operation
pe-util copied to clipboard

Build on Windows / Windows binary release

Open piegamesde opened this issue 4 years ago • 6 comments

I'm in the unfortunate situation of having to build things on Windows. And I cannot get peldd compiled on it. cmake says it can't find boost:

-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19042.
CMake Warning at C:/msys64/mingw64/share/cmake-3.19/Modules/FindBoost.cmake:1204 (message):
  New Boost version may have incorrect or missing dependencies and imported
  targets
Call Stack (most recent call first):
  C:/msys64/mingw64/share/cmake-3.19/Modules/FindBoost.cmake:1326 (_Boost_COMPONENT_DEPENDENCIES)
  C:/msys64/mingw64/share/cmake-3.19/Modules/FindBoost.cmake:1935 (_Boost_MISSING_DEPENDENCIES)
  CMakeLists.txt:5 (find_package)


CMake Warning at C:/msys64/mingw64/share/cmake-3.19/Modules/FindBoost.cmake:1204 (message):
  New Boost version may have incorrect or missing dependencies and imported
  targets
Call Stack (most recent call first):
  C:/msys64/mingw64/share/cmake-3.19/Modules/FindBoost.cmake:1326 (_Boost_COMPONENT_DEPENDENCIES)
  C:/msys64/mingw64/share/cmake-3.19/Modules/FindBoost.cmake:1935 (_Boost_MISSING_DEPENDENCIES)
  CMakeLists.txt:5 (find_package)


-- Could NOT find Boost (missing: system filesystem) (found suitable version "1.75.0", minimum required is "1.54")

I do have boost installed, but it's not the boost package, but mingw-w64-x86_64-boost instead.

piegamesde avatar Mar 02 '21 00:03 piegamesde

I have zero experience building things on windows. So far I just cross-compiled for Windows under Fedora using mingw packages. Which worked surprisingly well.

I might be wrong, but the cmake messages look like cmake just finds the boost headers but now shared libraries.

gsauthof avatar Mar 07 '21 17:03 gsauthof

This tool looks good, I also would like to see if someone can have a Windows release. Thanks.

asmwarrior avatar Mar 03 '22 13:03 asmwarrior

Here is the steps I just tried:

$ git clone --recurse-submodules https://github.com/gsauthof/pe-util.git
Cloning into 'pe-util'...
remote: Enumerating objects: 61, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 61 (delta 0), reused 1 (delta 0), pack-reused 58
Receiving objects: 100% (61/61), 17.38 KiB | 847.00 KiB/s, done.
Resolving deltas: 100% (31/31), done.
Submodule 'pe-parse' (https://github.com/trailofbits/pe-parse.git) registered for path 'pe-parse'
Cloning into 'D:/code/temp/pe-util/pe-parse'...
remote: Enumerating objects: 1542, done.
remote: Counting objects: 100% (105/105), done.
remote: Compressing objects: 100% (72/72), done.
remote: Total 1542 (delta 35), reused 64 (delta 20), pack-reused 1437
Receiving objects: 100% (1542/1542), 616.33 KiB | 865.00 KiB/s, done.
Resolving deltas: 100% (793/793), done.
Submodule path 'pe-parse': checked out '752f526e2eb27f6bec15be00afe92226b51d1613'

Now, under the msys2's mingw64 shell, I have such log:

zyh@WINMICR-0PLE9E2 MINGW64 /d/code/temp/pe-util
# mkdir build

zyh@WINMICR-0PLE9E2 MINGW64 /d/code/temp/pe-util
# cd build

zyh@WINMICR-0PLE9E2 MINGW64 /d/code/temp/pe-util/build
# cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release ../
-- The CXX compiler identification is GNU 11.2.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: F:/msys2/mingw64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Boost: F:/msys2/mingw64/include (found suitable version "1.78.0", minimum required is "1.54") found components: system filesystem
-- Configuring done
-- Generating done
-- Build files have been written to: D:/code/temp/pe-util/build

zyh@WINMICR-0PLE9E2 MINGW64 /d/code/temp/pe-util/build
# mingw32-make
[ 25%] Building CXX object CMakeFiles/peldd.dir/peldd.cc.obj
[ 50%] Building CXX object CMakeFiles/peldd.dir/pe-parse/pe-parser-library/src/parse.cpp.obj
[ 75%] Building CXX object CMakeFiles/peldd.dir/pe-parse/pe-parser-library/src/buffer.cpp.obj
D:\code\temp\pe-util\pe-parse\pe-parser-library\src\buffer.cpp:40:10: fatal error: sys/mman.h: No such file or directory
   40 | #include <sys/mman.h>
      |          ^~~~~~~~~~~~
compilation terminated.
mingw32-make[2]: *** [CMakeFiles\peldd.dir\build.make:106: CMakeFiles/peldd.dir/pe-parse/pe-parser-library/src/buffer.cpp.obj] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:82: CMakeFiles/peldd.dir/all] Error 2
mingw32-make: *** [Makefile:135: all] Error 2

I just checked the parse.cpp, it looks like the WIN32 is not defined. so I just changed it to _WIN32, here is the patch:

 pe-parser-library/src/buffer.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pe-parser-library/src/buffer.cpp b/pe-parser-library/src/buffer.cpp
index b9b0f8f..c20ce7b 100644
--- a/pe-parser-library/src/buffer.cpp
+++ b/pe-parser-library/src/buffer.cpp
@@ -28,7 +28,7 @@ THE SOFTWARE.
 // keep this header above "windows.h" because it contains many types
 #include <parser-library/parse.h>
 
-#ifdef WIN32
+#ifdef _WIN32
 
 #define WIN32_LEAN_AND_MEAN
 #define VC_EXTRALEAN

And now, continue the build.

zyh@WINMICR-0PLE9E2 MINGW64 /d/code/temp/pe-util/build
# mingw32-make
Consolidate compiler generated dependencies of target peldd
[ 25%] Building CXX object CMakeFiles/peldd.dir/pe-parse/pe-parser-library/src/buffer.cpp.obj
[ 50%] Linking CXX executable peldd.exe
[100%] Built target peldd

It looks like the peldd.exe is built now.

asmwarrior avatar Mar 03 '22 14:03 asmwarrior

I just see the that latest version (master head) of buffer.cpp already have this fixed.

pe-parse/buffer.cpp at master · trailofbits/pe-parse

Do you want to update your sub module to the latest revision?

asmwarrior avatar Mar 03 '22 14:03 asmwarrior

Well, when try to run the command, I see some errors:

F:\code\cb-64bit>which peldd
F:\msys2\mingw64\bin\peldd.EXE

F:\code\cb-64bit>peldd

F:\code\cb-64bit>peldd codeblocks.exe
SHFOLDER.dll
codeblocks.dll
exchndl.dll
libgcc_s_seh-1.dll
libstdc++-6.dll
wxmsw315u_gcc_cb.dll

F:\code\cb-64bit>peldd codeblocks.exe --all
Error: boost::filesystem::directory_iterator::construct: 系统找不到指定的路径。 [system:3]: "/usr/x86_64-w64-mingw32/sys-root/mingw/bin"

F:\code\cb-64bit>

The Chinese words means the system can not find the specified path.

asmwarrior avatar Mar 03 '22 14:03 asmwarrior

Have a look at #10

roussosalex avatar Mar 03 '22 21:03 roussosalex