From fba26074e9ae00f1c404c888561bfd9b5d70d89d Mon Sep 17 00:00:00 2001 From: visuve Date: Tue, 2 Apr 2024 19:09:14 +0300 Subject: [PATCH 1/2] Add support for Qt 6 --- .gitignore | 2 +- build_qt6.sh | 41 +++++++++++++++++++++++ commander/CMakeLists.txt | 7 ++-- parser/CMakeLists.txt | 7 ++-- parser/Formatter.cpp | 2 +- parser/include/bearparser/WatchedLocker.h | 5 +++ parser/pe/FileHdrWrapper.cpp | 6 +++- 7 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 build_qt6.sh diff --git a/.gitignore b/.gitignore index 522ed6d7d..dd65d761c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ build_qt5/ build_qt4/ test_cases/ docs/ - +.vs/ diff --git a/build_qt6.sh b/build_qt6.sh new file mode 100644 index 000000000..eb45c32e5 --- /dev/null +++ b/build_qt6.sh @@ -0,0 +1,41 @@ +#!/bin/bash +echo "Trying to autobuild bearparser..." + +#QT check + +QT_VER=$(qmake -v) +str=$QT_VER +substr="Qt version 6" + +echo "$QT_VER" +if [[ $str == *"$substr"* ]]; then + echo "[+] Qt6 found!" +else + str2=$(whereis qt6) + substr2="/qt6" + if [[ $str2 == *"$substr2"* ]]; then + echo "[+] Qt6 found!" + else + echo "Install Qt6 SDK first" + exit -1 + fi +fi + +CMAKE_VER=$(cmake --version) +CMAKEV="cmake version" +if echo "$CMAKE_VER" | grep -q "$CMAKEV"; then + echo "[+] CMake found!" +else + echo "[-] CMake NOT found!" + echo "Install cmake first" + exit -1 +fi + +BUILD_DIR=build + +mkdir $BUILD_DIR +echo "[+] build directory created" +cd $BUILD_DIR +cmake -G "CodeLite - Unix Makefiles" -DUSE_QT4=OFF -DCMAKE_INSTALL_PREFIX:PATH=$(pwd) .. +cmake --build . --target install + diff --git a/commander/CMakeLists.txt b/commander/CMakeLists.txt index 41f743b58..bc3e34283 100644 --- a/commander/CMakeLists.txt +++ b/commander/CMakeLists.txt @@ -7,8 +7,9 @@ if(USE_QT4) INCLUDE( ${QT_USE_FILE} ) ADD_DEFINITIONS( ${QT_DEFINITIONS} ) else() - find_package(Qt5Core REQUIRED) - get_target_property(QtCore_location Qt5::Core LOCATION) + find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED) + find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED) + get_target_property(QtCore_location Qt${QT_VERSION_MAJOR}::Core LOCATION) endif() set (imps_srcs @@ -30,7 +31,7 @@ target_link_libraries(${PROJECT_NAME} ${PARSER_LIB}) if(USE_QT4) target_link_libraries (${PROJECT_NAME} ${QT_QTCORE_LIBRARIES} ) else() - target_link_libraries(${PROJECT_NAME} Qt5::Core) + target_link_libraries(${PROJECT_NAME} Qt${QT_VERSION_MAJOR}::Core) endif() #install diff --git a/parser/CMakeLists.txt b/parser/CMakeLists.txt index e8852d411..ee274179f 100644 --- a/parser/CMakeLists.txt +++ b/parser/CMakeLists.txt @@ -11,8 +11,9 @@ if(USE_QT4) INCLUDE( ${QT_USE_FILE} ) ADD_DEFINITIONS( ${QT_DEFINITIONS} ) else() - find_package(Qt5Core REQUIRED) - get_target_property(QtCore_location Qt5::Core LOCATION) + find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED) + find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED) + get_target_property(QtCore_location Qt${QT_VERSION_MAJOR}::Core LOCATION) endif() include_directories (include/bearparser) @@ -157,7 +158,7 @@ target_include_directories(bearparser PUBLIC "${CMAKE_CURRENT_LIST_DIR}/include/ if(USE_QT4) target_link_libraries (bearparser ${QT_QTCORE_LIBRARIES} ) else() - target_link_libraries(bearparser Qt5::Core) + target_link_libraries(bearparser Qt${QT_VERSION_MAJOR}::Core) endif() diff --git a/parser/Formatter.cpp b/parser/Formatter.cpp index 5005fa2a8..5abc2421f 100644 --- a/parser/Formatter.cpp +++ b/parser/Formatter.cpp @@ -21,7 +21,7 @@ const QString Formatter::operator[](std::size_t idx) const } return "\\x"+ QString::number(b, 16).leftJustified(2,'0'); } - return QString(b); + return QChar(b); } /* diff --git a/parser/include/bearparser/WatchedLocker.h b/parser/include/bearparser/WatchedLocker.h index 85a18c584..a2b5f2205 100644 --- a/parser/include/bearparser/WatchedLocker.h +++ b/parser/include/bearparser/WatchedLocker.h @@ -3,7 +3,12 @@ #include #include + +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) +class WatchedLocker : public QMutexLocker { +#else class WatchedLocker : public QMutexLocker { +#endif public: WatchedLocker(QMutex *mutex, bool show = false, const char *func = nullptr) : QMutexLocker(mutex), showLock(show) diff --git a/parser/pe/FileHdrWrapper.cpp b/parser/pe/FileHdrWrapper.cpp index db1363aba..fd25eb551 100644 --- a/parser/pe/FileHdrWrapper.cpp +++ b/parser/pe/FileHdrWrapper.cpp @@ -9,7 +9,11 @@ namespace util { { const time_t rawtime = (const time_t)timestamp; QString format = "dddd, dd.MM.yyyy hh:mm:ss"; - QDateTime date1(QDateTime(QDateTime::fromTime_t(rawtime))); +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) + QDateTime date1(QDateTime::fromSecsSinceEpoch(rawtime)); +#else + QDateTime date1(QDateTime::fromTime_t(rawtime)); +#endif return date1.toUTC().toString(format) + " UTC"; } }; From 406829819b7cbd57e9f3349a683e7f7821f9feef Mon Sep 17 00:00:00 2001 From: visuve Date: Wed, 3 Apr 2024 21:57:41 +0300 Subject: [PATCH 2/2] Relax Qt minor version requirements See https://github.com/hasherezade/bearparser/pull/28 for more details --- parser/include/bearparser/WatchedLocker.h | 2 +- parser/pe/FileHdrWrapper.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/parser/include/bearparser/WatchedLocker.h b/parser/include/bearparser/WatchedLocker.h index a2b5f2205..44d7490d4 100644 --- a/parser/include/bearparser/WatchedLocker.h +++ b/parser/include/bearparser/WatchedLocker.h @@ -4,7 +4,7 @@ #include -#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) class WatchedLocker : public QMutexLocker { #else class WatchedLocker : public QMutexLocker { diff --git a/parser/pe/FileHdrWrapper.cpp b/parser/pe/FileHdrWrapper.cpp index fd25eb551..01ad12418 100644 --- a/parser/pe/FileHdrWrapper.cpp +++ b/parser/pe/FileHdrWrapper.cpp @@ -9,7 +9,7 @@ namespace util { { const time_t rawtime = (const time_t)timestamp; QString format = "dddd, dd.MM.yyyy hh:mm:ss"; -#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) QDateTime date1(QDateTime::fromSecsSinceEpoch(rawtime)); #else QDateTime date1(QDateTime::fromTime_t(rawtime));