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

Trouble compiling natively in windows using msys2 (64 bit) mingw64 - (Solved!) #35

Closed
jack4455667788 opened this issue May 18, 2024 · 11 comments
Labels
question How to use/compile/deploy PPPwn_cpp

Comments

@jack4455667788
Copy link

jack4455667788 commented May 18, 2024

I have encountered all sorts of issues, and although i have finally gotten the darn thing to build successfully - it isn't functional. I'm hoping someone can give me some direction on what I'm doing wrong, or share what they did to successfully compile natively in windows.

Issues Encountered:

  1. Path issues. Packet_ROOT=/msys64/usr/src/npcap-sdk-1.13, Packet_ROOT="/msys64/usr/src/npcap-sdk-1.13", Packet_ROOT=C:\msys64\usr\src\npcap-sdk-1.13, Packet_ROOT=\C:\msys64\usr\src\npcap-sdk-1.13, Packet_ROOT=/C:\msys64\usr\src\npcap-sdk-1.13 (last two suggested here) all fail with "-- Could NOT find Packet (missing: Packet_LIBRARY Packet_INCLUDE_DIR)". Only relative paths (in unix style : Packet_ROOT=../npcap-sdk-1.13 ) and quoted full paths (in windows style : Packet_ROOT="C:\msys64\usr\src\npcap-sdk-1.13") work.
  2. If mingw-w64-x86_64-libpcap (which is currently version 1.10.4-1) is not installed (using command "pacman -S mingw-w64-x86_64-libpcap") - you will receive the "-- Could NOT find PCAP (missing: PCAP_LIBRARY PCAP_INCLUDE_DIR)" error. With mingw-w64-x86_64-libpcap installed, pppwn.exe compiles but is broken - this is my biggest/current hurdle. pppwn.exe requires libpcap.dll, libcrypto-3-x64.dll, libssl-3-x64.dll (does not contain the required libraries and needs external dlls) and worst of all simply does not work. "pppwn.exe list" always returns no interfaces and no interface name I've tried has been effective. I have tried uninstalling the prebuilt package and compiled libpcap from source (https://www.tcpdump.org/release/libpcap-1.10.4.tar.xz) but this makes things even worse - requiring libdbus-1-3.dll and pcap.dll (renamed libpcap.dll) along with the others mentioned above and now "pppwn.exe list" fails with "[ERROR: /build/_deps/pcapplusplus-src/Pcap++/src/PcapLiveDevice.cpp: setDeviceMtu:713] Error in retrieving MTU: Adapter is NULL
    [ERROR: /build/_deps/pcapplusplus-src/Pcap++/src/PcapLiveDevice.cpp: setDeviceMacAddress:774] Error in retrieving MAC address: Adapter is NULL
    [ERROR: /build/_deps/pcapplusplus-src/Pcap++/src/PcapLiveDevice.cpp: setDeviceMtu:713] Error in retrieving MTU: Adapter is NULL
    [ERROR: /build/_deps/pcapplusplus-src/Pcap++/src/PcapLiveDevice.cpp: setDeviceMacAddress:774] Error in retrieving MAC address: Adapter is NULL
    dbus-system D-Bus system bus
    dbus-session D-Bus session bus"
  3. The compilation instructions in the readme.md do not include any steps for native compilation in windows. The commands I have used, which - granted - do not compile a working copy of pppwn.exe are below
  • git clone https://github.com/xfangfang/PPPwn_cpp
  • cd PPPwn_cpp
  • cmake -B build -DPacket_ROOT=../npcap-sdk-1.13
  • cd build ( "cmake --build build -t pppwn" from the current directory also works, and appears to do the same thing / produce the same files as these last 2 commands)
  • ninja (this builds)

I am at a loss as to how to proceed (specifically with issue #2 above). Any direction/tips/input would be greatly appreciated!

Bonus - Would zig be a good tool to compile the pppwn payloads in windows? Any direction on making this work?

Thanks in any case.


Output of cmake command above, showing I am using gnu cc and c++ - possibly useful in debugging?

$ cmake -B build -DPacket_ROOT=../npcap-sdk-1.13
-- Building for: Ninja
-- The C compiler identification is GNU 13.2.0
-- The CXX compiler identification is GNU 13.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/mingw64/bin/cc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/msys64/mingw64/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PCAP: C:/msys64/mingw64/lib/libpcap.dll.a
-- Performing Test PCAP_LINKS_SOLO
-- Performing Test PCAP_LINKS_SOLO - Success
-- Looking for pcap_set_immediate_mode
-- Looking for pcap_set_immediate_mode - found
-- Looking for pcap_setdirection
-- Looking for pcap_setdirection - found
-- Found Packet: C:/msys64/usr/src/npcap-sdk-1.13/Lib/x64/Packet.lib
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
CMake Deprecation Warning at build/_deps/pcapplusplus-src/3rdParty/MemPlumber/MemPlumber/CMakeLists.txt:1 (cmake_minimum_required):
Compatibility with CMake < 3.5 will be removed from a future version of
CMake.

Update the VERSION argument value or use a ... suffix to tell
CMake that the project does not need compatibility with older versions.

-- Looking for backtrace
-- Looking for backtrace - not found
-- Could NOT find Backtrace (missing: Backtrace_LIBRARY Backtrace_INCLUDE_DIR)
-- Backtrace not found or not supported!
-- Configuring done (16.4s)
-- Generating done (0.1s)
-- Build files have been written to: C:/msys64/usr/src/PPPwn_cpp/build

@xfangfang
Copy link
Owner

xfangfang commented May 18, 2024

I have said it many times in many issues:Please refer to: https://github.com/xfangfang/PPPwn_cpp/blob/main/.github/workflows/ci.yaml

  1. libpcap doesn't support msvcrt (MINGW32/64), you can use CLANG32/CLANG64/UCRT64 instead
  2. or you can use the wpcap.dll provided by npcap: -DPCAP_ROOT="sdk-path" (not -DPcaket_ROOT=...)

if you just want a safe build, the nightly-build is build by the workflow under GitHub Actions you can check every step in the build process.

@xfangfang xfangfang added the question How to use/compile/deploy PPPwn_cpp label May 18, 2024
@oresterosso75
Copy link

When I thought I had succeeded, by running the command cmake --build build -t pppwn I got this error

`C:\Users\PCgames\Desktop\PPPwn_cpp-main>cmake --build build -t pppwn
Versione di MSBuild L17.9.8+b34f75857 per .NET Framework

Common++.vcxproj -> C:\Users\PCgames\Desktop\PPPwn_cpp-main\build_deps\pcapplusplus-build\Common++\Debug\Common++.li
b
hash-library.vcxproj -> C:\Users\PCgames\Desktop\PPPwn_cpp-main\build_deps\pcapplusplus-build\3rdParty\hash-library
hash-library.dir\Debug\hash-library.lib
Packet++.vcxproj -> C:\Users\PCgames\Desktop\PPPwn_cpp-main\build_deps\pcapplusplus-build\Packet++\Debug\Packet++.li
b
light_pcapng.vcxproj -> C:\Users\PCgames\Desktop\PPPwn_cpp-main\build_deps\pcapplusplus-build\3rdParty\LightPcapNg\l
ight_pcapng.dir\Debug\light_pcapng.lib
cl : error della riga di comando D8021 : argomento numerico '/Wno-macro-redefined' non valido
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(755,5): e
rror MSB6006: "CL.exe" terminato con il codice 2. [C:\Users\PCgames\Desktop\PPPwn_cpp-main\build_deps\pcap-build\pcap_
static.vcxproj]`

@jack4455667788
Copy link
Author

jack4455667788 commented May 19, 2024

Thank you for the quick and helpful response! Thanks to you i got it working, and i was able to build stage1 of pppwn using zig as well - however stage2 is still bombing with a linker error. I used the stage1 and the compiled pppwn_cpp to successfully jailbreak a ps4 pro 7215B on 10.50 on the first try.

  1. libpcap doesn't support msvcrt (MINGW32/64), you can use CLANG32/CLANG64/UCRT64 instead

Clang64 exhibited the exact same problems detailed above. When compiled with the pre-built libpcap package, the interface list is always empty, and when built with the libpcap compiled from source it gives the errors. Neither work.

UCRT64 (when configured properly/standard) uses msvc, so that wouldn't work, right?

In any case, libpcap simply doesn't function when used - although everything compiles successfully with no errors/warnings. Interestingly, the libraries are always external (.dlls) when using libpcap, and statically in the executable as expected when winpcap is used (which was the magic bullet for me)

I finally got the working copy built in MINGW64 (using gcc as the compiler). As far as I am aware, msvcrt is not involved.

  1. or you can use the wpcap.dll provided by npcap: -DPCAP_ROOT="sdk-path" (not -DPcaket_ROOT=...)

This was the key for me. Thank you.

The command i used that finally built the working copy was

  • cmake -B build -DPacket_ROOT=../npcap-sdk-1.13 -DPCAP_ROOT=../npcap-sdk-1.13

However, it required uninstalling llbpcap entirely in order to work (which doesn't seem right). When libpcap is installed - it is used even when the -DPCAP_ROOT is specified as above, and -DUSE_SYSTEM_PCAP=OFF just causes linking to bomb (although it seems to build pcap from source, it seems the libraries are not passed to the linker properly).

Thanks again! Now if i can just figure out why stage2 compilation is bombing on linking (with zig), everything can be done natively in windows.

@xfangfang
Copy link
Owner

@jack4455667788 https://www.msys2.org/docs/environments/

mingw64: msvcrt
ucrt64/clang64: ucrt

@jack4455667788
Copy link
Author

jack4455667788 commented May 19, 2024

Thanks for clearing that up for me!

However, as i said - building in ucrt or clang with libpcap (either precompiled or compiled from source) succeeded the same way as in mingw64 and all behaved identically (i.e. did not function). If there is a way to build a functioning copy using libpcap natively in windows - i couldn't figure it out regardless of the compiling environment of msys2 i tried.

@jack4455667788
Copy link
Author

jack4455667788 commented May 20, 2024

When I thought I had succeeded, by running the command cmake --build build -t pppwn I got this error

`C:\Users\PCgames\Desktop\PPPwn_cpp-main>cmake --build build -t pppwn Versione di MSBuild L17.9.8+b34f75857 per .NET Framework

Common++.vcxproj -> C:\Users\PCgames\Desktop\PPPwn_cpp-main\build_deps\pcapplusplus-build\Common++\Debug\Common++.li b hash-library.vcxproj -> C:\Users\PCgames\Desktop\PPPwn_cpp-main\build_deps\pcapplusplus-build\3rdParty\hash-library hash-library.dir\Debug\hash-library.lib Packet++.vcxproj -> C:\Users\PCgames\Desktop\PPPwn_cpp-main\build_deps\pcapplusplus-build\Packet++\Debug\Packet++.li b light_pcapng.vcxproj -> C:\Users\PCgames\Desktop\PPPwn_cpp-main\build_deps\pcapplusplus-build\3rdParty\LightPcapNg\l ight_pcapng.dir\Debug\light_pcapng.lib cl : error della riga di comando D8021 : argomento numerico '/Wno-macro-redefined' non valido C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(755,5): e rror MSB6006: "CL.exe" terminato con il codice 2. [C:\Users\PCgames\Desktop\PPPwn_cpp-main\build_deps\pcap-build\pcap_ static.vcxproj]`

I did not build in visual studio, nor use msvc as the compiler (which I assume you are) but this suggests that "Wno-macro-redefined" is not a valid argument to your compiler. Find it and try commenting it out (it's line 82 in the cmakelists.txt - but there is a second flag included there as well which you may not want to remove.). It may not work, or it may generate an output that doesn't work - but give it a whirl (or try using a compiler which does understand that flag, like clang or gcc)

@jack4455667788 jack4455667788 changed the title Trouble compiling natively in windows using msys2 (64 bit) mingw64 Trouble compiling natively in windows using msys2 (64 bit) mingw64 - Solved May 20, 2024
@jack4455667788 jack4455667788 changed the title Trouble compiling natively in windows using msys2 (64 bit) mingw64 - Solved Trouble compiling natively in windows using msys2 (64 bit) mingw64 - (Solved!) May 20, 2024
@oresterosso75
Copy link

Quando pensavo di esserci riuscito, eseguendo il comando cmake --build build -t pppwn ho ricevuto questo errore
C:\Users\PCgames\Desktop\PPPwn_cpp-main>cmake --build build -t pppwn Versione di MSBuild L17.9.8+b34f75857 per .NET Framework Common++.vcxproj -> C:\Users\PCgames\Desktop\PPPwn_cpp-main\build_deps\pcapplusplus-build\Common++\Debug\Common++.li b hash-library.vcxproj -> C:\Users\PCgames\Desktop\PPPwn_cpp- main\build_deps\pcapplusplus-build\3rdParty\hash-library hash-library.dir\Debug\hash-library.lib Packet++.vcxproj -> C:\Users\PCgames\Desktop\PPPwn_cpp-main\build_deps\pcapplusplus-build\ Packet++\Debug\Packet++.li b light_pcapng.vcxproj -> C:\Users\PCgames\Desktop\PPPwn_cpp-main\build_deps\pcapplusplus-build\3rdParty\LightPcapNg\l ight_pcapng.dir\Debug\light_pcapng.lib cl : errore della riga di comando D8021 : argomento numerico '/Wno-macro-refine' non valido C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(755,5): e rror MSB6006: "CL.exe" terminato con il codice 2. [C:\Users\PCgames\Desktop\PPPwn_cpp-main\build_deps\pcap-build\pcap_ static.vcxproj]

Non ho creato in Visual Studio, né ho utilizzato msvc come compilatore (cosa che presumo tu sia) ma questo suggerisce che "Wno-macro-refined" non è un argomento valido per il tuo compilatore. Trovalo e prova a commentarlo (è la riga 82 nel cmakelists.txt - ma lì è incluso anche un secondo flag che potresti non voler rimuovere). Potrebbe non funzionare, o potrebbe generare un output che non funziona, ma provalo (o prova a utilizzare un compilatore che comprenda quel flag, come clang o gcc)

I followed your advice and decided to use msys2 + gcc
Although the first part was successfully resolved, this is what happens next:
project

@oresterosso75
Copy link

oresterosso75 commented May 20, 2024

alleluia!!
I finally succeeded.
now inside the build folder the file pppwn.exe has been created, if I launch it I see a window that opens and immediately closes.
I don't quite understand how to use this, could you tell me the correct use?

# cmake --build build -t pppwn [16/100] Building CXX object _deps/pcapplusplus-.../CMakeFiles/Packet++.dir/src/DnsResource.cpp.obj In member function 'uint8_t* pcpp::IDnsResource::getRawData() const', inlined from 'pcpp::IDnsResource::IDnsResource(pcpp::DnsLayer*, size_t)' at C:/Users/PCgames/Des ktop/PPPwn_cpp-main/build/_deps/pcapplusplus-src/Packet++/src/DnsResource.cpp:16:51: C:/Users/PCgames/Desktop/PPPwn_cpp-main/build/_deps/pcapplusplus-src/Packet++/src/DnsResource.cpp:29 :24: warning: '*this.pcpp::IDnsResource::m_ExternalRawData' may be used uninitialized [-Wmaybe-unini tialized] 29 | return m_ExternalRawData; | ^~~~~~~~~~~~~~~~~ [100/100] Linking CXX executable pppwn.exe

@jack4455667788
Copy link
Author

jack4455667788 commented May 20, 2024

alleluia!!
I finally succeeded.

Congrats! Out of curiosity, and because it could possibly help others with the same issue, what did you do to solve the issue you encountered?

if I launch it I see a window that opens and immediately closes.
I don't quite understand how to use this, could you tell me the correct use?

It's a command line tool, it has no gui (there are gui's available for it you could find/build). It is meant to be run from the command line (cmd or in msys2 will work). The command line pppwn.exe --help will explain the syntax if you want to use it directly. The one snag is that when you use pppwn.exe list to print out the interface name for your ethernet, for example \Device\NPF_{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} Ethernet Controller Name, that name will need to be passed to pppwn in quotes and only include the text before the first " " character. In the example above, the correct format would be pppwn.exe --interface "\Device\NPF_{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"

This video shows how to set up the gui and use what you've built https://www.youtube.com/watch?v=GFuWbmJPbok (you'll just need to swap in your copy of pppwn.exe if you choose to download the loader gui the way he shows in the video).

@oresterosso75
Copy link

alleluia!!
Alla fine ci sono riuscito.

Congratulazioni! Per curiosità e poiché potrebbe aiutare altri con lo stesso problema, cosa hai fatto per risolvere il problema riscontrato?

se lo lancio vedo una finestra che si apre e si chiude subito.
Non ho ben capito come si usa, sapreste dirmi l'uso corretto?

È uno strumento da riga di comando, non ha GUI (ci sono GUI disponibili che potresti trovare/costruire). È pensato per essere eseguito dalla riga di comando (funzionerà cmd o in msys2). La riga di comando pppwn.exe --helpspiegherà la sintassi se desideri utilizzarla direttamente. L'unico problema è che quando usi pppwn.exe listper stampare il nome dell'interfaccia per la tua Ethernet, ad esempio \Device\NPF_{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} Ethernet Controller Name, quel nome dovrà essere passato a pppwn tra virgolette e includere solo il testo prima del primo carattere " ". Nell'esempio sopra, il formato corretto sarebbepppwn.exe --interface "\Device\NPF_{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"

Questo video mostra come impostare la GUI e utilizzare ciò che hai creato https://www.youtube.com/watch?v=GFuWbmJPbok (dovrai solo scambiare la tua copia di pppwn.exe se lo desideri scarica la GUI del caricatore come mostra nel video).

Problem solved.
Thank you so much for your support but above all for sharing your project with us.
How did I solve my problem?
The problem I encountered seemed to be related to the failure to declare asprintf in the header files included by pcap-npf.c. Asprintf is a standard C99 function, but may not be available on all platforms or compilers.
For my MinGW64 environment, asprintf was apparently not available by default. However, I thought I could include support for GNU extensions by installing libiberty, which includes this feature.
Searching the pacman repository I find that this function was not available for msys2.
I solved it with the alternative package mingw-w64-x86_64-binutils, it provides the binary tools needed for compiling with MinGW-w64, including asprintf and libiberty. Thanks to this I was able to solve the asprintf failure to declare problem that I was encountering.
I started compiling the project again (native build):
cmake -B build -DPacket_ROOT=
(you must include the npcap_sdk path)
and with the next step cmake --build build -t pppwn magically compiled.

@jack4455667788
Copy link
Author

jack4455667788 commented May 20, 2024

Thank you so much for your support

My pleasure. It is good to help when we can!

but above all for sharing your project with us

It isn't my project, but I also share your gratitude towards @xfangfang (and of course @TheOfficialFloW)!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question How to use/compile/deploy PPPwn_cpp
Projects
None yet
Development

No branches or pull requests

3 participants