My version of hexadecimal editor for the Dear ImGui
Features
- Automatically adjust visible bytes count depending on the window width
- Read-only mode
- Optional ascii display
- Separators support
- Support for lowercase bytes
- Keyboard navigation
- Custom read/write/name callbacks
- Render zeroes as disabled (idea from the ocronut's hex editor version)
- Custom highlighting (with automatic text contrast selection)
- Clipboard support
Example:
Note
Hex editor doesn't require you to implement callbacks at all.
static ImGuiHexEditorState hex_state;
hex_state.ReadCallback = [](ImGuiHexEditorState* state, size_t offset, void* buf, size_t size) -> size_t {
SIZE_T read;
ReadProcessMemory(GetCurrentProcess(), (char*)state->Bytes + offset, buf, size, &read);
return read;
};
hex_state.WriteCallback = [](ImGuiHexEditorState* state, size_t offset, void* buf, size_t size) -> size_t {
SIZE_T write;
WriteProcessMemory(GetCurrentProcess(), (char*)state->Bytes + offset, buf, size, &write);
return write;
};
hex_state.GetAddressNameCallback = [](ImGuiHexEditorState* state, size_t offset, char* buf, size_t size) -> bool
{
if (offset >= 0 && offset < sizeof(ImGuiIO))
{
snprintf(buf, size, "io+%0.*zX", 4, offset);
return true;
}
return false;
};
hex_state.SingleHighlightCallback = [](ImGuiHexEditorState* state, int offset, ImColor* color, ImColor* text_color, ImColor* border_color) -> ImGuiHexEditorHighlightFlags
{
if (offset >= 100 && offset <= 150)
{
*color = ImColor(user_highlight_color);
return ImGuiHexEditorHighlightFlags_Apply | ImGuiHexEditorHighlightFlags_TextAutomaticContrast | ImGuiHexEditorHighlightFlags_Ascii
| ImGuiHexEditorHighlightFlags_BorderAutomaticContrast;
}
return ImGuiHexEditorHighlightFlags_None;
};
hex_state.HighlightRanges.clear();
{
ImGuiHexEditorHighlightRange range;
range.From = 200;
range.To = 250;
range.Color = ImColor(user_highlight_color);
range.Flags = ImGuiHexEditorHighlightFlags_TextAutomaticContrast | ImGuiHexEditorHighlightFlags_FullSized
| ImGuiHexEditorHighlightFlags_Ascii | ImGuiHexEditorHighlightFlags_Border | ImGuiHexEditorHighlightFlags_BorderAutomaticContrast;
hex_state.HighlightRanges.push_back(range);
}
hex_state.Bytes = (void*)&ImGui::GetIO();
hex_state.MaxBytes = sizeof(ImGuiIO) + 0x1000;
ImGui::BeginHexEditor("##HexEditor", &hex_state);
ImGui::EndHexEditor();
TODO:
- Support for any amount of address chars for automatical bytes count selection.