Skip to content

Commit

Permalink
make selector copy only copy the addr itself
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvolton committed Jun 3, 2024
1 parent 8e096d3 commit 36400d3
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
5 changes: 3 additions & 2 deletions src/pages/Attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ void DevTools::drawNodeAttributes(CCNode* node) {
std::string addr = "N/A";
ImGui::Text("CCMenuItem selector: %s", addr.c_str());
} else {
const auto addr = formatAddressIntoOffset(addresser::getNonVirtual(selector));
const auto addr = formatAddressIntoOffset(addresser::getNonVirtual(selector), true);
ImGui::Text("CCMenuItem selector: %s", addr.c_str());
ImGui::SameLine();
if (ImGui::Button(U8STR(FEATHER_COPY " Copy##copymenuitem"))) {
clipboard::write(addr);
const auto addrNoModule = formatAddressIntoOffset(addresser::getNonVirtual(selector), false);
clipboard::write(addrNoModule);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/platform/Android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ using namespace geode::prelude;

#include "utils.hpp"

std::string formatAddressIntoOffsetImpl(uintptr_t addr) {
std::string formatAddressIntoOffsetImpl(uintptr_t addr, bool module) {
if (addr > base::get() && addr - 0x1000000 < base::get())
return fmt::format("libcocos2d.so + {:#x}", addr - base::get());
if(module) return fmt::format("libcocos2d.so + {:#x}", addr - base::get());
else return fmt::format("{:#x}", addr - base::get());
return fmt::format("{:#x}", addr);
}

Expand Down
5 changes: 3 additions & 2 deletions src/platform/Mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
return ghc::filesystem::path(imageName).filename().string();
}

std::string formatAddressIntoOffsetImpl(uintptr_t addr) {
std::string formatAddressIntoOffsetImpl(uintptr_t addr, bool module) {
auto image = imageFromAddress(reinterpret_cast<void const*>(addr));
std::string imageName;
uintptr_t base;
Expand All @@ -82,7 +82,8 @@
imageName = getImageName(image);
}

return fmt::format("{} + {:#x}", imageName, addr - base);
if(module) return fmt::format("{} + {:#x}", imageName, addr - base);
else return fmt::format("{:#x}", addr - base);
}

#endif
5 changes: 3 additions & 2 deletions src/platform/Win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class $modify(CCEGLView) {

#include "utils.hpp"

std::string formatAddressIntoOffsetImpl(uintptr_t addr) {
std::string formatAddressIntoOffsetImpl(uintptr_t addr, bool module) {
HMODULE mod;

if (!GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
Expand All @@ -62,7 +62,8 @@ std::string formatAddressIntoOffsetImpl(uintptr_t addr) {
wchar_t buffer[MAX_PATH];
std::string const module_name = (!mod || !GetModuleFileNameW(mod, buffer, MAX_PATH)) ? "Unknown" : std::filesystem::path(buffer).filename().string();

return fmt::format("{} + {:#x}", module_name, addr - reinterpret_cast<uintptr_t>(mod));
if(module) return fmt::format("{} + {:#x}", module_name, addr - reinterpret_cast<uintptr_t>(mod));
return fmt::format("{:#x}", addr - reinterpret_cast<uintptr_t>(mod));
}

#endif
16 changes: 10 additions & 6 deletions src/platform/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

#include <unordered_map>

std::string formatAddressIntoOffset(uintptr_t addr) {
static std::unordered_map<uintptr_t, std::string> formatted;
std::string formatAddressIntoOffset(uintptr_t addr, bool module) {
static std::unordered_map<uintptr_t, std::pair<std::string, std::string>> formatted;
auto it = formatted.find(addr);
if (it != formatted.end()) {
return it->second;
if(module) return it->second.first;
else return it->second.second;
} else {
auto const txt = formatAddressIntoOffsetImpl(addr);
formatted.insert({ addr, txt });
return txt;
auto const txt = formatAddressIntoOffsetImpl(addr, true);
auto const txtNoModule = formatAddressIntoOffsetImpl(addr, false);
auto const pair = std::make_pair(txt, txtNoModule);
formatted.insert({ addr, pair });
if(module) return pair.first;
else return pair.second;
}
}
4 changes: 2 additions & 2 deletions src/platform/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
#include <string>
#include <stdint.h>

std::string formatAddressIntoOffset(uintptr_t addr);
std::string formatAddressIntoOffset(uintptr_t addr, bool module);

std::string formatAddressIntoOffsetImpl(uintptr_t addr);
std::string formatAddressIntoOffsetImpl(uintptr_t addr, bool module);

0 comments on commit 36400d3

Please sign in to comment.