From 30091e0b50f8cde0a5ff1972bd00bb8711036812 Mon Sep 17 00:00:00 2001 From: "A. Challande" Date: Wed, 31 Mar 2021 10:56:41 +0200 Subject: [PATCH 1/4] feat: Add 64 bit compilation --- CMakeLists.txt | 7 +------ README.md | 10 ++++++++++ build.sh | 22 ++++++++++++---------- challenges/Azurad/CMakeLists.txt | 4 ++-- challenges/Blubber/CMakeLists.txt | 2 +- challenges/CML/CMakeLists.txt | 2 +- challenges/Charter/CMakeLists.txt | 2 +- challenges/FUN/lib/cgc_stdint.h | 9 +++++++-- challenges/FailAV/CMakeLists.txt | 2 +- challenges/Messaging/CMakeLists.txt | 2 +- challenges/PTaaS/CMakeLists.txt | 2 +- challenges/ValveChecks/CMakeLists.txt | 2 +- cmake/32.cmake | 21 +++++++++++++++++++++ cmake/64.cmake | 11 +++++++++++ 14 files changed, 71 insertions(+), 27 deletions(-) create mode 100644 cmake/32.cmake create mode 100644 cmake/64.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 816cb8166..a5e56676d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ # Using this min version for now cmake_minimum_required(VERSION 3.1) -project(challenge_sets) +project(challenge_sets C CXX) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Needed for newer challenges @@ -58,13 +58,8 @@ else(WIN32) -fcommon -w -g3 - -m32 ) - # Link everything 32-bit (until we have a 64-bit option) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32") - # Linker options # Dynamic by default option(BUILD_SHARED_LIBS "" ON) diff --git a/README.md b/README.md index 4761a307c..28ec000b3 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,16 @@ $ NO_PYTHON_I_KNOW_WHAT_I_AM_DOING_I_SWEAR=1 ./build.sh This is **not** a publicly supported build mode. +#### Build 32-bits version of the challenges +By default, the build system will build 64 bits version of the challenge. +However, by defining `BUILD32`, the build system will build 32-bits version of the challenge. + +```bash +$ BUILD32=1 ./build.sh +``` + +Note: This has only been tested on *Linux* + ### Windows The following packages are required for building the challenges on Windows: diff --git a/build.sh b/build.sh index 7c94cf4a2..5c395b7c8 100755 --- a/build.sh +++ b/build.sh @@ -14,20 +14,22 @@ if [[ -z "${NO_PYTHON_I_KNOW_WHAT_I_AM_DOING_I_SWEAR}" ]]; then fi fi -echo "Creating build directory" -mkdir -p "${DIR}/build" -cd "${DIR}/build" - echo "Creating Makefiles" CMAKE_OPTS="${CMAKE_OPTS} -DCMAKE_EXPORT_COMPILE_COMMANDS=ON" -# Honor CC and CXX environment variables, default to clang otherwise -CC=${CC:-clang} -CXX=${CXX:-clang++} +if [ -n "$BUILD32" ]; then + echo "Building32"; + CMAKE_OPTS="$CMAKE_OPTS -DCMAKE_TOOLCHAIN_FILE=../cmake/32.cmake" + BUILD_DIR="build32" +else + echo "Building64"; + CMAKE_OPTS="$CMAKE_OPTS -DCMAKE_TOOLCHAIN_FILE=../cmake/64.cmake" + BUILD_DIR="build64" +fi; -CMAKE_OPTS="$CMAKE_OPTS -DCMAKE_C_COMPILER=$CC" -CMAKE_OPTS="$CMAKE_OPTS -DCMAKE_ASM_COMPILER=$CC" -CMAKE_OPTS="$CMAKE_OPTS -DCMAKE_CXX_COMPILER=$CXX" +echo "Creating build directory" +mkdir -p "${DIR}/${BUILD_DIR}" +cd "${DIR}/${BUILD_DIR}" LINK=${LINK:-SHARED} case $LINK in diff --git a/challenges/Azurad/CMakeLists.txt b/challenges/Azurad/CMakeLists.txt index 3a35022bd..250b8691b 100644 --- a/challenges/Azurad/CMakeLists.txt +++ b/challenges/Azurad/CMakeLists.txt @@ -1,6 +1,6 @@ -add_compile_options( -fno-exceptions -fno-rtti -DCPLUSPLUS ) +add_compile_options( -fno-exceptions -fno-rtti -DCPLUSPLUS) set( SERVICE_ID "00119" ) set( AUTHOR_ID "KPRCA" ) -add_compile_options( -Oz -g ) +add_compile_options( -Os -g ) set( VULN_COUNT "1" ) buildCB() diff --git a/challenges/Blubber/CMakeLists.txt b/challenges/Blubber/CMakeLists.txt index 7ead51731..958bccfa4 100644 --- a/challenges/Blubber/CMakeLists.txt +++ b/challenges/Blubber/CMakeLists.txt @@ -1,6 +1,6 @@ add_compile_options( -fno-exceptions -fno-rtti -DCPLUSPLUS ) set( SERVICE_ID "00111" ) set( AUTHOR_ID "KPRCA" ) -add_compile_options( -O1 -g ) +add_compile_options( -O1 -g -fpermissive -fms-extensions ) set( VULN_COUNT "1" ) buildCB() diff --git a/challenges/CML/CMakeLists.txt b/challenges/CML/CMakeLists.txt index 42a9d4cda..c9b962026 100644 --- a/challenges/CML/CMakeLists.txt +++ b/challenges/CML/CMakeLists.txt @@ -1,4 +1,4 @@ -add_compile_options( -fno-exceptions -fno-rtti -DCPLUSPLUS ) +add_compile_options( -fno-exceptions -fno-rtti -DCPLUSPLUS -fpermissive -fms-extensions) set( SERVICE_ID "00097" ) set( AUTHOR_ID "KPRCA" ) add_compile_options( -O3 -g ) diff --git a/challenges/Charter/CMakeLists.txt b/challenges/Charter/CMakeLists.txt index 3d10e1768..b1644cd72 100644 --- a/challenges/Charter/CMakeLists.txt +++ b/challenges/Charter/CMakeLists.txt @@ -1,7 +1,7 @@ set( POLLS_TESTING_SEED "-710644949" ) set( POLLS_RELEASE_MAX_DEPTH "20" ) set( POLLS_RELEASE_SEED "40" ) -add_compile_options( -O0 -g -mno-sse -fblocks ) +add_compile_options( -O0 -g -msse2 -fblocks ) set( SERVICE_ID "00006" ) set( AUTHOR_ID "CROMU" ) set( NO_STRIP "1" ) diff --git a/challenges/FUN/lib/cgc_stdint.h b/challenges/FUN/lib/cgc_stdint.h index 56b0258b8..6558f21df 100644 --- a/challenges/FUN/lib/cgc_stdint.h +++ b/challenges/FUN/lib/cgc_stdint.h @@ -11,8 +11,13 @@ typedef unsigned short int uint16_t; typedef unsigned int uint32_t; typedef unsigned long long int uint64_t; -typedef int intptr_t; -typedef unsigned int uintptr_t; +#ifdef X32_COMPILE + typedef int32_t intptr_t; + typedef uint32_t uintptr_t; +#else + typedef int64_t intptr_t; + typedef uint64_t uintptr_t; +#endif # define __INT64_C(c) c ## LL # define __UINT64_C(c) c ## ULL diff --git a/challenges/FailAV/CMakeLists.txt b/challenges/FailAV/CMakeLists.txt index ed717c236..b3d2fbffd 100644 --- a/challenges/FailAV/CMakeLists.txt +++ b/challenges/FailAV/CMakeLists.txt @@ -1,7 +1,7 @@ set( VULN_COUNT "1" ) add_compile_options( -fno-exceptions -fno-rtti -DCPLUSPLUS ) set( override LDFLAGS "-nostdlib -static -Ttext=0x90000000" ) -add_compile_options( -Oz -g ) +add_compile_options( -Os -g -fpermissive -fms-extensions) set( SERVICE_ID "00091" ) set( AUTHOR_ID "KPRCA" ) buildCB() diff --git a/challenges/Messaging/CMakeLists.txt b/challenges/Messaging/CMakeLists.txt index 37af7b29b..41e416c96 100644 --- a/challenges/Messaging/CMakeLists.txt +++ b/challenges/Messaging/CMakeLists.txt @@ -1,6 +1,6 @@ add_compile_options( -fno-exceptions -fno-rtti -DCPLUSPLUS ) set( SERVICE_ID "00075" ) set( AUTHOR_ID "KPRCA" ) -add_compile_options( -O3 -g -DDISABLE_HEAP_GUARD ) +add_compile_options( -O3 -g -DDISABLE_HEAP_GUARD -fpermissive -fms-extensions ) set( VULN_COUNT "1" ) buildCB() diff --git a/challenges/PTaaS/CMakeLists.txt b/challenges/PTaaS/CMakeLists.txt index d1cfaa86b..0d05a44ef 100644 --- a/challenges/PTaaS/CMakeLists.txt +++ b/challenges/PTaaS/CMakeLists.txt @@ -1,6 +1,6 @@ set( SERVICE_ID "00054" ) set( AUTHOR_ID "NRFIN" ) -add_compile_options( -O0 -g -mno-sse ) +add_compile_options( -O0 -g -msse2 ) set( VULN_COUNT "1" ) buildCB() buildSO() diff --git a/challenges/ValveChecks/CMakeLists.txt b/challenges/ValveChecks/CMakeLists.txt index 93002d65f..2ab2b3411 100644 --- a/challenges/ValveChecks/CMakeLists.txt +++ b/challenges/ValveChecks/CMakeLists.txt @@ -1,6 +1,6 @@ set( POLLS_TESTING_SEED "1677617456" ) set( POLLS_RELEASE_SEED "1681795162" ) -add_compile_options( -mno-sse -O0 -g -fcommon ) +add_compile_options( -msse2 -O0 -g -fcommon ) set( SERVICE_ID "00016" ) set( AUTHOR_ID "NRFIN" ) set( POLLS_RELEASE_COUNT "1000" ) diff --git a/cmake/32.cmake b/cmake/32.cmake new file mode 100644 index 000000000..ca060ef1b --- /dev/null +++ b/cmake/32.cmake @@ -0,0 +1,21 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR i686) + +set(CMAKE_C_COMPILER clang) +set(CMAKE_CXX_COMPILER clang++) + +if(WIN32) + set(CMAKE_ASM_MASM_COMPILER clang) +else(WIN32) + set(CMAKE_ASM_COMPILER clang) +endif(WIN32) + +set(CMAKE_C_FLAGS_INIT -m32) +set(CMAKE_CXX_FLAGS_INIT -m32) +set(CMAKE_ASM_FLAGS_INIT -m32) + +set(CMAKE_EXE_LINKER_FLAGS_INIT -m32) +set(CMAKE_SHARED_LINKER_FLAGS_INIT -m32) +set(CMAKE_MODULE_LINKER_FLAGS_INIT -m32) + +add_compile_definitions(X32_COMPILE) \ No newline at end of file diff --git a/cmake/64.cmake b/cmake/64.cmake new file mode 100644 index 000000000..08501eef2 --- /dev/null +++ b/cmake/64.cmake @@ -0,0 +1,11 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR amd64) + +set(CMAKE_C_COMPILER clang) +set(CMAKE_CXX_COMPILER clang++) + +if(WIN32) + set(CMAKE_ASM_MASM_COMPILER clang) +else(WIN32) + set(CMAKE_ASM_COMPILER clang) +endif(WIN32) \ No newline at end of file From b798e06052d04af421bd742d2f4e17b299c1a6a1 Mon Sep 17 00:00:00 2001 From: "A. Challande" Date: Wed, 31 Mar 2021 11:00:25 +0200 Subject: [PATCH 2/4] fix: Support multiple host systems --- cmake/32.cmake | 1 - cmake/64.cmake | 1 - 2 files changed, 2 deletions(-) diff --git a/cmake/32.cmake b/cmake/32.cmake index ca060ef1b..5152981a6 100644 --- a/cmake/32.cmake +++ b/cmake/32.cmake @@ -1,4 +1,3 @@ -set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR i686) set(CMAKE_C_COMPILER clang) diff --git a/cmake/64.cmake b/cmake/64.cmake index 08501eef2..3dd6fa147 100644 --- a/cmake/64.cmake +++ b/cmake/64.cmake @@ -1,4 +1,3 @@ -set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR amd64) set(CMAKE_C_COMPILER clang) From ec72d483575b57c95bf647097d9cde9a7c68c9ce Mon Sep 17 00:00:00 2001 From: "A. Challande" Date: Wed, 31 Mar 2021 16:31:31 +0200 Subject: [PATCH 3/4] feat: Revert default build to 32bits --- README.md | 6 +++--- build.sh | 10 ++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 28ec000b3..5d3d9ca9b 100644 --- a/README.md +++ b/README.md @@ -74,11 +74,11 @@ $ NO_PYTHON_I_KNOW_WHAT_I_AM_DOING_I_SWEAR=1 ./build.sh This is **not** a publicly supported build mode. #### Build 32-bits version of the challenges -By default, the build system will build 64 bits version of the challenge. -However, by defining `BUILD32`, the build system will build 32-bits version of the challenge. +By default, the build system will build 32 bits version of the challenges. +However, by defining `BUILD64`, the build system will build 64-bits version of the challenges. ```bash -$ BUILD32=1 ./build.sh +$ BUILD64=1 ./build.sh ``` Note: This has only been tested on *Linux* diff --git a/build.sh b/build.sh index 5c395b7c8..c0d13056d 100755 --- a/build.sh +++ b/build.sh @@ -17,14 +17,12 @@ fi echo "Creating Makefiles" CMAKE_OPTS="${CMAKE_OPTS} -DCMAKE_EXPORT_COMPILE_COMMANDS=ON" -if [ -n "$BUILD32" ]; then - echo "Building32"; - CMAKE_OPTS="$CMAKE_OPTS -DCMAKE_TOOLCHAIN_FILE=../cmake/32.cmake" - BUILD_DIR="build32" -else - echo "Building64"; +if [ -n "$BUILD64" ]; then CMAKE_OPTS="$CMAKE_OPTS -DCMAKE_TOOLCHAIN_FILE=../cmake/64.cmake" BUILD_DIR="build64" +else + CMAKE_OPTS="$CMAKE_OPTS -DCMAKE_TOOLCHAIN_FILE=../cmake/32.cmake" + BUILD_DIR="build" fi; echo "Creating build directory" From 5c44cec546826ca023788264d66731c3f3cfee89 Mon Sep 17 00:00:00 2001 From: "A. Challande" Date: Wed, 31 Mar 2021 16:33:11 +0200 Subject: [PATCH 4/4] doc: Update README to reflect changes to default build type. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5d3d9ca9b..909080f81 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ $ NO_PYTHON_I_KNOW_WHAT_I_AM_DOING_I_SWEAR=1 ./build.sh This is **not** a publicly supported build mode. -#### Build 32-bits version of the challenges +#### Build 64-bits version of the challenges By default, the build system will build 32 bits version of the challenges. However, by defining `BUILD64`, the build system will build 64-bits version of the challenges.