provider: Added insert bytes feature
This commit is contained in:
parent
ee8b665472
commit
9ddd97a6eb
@ -28,7 +28,8 @@ namespace hex::prv {
|
||||
virtual void read(u64 offset, void *buffer, size_t size, bool overlays = true);
|
||||
virtual void write(u64 offset, const void *buffer, size_t size);
|
||||
|
||||
virtual void resize(ssize_t newSize);
|
||||
virtual void resize(size_t newSize);
|
||||
virtual void insert(u64 offset, size_t size);
|
||||
|
||||
virtual void save();
|
||||
virtual void saveAs(const fs::path &path);
|
||||
|
@ -34,7 +34,23 @@ namespace hex::prv {
|
||||
void Provider::save() { }
|
||||
void Provider::saveAs(const fs::path &path) { }
|
||||
|
||||
void Provider::resize(ssize_t newSize) { }
|
||||
void Provider::resize(size_t newSize) { }
|
||||
|
||||
void Provider::insert(u64 offset, size_t size) {
|
||||
auto &patches = getPatches();
|
||||
|
||||
std::vector<std::pair<u64, u8>> patchesToMove;
|
||||
|
||||
for (auto &[address, value] : patches) {
|
||||
if (address > offset)
|
||||
patchesToMove.emplace_back(address, value);
|
||||
}
|
||||
|
||||
for (const auto &[address, value] : patchesToMove)
|
||||
patches.erase(address);
|
||||
for (const auto &[address, value] : patchesToMove)
|
||||
patches.insert({ address + offset, value });
|
||||
}
|
||||
|
||||
void Provider::applyOverlays(u64 offset, void *buffer, size_t size) {
|
||||
for (auto &overlay : this->m_overlays) {
|
||||
|
@ -23,10 +23,10 @@
|
||||
|
||||
namespace hex {
|
||||
|
||||
static LONG_PTR oldWndProc;
|
||||
static float titleBarHeight;
|
||||
static ImGuiMouseCursor mouseCursorIcon;
|
||||
static BOOL compositionEnabled = false;
|
||||
static LONG_PTR g_oldWndProc;
|
||||
static float g_titleBarHeight;
|
||||
static ImGuiMouseCursor g_mouseCursorIcon;
|
||||
static BOOL g_compositionEnabled = false;
|
||||
|
||||
static LRESULT windowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
||||
switch (uMsg) {
|
||||
@ -37,7 +37,7 @@
|
||||
RECT &rect = *reinterpret_cast<RECT*>(lParam);
|
||||
RECT client = rect;
|
||||
|
||||
CallWindowProc((WNDPROC)oldWndProc, hwnd, uMsg, wParam, lParam);
|
||||
CallWindowProc((WNDPROC)g_oldWndProc, hwnd, uMsg, wParam, lParam);
|
||||
|
||||
if (IsMaximized(hwnd)) {
|
||||
WINDOWINFO windowInfo = { .cbSize = sizeof(WINDOWINFO) };
|
||||
@ -60,23 +60,23 @@
|
||||
switch (cursorPos) {
|
||||
case HTRIGHT:
|
||||
case HTLEFT:
|
||||
mouseCursorIcon = ImGuiMouseCursor_ResizeEW;
|
||||
g_mouseCursorIcon = ImGuiMouseCursor_ResizeEW;
|
||||
break;
|
||||
case HTTOP:
|
||||
case HTBOTTOM:
|
||||
mouseCursorIcon = ImGuiMouseCursor_ResizeNS;
|
||||
g_mouseCursorIcon = ImGuiMouseCursor_ResizeNS;
|
||||
break;
|
||||
case HTTOPLEFT:
|
||||
case HTBOTTOMRIGHT:
|
||||
mouseCursorIcon = ImGuiMouseCursor_ResizeNWSE;
|
||||
g_mouseCursorIcon = ImGuiMouseCursor_ResizeNWSE;
|
||||
break;
|
||||
case HTTOPRIGHT:
|
||||
case HTBOTTOMLEFT:
|
||||
mouseCursorIcon = ImGuiMouseCursor_ResizeNESW;
|
||||
g_mouseCursorIcon = ImGuiMouseCursor_ResizeNESW;
|
||||
break;
|
||||
case HTCAPTION:
|
||||
case HTCLIENT:
|
||||
mouseCursorIcon = ImGuiMouseCursor_None;
|
||||
g_mouseCursorIcon = ImGuiMouseCursor_None;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -129,7 +129,7 @@
|
||||
return HTBOTTOMRIGHT;
|
||||
case RegionClient:
|
||||
default:
|
||||
if ((cursor.y < (window.top + titleBarHeight * 2)) && !(ImGui::IsAnyItemHovered() || ImGui::IsPopupOpen(nullptr, ImGuiPopupFlags_AnyPopupId)))
|
||||
if ((cursor.y < (window.top + g_titleBarHeight * 2)) && !(ImGui::IsAnyItemHovered() || ImGui::IsPopupOpen(nullptr, ImGuiPopupFlags_AnyPopupId)))
|
||||
return HTCAPTION;
|
||||
else break;
|
||||
}
|
||||
@ -161,7 +161,7 @@
|
||||
default: break;
|
||||
}
|
||||
|
||||
return CallWindowProc((WNDPROC)oldWndProc, hwnd, uMsg, wParam, lParam);
|
||||
return CallWindowProc((WNDPROC)g_oldWndProc, hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
|
||||
@ -233,7 +233,7 @@
|
||||
// Setup borderless window
|
||||
auto hwnd = glfwGetWin32Window(this->m_window);
|
||||
|
||||
oldWndProc = ::SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)windowProc);
|
||||
g_oldWndProc = ::SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)windowProc);
|
||||
|
||||
MARGINS borderless = { 1, 1, 1, 1 };
|
||||
::DwmExtendFrameIntoClientArea(hwnd, &borderless);
|
||||
@ -266,12 +266,12 @@
|
||||
}
|
||||
|
||||
void Window::beginNativeWindowFrame() {
|
||||
titleBarHeight = ImGui::GetCurrentWindow()->MenuBarHeight();
|
||||
g_titleBarHeight = ImGui::GetCurrentWindow()->MenuBarHeight();
|
||||
}
|
||||
|
||||
void Window::endNativeWindowFrame() {
|
||||
if (mouseCursorIcon != ImGuiMouseCursor_None) {
|
||||
ImGui::SetMouseCursor(mouseCursorIcon);
|
||||
if (g_mouseCursorIcon != ImGuiMouseCursor_None) {
|
||||
ImGui::SetMouseCursor(g_mouseCursorIcon);
|
||||
}
|
||||
|
||||
switch (ImGui::GetMouseCursor()) {
|
||||
@ -310,7 +310,7 @@
|
||||
}
|
||||
|
||||
void Window::drawTitleBar() {
|
||||
auto buttonSize = ImVec2(titleBarHeight * 1.5F, titleBarHeight - 1);
|
||||
auto buttonSize = ImVec2(g_titleBarHeight * 1.5F, g_titleBarHeight - 1);
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetColorU32(ImGuiCol_MenuBarBg));
|
||||
|
@ -29,7 +29,9 @@ namespace hex::plugin::builtin::prv {
|
||||
|
||||
void read(u64 offset, void *buffer, size_t size, bool overlays) override;
|
||||
void write(u64 offset, const void *buffer, size_t size) override;
|
||||
void resize(ssize_t newSize) override;
|
||||
|
||||
void resize(size_t newSize) override;
|
||||
void insert(u64 offset, size_t size) override;
|
||||
|
||||
void readRaw(u64 offset, void *buffer, size_t size) override;
|
||||
void writeRaw(u64 offset, const void *buffer, size_t size) override;
|
||||
|
@ -22,7 +22,6 @@ class GDBProvider : public hex::prv::Provider {
|
||||
|
||||
void read(u64 offset, void *buffer, size_t size, bool overlays) override;
|
||||
void write(u64 offset, const void *buffer, size_t size) override;
|
||||
void resize(ssize_t newSize) override;
|
||||
|
||||
void readRaw(u64 offset, void *buffer, size_t size) override;
|
||||
void writeRaw(u64 offset, const void *buffer, size_t size) override;
|
||||
@ -48,6 +47,8 @@ class GDBProvider : public hex::prv::Provider {
|
||||
std::string m_ipAddress;
|
||||
int m_port;
|
||||
|
||||
u64 m_size;
|
||||
|
||||
constexpr static size_t CacheLineSize = 0x1000;
|
||||
|
||||
struct CacheLine {
|
||||
|
@ -101,16 +101,40 @@ namespace hex::plugin::builtin::prv {
|
||||
}
|
||||
}
|
||||
|
||||
void FileProvider::resize(ssize_t newSize) {
|
||||
void FileProvider::resize(size_t newSize) {
|
||||
this->close();
|
||||
|
||||
{
|
||||
File(this->m_path, File::Mode::Write).setSize(newSize);
|
||||
auto file = File(this->m_path, File::Mode::Write);
|
||||
|
||||
file.setSize(newSize);
|
||||
this->m_fileSize = file.getSize();
|
||||
}
|
||||
|
||||
this->open();
|
||||
}
|
||||
|
||||
void FileProvider::insert(u64 offset, size_t size) {
|
||||
auto oldSize = this->getActualSize();
|
||||
this->resize(oldSize + size);
|
||||
|
||||
std::vector<u8> buffer(0x1000);
|
||||
const std::vector<u8> zeroBuffer(0x1000);
|
||||
|
||||
auto position = oldSize;
|
||||
while (position > offset) {
|
||||
size_t readSize = (position >= (offset + buffer.size())) ? buffer.size() : (position - offset);
|
||||
|
||||
position -= readSize;
|
||||
|
||||
this->readRaw(position, buffer.data(), readSize);
|
||||
this->writeRaw(position, zeroBuffer.data(), readSize);
|
||||
this->writeRaw(position + size, buffer.data(), readSize);
|
||||
}
|
||||
|
||||
Provider::insert(offset, size);
|
||||
}
|
||||
|
||||
size_t FileProvider::getActualSize() const {
|
||||
return this->m_fileSize;
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ namespace hex::plugin::builtin::prv {
|
||||
|
||||
}
|
||||
|
||||
GDBProvider::GDBProvider() : Provider() {
|
||||
GDBProvider::GDBProvider() : Provider(), m_size(0xFFFF'FFFF) {
|
||||
|
||||
}
|
||||
|
||||
@ -218,12 +218,8 @@ namespace hex::plugin::builtin::prv {
|
||||
|
||||
}
|
||||
|
||||
void GDBProvider::resize(ssize_t newSize) {
|
||||
|
||||
}
|
||||
|
||||
size_t GDBProvider::getActualSize() const {
|
||||
return 0xFFFF'FFFF;
|
||||
return this->m_size;
|
||||
}
|
||||
|
||||
std::string GDBProvider::getName() const {
|
||||
@ -303,6 +299,12 @@ namespace hex::plugin::builtin::prv {
|
||||
ImGui::InputText("hex.builtin.provider.gdb.ip"_lang, this->m_ipAddress.data(), this->m_ipAddress.capacity(), ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &this->m_ipAddress);
|
||||
ImGui::InputInt("hex.builtin.provider.gdb.port"_lang, &this->m_port, 0, 0);
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::TextUnformatted("0x");
|
||||
ImGui::SameLine();
|
||||
ImGui::InputScalar("hex.common.size"_lang, ImGuiDataType_U64, &this->m_size, nullptr, nullptr, "%llx", ImGuiInputTextFlags_CharsHexadecimal);
|
||||
|
||||
if (this->m_port < 0)
|
||||
this->m_port = 0;
|
||||
else if (this->m_port > 0xFFFF)
|
||||
|
@ -317,16 +317,40 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
|
||||
if (ImGui::BeginPopupModal("hex.builtin.view.hexeditor.menu.edit.resize"_lang, nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
ImGui::InputScalar("hex.common.size"_lang, ImGuiDataType_U64, &this->m_resizeSize, nullptr, nullptr, "0x%016llx", ImGuiInputTextFlags_CharsHexadecimal);
|
||||
ImGui::TextUnformatted("0x");
|
||||
ImGui::SameLine();
|
||||
ImGui::InputScalar("hex.common.size"_lang, ImGuiDataType_U64, &this->m_resizeSize, nullptr, nullptr, "%llx", ImGuiInputTextFlags_CharsHexadecimal);
|
||||
ImGui::NewLine();
|
||||
|
||||
confirmButtons("hex.common.set"_lang, "hex.common.cancel"_lang,
|
||||
[this, &provider]{
|
||||
provider->resize(this->m_resizeSize);
|
||||
ImGui::CloseCurrentPopup();
|
||||
}, []{
|
||||
ImGui::CloseCurrentPopup();
|
||||
});
|
||||
[this, &provider]{
|
||||
provider->resize(this->m_resizeSize);
|
||||
ImGui::CloseCurrentPopup();
|
||||
},
|
||||
[] {
|
||||
ImGui::CloseCurrentPopup();
|
||||
});
|
||||
|
||||
if (ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Escape)))
|
||||
ImGui::CloseCurrentPopup();
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
if (ImGui::BeginPopupModal("hex.builtin.view.hexeditor.menu.edit.insert"_lang, nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
ImGui::TextUnformatted("0x");
|
||||
ImGui::SameLine();
|
||||
ImGui::InputScalar("hex.common.size"_lang, ImGuiDataType_U64, &this->m_resizeSize, nullptr, nullptr, "%llx", ImGuiInputTextFlags_CharsHexadecimal);
|
||||
ImGui::NewLine();
|
||||
|
||||
confirmButtons("hex.common.set"_lang, "hex.common.cancel"_lang,
|
||||
[this, &provider] {
|
||||
provider->insert(std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd), this->m_resizeSize);
|
||||
ImGui::CloseCurrentPopup();
|
||||
},
|
||||
[] {
|
||||
ImGui::CloseCurrentPopup();
|
||||
});
|
||||
|
||||
if (ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Escape)))
|
||||
ImGui::CloseCurrentPopup();
|
||||
@ -1010,6 +1034,13 @@ namespace hex::plugin::builtin {
|
||||
ImGui::OpenPopup("hex.builtin.view.hexeditor.menu.edit.resize"_lang);
|
||||
});
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.edit.insert"_lang, nullptr, false, providerValid && provider->isResizable())) {
|
||||
View::doLater([this]{
|
||||
this->m_resizeSize = 0;
|
||||
ImGui::OpenPopup("hex.builtin.view.hexeditor.menu.edit.insert"_lang);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void ViewHexEditor::registerEvents() {
|
||||
|
@ -244,7 +244,8 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.select_all", "Alles auswählen" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.bookmark", "Lesezeichen erstellen" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.set_base", "Basisadresse setzen" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.resize", "Grösse ändern" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.resize", "Grösse ändern..." },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.insert", "Einsetzen..." },
|
||||
|
||||
{ "hex.builtin.view.information.name", "Dateninformationen" },
|
||||
{ "hex.builtin.view.information.control", "Einstellungen" },
|
||||
|
@ -246,7 +246,8 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.select_all", "Select all" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.bookmark", "Create bookmark" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.set_base", "Set base address" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.resize", "Resize" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.resize", "Resize..." },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.insert", "Insert..." },
|
||||
|
||||
{ "hex.builtin.view.information.name", "Data Information" },
|
||||
{ "hex.builtin.view.information.control", "Control" },
|
||||
|
@ -243,7 +243,8 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.select_all", "Seleziona tutti" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.bookmark", "Crea segnalibro" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.set_base", "Imposta indirizzo di base" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.resize", "Ridimensiona" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.resize", "Ridimensiona..." },
|
||||
//{ "hex.builtin.view.hexeditor.menu.edit.insert", "Insert..." },
|
||||
|
||||
{ "hex.builtin.view.information.name", "Informazione sui Dati" },
|
||||
{ "hex.builtin.view.information.control", "Controllo" },
|
||||
|
@ -243,7 +243,8 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.select_all", "全选" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.bookmark", "添加书签" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.set_base", "设置基地址" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.resize", "修改大小" },
|
||||
{ "hex.builtin.view.hexeditor.menu.edit.resize", "修改大小..." },
|
||||
//{ "hex.builtin.view.hexeditor.menu.edit.insert", "Insert..." },
|
||||
|
||||
{ "hex.builtin.view.information.name", "数据信息" },
|
||||
{ "hex.builtin.view.information.control", "控制" },
|
||||
|
Loading…
x
Reference in New Issue
Block a user