xfangfang / PPPwn_cpp

C++ rewrite of PPPwn (PlayStation 4 PPPoE RCE)
GNU General Public License v3.0
350 stars 48 forks source link

fails to cross-build/compile for Windows #23

Closed EatThisRock closed 1 month ago

EatThisRock commented 1 month ago

When running cmake --build build -t pppwn

I get:

[ 0%] Building CXX object _deps/pcapplusplus-build/Common++/CMakeFiles/Common++.dir/src/GeneralUtils.cpp.obj In file included from :434: :10:9: error: macro name must be an identifier 10 | #define -D_Postinvalid | ^ 1 error generated. gmake[3]: [_deps/pcapplusplus-build/Common++/CMakeFiles/Common++.dir/build.make:77: _deps/pcapplusplus-build/Common++/CMakeFiles/Common++.dir/src/GeneralUtils.cpp.obj] Error 1 gmake[2]: [CMakeFiles/Makefile2:1031: _deps/pcapplusplus-build/Common++/CMakeFiles/Common++.dir/all] Error 2 gmake[1]: [CMakeFiles/Makefile2:402: CMakeFiles/pppwn.dir/rule] Error 2 gmake: [Makefile:182: pppwn] Error 2

Can't seem to find a reason for it?

I am using Ubuntu WSL on Windows 10.

Using Ubuntu WSL, I can compile/build the linux binary and runs just fine.

xfangfang commented 1 month ago

What commands did you input from the beginning.

EatThisRock commented 1 month ago

If you mean before compiling, I used: cmake -B build -DZIG_TARGET=x86_64-windows-gnu -DUSE_SYSTEM_PCAP=OFF -DPacket_ROOT=/mnt/c/Users/USERNAME/Desktop/PS4/npcap_win_sdk

If it helps I have a log, of the output from this.

xfangfang commented 1 month ago
  1. is the version of npcap SDK 1.13?
  2. If the build directory was previously used to compile with different cmake option, please delete it and try again
  3. Using MSYS2 mingw32/64 to do a native compile
  4. Using a real linux or mac to cross compile

You can check the workflow for more information (both mingw and cross compile from linux are contained )

https://github.com/xfangfang/PPPwn_cpp/blob/main/.github/workflows/ci.yaml

EatThisRock commented 1 month ago

Thanks, I've done 1-2 before. But 3 seems like a good suggestion.

EatThisRock commented 1 month ago

After spending more time into it and given mingw64 was failing elsewhere with no solution in sight, I was able to fix it by adding

#ifndef _Post_invalid_ 
#define _Post_invalid_    
#endif

to Packet32.h from npcap sdk/include folder.

and commented out add_compile_definitions(-D_Post_invalid_=) on CMakeLists.txt, it was able to compile just fine with WSL Ubuntu on Windows 10.

After having npcap installed in windows the compiled binary runs with better success rate than vanilla PPPwn

I am not sure if is the 'right' solution, but is a workaround if anyone is interested.

sauce

xfangfang commented 1 month ago

if cmake >= 3.26 it will remove the leading -D in add_compile_definitions(-D_Post_invalid_=).

So I guess the issue was caused by the cmake version. I just submitted an update, and now it should be possible to compile without modifying the npcap SDK.

https://github.com/xfangfang/PPPwn_cpp/commit/f5940c39a1ec5dbd7a986cffd706932727f1f7fd

EatThisRock commented 1 month ago

if cmake >= 3.26 it will remove the leading -D in add_compile_definitions(-D_Post_invalid_=).

So I guess the issue was caused by the cmake version. I just submitted an update, and now it should be possible to compile without modifying the npcap SDK.

f5940c3

Neato, definitely is a better option. Thank you

oresterosso75 commented 1 month ago

yet the path is correct! why do I get this error?

`-- Could NOT find Packet (missing: Packet_LIBRARY Packet_INCLUDE_DIR) CMake Error at build/_deps/pcapplusplus-src/CMakeLists.txt:127 (message): Please specify Packet library -DPacket_ROOT=

-- Configuring incomplete, errors occurred!`

xfangfang commented 1 month ago

@oresterosso75

You need to provide the environment and cmake command. while referring to the workflow mentioned earlier.

In Linux, you need to pay attention to the issue of path capitalization (which is why workflow modified the path of sdk). The cmake option set for compiling using mingw and cross-compiling in Linux are different (-DPACP_ROOT /-DPacket_ROOT)

oresterosso75 commented 1 month ago

@oresterosso75

È necessario fornire l'ambiente e il comando cmake. facendo riferimento al flusso di lavoro menzionato in precedenza.

In Linux, è necessario prestare attenzione al problema della capitalizzazione del percorso (motivo per cui il flusso di lavoro ha modificato il percorso dell'SDK). L'opzione cmake impostata per la compilazione utilizzando mingw e la compilazione incrociata in Linux è diversa (-DPACP_ROOT /-DPacket_ROOT)

Never before have I found myself in difficulty like today, I have truly tried everything. I'm forced to give up

xfangfang commented 1 month ago

@oresterosso75 Providing an error message cannot solve any problem. You need to show what you have done so that others can help you.

example: I am trying to cross compile to Windows under Ubuntu 22.04, using cmake -DPacket_ROOT=... Afterwards, an error occurred, and here is the path to npcap sdk: tree sdk ....

You really need to learn this article: http://catb.org/~esr/faqs/smart-questions.html

oresterosso75 commented 1 month ago

@oresterosso75Fornire un messaggio di errore non può risolvere alcun problema. Devi mostrare ciò che hai fatto in modo che gli altri possano aiutarti.

esempio: sto provando a eseguire la compilazione incrociata su Windows con Ubuntu 22.04, utilizzando cmake -DPacket_ROOT=...Afterwards, si è verificato un errore ed ecco il percorso di npcap sdk: tree sdk....

Hai davvero bisogno di imparare questo articolo: http://catb.org/~esr/faqs/smart-questions.html

I actually didn't provide much detail about my problem. I apologize for this. to recap, I'm compiling from CMD windows with the following command: cmake -B build -DZIG_TARGET=x86_64-windows-gnu -DUSE_SYSTEM_PCAP=OFF -DPacket_ROOT="C:\PPPwn_cpp-main\npcap-sdk". this is the complete result:

`-- ZIG_TARGET: x86_64-windows-gnu -- OS: Windows -- ARCH: x86_64 -- Custom compile options: -- The C compiler identification is Clang 17.0.6 -- The CXX compiler identification is Clang 17.0.6 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /c/PPPwn_cpp-main/build/vendor/zig-tools/zig-cc.sh - 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/PPPwn_cpp-main/build/vendor/zig-tools/zig-cpp.sh - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done CMake Deprecation Warning at build/_deps/pcap-src/CMakeLists.txt:16 (cmake_policy): The OLD behavior for policy CMP0042 will be removed from a future version of CMake.

The cmake-policies(7) manual explains that the OLD behaviors of all policies are deprecated and that a policy should be set to OLD only under specific short-term circumstances. Projects should be ported to the NEW behavior and not rely on setting a policy to OLD.

-- Building 64-bit -- Checking C compiler flag -std=gnu99 -- Performing Test std-gnu99 -- Performing Test std-gnu99 - Success -- Found Packet: C:/PPPwn_cpp-main/npcap-sdk/include -- Looking for PacketIsLoopbackAdapter -- Looking for PacketIsLoopbackAdapter - not found -- Looking for PacketGetTimestampModes -- Looking for PacketGetTimestampModes - not found -- checking for Npcap's version.h -- Looking for WINPCAP_PRODUCT_NAME -- Looking for WINPCAP_PRODUCT_NAME - not found -- MISSING version.h -- Use STATIC runtime -- Looking for inttypes.h -- Looking for inttypes.h - found -- Looking for stdint.h -- Looking for stdint.h - found -- Looking for unistd.h -- Looking for unistd.h - found -- Looking for bitypes.h -- Looking for bitypes.h - not found -- Performing Test HAVE_ATOMIC_LOADN -- Performing Test HAVEATOMIC_LOAD_N - Success -- Performing Test HAVE_ATOMIC_STOREN -- Performing Test HAVEATOMIC_STORE_N - Success -- Looking for strerror -- Looking for strerror - found -- Looking for strerror_r -- Looking for strerror_r - not found -- Looking for _wcserror_s -- Looking for _wcserror_s - found -- Looking for vsnprintf -- Looking for vsnprintf - found -- Looking for snprintf -- Looking for snprintf - found -- Looking for strlcpy -- Looking for strlcpy - not found -- Looking for strlcat -- Looking for strlcat - not found -- Looking for asprintf -- Looking for asprintf - found -- Looking for vasprintf -- Looking for vasprintf - found -- Looking for strtok_r -- Looking for strtok_r - found -- Looking for getaddrinfo -- Looking for getaddrinfo - found -- Looking for getnetbyname_r -- Looking for getnetbyname_r - not found -- Looking for getprotobyname_r -- Looking for getprotobyname_r - not found -- Looking for sys/types.h -- Looking for sys/types.h - found -- Looking for stddef.h -- Looking for stddef.h - found -- Check size of struct sockaddr_storage -- Check size of struct sockaddr_storage - done -- Check size of socklen_t -- Check size of socklen_t - failed -- Performing Test HAVE_STRUCT_SOCKADDR_SA_LEN -- Performing Test HAVE_STRUCT_SOCKADDR_SA_LEN - Failed -- Looking for ffs -- Looking for ffs - not found -- Looking for ether_hostton -- Looking for ether_hostton - not found -- Support IPv6 -- Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR) -- Packet capture mechanism type: npf -- Performing Test PCAP_SUPPORT_NETMAP -- Performing Test PCAP_SUPPORT_NETMAP - Failed -- Could NOT find dpdk (missing: dpdk_INCLUDE_DIRS dpdk_LIBRARIES) WARNING,We couldn't find DPDK with pkg-config. If you want DPDK support, make sure that pkg-config is installed, that DPDK 18.02.2 or later is installed, and that DPDK provides a .pc file. -- Could NOT find DAG (missing: DAG_INCLUDE_DIR DAG_LIBRARY DAGCONF_LIBRARY) -- Looking for msg.h -- Looking for msg.h - not found -- Could NOT find SNF (missing: SNF_INCLUDE_DIR SNF_LIBRARY) -- Could NOT find AirPcap (missing: AirPcap_INCLUDE_DIR AirPcap_LIBRARY) -- Could NOT find TC (missing: TC_INCLUDE_DIR TC_LIBRARY) -- Performing Test HAVE_STRUCT_MSGHDR_MSG_CONTROL -- Performing Test HAVE_STRUCT_MSGHDR_MSG_CONTROL - Failed -- Performing Test HAVE_STRUCT_MSGHDR_MSG_FLAGS -- Performing Test HAVE_STRUCT_MSGHDR_MSG_FLAGS - Failed -- Checking C compiler flag -fvisibility=hidden -- Performing Test fvisibility-hidden -- Performing Test fvisibility-hidden - Success -- Lexical analyzer generator: /c/PPPwn_cpp-main/win_flex/win_flex.exe -- Parser generator: /c/PPPwn_cpp-main/win_flex/win_bison.exe -- Found PCAP: pcap_static -- Performing Test PCAP_LINKS_SOLO -- Performing Test PCAP_LINKS_SOLO - Failed -- Performing Test CMAKE_HAVE_LIBC_PTHREAD -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed -- Looking for pthread_create in pthreads -- Looking for pthread_create in pthreads - not found -- Looking for pthread_create in pthread -- Looking for pthread_create in pthread - not found -- Check if compiler accepts -pthread -- Check if compiler accepts -pthread - no -- Found Threads: TRUE -- Found Packet: C:/PPPwn_cpp-main/npcap-sdk/lib/x64/Packet.lib 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 (224.2s) CMake Error in CMakeLists.txt: Target "Pcap++" contains relative path in its INTERFACE_INCLUDE_DIRECTORIES:

"C:/PPPwn_cpp-main/npcap-sdk/include"

CMake Error in CMakeLists.txt: Target "pppwn_static" contains relative path in its INTERFACE_INCLUDE_DIRECTORIES:

"C:/PPPwn_cpp-main/npcap-sdk/include"

CMake Error in build/_deps/pcapplusplus-src/Pcap++/CMakeLists.txt: Target "Packet::Packet" contains relative path in its INTERFACE_INCLUDE_DIRECTORIES:

"C:/PPPwn_cpp-main/npcap-sdk/include"

CMake Error in build/_deps/pcapplusplus-src/Pcap++/CMakeLists.txt: Target "Packet::Packet" contains relative path in its INTERFACE_INCLUDE_DIRECTORIES:

"C:/PPPwn_cpp-main/npcap-sdk/include"

-- Generating done (1.7s) CMake Generate step failed. Build files cannot be regenerated correctly.`

xfangfang commented 1 month ago

@oresterosso75 As mentioned earlier, either use mingw32/64 for native compilation or cross compile with Linux(macOS, WSL...)

These two compilation methods have been confirmed, you can refer to the workflow.

I haven't tried running cmake directly in CMD for compilation, but it should be a little complex and require manual handling of dependency issues.

Maybe you can try changing the SDK path to: \C:\PPPwn_cpp-main\npcap-sdk or /C:\PPPwn_cpp-main\npcap-sdk