1
0
mirror of synced 2024-11-16 12:03:22 +01:00
ImHex/plugins/libimhex/source/api/imhex_api.cpp

86 lines
2.4 KiB
C++
Raw Normal View History

2021-01-20 20:16:24 +01:00
#include <hex/api/imhex_api.hpp>
#include <hex/api/event.hpp>
#include <hex/helpers/shared_data.hpp>
2021-08-21 15:03:44 +02:00
#include <unistd.h>
build/plugins: Added initial support for Rust plugins (#327) * build: Added initial support for Rust plugins * github: Install correct rust version * github: Fixed rustup command * github: Fix swapped win/linux commands * github: Install linux rust toolchain on Linux * github: Add rustup parameters to correct command * build: libimhex-rust -> hex * rust-plugins: Disable optimization to export functions correctly * build: Use cdylib instead of dylib * build: Fixed rust building and artifact copying * build: Fixed installing plugins * build: Fix copying and installing on Windows * github: Added windows debugging * github: Use curl instead of wget * github: Added debug on failure * github: Update path variable with rust toolchain path * build/github: Set rust location so cmake can find it * build: Remove leftovers * api: Added rust wrappers for the ImHexAPI * rust: Fixed compile flags with older gcc/clang * build: Enable concepts for cxx.rs * build: Explicitly set compiler for cxx.rs * rust: Added imgui-rs to libimhex-rust * rust: Export functions with double underscore prefix on mac * rust: Export functions adjusted for ABI * Add Rust target folder to gitignore * Add vendored imgui-rs copy * Add Context::current() to vendored imgui-rs * Fix libimhex not exporting cimgui symbols * Simplify plugin export mangling * build: Fixed cimgui linking * build: Only specify --export-all-symbols on Windows * Add context setting to Rust plugins * rust: Cleanup * deps: Update curl Co-authored-by: jam1garner <8260240+jam1garner@users.noreply.github.com>
2021-10-16 11:37:29 +02:00
#include <hex/helpers/logger.hpp>
2021-01-20 20:16:24 +01:00
namespace hex {
build/plugins: Added initial support for Rust plugins (#327) * build: Added initial support for Rust plugins * github: Install correct rust version * github: Fixed rustup command * github: Fix swapped win/linux commands * github: Install linux rust toolchain on Linux * github: Add rustup parameters to correct command * build: libimhex-rust -> hex * rust-plugins: Disable optimization to export functions correctly * build: Use cdylib instead of dylib * build: Fixed rust building and artifact copying * build: Fixed installing plugins * build: Fix copying and installing on Windows * github: Added windows debugging * github: Use curl instead of wget * github: Added debug on failure * github: Update path variable with rust toolchain path * build/github: Set rust location so cmake can find it * build: Remove leftovers * api: Added rust wrappers for the ImHexAPI * rust: Fixed compile flags with older gcc/clang * build: Enable concepts for cxx.rs * build: Explicitly set compiler for cxx.rs * rust: Added imgui-rs to libimhex-rust * rust: Export functions with double underscore prefix on mac * rust: Export functions adjusted for ABI * Add Rust target folder to gitignore * Add vendored imgui-rs copy * Add Context::current() to vendored imgui-rs * Fix libimhex not exporting cimgui symbols * Simplify plugin export mangling * build: Fixed cimgui linking * build: Only specify --export-all-symbols on Windows * Add context setting to Rust plugins * rust: Cleanup * deps: Update curl Co-authored-by: jam1garner <8260240+jam1garner@users.noreply.github.com>
2021-10-16 11:37:29 +02:00
void ImHexApi::Common::sayHello() {
log::warn("Hello!");
}
void ImHexApi::Common::closeImHex(bool noQuestions) {
EventManager::post<RequestCloseImHex>(noQuestions);
}
void ImHexApi::Common::restartImHex() {
EventManager::post<RequestCloseImHex>(false);
std::atexit([]{
execve(SharedData::mainArgv[0], SharedData::mainArgv, nullptr);
});
}
void ImHexApi::Bookmarks::add(Region region, const std::string &name, const std::string &comment, u32 color) {
2021-01-20 20:16:24 +01:00
Entry entry;
entry.region = region;
entry.name.reserve(name.length());
entry.comment.reserve(comment.length());
std::copy(name.begin(), name.end(), std::back_inserter(entry.name));
std::copy(comment.begin(), comment.end(), std::back_inserter(entry.comment));
entry.locked = false;
2021-01-20 20:16:24 +01:00
entry.color = color;
EventManager::post<RequestAddBookmark>(entry);
2021-01-20 20:16:24 +01:00
}
void ImHexApi::Bookmarks::add(u64 addr, size_t size, const std::string &name, const std::string &comment, u32 color) {
2021-01-20 20:16:24 +01:00
Bookmarks::add(Region{addr, size}, name, comment, color);
}
std::list<ImHexApi::Bookmarks::Entry>& ImHexApi::Bookmarks::getEntries() {
return SharedData::bookmarkEntries;
}
prv::Provider* ImHexApi::Provider::get() {
if (!ImHexApi::Provider::isValid())
return nullptr;
return SharedData::providers[SharedData::currentProvider];
}
const std::vector<prv::Provider*>& ImHexApi::Provider::getProviders() {
return SharedData::providers;
}
bool ImHexApi::Provider::isValid() {
return !SharedData::providers.empty();
}
void ImHexApi::Provider::add(prv::Provider *provider) {
SharedData::providers.push_back(provider);
SharedData::currentProvider = SharedData::providers.size() - 1;
}
void ImHexApi::Provider::remove(prv::Provider *provider) {
auto &providers = SharedData::providers;
auto it = std::find(providers.begin(), providers.end(), provider);
providers.erase(it);
if (it - providers.begin() == SharedData::currentProvider)
SharedData::currentProvider = 0;
delete provider;
}
2021-01-20 20:16:24 +01:00
}