Added MSVC symbol demangling, switched to LLVM libs for demangling
This commit is contained in:
parent
f17d6c2359
commit
acc10930c2
@ -6,10 +6,16 @@ set(CMAKE_CXX_STANDARD 20)
|
|||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
pkg_search_module(GLFW REQUIRED glfw3)
|
pkg_search_module(GLFW REQUIRED glfw3)
|
||||||
pkg_search_module(GLM REQUIRED glm)
|
pkg_search_module(GLM REQUIRED glm)
|
||||||
|
pkg_search_module(CRYPTO REQUIRED libcrypto)
|
||||||
pkg_search_module(CAPSTONE REQUIRED capstone)
|
pkg_search_module(CAPSTONE REQUIRED capstone)
|
||||||
find_package(OpenGL REQUIRED)
|
find_package(OpenGL REQUIRED)
|
||||||
|
find_package(LLVM REQUIRED CONFIG)
|
||||||
|
|
||||||
|
llvm_map_components_to_libnames(demangler)
|
||||||
|
|
||||||
|
include_directories(include ${GLFW_INCLUDE_DIRS} ${CAPSTONE_INCLUDE_DIRS} ${LLVM_INCLUDE_DIRS} libs/ImGui/include libs/glad/include)
|
||||||
|
add_definitions(${LLVM_DEFINITIONS})
|
||||||
|
|
||||||
include_directories(include ${GLFW_INCLUDE_DIRS} ${CAPSTONE_INCLUDE_DIRS} libs/ImGui/include libs/glad/include)
|
|
||||||
SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -DIMGUI_IMPL_OPENGL_LOADER_GLAD")
|
SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -DIMGUI_IMPL_OPENGL_LOADER_GLAD")
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
@ -58,10 +64,12 @@ add_executable(ImHex
|
|||||||
resource.rc
|
resource.rc
|
||||||
)
|
)
|
||||||
|
|
||||||
|
llvm_map_components_to_libnames(LLVM_LIBRARIES Demangle)
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
target_link_libraries(ImHex libglfw3.a libgcc.a libstdc++.a libmagic.a libgnurx.a libtre.a libintl.a libiconv.a shlwapi.lib libcrypto.a libwinpthread.a libcapstone.a)
|
target_link_libraries(ImHex libglfw3.a libgcc.a libstdc++.a libmagic.a libgnurx.a libtre.a libintl.a libiconv.a shlwapi.lib libcrypto.a libwinpthread.a libcapstone.a ${LLVM_LIBRARIES})
|
||||||
endif (WIN32)
|
endif (WIN32)
|
||||||
|
|
||||||
if (UNIX)
|
if (UNIX)
|
||||||
target_link_libraries(ImHex libglfw.so libmagic.so libcrypto.so libdl.so libcapstone.so)
|
target_link_libraries(ImHex libglfw.so libmagic.so libcrypto.so libdl.so libcapstone.so ${LLVM_LIBRARIES})
|
||||||
endif (UNIX)
|
endif (UNIX)
|
@ -165,25 +165,6 @@ namespace hex {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string demangleItaniumSymbol(const std::string &mangledSymbol) {
|
|
||||||
size_t length = 0;
|
|
||||||
int status = 0;
|
|
||||||
char *demangledSymbol = abi::__cxa_demangle(mangledSymbol.c_str(), nullptr, &length, &status);
|
|
||||||
|
|
||||||
if (demangledSymbol == nullptr)
|
|
||||||
return "< ??? >";
|
|
||||||
|
|
||||||
std::string result = demangledSymbol;
|
|
||||||
|
|
||||||
free(demangledSymbol);
|
|
||||||
|
|
||||||
if (status != 0)
|
|
||||||
result = "< ??? >";
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class ScopeExit {
|
class ScopeExit {
|
||||||
public:
|
public:
|
||||||
ScopeExit(std::function<void()> func) : m_func(func) {}
|
ScopeExit(std::function<void()> func) : m_func(func) {}
|
||||||
|
@ -30,6 +30,11 @@ namespace hex {
|
|||||||
std::vector<FoundString> m_foundStrings;
|
std::vector<FoundString> m_foundStrings;
|
||||||
int m_minimumLength = 5;
|
int m_minimumLength = 5;
|
||||||
char *m_filter;
|
char *m_filter;
|
||||||
|
|
||||||
|
std::string m_selectedString;
|
||||||
|
std::string m_demangledName;
|
||||||
|
|
||||||
|
void createStringContextMenu(const FoundString &foundString);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#include <llvm/Demangle/Demangle.h>
|
||||||
|
|
||||||
using namespace std::literals::string_literals;
|
using namespace std::literals::string_literals;
|
||||||
|
|
||||||
namespace hex {
|
namespace hex {
|
||||||
@ -24,15 +26,21 @@ namespace hex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void createStringContextMenu(const FoundString &foundString) {
|
void ViewStrings::createStringContextMenu(const FoundString &foundString) {
|
||||||
if (ImGui::TableGetHoveredColumn() == 2 && ImGui::IsMouseReleased(1))
|
if (ImGui::TableGetHoveredColumn() == 2 && ImGui::IsMouseReleased(1) && ImGui::IsItemHovered()) {
|
||||||
ImGui::OpenPopup("StringContextMenu");
|
ImGui::OpenPopup("StringContextMenu");
|
||||||
|
this->m_selectedString = foundString.string;
|
||||||
|
}
|
||||||
if (ImGui::BeginPopup("StringContextMenu")) {
|
if (ImGui::BeginPopup("StringContextMenu")) {
|
||||||
if (ImGui::MenuItem("Copy string"))
|
if (ImGui::MenuItem("Copy string")) {
|
||||||
ImGui::SetClipboardText(foundString.string.c_str());
|
ImGui::SetClipboardText(this->m_selectedString.c_str());
|
||||||
|
}
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
if (ImGui::MenuItem("Copy demangled string"))
|
if (ImGui::MenuItem("Demangle")) {
|
||||||
ImGui::SetClipboardText(demangleItaniumSymbol(foundString.string).c_str());
|
this->m_demangledName = llvm::demangle(this->m_selectedString);
|
||||||
|
if (!this->m_demangledName.empty())
|
||||||
|
View::doLater([]{ ImGui::OpenPopup("Demangled Name"); });
|
||||||
|
}
|
||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -140,16 +148,15 @@ namespace hex {
|
|||||||
Region selectRegion = { foundString.offset, foundString.size };
|
Region selectRegion = { foundString.offset, foundString.size };
|
||||||
View::postEvent(Events::SelectionChangeRequest, &selectRegion);
|
View::postEvent(Events::SelectionChangeRequest, &selectRegion);
|
||||||
}
|
}
|
||||||
|
ImGui::PushID(i + 1);
|
||||||
|
createStringContextMenu(foundString);
|
||||||
|
ImGui::PopID();
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::Text("0x%08lx : 0x%08lx", foundString.offset, foundString.offset + foundString.size);
|
ImGui::Text("0x%08lx : 0x%08lx", foundString.offset, foundString.offset + foundString.size);
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
ImGui::Text("0x%04lx", foundString.size);
|
ImGui::Text("0x%04lx", foundString.size);
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
ImGui::Text("%s", foundString.string.c_str());
|
ImGui::Text("%s", foundString.string.c_str());
|
||||||
|
|
||||||
ImGui::PushID(i + 1);
|
|
||||||
createStringContextMenu(foundString);
|
|
||||||
ImGui::PopID();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
clipper.End();
|
clipper.End();
|
||||||
@ -159,6 +166,19 @@ namespace hex {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
|
if (ImGui::BeginPopup("Demangled Name")) {
|
||||||
|
if (ImGui::BeginChild("##scrolling", ImVec2(500, 150))) {
|
||||||
|
ImGui::Text("Demangled Name");
|
||||||
|
ImGui::Separator();
|
||||||
|
ImGui::TextWrapped("%s", this->m_demangledName.c_str());
|
||||||
|
ImGui::EndChild();
|
||||||
|
ImGui::NewLine();
|
||||||
|
if (ImGui::Button("Copy"))
|
||||||
|
ImGui::SetClipboardText(this->m_demangledName.c_str());
|
||||||
|
}
|
||||||
|
ImGui::EndPopup();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewStrings::createMenu() {
|
void ViewStrings::createMenu() {
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
#include "views/view_tools.hpp"
|
#include "views/view_tools.hpp"
|
||||||
|
|
||||||
#include <cxxabi.h>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
|
|
||||||
|
#include <llvm/Demangle/Demangle.h>
|
||||||
|
|
||||||
namespace hex {
|
namespace hex {
|
||||||
|
|
||||||
ViewTools::ViewTools() : View("Tools") {
|
ViewTools::ViewTools() : View("Tools") {
|
||||||
@ -30,9 +31,9 @@ namespace hex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ViewTools::drawDemangler() {
|
void ViewTools::drawDemangler() {
|
||||||
if (ImGui::CollapsingHeader("Itanium demangler")) {
|
if (ImGui::CollapsingHeader("Itanium/MSVC demangler")) {
|
||||||
if (ImGui::InputText("Mangled name", this->m_mangledBuffer, 0xF'FFFF)) {
|
if (ImGui::InputText("Mangled name", this->m_mangledBuffer, 0xF'FFFF)) {
|
||||||
this->m_demangledName = demangleItaniumSymbol(this->m_mangledBuffer);
|
this->m_demangledName = llvm::demangle(this->m_mangledBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::InputText("Demangled name", this->m_demangledName.data(), this->m_demangledName.size(), ImGuiInputTextFlags_ReadOnly);
|
ImGui::InputText("Demangled name", this->m_demangledName.data(), this->m_demangledName.size(), ImGuiInputTextFlags_ReadOnly);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user