Compare commits

..

7 Commits

14 changed files with 49 additions and 33 deletions

View File

@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.16)
# Updating the version here will update it throughout ImHex as well
set(IMHEX_VERSION "1.16.0")
set(IMHEX_VERSION "1.16.1")
project(imhex VERSION ${IMHEX_VERSION})
set(CMAKE_CXX_STANDARD 20)

View File

@@ -41,6 +41,9 @@ namespace hex::pl {
}
[[nodiscard]] std::unique_ptr<ASTNode> evaluate(Evaluator *evaluator) const override {
auto startOffset = evaluator->dataOffset();
ON_SCOPE_EXIT { evaluator->dataOffset() = startOffset; };
std::vector<Token::Literal> evaluatedParams;
for (auto &param : this->m_params) {
const auto expression = param->evaluate(evaluator)->evaluate(evaluator);

View File

@@ -48,9 +48,11 @@ namespace hex::pl {
evaluator->addCustomFunction(this->m_name, paramCount, [this](Evaluator *ctx, const std::vector<Token::Literal> &params) -> std::optional<Token::Literal> {
std::vector<std::shared_ptr<Pattern>> variables;
auto startOffset = ctx->dataOffset();
ctx->pushScope(nullptr, variables);
ON_SCOPE_EXIT {
ctx->popScope();
ctx->dataOffset() = startOffset;
};
if (this->m_parameterPack.has_value()) {

View File

@@ -16,9 +16,13 @@
namespace ImGui {
int UpdateStringSizeCallback(ImGuiInputTextCallbackData *data) {
auto &mathInput = *static_cast<std::string *>(data->UserData);
if (data->EventFlag == ImGuiInputTextFlags_CallbackResize) {
auto &string = *static_cast<std::string *>(data->UserData);
string.resize(data->BufSize);
data->Buf = string.data();
}
mathInput.resize(data->BufTextLen + 1);
return 0;
}

View File

@@ -55,8 +55,8 @@ namespace hex::plugin::builtin {
i64 m_gotoAddressRelative = 0;
bool m_gotoRequested = false;
char m_baseAddressBuffer[0x20] = { 0 };
u64 m_resizeSize = 0;
u64 m_baseAddress = 0;
u64 m_resizeSize = 0;
std::vector<u8> m_dataToSave;
std::set<pl::Pattern *> m_highlightedPatterns;
@@ -74,7 +74,7 @@ namespace hex::plugin::builtin {
void drawSearchPopup();
void drawSearchInput(std::vector<char> *currBuffer, ImGuiInputTextFlags flags);
void performSearch(char *buffer);
void performSearch(const char *buffer);
void performSearchNext();
void performSearchPrevious();
static int inputCallback(ImGuiInputTextCallbackData *data);

View File

@@ -139,7 +139,7 @@ namespace hex::plugin::builtin {
}
}
LogConsole::abortEvaluation("failed to find sequence");
return i128(-1);
});
/* read_unsigned(address, size) */

View File

@@ -314,7 +314,7 @@ namespace hex::plugin::builtin::prv {
#else
if (ImGui::InputText("hex.builtin.provider.disk.selected_disk"_lang, this->m_pathBuffer.data(), this->m_pathBuffer.capacity(), ImGuiInputTextFlags_CallbackResize, ImGui::UpdateStringSizeCallback, &this->m_pathBuffer))
if (ImGui::InputText("hex.builtin.provider.disk.selected_disk"_lang, this->m_pathBuffer.data(), this->m_pathBuffer.size(), ImGuiInputTextFlags_CallbackResize, ImGui::UpdateStringSizeCallback, &this->m_pathBuffer))
this->m_path = this->m_pathBuffer;
#endif

View File

@@ -297,7 +297,7 @@ namespace hex::plugin::builtin::prv {
void GDBProvider::drawLoadInterface() {
ImGui::InputText("hex.builtin.provider.gdb.ip"_lang, this->m_ipAddress.data(), this->m_ipAddress.capacity(), ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &this->m_ipAddress);
ImGui::InputText("hex.builtin.provider.gdb.ip"_lang, this->m_ipAddress.data(), this->m_ipAddress.size(), ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &this->m_ipAddress);
ImGui::InputInt("hex.builtin.provider.gdb.port"_lang, &this->m_port, 0, 0);
ImGui::Separator();

View File

@@ -230,7 +230,7 @@ namespace hex::plugin::builtin {
"hex.builtin.setting.font", "hex.builtin.setting.font.font_path", "", [](auto name, nlohmann::json &setting) {
fontPath = static_cast<std::string>(setting);
if (ImGui::InputText("##font_path", fontPath.data(), fontPath.capacity(), ImGuiInputTextFlags_CallbackResize, ImGui::UpdateStringSizeCallback, &fontPath)) {
if (ImGui::InputText("##font_path", fontPath.data(), fontPath.size(), ImGuiInputTextFlags_CallbackResize, ImGui::UpdateStringSizeCallback, &fontPath)) {
setting = fontPath;
return true;
}

View File

@@ -106,9 +106,9 @@ namespace hex::plugin::builtin {
static auto replacePattern = [] { std::string s; s.reserve(0xFFF); return s; }();
static auto regexOutput = [] { std::string s; s.reserve(0xFFF); return s; }();
bool changed1 = ImGui::InputText("hex.builtin.tools.regex_replacer.pattern"_lang, regexPattern.data(), regexPattern.capacity(), ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &regexPattern);
bool changed2 = ImGui::InputText("hex.builtin.tools.regex_replacer.replace"_lang, replacePattern.data(), replacePattern.capacity(), ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &replacePattern);
bool changed3 = ImGui::InputTextMultiline("hex.builtin.tools.regex_replacer.input"_lang, regexInput.data(), regexInput.capacity(), ImVec2(0, 0), ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &regexInput);
bool changed1 = ImGui::InputText("hex.builtin.tools.regex_replacer.pattern"_lang, regexPattern.data(), regexPattern.size(), ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &regexPattern);
bool changed2 = ImGui::InputText("hex.builtin.tools.regex_replacer.replace"_lang, replacePattern.data(), replacePattern.size(), ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &replacePattern);
bool changed3 = ImGui::InputTextMultiline("hex.builtin.tools.regex_replacer.input"_lang, regexInput.data(), regexInput.size(), ImVec2(0, 0), ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &regexInput);
if (changed1 || changed2 || changed3) {
try {
@@ -124,7 +124,7 @@ namespace hex::plugin::builtin {
static std::array<float, 4> pickedColor = { 0 };
ImGui::SetNextItemWidth(300.0F);
ImGui::ColorPicker4("hex.builtin.tools.color"_lang, pickedColor.data(), ImGuiColorEditFlags_Uint8 | ImGuiColorEditFlags_AlphaBar | ImGuiColorEditFlags_DisplayRGB | ImGuiColorEditFlags_DisplayHSV | ImGuiColorEditFlags_DisplayHex);
ImGui::ColorPicker4("hex.builtin.tools.color"_lang, pickedColor.data(), ImGuiColorEditFlags_Uint8 | ImGuiColorEditFlags_AlphaBar | ImGuiColorEditFlags_AlphaPreviewHalf | ImGuiColorEditFlags_DisplayRGB | ImGuiColorEditFlags_DisplayHSV | ImGuiColorEditFlags_DisplayHex);
ImGui::NewLine();
}
@@ -194,7 +194,8 @@ namespace hex::plugin::builtin {
return std::move(evaluator);
}();
enum class MathDisplayType {
enum class MathDisplayType
{
Standard,
Scientific,
Engineering,
@@ -414,7 +415,7 @@ namespace hex::plugin::builtin {
}
ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth());
if (ImGui::InputText("##input", mathInput.data(), mathInput.capacity(), ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &mathInput)) {
if (ImGui::InputText("##input", mathInput.data(), mathInput.size(), ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &mathInput)) {
ImGui::SetKeyboardFocusHere();
evaluate = true;
}
@@ -680,7 +681,7 @@ namespace hex::plugin::builtin {
bool startSearch;
startSearch = ImGui::InputText("##search", searchString.data(), searchString.capacity(), ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &searchString);
startSearch = ImGui::InputText("##search", searchString.data(), searchString.size(), ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &searchString);
ImGui::SameLine();
ImGui::BeginDisabled(searchProcess.valid() && searchProcess.wait_for(0s) != std::future_status::ready || searchString.empty());
@@ -746,7 +747,7 @@ namespace hex::plugin::builtin {
{
ImGui::TextUnformatted("hex.builtin.tools.file_tools.shredder.input"_lang);
ImGui::SameLine();
ImGui::InputText("##path", selectedFile.data(), selectedFile.capacity(), ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &selectedFile);
ImGui::InputText("##path", selectedFile.data(), selectedFile.size(), ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &selectedFile);
ImGui::SameLine();
if (ImGui::Button("...")) {
hex::openFileBrowser("hex.builtin.tools.file_tools.shredder.picker"_lang, DialogMode::Open, {}, [](const auto &path) {
@@ -888,7 +889,7 @@ namespace hex::plugin::builtin {
if (ImGui::BeginChild("split_settings", { 0, ImGui::GetTextLineHeightWithSpacing() * 7 }, true, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) {
ImGui::BeginDisabled(splitting);
{
ImGui::InputText("##path", selectedFile.data(), selectedFile.capacity(), ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &selectedFile);
ImGui::InputText("##path", selectedFile.data(), selectedFile.size(), ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &selectedFile);
ImGui::SameLine();
if (ImGui::Button("...##input")) {
hex::openFileBrowser("hex.builtin.tools.file_tools.splitter.picker.input"_lang, DialogMode::Open, {}, [](const auto &path) {
@@ -898,7 +899,7 @@ namespace hex::plugin::builtin {
ImGui::SameLine();
ImGui::TextUnformatted("hex.builtin.tools.file_tools.splitter.input"_lang);
ImGui::InputText("##base_path", baseOutputPath.data(), baseOutputPath.capacity(), ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &baseOutputPath);
ImGui::InputText("##base_path", baseOutputPath.data(), baseOutputPath.size(), ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &baseOutputPath);
ImGui::SameLine();
if (ImGui::Button("...##output")) {
hex::openFileBrowser("hex.builtin.tools.file_tools.splitter.picker.output"_lang, DialogMode::Save, {}, [](const auto &path) {
@@ -1051,7 +1052,7 @@ namespace hex::plugin::builtin {
ImGui::BeginDisabled(combining);
{
ImGui::InputText("##output_path", outputPath.data(), outputPath.capacity(), ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &outputPath);
ImGui::InputText("##output_path", outputPath.data(), outputPath.size(), ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &outputPath);
ImGui::SameLine();
if (ImGui::Button("...")) {
hex::openFileBrowser("hex.builtin.tools.file_tools.combiner.output.picker"_lang, DialogMode::Save, {}, [](const auto &path) {

View File

@@ -148,7 +148,7 @@ namespace hex::plugin::builtin {
if (locked)
ImGui::TextUnformatted(name.data());
else
ImGui::InputText("##nameInput", name.data(), name.capacity(), ImGuiInputTextFlags_CallbackResize, ImGui::UpdateStringSizeCallback, &name);
ImGui::InputText("##nameInput", name.data(), name.size(), ImGuiInputTextFlags_CallbackResize, ImGui::UpdateStringSizeCallback, &name);
ImGui::NewLine();
ImGui::TextUnformatted("hex.builtin.view.bookmarks.header.comment"_lang);
@@ -157,7 +157,7 @@ namespace hex::plugin::builtin {
if (locked)
ImGui::TextFormattedWrapped("{}", comment.data());
else
ImGui::InputTextMultiline("##commentInput", comment.data(), comment.capacity(), ImVec2(0, 0), ImGuiInputTextFlags_CallbackResize, ImGui::UpdateStringSizeCallback, &comment);
ImGui::InputTextMultiline("##commentInput", comment.data(), comment.size(), ImVec2(0, 0), ImGuiInputTextFlags_CallbackResize, ImGui::UpdateStringSizeCallback, &comment);
ImGui::NewLine();
}

View File

@@ -85,7 +85,7 @@ namespace hex::plugin::builtin {
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
ImGui::SetKeyboardFocusHere();
if (ImGui::InputText("##InspectorLineEditing", this->m_editingValue.data(), this->m_editingValue.capacity(), ImGuiInputTextFlags_CallbackResize | ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll, ImGui::UpdateStringSizeCallback, &this->m_editingValue)) {
if (ImGui::InputText("##InspectorLineEditing", this->m_editingValue.data(), this->m_editingValue.size(), ImGuiInputTextFlags_CallbackResize | ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll, ImGui::UpdateStringSizeCallback, &this->m_editingValue)) {
auto bytes = (*editingFunction)(this->m_editingValue, this->m_endian);
provider->write(this->m_startAddress, bytes.data(), bytes.size());

View File

@@ -330,12 +330,12 @@ namespace hex::plugin::builtin {
}
if (ImGui::BeginPopupModal("hex.builtin.view.hex_editor.menu.edit.set_base"_lang, nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::InputText("hex.builtin.common.address"_lang, this->m_baseAddressBuffer, 16, ImGuiInputTextFlags_CharsHexadecimal);
ImGui::InputHexadecimal("hex.builtin.common.address"_lang, &this->m_baseAddress, ImGuiInputTextFlags_CharsHexadecimal);
ImGui::NewLine();
confirmButtons(
"hex.builtin.common.set"_lang, "hex.builtin.common.cancel"_lang, [this, &provider] {
provider->setBaseAddress(strtoull(this->m_baseAddressBuffer, nullptr, 16));
provider->setBaseAddress(this->m_baseAddress);
ImGui::CloseCurrentPopup(); }, [] { ImGui::CloseCurrentPopup(); });
if (ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Escape)))
@@ -495,12 +495,15 @@ namespace hex::plugin::builtin {
static std::vector<std::pair<u64, u64>> findString(hex::prv::Provider *&provider, std::string string) {
std::vector<std::pair<u64, u64>> results;
if (string.empty())
return {};
u32 foundCharacters = 0;
std::vector<u8> buffer(1024, 0x00);
size_t dataSize = provider->getSize();
for (u64 offset = 0; offset < dataSize; offset += 1024) {
size_t usedBufferSize = std::min(u64(buffer.size()), dataSize - offset);
size_t usedBufferSize = std::min<size_t>({ buffer.size(), dataSize - offset, string.size() });
provider->read(offset + provider->getBaseAddress() + provider->getCurrentPageAddress(), buffer.data(), usedBufferSize);
for (u64 i = 0; i < usedBufferSize; i++) {
@@ -525,6 +528,9 @@ namespace hex::plugin::builtin {
if ((string.size() % 2) == 1)
string = "0" + string;
if (string.empty())
return {};
std::vector<u8> hex;
hex.reserve(string.size() / 2);
@@ -538,7 +544,7 @@ namespace hex::plugin::builtin {
std::vector<u8> buffer(1024, 0x00);
size_t dataSize = provider->getSize();
for (u64 offset = 0; offset < dataSize; offset += 1024) {
size_t usedBufferSize = std::min(u64(buffer.size()), dataSize - offset);
size_t usedBufferSize = std::min<size_t>({ buffer.size(), dataSize - offset, hex.size() });
provider->read(offset + provider->getBaseAddress() + provider->getCurrentPageAddress(), buffer.data(), usedBufferSize);
for (u64 i = 0; i < usedBufferSize; i++) {
@@ -574,7 +580,7 @@ namespace hex::plugin::builtin {
ImGui::EndTabItem();
}
void ViewHexEditor::performSearch(char *buffer) {
void ViewHexEditor::performSearch(const char *buffer) {
auto provider = ImHexApi::Provider::get();
*this->m_lastSearchBuffer = this->m_searchFunction(provider, buffer);
@@ -796,7 +802,7 @@ namespace hex::plugin::builtin {
ImGui::Separator();
if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.edit.bookmark"_lang, nullptr, false, this->m_memoryEditor.DataPreviewAddr != -1 && this->m_memoryEditor.DataPreviewAddrEnd != -1)) {
auto base = ImHexApi::Provider::get()->getBaseAddress();
auto base = provider->getBaseAddress();
size_t start = base + std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd);
size_t end = base + std::max(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd);
@@ -805,7 +811,7 @@ namespace hex::plugin::builtin {
}
if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.edit.set_base"_lang, nullptr, false, providerValid && provider->isReadable())) {
std::memset(this->m_baseAddressBuffer, 0x00, sizeof(this->m_baseAddressBuffer));
this->m_baseAddress = provider->getBaseAddress();
ImHexApi::Tasks::doLater([] { ImGui::OpenPopup("hex.builtin.view.hex_editor.menu.edit.set_base"_lang); });
}

View File

@@ -421,7 +421,7 @@ namespace hex::plugin::builtin {
ImGui::TableNextColumn();
ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth());
ImGui::InputText("###name", name.data(), name.capacity(), ImGuiInputTextFlags_CallbackResize, ImGui::UpdateStringSizeCallback, &name);
ImGui::InputText("###name", name.data(), name.size(), ImGuiInputTextFlags_CallbackResize, ImGui::UpdateStringSizeCallback, &name);
ImGui::PopItemWidth();
ImGui::TableNextColumn();
@@ -452,7 +452,7 @@ namespace hex::plugin::builtin {
case EnvVarType::String:
{
auto displayValue = hex::get_or<std::string>(value, "");
ImGui::InputText("###value", displayValue.data(), displayValue.capacity(), ImGuiInputTextFlags_CallbackResize, ImGui::UpdateStringSizeCallback, &displayValue);
ImGui::InputText("###value", displayValue.data(), displayValue.size(), ImGuiInputTextFlags_CallbackResize, ImGui::UpdateStringSizeCallback, &displayValue);
value = displayValue;
break;
}