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>
|
|
|
|
|
2021-10-16 11:37:29 +02:00
|
|
|
#include <hex/helpers/logger.hpp>
|
|
|
|
|
2021-01-20 20:16:24 +01:00
|
|
|
namespace hex {
|
|
|
|
|
2021-10-16 11:37:29 +02:00
|
|
|
void ImHexApi::Common::sayHello() {
|
|
|
|
log::warn("Hello!");
|
|
|
|
}
|
|
|
|
|
2021-08-21 13:55:21 +02:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
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));
|
2021-02-24 21:42:18 +01:00
|
|
|
entry.locked = false;
|
2021-01-20 20:16:24 +01:00
|
|
|
|
|
|
|
entry.color = color;
|
|
|
|
|
2021-03-27 11:36:36 +01:00
|
|
|
EventManager::post<RequestAddBookmark>(entry);
|
2021-01-20 20:16:24 +01:00
|
|
|
}
|
|
|
|
|
2021-09-08 15:18:24 +02: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;
|
|
|
|
}
|
|
|
|
|
2021-09-21 02:29:54 +02:00
|
|
|
|
|
|
|
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
|
|
|
}
|