diff --git a/.gitignore b/.gitignore index 2434a07e..cdd35713 100644 --- a/.gitignore +++ b/.gitignore @@ -14,7 +14,7 @@ # Compiled Dynamic libraries *.so *.dylib -*.dll +#*.dll # Fortran module files *.mod diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index e71e6fb6..3e3a93e5 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -196,12 +196,10 @@ endif() if (WIN32) add_custom_command(TARGET debuggercore PRE_LINK - COMMAND ${CMAKE_COMMAND} -E echo "Copying DbgEng Redistributable" - COMMAND ${CMAKE_COMMAND} -E make_directory ${BN_CORE_PLUGIN_DIR}/dbgeng - COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/adapters/dbgeng/X64 Debuggers And Tools-x64_en-us.msi" - ${BN_CORE_PLUGIN_DIR}/dbgeng - COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/adapters/dbgeng/X86 Debuggers And Tools-x86_en-us.msi" - ${BN_CORE_PLUGIN_DIR}/dbgeng + COMMAND ${CMAKE_COMMAND} -E echo "Copying DbgEng DLLs" + COMMAND ${CMAKE_COMMAND} -E copy_directory + "${PROJECT_SOURCE_DIR}/adapters/dbgeng/" + ${LIBRARY_OUTPUT_DIRECTORY_PATH}/dbgeng ) endif() diff --git a/core/adapters/dbgeng/X64 Debuggers And Tools-x64_en-us.msi b/core/adapters/dbgeng/X64 Debuggers And Tools-x64_en-us.msi deleted file mode 100644 index f030d8ed..00000000 Binary files a/core/adapters/dbgeng/X64 Debuggers And Tools-x64_en-us.msi and /dev/null differ diff --git a/core/adapters/dbgeng/X86 Debuggers And Tools-x86_en-us.msi b/core/adapters/dbgeng/X86 Debuggers And Tools-x86_en-us.msi deleted file mode 100644 index 04cdd583..00000000 Binary files a/core/adapters/dbgeng/X86 Debuggers And Tools-x86_en-us.msi and /dev/null differ diff --git a/core/adapters/dbgeng/amd64/dbgcore.dll b/core/adapters/dbgeng/amd64/dbgcore.dll new file mode 100644 index 00000000..3b63a07a Binary files /dev/null and b/core/adapters/dbgeng/amd64/dbgcore.dll differ diff --git a/core/adapters/dbgeng/amd64/dbgeng.dll b/core/adapters/dbgeng/amd64/dbgeng.dll new file mode 100644 index 00000000..9b133292 Binary files /dev/null and b/core/adapters/dbgeng/amd64/dbgeng.dll differ diff --git a/core/adapters/dbgeng/amd64/dbghelp.dll b/core/adapters/dbgeng/amd64/dbghelp.dll new file mode 100644 index 00000000..cad18551 Binary files /dev/null and b/core/adapters/dbgeng/amd64/dbghelp.dll differ diff --git a/core/adapters/dbgeng/amd64/dbgmodel.dll b/core/adapters/dbgeng/amd64/dbgmodel.dll new file mode 100644 index 00000000..9187bc76 Binary files /dev/null and b/core/adapters/dbgeng/amd64/dbgmodel.dll differ diff --git a/core/adapters/dbgeng/amd64/dbgsrv.exe b/core/adapters/dbgeng/amd64/dbgsrv.exe new file mode 100644 index 00000000..8a6aa652 Binary files /dev/null and b/core/adapters/dbgeng/amd64/dbgsrv.exe differ diff --git a/core/adapters/dbgeng/x86/dbgcore.dll b/core/adapters/dbgeng/x86/dbgcore.dll new file mode 100644 index 00000000..de7a8ba0 Binary files /dev/null and b/core/adapters/dbgeng/x86/dbgcore.dll differ diff --git a/core/adapters/dbgeng/x86/dbgeng.dll b/core/adapters/dbgeng/x86/dbgeng.dll new file mode 100644 index 00000000..b9ae8448 Binary files /dev/null and b/core/adapters/dbgeng/x86/dbgeng.dll differ diff --git a/core/adapters/dbgeng/x86/dbghelp.dll b/core/adapters/dbgeng/x86/dbghelp.dll new file mode 100644 index 00000000..c79b6db7 Binary files /dev/null and b/core/adapters/dbgeng/x86/dbghelp.dll differ diff --git a/core/adapters/dbgeng/x86/dbgmodel.dll b/core/adapters/dbgeng/x86/dbgmodel.dll new file mode 100644 index 00000000..2f64f165 Binary files /dev/null and b/core/adapters/dbgeng/x86/dbgmodel.dll differ diff --git a/core/adapters/dbgeng/x86/dbgsrv.exe b/core/adapters/dbgeng/x86/dbgsrv.exe new file mode 100644 index 00000000..a7b3610a Binary files /dev/null and b/core/adapters/dbgeng/x86/dbgsrv.exe differ diff --git a/core/adapters/dbgengadapter.cpp b/core/adapters/dbgengadapter.cpp index b66a0578..4813a073 100644 --- a/core/adapters/dbgengadapter.cpp +++ b/core/adapters/dbgengadapter.cpp @@ -68,7 +68,7 @@ static bool IsValidDbgEngPaths(const std::string& path) std::string DbgEngAdapter::GetDbgEngPath(const std::string& arch) { std::string path; - if (arch == "x64") + if (arch == "amd64") path = Settings::Instance()->Get("debugger.x64dbgEngPath"); else path = Settings::Instance()->Get("debugger.x86dbgEngPath"); @@ -84,21 +84,11 @@ std::string DbgEngAdapter::GetDbgEngPath(const std::string& arch) } // If the user does not specify a path (the default case), find the one from the %APPDATA% or %PROGRAMDATA% - char appData[MAX_PATH]; - // For a system installation, the path is %APPDATA%\Binary Ninja\dbgeng\Windows Kits\10\Debuggers - if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_APPDATA, NULL, 0, appData))) + char debuggerPath[MAX_PATH]; + HMODULE handle = GetModuleHandleA("debuggercore.dll"); + if (handle && (GetModuleFileNameA(handle, debuggerPath, MAX_PATH))) { - auto debuggerRoot = - filesystem::path(appData) / "Binary Ninja" / "dbgeng" / "Windows Kits" / "10" / "Debuggers" / arch; - if (IsValidDbgEngPaths(debuggerRoot.string())) - return debuggerRoot.string(); - } - - // For a system installation, the path is %PROGRAMDATA%\Binary Ninja\dbgeng\Windows Kits\10\Debuggers - if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_COMMON_APPDATA, NULL, 0, appData))) - { - auto debuggerRoot = - filesystem::path(appData) / "Binary Ninja" / "dbgeng" / "Windows Kits" / "10" / "Debuggers" / arch; + auto debuggerRoot = filesystem::path(debuggerPath).parent_path() / "dbgeng" / arch; if (IsValidDbgEngPaths(debuggerRoot.string())) return debuggerRoot.string(); } @@ -171,7 +161,7 @@ static bool LoadOneDLL(const string& path, const string& name, bool strictCheckP bool DbgEngAdapter::LoadDngEngLibraries() { - auto enginePath = GetDbgEngPath("x64"); + auto enginePath = GetDbgEngPath("amd64"); if (enginePath.empty()) { LogWarn("The debugger cannot find the path for the DbgEng DLLs. " @@ -289,7 +279,7 @@ bool DbgEngAdapter::Start() { auto pipeName = GenerateRandomPipeName(); auto connectString = fmt::format("npipe:pipe={},Server=localhost", pipeName); - auto arch = m_defaultArchitecture == "x86_64" ? "x64" : "x86"; + auto arch = m_defaultArchitecture == "x86_64" ? "amd64" : "x86"; auto enginePath = GetDbgEngPath(arch); if (enginePath.empty()) return false; diff --git a/ui/ui.cpp b/ui/ui.cpp index 757f3dd3..1fb21ebb 100644 --- a/ui/ui.cpp +++ b/ui/ui.cpp @@ -120,69 +120,6 @@ static void JumpToIPCallback(BinaryView* view, UIContext* context) frame->navigate(controller->GetData(), controller->IP(), true, true); } -#ifdef WIN32 - #include "msi.h" - #include - -static bool InstallDbgEngRedistributable() -{ - std::filesystem::path dbgEngPath; - if (getenv("BN_STANDALONE_DEBUGGER") != nullptr) - { - auto pluginsPath = BinaryNinja::GetUserPluginDirectory(); - if (pluginsPath.empty()) - return false; - - auto path = std::filesystem::path(pluginsPath); - dbgEngPath = path / "dbgeng"; - } - else - { - auto installPath = BinaryNinja::GetInstallDirectory(); - if (installPath.empty()) - return false; - - auto path = std::filesystem::path(installPath); - dbgEngPath = path / "plugins" / "dbgeng"; - } - - if (!std::filesystem::exists(dbgEngPath)) - { - LogWarn("path %d does not exists", dbgEngPath.string().c_str()); - return false; - } - - string cmdLine = "ACTION=ADMIN TARGETDIR="; - - char appData[MAX_PATH]; - if (!SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_APPDATA, NULL, 0, appData))) - return false; - - auto debuggerRoot = filesystem::path(appData) / "Binary Ninja" / "dbgeng"; - cmdLine = cmdLine + '"' + debuggerRoot.string() + '"'; - - auto x64Path = dbgEngPath / "X64 Debuggers And Tools-x64_en-us.msi"; - auto ret = MsiInstallProductA(x64Path.string().c_str(), cmdLine.c_str()); - if (ret != ERROR_SUCCESS) - return false; - - auto x86Path = dbgEngPath / "X86 Debuggers And Tools-x86_en-us.msi"; - ret = MsiInstallProductA((char*)x86Path.string().c_str(), cmdLine.c_str()); - if (ret != ERROR_SUCCESS) - return false; - - auto versionFilePath = debuggerRoot / "version.txt"; - auto file = fopen(versionFilePath.string().c_str(), "w"); - if (file == nullptr) - return false; - - const char* DEBUGGER_REDIST_VERSION = "10.0.22621.1"; - fwrite(DEBUGGER_REDIST_VERSION, 1, strlen(DEBUGGER_REDIST_VERSION), file); - fclose(file); - return true; -} -#endif - //static bool ShowAsCode(BinaryView* view, uint64_t addr) //{ @@ -886,24 +823,6 @@ void GlobalDebuggerUI::SetupMenu(UIContext* context) }, connectedAndStopped)); debuggerMenu->addAction("Force Update Memory Cache", "Misc"); - -#ifdef WIN32 - UIAction::registerAction("Reinstall DbgEng Redistributable"); - context->globalActions()->bindAction("Reinstall DbgEng Redistributable", UIAction([=](const UIActionContext& ctxt) { - if (!InstallDbgEngRedistributable()) - { - QMessageBox::warning(nullptr, QString("Failed to install"), - QString("Failed to install DbgEng redistributable. " - "The debugger is likely to malfunction")); - } - else - { - QMessageBox::warning( - nullptr, QString("Successfully installed"), QString("Successfully installed DbgEng redistributable.")); - } - })); - debuggerMenu->addAction("Reinstall DbgEng Redistributable", "Misc"); -#endif }