1
0
Fork 0

Initial functional cmkr port

This commit is contained in:
Duncan Ogilvie 2021-06-19 17:29:20 +02:00
parent b4f55233d3
commit 84a18ab251
28 changed files with 1541 additions and 16 deletions

1061
CMakeLists.txt Normal file

File diff suppressed because it is too large Load Diff

224
cmake.toml Normal file
View File

@ -0,0 +1,224 @@
[cmake]
version = "3.15"
cmkr-include = "cmake/cmkr.cmake"
[project]
name = "x64dbg"
description = "An open-source x64/x32 debugger for windows."
include-before = [
"cmake/VSToolchain.cmake"
]
include-after = [
"cmake/Qt5Helpers.cmake",
"cmake/ParallelCompilation.cmake",
]
[conditions]
x86 = "CMAKE_SIZEOF_VOID_P EQUAL 4"
x64 = "CMAKE_SIZEOF_VOID_P EQUAL 8"
[find-package]
Qt5 = { components = ["Widgets", "Network", "WinExtras"] }
[target.zydis_wrapper]
type = "static"
sources = [
"src/zydis_wrapper/*.cpp",
"src/zydis_wrapper/*.h",
"src/zydis_wrapper/zydis/include/**.h",
"src/zydis_wrapper/zydis/src/*.c",
"src/zydis_wrapper/zydis/src/Generated/*.inc",
]
private-include-directories = [
"src/zydis_wrapper/zydis/src",
]
include-directories = [
"src/zydis_wrapper/zydis/include",
"src/zydis_wrapper",
]
[target.bridge]
type = "shared"
sources = [
"src/bridge/*.cpp",
"src/bridge/*.c",
"src/bridge/*.h",
]
private-compile-definitions = [
"BUILD_BRIDGE",
]
[target.bridge.properties]
x86.OUTPUT_NAME = "x32bridge"
x64.OUTPUT_NAME = "x64bridge"
[target.btparser]
type = "static"
sources = [
"src/dbg/btparser/btparser/lexer.cpp",
"src/dbg/btparser/btparser/parser.cpp",
"src/dbg/btparser/btparser/ast.h",
"src/dbg/btparser/btparser/helpers.h",
"src/dbg/btparser/btparser/keywords.h",
"src/dbg/btparser/btparser/lexer.h",
"src/dbg/btparser/btparser/operators.h",
"src/dbg/btparser/btparser/parser.h",
"src/dbg/btparser/btparser/testfiles.h ",
]
include-directories = [
"src/dbg/btparser",
]
[target.dbg]
type = "shared"
sources = [
"src/dbg/*.cpp",
"src/dbg/*.h",
"src/dbg/analysis/*.cpp",
"src/dbg/analysis/*.h",
"src/dbg/commands/*.cpp",
"src/dbg/commands/*.h",
"src/dbg/DeviceNameResolver/*.h",
"src/dbg/jansson/*.h",
"src/dbg/lz4/*.h",
"src/dbg/msdia/*.cpp",
"src/dbg/msdia/*.h",
"src/dbg/ntdll/*.h",
"src/dbg/TitanEngine/*.h",
"src/dbg/WinInet-Downloader/*.cpp",
"src/dbg/WinInet-Downloader/*.h",
"src/dbg/XEDParse/*.h",
]
private-link-libraries = [
"zydis_wrapper",
"bridge",
"btparser",
"Psapi",
"Shlwapi",
"Ws2_32",
]
x86.private-link-libraries = [
"${CMAKE_CURRENT_SOURCE_DIR}/src/dbg/dbghelp/dbghelp_x86.lib",
"${CMAKE_CURRENT_SOURCE_DIR}/src/dbg/DeviceNameResolver/DeviceNameResolver_x86.lib",
"${CMAKE_CURRENT_SOURCE_DIR}/src/dbg/jansson/jansson_x86.lib",
"${CMAKE_CURRENT_SOURCE_DIR}/src/dbg/lz4/lz4_x86.lib",
"${CMAKE_CURRENT_SOURCE_DIR}/src/dbg/ntdll/ntdll_x86.lib",
"${CMAKE_CURRENT_SOURCE_DIR}/src/dbg/TitanEngine/TitanEngine_x86.lib",
"${CMAKE_CURRENT_SOURCE_DIR}/src/dbg/XEDParse/XEDParse_x86.lib",
]
x64.private-link-libraries = [
"${CMAKE_CURRENT_SOURCE_DIR}/src/dbg/dbghelp/dbghelp_x64.lib",
"${CMAKE_CURRENT_SOURCE_DIR}/src/dbg/DeviceNameResolver/DeviceNameResolver_x64.lib",
"${CMAKE_CURRENT_SOURCE_DIR}/src/dbg/jansson/jansson_x64.lib",
"${CMAKE_CURRENT_SOURCE_DIR}/src/dbg/lz4/lz4_x64.lib",
"${CMAKE_CURRENT_SOURCE_DIR}/src/dbg/ntdll/ntdll_x64.lib",
"${CMAKE_CURRENT_SOURCE_DIR}/src/dbg/TitanEngine/TitanEngine_x64.lib",
"${CMAKE_CURRENT_SOURCE_DIR}/src/dbg/XEDParse/XEDParse_x64.lib",
]
private-compile-definitions = [
"BUILD_DBG",
]
private-include-directories = [
"src/dbg",
"src/dbg/analysis",
"src/dbg/commands",
]
[target.dbg.properties]
x86.OUTPUT_NAME = "x32dbg"
x64.OUTPUT_NAME = "x64dbg"
[target.gui]
type = "shared"
sources = [
"src/gui/**.cpp",
"src/gui/**.h",
"src/gui/**.ui",
"src/gui/**.qrc",
]
private-link-libraries = [
"Qt5::Widgets",
"Qt5::Network",
"Qt5::WinExtras",
"zydis_wrapper",
"bridge",
"winmm",
]
x86.private-link-libraries = [
"${CMAKE_CURRENT_SOURCE_DIR}/src/gui/Src/ThirdPartyLibs/ldconvert/ldconvert_x86.lib",
]
x64.private-link-libraries = [
"${CMAKE_CURRENT_SOURCE_DIR}/src/gui/Src/ThirdPartyLibs/ldconvert/ldconvert_x64.lib",
]
private-include-directories = [
"src",
"src/gui/Src",
"src/gui/Src/Gui",
"src/gui/Src/BasicView",
"src/gui/Src/Disassembler",
"src/gui/Src/Memory",
"src/gui/Src/Bridge",
"src/gui/Src/Global",
"src/gui/Src/Utils",
"src/gui/Src/ThirdPartyLibs/ldconvert",
]
private-compile-definitions = [
"BUILD_LIB",
"NOMINMAX",
]
cmake-after = """
# Enable Qt moc/rrc/uic support
target_qt(${CMKR_TARGET})
# Copy Qt DLLs next to the application
target_windeployqt(${CMKR_TARGET})
"""
[target.gui.properties]
x86.OUTPUT_NAME = "x32gui"
x64.OUTPUT_NAME = "x64gui"
[target.loaddll]
type = "executable"
sources = [
"src/loaddll/loaddll.cpp",
]
[target.exe]
type = "executable"
sources = [
"src/exe/*.cpp",
"src/exe/*.h",
"src/exe/manifest.xml",
"src/exe/resource.rc",
"src/exe/strings.rc",
]
x86.sources = ["src/exe/icon32.rc"]
x64.sources = ["src/exe/icon64.rc"]
link-libraries = [
"bridge",
]
[target.exe.properties]
x86.OUTPUT_NAME = "x32dbg"
x64.OUTPUT_NAME = "x64dbg"
x86.PDB_NAME = "x32dbg_exe"
x64.PDB_NAME = "x64dbg_exe"
WIN32_EXECUTABLE = "ON"
[target.launcher]
type = "executable"
condition = "x86"
sources = [
"src/launcher/*.cpp",
"src/exe/icon.rc",
"src/exe/resource.rc",
"src/exe/strings.rc",
]
link-libraries = [
"Shlwapi",
]
[target.launcher.properties]
OUTPUT_NAME = "x96dbg"
WIN32_EXECUTABLE = "ON"

View File

@ -0,0 +1,8 @@
# Visual Studio generator specific flags
if (CMAKE_GENERATOR MATCHES "Visual Studio")
# HACK: DO NOT this to add compiler flags/definitions, use target_compile_options on a
# target instead https://cmake.org/cmake/help/latest/command/target_compile_options.html
# Enable multiprocessor compilation
add_compile_options(/MP)
endif()

74
cmake/Qt5Helpers.cmake Normal file
View File

@ -0,0 +1,74 @@
# https://github.com/mrexodia/Qt5CMakeTemplate
# License: BSL-1.0
# Make the project look nicer in IDEs
set_property(GLOBAL PROPERTY AUTOGEN_SOURCE_GROUP "Generated Files")
set_property(GLOBAL PROPERTY AUTOGEN_TARGETS_FOLDER "CMakePredefinedTargets")
# Install Visual Studio runtime
include(InstallRequiredSystemLibraries)
# Helper function to enable moc/rcc/uic
function(target_qt target)
set_target_properties(${target} PROPERTIES
AUTOMOC
ON
AUTORCC
ON
AUTOUIC
ON
)
endfunction()
# Helper function to deploy Qt DLLs
function(target_windeployqt deploy_target)
# Based on: https://stackoverflow.com/a/41199492/1806760
# TODO: set VCINSTALLDIR environment variable to copy MSVC runtime DLLs
if(Qt5_FOUND AND WIN32 AND TARGET Qt5::qmake AND NOT TARGET Qt5::windeployqt)
get_target_property(_qt5_qmake_location Qt5::qmake IMPORTED_LOCATION)
execute_process(
COMMAND "${_qt5_qmake_location}" -query QT_INSTALL_PREFIX
RESULT_VARIABLE return_code
OUTPUT_VARIABLE qt5_install_prefix
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(imported_location "${qt5_install_prefix}/bin/windeployqt.exe")
if(EXISTS ${imported_location})
add_executable(Qt5::windeployqt IMPORTED)
set_target_properties(Qt5::windeployqt PROPERTIES
IMPORTED_LOCATION ${imported_location}
)
endif()
endif()
if(TARGET Qt5::windeployqt AND NOT TARGET ${deploy_target}-windeployqt)
# Create a target that rebuilds when cmake is re-run
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${deploy_target}-windeployqt.c" "static void foo() { }\n")
add_library(${deploy_target}-windeployqt STATIC
"${CMAKE_CURRENT_BINARY_DIR}/${deploy_target}-windeployqt.c"
)
set_target_properties(${deploy_target}-windeployqt PROPERTIES
FOLDER "CMakePredefinedTargets"
)
# Execute windeployqt in a tmp directory after build
add_custom_command(TARGET ${deploy_target}-windeployqt
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_CURRENT_BINARY_DIR}/${deploy_target}-windeployqt"
COMMAND Qt5::windeployqt --no-compiler-runtime --dir "${CMAKE_CURRENT_BINARY_DIR}/${deploy_target}-windeployqt" "$<TARGET_FILE:${deploy_target}>"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_BINARY_DIR}/${deploy_target}-windeployqt" "$<TARGET_FILE_DIR:${deploy_target}>"
)
# Copy deployment directory during installation
install(
DIRECTORY
"${CMAKE_CURRENT_BINARY_DIR}/${deploy_target}-windeployqt/"
DESTINATION bin
)
endif()
endfunction()

8
cmake/VSToolchain.cmake Normal file
View File

@ -0,0 +1,8 @@
# Set up a more familiar Visual Studio configuration
# Override these options with -DCMAKE_OPTION=Value
#
# See: https://cmake.org/cmake/help/latest/command/set.html#set-cache-entry
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/DEBUG:FULL /INCREMENTAL:NO /OPT:REF /OPT:ICF" CACHE STRING "")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "/DEBUG:FULL /INCREMENTAL:NO /OPT:REF /OPT:ICF" CACHE STRING "")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "")

162
cmake/cmkr.cmake Normal file
View File

@ -0,0 +1,162 @@
include_guard()
# Change these defaults to point to your infrastructure if desired
set(CMKR_REPO "https://github.com/build-cpp/cmkr" CACHE STRING "cmkr git repository" FORCE)
set(CMKR_TAG "archive_a718dfd6" CACHE STRING "cmkr git tag (this needs to be available forever)" FORCE)
# Set these from the command line to customize for development/debugging purposes
set(CMKR_EXECUTABLE "" CACHE FILEPATH "cmkr executable")
set(CMKR_SKIP_GENERATION OFF CACHE BOOL "skip automatic cmkr generation")
# Disable cmkr if generation is disabled
if(DEFINED ENV{CI} OR CMKR_SKIP_GENERATION)
message(STATUS "[cmkr] Skipping automatic cmkr generation")
macro(cmkr)
endmacro()
return()
endif()
# Disable cmkr if no cmake.toml file is found
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake.toml")
message(AUTHOR_WARNING "[cmkr] Not found: ${CMAKE_CURRENT_SOURCE_DIR}/cmake.toml")
macro(cmkr)
endmacro()
return()
endif()
# Convert a Windows native path to CMake path
if(CMKR_EXECUTABLE MATCHES "\\\\")
string(REPLACE "\\" "/" CMKR_EXECUTABLE_CMAKE "${CMKR_EXECUTABLE}")
set(CMKR_EXECUTABLE "${CMKR_EXECUTABLE_CMAKE}" CACHE FILEPATH "" FORCE)
unset(CMKR_EXECUTABLE_CMAKE)
endif()
# Helper macro to execute a process (COMMAND_ERROR_IS_FATAL ANY is 3.19 and higher)
function(cmkr_exec)
execute_process(COMMAND ${ARGV} RESULT_VARIABLE CMKR_EXEC_RESULT)
if(NOT CMKR_EXEC_RESULT EQUAL 0)
message(FATAL_ERROR "cmkr_exec(${ARGV}) failed (exit code ${CMKR_EXEC_RESULT})")
endif()
endfunction()
# Windows-specific hack (CMAKE_EXECUTABLE_PREFIX is not set at the moment)
if(WIN32)
set(CMKR_EXECUTABLE_NAME "cmkr.exe")
else()
set(CMKR_EXECUTABLE_NAME "cmkr")
endif()
# Use cached cmkr if found
set(CMKR_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/_cmkr_${CMKR_TAG}")
set(CMKR_CACHED_EXECUTABLE "${CMKR_DIRECTORY}/bin/${CMKR_EXECUTABLE_NAME}")
if(NOT CMKR_CACHED_EXECUTABLE STREQUAL CMKR_EXECUTABLE AND CMKR_EXECUTABLE MATCHES "^${CMAKE_CURRENT_BINARY_DIR}/_cmkr")
message(AUTHOR_WARNING "[cmkr] Upgrading '${CMKR_EXECUTABLE}' to '${CMKR_CACHED_EXECUTABLE}'")
unset(CMKR_EXECUTABLE CACHE)
endif()
if(CMKR_EXECUTABLE AND EXISTS "${CMKR_EXECUTABLE}")
message(VERBOSE "[cmkr] Found cmkr: '${CMKR_EXECUTABLE}'")
elseif(CMKR_EXECUTABLE AND NOT CMKR_EXECUTABLE STREQUAL CMKR_CACHED_EXECUTABLE)
message(FATAL_ERROR "[cmkr] '${CMKR_EXECUTABLE}' not found")
else()
set(CMKR_EXECUTABLE "${CMKR_CACHED_EXECUTABLE}" CACHE FILEPATH "Full path to cmkr executable" FORCE)
message(VERBOSE "[cmkr] Bootstrapping '${CMKR_EXECUTABLE}'")
message(STATUS "[cmkr] Fetching cmkr...")
if(EXISTS "${CMKR_DIRECTORY}")
cmkr_exec("${CMAKE_COMMAND}" -E rm -rf "${CMKR_DIRECTORY}")
endif()
find_package(Git QUIET REQUIRED)
cmkr_exec("${GIT_EXECUTABLE}"
clone
--config advice.detachedHead=false
--branch ${CMKR_TAG}
--depth 1
${CMKR_REPO}
"${CMKR_DIRECTORY}"
)
message(STATUS "[cmkr] Building cmkr...")
cmkr_exec("${CMAKE_COMMAND}"
--no-warn-unused-cli
"${CMKR_DIRECTORY}"
"-B${CMKR_DIRECTORY}/build"
"-DCMAKE_BUILD_TYPE=Release"
"-DCMAKE_INSTALL_PREFIX=${CMKR_DIRECTORY}"
"-DCMKR_GENERATE_DOCUMENTATION=OFF"
)
cmkr_exec("${CMAKE_COMMAND}"
--build "${CMKR_DIRECTORY}/build"
--config Release
--parallel
)
cmkr_exec("${CMAKE_COMMAND}"
--install "${CMKR_DIRECTORY}/build"
--config Release
--prefix "${CMKR_DIRECTORY}"
--component cmkr
)
if(NOT EXISTS ${CMKR_EXECUTABLE})
message(FATAL_ERROR "[cmkr] Failed to bootstrap '${CMKR_EXECUTABLE}'")
endif()
cmkr_exec("${CMKR_EXECUTABLE}" version)
message(STATUS "[cmkr] Bootstrapped ${CMKR_EXECUTABLE}")
endif()
execute_process(COMMAND "${CMKR_EXECUTABLE}" version
RESULT_VARIABLE CMKR_EXEC_RESULT
)
if(NOT CMKR_EXEC_RESULT EQUAL 0)
message(FATAL_ERROR "[cmkr] Failed to get version, try clearing the cache and rebuilding")
endif()
# This is the macro that contains black magic
macro(cmkr)
# When this macro is called from the generated file, fake some internal CMake variables
get_source_file_property(CMKR_CURRENT_LIST_FILE "${CMAKE_CURRENT_LIST_FILE}" CMKR_CURRENT_LIST_FILE)
if(CMKR_CURRENT_LIST_FILE)
set(CMAKE_CURRENT_LIST_FILE "${CMKR_CURRENT_LIST_FILE}")
get_filename_component(CMAKE_CURRENT_LIST_DIR "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY)
endif()
# File-based include guard (include_guard is not documented to work)
get_source_file_property(CMKR_INCLUDE_GUARD "${CMAKE_CURRENT_LIST_FILE}" CMKR_INCLUDE_GUARD)
if(NOT CMKR_INCLUDE_GUARD)
set_source_files_properties("${CMAKE_CURRENT_LIST_FILE}" PROPERTIES CMKR_INCLUDE_GUARD TRUE)
file(SHA256 "${CMAKE_CURRENT_LIST_FILE}" CMKR_LIST_FILE_SHA256_PRE)
# Generate CMakeLists.txt
cmkr_exec("${CMKR_EXECUTABLE}" gen
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
file(SHA256 "${CMAKE_CURRENT_LIST_FILE}" CMKR_LIST_FILE_SHA256_POST)
# Delete the temporary file if it was left for some reason
set(CMKR_TEMP_FILE "${CMAKE_CURRENT_SOURCE_DIR}/CMakerLists.txt")
if(EXISTS "${CMKR_TEMP_FILE}")
file(REMOVE "${CMKR_TEMP_FILE}")
endif()
if(NOT CMKR_LIST_FILE_SHA256_PRE STREQUAL CMKR_LIST_FILE_SHA256_POST)
# Copy the now-generated CMakeLists.txt to CMakerLists.txt
# This is done because you cannot include() a file you are currently in
configure_file(CMakeLists.txt "${CMKR_TEMP_FILE}" COPYONLY)
# Add the macro required for the hack at the start of the cmkr macro
set_source_files_properties("${CMKR_TEMP_FILE}" PROPERTIES
CMKR_CURRENT_LIST_FILE "${CMAKE_CURRENT_LIST_FILE}"
)
# 'Execute' the newly-generated CMakeLists.txt
include("${CMKR_TEMP_FILE}")
# Delete the generated file
file(REMOVE "${CMKR_TEMP_FILE}")
# Do not execute the rest of the original CMakeLists.txt
return()
endif()
# Resume executing the unmodified CMakeLists.txt
endif()
endmacro()

View File

@ -1,12 +0,0 @@
#include "_global.h"
#include "log.h"
log::log(void)
{
}
log::~log(void)
{
GuiAddLogMessage(message.str().c_str());
}

View File

@ -734,7 +734,7 @@ void HexEditDialog::printData(DataType type)
{
INETNTOPW InetNtopW;
int numIPs = mData.size() / 16;
HMODULE hWinsock = LoadLibrary(L"ws2_32.dll");
HMODULE hWinsock = LoadLibraryW(L"ws2_32.dll");
InetNtopW = INETNTOPW(GetProcAddress(hWinsock, "InetNtopW"));
if(InetNtopW)
{

View File

@ -2066,7 +2066,7 @@ void MainWindow::clickFavouriteTool()
}
mLastLogLabel->setText(toolPath);
PROCESS_INFORMATION procinfo;
STARTUPINFO startupinfo;
STARTUPINFOW startupinfo;
memset(&procinfo, 0, sizeof(PROCESS_INFORMATION));
memset(&startupinfo, 0, sizeof(startupinfo));
startupinfo.cb = sizeof(startupinfo);

View File

@ -165,7 +165,7 @@ QString getSymbolicNameStr(duint addr)
QIcon getFileIcon(QString file)
{
SHFILEINFO info;
SHFILEINFOW info;
if(SHGetFileInfoW((const wchar_t*)file.utf16(), 0, &info, sizeof(info), SHGFI_ICON) == 0)
return QIcon(); //API error
QIcon result = QIcon(QtWin::fromHICON(info.hIcon));

View File

@ -309,7 +309,7 @@ static void restartInstall()
ShellExecute(nullptr, operation, szModulePath, TEXT("::install"), szCurrentDir, SW_SHOWNORMAL);
}
static BOOL CALLBACK DlgLauncher(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
static INT_PTR CALLBACK DlgLauncher(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{