Skip to content

Commit

Permalink
Update to latest DbgEng DLLs
Browse files Browse the repository at this point in the history
  • Loading branch information
xusheng6 committed Mar 22, 2024
1 parent 58f6f5b commit a125a23
Show file tree
Hide file tree
Showing 16 changed files with 12 additions and 105 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
#*.dll

# Fortran module files
*.mod
Expand Down
10 changes: 4 additions & 6 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Binary file not shown.
Binary file not shown.
Binary file added core/adapters/dbgeng/amd64/dbgcore.dll
Binary file not shown.
Binary file added core/adapters/dbgeng/amd64/dbgeng.dll
Binary file not shown.
Binary file added core/adapters/dbgeng/amd64/dbghelp.dll
Binary file not shown.
Binary file added core/adapters/dbgeng/amd64/dbgmodel.dll
Binary file not shown.
Binary file added core/adapters/dbgeng/amd64/dbgsrv.exe
Binary file not shown.
Binary file added core/adapters/dbgeng/x86/dbgcore.dll
Binary file not shown.
Binary file added core/adapters/dbgeng/x86/dbgeng.dll
Binary file not shown.
Binary file added core/adapters/dbgeng/x86/dbghelp.dll
Binary file not shown.
Binary file added core/adapters/dbgeng/x86/dbgmodel.dll
Binary file not shown.
Binary file added core/adapters/dbgeng/x86/dbgsrv.exe
Binary file not shown.
24 changes: 7 additions & 17 deletions core/adapters/dbgengadapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>("debugger.x64dbgEngPath");
else
path = Settings::Instance()->Get<string>("debugger.x86dbgEngPath");
Expand All @@ -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();
}
Expand Down Expand Up @@ -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. "
Expand Down Expand Up @@ -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;
Expand Down
81 changes: 0 additions & 81 deletions ui/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Shlobj.h>

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)
//{
Expand Down Expand Up @@ -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
}


Expand Down

0 comments on commit a125a23

Please sign in to comment.