impr: Replace hex::unused with std::ignore

This commit is contained in:
WerWolv
2024-12-14 21:35:54 +01:00
parent 3f316e42f2
commit 7f75706584
43 changed files with 173 additions and 139 deletions

View File

@@ -212,7 +212,7 @@ namespace hex::plugin::builtin {
// Clear temporary achievements when the last provider is closed
EventProviderChanged::subscribe([](hex::prv::Provider *oldProvider, const hex::prv::Provider *newProvider) {
hex::unused(oldProvider);
std::ignore = oldProvider;
if (newProvider == nullptr) {
AchievementManager::clearTemporary();
}

View File

@@ -28,7 +28,7 @@ namespace hex::plugin::builtin {
using namespace hex::literals;
void handleVersionCommand(const std::vector<std::string> &args) {
hex::unused(args);
std::ignore = args;
hex::log::print(std::string(romfs::get("logo.ans").string()),
ImHexApi::System::getImHexVersion(),
@@ -40,7 +40,7 @@ namespace hex::plugin::builtin {
}
void handleHelpCommand(const std::vector<std::string> &args) {
hex::unused(args);
std::ignore = args;
hex::log::print(
"ImHex - A Hex Editor for Reverse Engineers, Programmers and people who value their retinas when working at 3 AM.\n"

View File

@@ -19,7 +19,7 @@ namespace hex::plugin::builtin {
~InformationProvider() override = default;
void process(Task &task, prv::Provider *provider, Region region) override {
hex::unused(task);
std::ignore = task;
m_provider = provider;
m_region = region;

View File

@@ -129,7 +129,8 @@ namespace hex::plugin::builtin {
ContentRegistry::DataInspector::add("hex.builtin.inspector.binary", sizeof(u8),
[](auto buffer, auto endian, auto style) {
hex::unused(endian, style);
std::ignore = endian;
std::ignore = style;
std::string binary = hex::format("0b{:08b}", buffer[0]);
@@ -138,7 +139,7 @@ namespace hex::plugin::builtin {
return binary;
};
}, [](const std::string &value, std::endian endian) -> std::vector<u8> {
hex::unused(endian);
std::ignore = endian;
std::string binary = value;
if (binary.starts_with("0b"))
@@ -269,7 +270,7 @@ namespace hex::plugin::builtin {
ContentRegistry::DataInspector::add("hex.builtin.inspector.sleb128", 1, (sizeof(i128) * 8 / 7) + 1,
[](auto buffer, auto endian, auto style) {
hex::unused(endian);
std::ignore = endian;
auto format = (style == Style::Decimal) ? "{0}{1:d}" : ((style == Style::Hexadecimal) ? "{0}0x{1:X}" : "{0}0o{1:o}");
@@ -281,7 +282,7 @@ namespace hex::plugin::builtin {
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
},
[](const std::string &value, std::endian endian) -> std::vector<u8> {
hex::unused(endian);
std::ignore = endian;
return hex::crypt::encodeSleb128(std::strtoll(value.c_str(), nullptr, 0));
}
@@ -289,7 +290,7 @@ namespace hex::plugin::builtin {
ContentRegistry::DataInspector::add("hex.builtin.inspector.uleb128", 1, (sizeof(u128) * 8 / 7) + 1,
[](auto buffer, auto endian, auto style) {
hex::unused(endian);
std::ignore = endian;
auto format = (style == Style::Decimal) ? "{0:d}" : ((style == Style::Hexadecimal) ? "0x{0:X}" : "0o{0:o}");
@@ -298,7 +299,7 @@ namespace hex::plugin::builtin {
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
},
[](const std::string &value, std::endian endian) -> std::vector<u8> {
hex::unused(endian);
std::ignore = endian;
return hex::crypt::encodeUleb128(std::strtoull(value.c_str(), nullptr, 0));
}
@@ -306,7 +307,8 @@ namespace hex::plugin::builtin {
ContentRegistry::DataInspector::add("hex.builtin.inspector.bool", sizeof(bool),
[](auto buffer, auto endian, auto style) {
hex::unused(endian, style);
std::ignore = endian;
std::ignore = style;
std::string value = [buffer] {
switch (buffer[0]) {
@@ -325,13 +327,14 @@ namespace hex::plugin::builtin {
ContentRegistry::DataInspector::add("hex.builtin.inspector.ascii", sizeof(char8_t),
[](auto buffer, auto endian, auto style) {
hex::unused(endian, style);
std::ignore = endian;
std::ignore = style;
auto value = makePrintable(*reinterpret_cast<char8_t *>(buffer.data()));
return [value] { ImGuiExt::TextFormatted("'{0}'", value.c_str()); return value; };
},
[](const std::string &value, std::endian endian) -> std::vector<u8> {
hex::unused(endian);
std::ignore = endian;
if (value.length() > 1) return { };
@@ -341,7 +344,7 @@ namespace hex::plugin::builtin {
ContentRegistry::DataInspector::add("hex.builtin.inspector.wide", sizeof(wchar_t),
[](auto buffer, auto endian, auto style) {
hex::unused(style);
std::ignore = style;
wchar_t wideChar = '\x00';
std::memcpy(&wideChar, buffer.data(), std::min(sizeof(wchar_t), buffer.size()));
@@ -369,7 +372,8 @@ namespace hex::plugin::builtin {
ContentRegistry::DataInspector::add("hex.builtin.inspector.utf8", sizeof(char8_t) * 4,
[](auto buffer, auto endian, auto style) {
hex::unused(endian, style);
std::ignore = endian;
std::ignore = style;
char utf8Buffer[5] = { 0 };
char codepointString[5] = { 0 };
@@ -391,7 +395,9 @@ namespace hex::plugin::builtin {
ContentRegistry::DataInspector::add("hex.builtin.inspector.string", 1,
[](auto buffer, auto endian, auto style) {
hex::unused(buffer, endian, style);
std::ignore = buffer;
std::ignore = endian;
std::ignore = style;
auto currSelection = ImHexApi::HexEditor::getSelection();
@@ -416,7 +422,7 @@ namespace hex::plugin::builtin {
return [value, copyValue] { ImGuiExt::TextFormatted("\"{0}\"", value.c_str()); return copyValue; };
},
[](const std::string &value, std::endian endian) -> std::vector<u8> {
hex::unused(endian);
std::ignore = endian;
return hex::decodeByteString(value);
}
@@ -424,7 +430,9 @@ namespace hex::plugin::builtin {
ContentRegistry::DataInspector::add("hex.builtin.inspector.string16", 2,
[](auto buffer, auto endian, auto style) {
hex::unused(buffer, endian, style);
std::ignore = buffer;
std::ignore = endian;
std::ignore = style;
auto currSelection = ImHexApi::HexEditor::getSelection();
@@ -456,7 +464,7 @@ namespace hex::plugin::builtin {
return [value, copyValue] { ImGuiExt::TextFormatted("L\"{0}\"", value.c_str()); return copyValue; };
},
[](const std::string &value, std::endian endian) -> std::vector<u8> {
hex::unused(endian);
std::ignore = endian;
return hex::decodeByteString(value);
}
@@ -465,7 +473,7 @@ namespace hex::plugin::builtin {
#if defined(OS_WINDOWS)
ContentRegistry::DataInspector::add("hex.builtin.inspector.time32", sizeof(u32), [](auto buffer, auto endian, auto style) {
hex::unused(style);
std::ignore = style;
auto endianAdjustedTime = hex::changeEndianness(*reinterpret_cast<u32 *>(buffer.data()), endian);
@@ -480,7 +488,7 @@ namespace hex::plugin::builtin {
});
ContentRegistry::DataInspector::add("hex.builtin.inspector.time64", sizeof(u64), [](auto buffer, auto endian, auto style) {
hex::unused(style);
std::ignore = style;
auto endianAdjustedTime = hex::changeEndianness(*reinterpret_cast<u64 *>(buffer.data()), endian);
@@ -497,7 +505,7 @@ namespace hex::plugin::builtin {
#else
ContentRegistry::DataInspector::add("hex.builtin.inspector.time", sizeof(time_t), [](auto buffer, auto endian, auto style) {
hex::unused(style);
std::ignore = style;
auto endianAdjustedTime = hex::changeEndianness(*reinterpret_cast<time_t *>(buffer.data()), endian);
@@ -526,7 +534,7 @@ namespace hex::plugin::builtin {
};
ContentRegistry::DataInspector::add("hex.builtin.inspector.dos_date", sizeof(DOSDate), [](auto buffer, auto endian, auto style) {
hex::unused(style);
std::ignore = style;
DOSDate date = { };
std::memcpy(&date, buffer.data(), sizeof(DOSDate));
@@ -538,7 +546,7 @@ namespace hex::plugin::builtin {
});
ContentRegistry::DataInspector::add("hex.builtin.inspector.dos_time", sizeof(DOSTime), [](auto buffer, auto endian, auto style) {
hex::unused(style);
std::ignore = style;
DOSTime time = { };
std::memcpy(&time, buffer.data(), sizeof(DOSTime));
@@ -550,7 +558,7 @@ namespace hex::plugin::builtin {
});
ContentRegistry::DataInspector::add("hex.builtin.inspector.guid", sizeof(GUID), [](auto buffer, auto endian, auto style) {
hex::unused(style);
std::ignore = style;
GUID guid = { };
std::memcpy(&guid, buffer.data(), sizeof(GUID));
@@ -572,7 +580,7 @@ namespace hex::plugin::builtin {
});
ContentRegistry::DataInspector::add("hex.builtin.inspector.rgba8", sizeof(u32), [](auto buffer, auto endian, auto style) {
hex::unused(style);
std::ignore = style;
ImColor value(hex::changeEndianness(*reinterpret_cast<u32 *>(buffer.data()), endian));
@@ -585,7 +593,7 @@ namespace hex::plugin::builtin {
});
ContentRegistry::DataInspector::add("hex.builtin.inspector.rgb565", sizeof(u16), [](auto buffer, auto endian, auto style) {
hex::unused(style);
std::ignore = style;
auto value = hex::changeEndianness(*reinterpret_cast<u16 *>(buffer.data()), endian);
ImColor color((value & 0x1F) << 3, ((value >> 5) & 0x3F) << 2, ((value >> 11) & 0x1F) << 3, 0xFF);

View File

@@ -16,7 +16,7 @@ namespace hex::plugin::builtin {
explicit DataVisualizerHexadecimal(const std::string &name) : DataVisualizer(name, ByteCount, CharCount) { }
void draw(u64 address, const u8 *data, size_t size, bool upperCase) override {
hex::unused(address);
std::ignore = address;
if (size == ByteCount)
ImGuiExt::TextFormatted(upperCase ? "{:0{}X}" : "{:0{}x}", *reinterpret_cast<const T*>(data), sizeof(T) * 2);
@@ -25,7 +25,8 @@ namespace hex::plugin::builtin {
}
bool drawEditing(u64 address, u8 *data, size_t size, bool upperCase, bool startedEditing) override {
hex::unused(address, startedEditing);
std::ignore = address;
std::ignore = startedEditing;
if (size == ByteCount) {
return drawDefaultScalarEditingTextBox(address, getFormatString(upperCase), ImGuiExt::getImGuiDataType<T>(), data, ImGuiInputTextFlags_CharsHexadecimal);
@@ -35,8 +36,8 @@ namespace hex::plugin::builtin {
}
private:
constexpr static inline auto ByteCount = sizeof(T);
constexpr static inline auto CharCount = ByteCount * 2;
constexpr static auto ByteCount = sizeof(T);
constexpr static auto CharCount = ByteCount * 2;
const static inline auto FormattingUpperCase = hex::format("%0{}{}X", CharCount, ImGuiExt::getFormatLengthSpecifier<T>());
const static inline auto FormattingLowerCase = hex::format("%0{}{}x", CharCount, ImGuiExt::getFormatLengthSpecifier<T>());
@@ -54,7 +55,7 @@ namespace hex::plugin::builtin {
DataVisualizerHexii() : DataVisualizer("hex.builtin.visualizer.hexii", ByteCount, CharCount) { }
void draw(u64 address, const u8 *data, size_t size, bool upperCase) override {
hex::unused(address);
std::ignore = address;
if (size == ByteCount) {
const u8 c = data[0];
@@ -78,7 +79,8 @@ namespace hex::plugin::builtin {
}
bool drawEditing(u64 address, u8 *data, size_t size, bool upperCase, bool startedEditing) override {
hex::unused(address, startedEditing);
std::ignore = address;
std::ignore = startedEditing;
if (size == ByteCount) {
return drawDefaultScalarEditingTextBox(address, getFormatString(upperCase), ImGuiExt::getImGuiDataType<u8>(), data, ImGuiInputTextFlags_CharsHexadecimal);
@@ -108,7 +110,8 @@ namespace hex::plugin::builtin {
explicit DataVisualizerDecimal(const std::string &name) : DataVisualizer(name, ByteCount, CharCount) { }
void draw(u64 address, const u8 *data, size_t size, bool upperCase) override {
hex::unused(address, upperCase);
std::ignore = address;
std::ignore = upperCase;
if (size == ByteCount) {
if (std::is_signed_v<T>)
@@ -121,7 +124,9 @@ namespace hex::plugin::builtin {
}
bool drawEditing(u64 address, u8 *data, size_t size, bool upperCase, bool startedEditing) override {
hex::unused(address, upperCase, startedEditing);
std::ignore = address;
std::ignore = upperCase;
std::ignore = startedEditing;
if (size == ByteCount) {
return drawDefaultScalarEditingTextBox(address, FormatString.c_str(), ImGuiExt::getImGuiDataType<T>(), data, ImGuiInputTextFlags_None);
@@ -131,8 +136,8 @@ namespace hex::plugin::builtin {
}
private:
constexpr static inline auto ByteCount = sizeof(T);
constexpr static inline auto CharCount = std::numeric_limits<T>::digits10 + 2;
constexpr static auto ByteCount = sizeof(T);
constexpr static auto CharCount = std::numeric_limits<T>::digits10 + 2;
const static inline auto FormatString = hex::format("%{}{}{}", CharCount, ImGuiExt::getFormatLengthSpecifier<T>(), std::is_signed_v<T> ? "d" : "u");
@@ -149,7 +154,7 @@ namespace hex::plugin::builtin {
explicit DataVisualizerFloatingPoint(const std::string &name) : DataVisualizer(name, ByteCount, CharCount) { }
void draw(u64 address, const u8 *data, size_t size, bool upperCase) override {
hex::unused(address);
std::ignore = address;
if (size == ByteCount)
ImGui::Text(getFormatString(upperCase), *reinterpret_cast<const T*>(data));
@@ -158,7 +163,9 @@ namespace hex::plugin::builtin {
}
bool drawEditing(u64 address, u8 *data, size_t size, bool upperCase, bool startedEditing) override {
hex::unused(address, upperCase, startedEditing);
std::ignore = address;
std::ignore = upperCase;
std::ignore = startedEditing;
if (size == ByteCount) {
return drawDefaultScalarEditingTextBox(address, getFormatString(upperCase), ImGuiExt::getImGuiDataType<T>(), data, ImGuiInputTextFlags_CharsScientific);
@@ -188,7 +195,7 @@ namespace hex::plugin::builtin {
explicit DataVisualizerFloatingPoint(const std::string &name) : DataVisualizer(name, ByteCount, CharCount) { }
void draw(u64 address, const u8 *data, size_t size, bool upperCase) override {
hex::unused(address);
std::ignore = address;
if (size == ByteCount)
ImGui::Text(getFormatString(upperCase), hex::float16ToFloat32(*reinterpret_cast<const u16*>(data)));
@@ -197,15 +204,15 @@ namespace hex::plugin::builtin {
}
bool drawEditing(u64 address, u8 *data, size_t size, bool upperCase, bool startedEditing) override {
hex::unused(startedEditing);
std::ignore = startedEditing;
this->draw(address, data, size, upperCase);
return false;
}
private:
constexpr static inline auto ByteCount = sizeof(Float16);
constexpr static inline auto CharCount = 14;
constexpr static auto ByteCount = sizeof(Float16);
constexpr static auto CharCount = 14;
const static inline auto FormatStringUpperCase = hex::format("%{}G", CharCount);
const static inline auto FormatStringLowerCase = hex::format("%{}g", CharCount);
@@ -223,7 +230,8 @@ namespace hex::plugin::builtin {
DataVisualizerRGBA8() : DataVisualizer("hex.builtin.visualizer.rgba8", 4, 2) { }
void draw(u64 address, const u8 *data, size_t size, bool upperCase) override {
hex::unused(address, upperCase);
std::ignore = address;
std::ignore = upperCase;
if (size == 4)
ImGui::ColorButton("##color", ImColor(data[0], data[1], data[2], data[3]), ImGuiColorEditFlags_AlphaPreview | ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_NoDragDrop, ImVec2(ImGui::GetColumnWidth(), ImGui::GetTextLineHeight()));
@@ -232,7 +240,10 @@ namespace hex::plugin::builtin {
}
bool drawEditing(u64 address, u8 *data, size_t size, bool upperCase, bool startedEditing) override {
hex::unused(address, data, size, upperCase);
std::ignore = address;
std::ignore = data;
std::ignore = size;
std::ignore = upperCase;
m_currColor = { float(data[0]) / 0xFF, float(data[1]) / 0xFF, float(data[2]) / 0xFF, float(data[3]) / 0xFF };
if (startedEditing) {
@@ -254,8 +265,8 @@ namespace hex::plugin::builtin {
return false;
}
std::array<float, 4> m_currColor = { 0 };
private:
std::array<float, 4> m_currColor = { };
};
class DataVisualizerBinary : public hex::ContentRegistry::HexEditor::DataVisualizer {
@@ -263,14 +274,15 @@ namespace hex::plugin::builtin {
DataVisualizerBinary() : DataVisualizer("hex.builtin.visualizer.binary", 1, 8) { }
void draw(u64 address, const u8 *data, size_t size, bool) override {
hex::unused(address);
std::ignore = address;
if (size == 1)
ImGuiExt::TextFormatted("{:08b}", *data);
}
bool drawEditing(u64 address, u8 *data, size_t, bool, bool startedEditing) override {
hex::unused(address, startedEditing);
std::ignore = address;
std::ignore = startedEditing;
if (startedEditing) {
m_inputBuffer = hex::format("{:08b}", *data);

View File

@@ -110,8 +110,8 @@ namespace hex::plugin::builtin {
});
EventProviderChanged::subscribe([](hex::prv::Provider *oldProvider, hex::prv::Provider *newProvider) {
hex::unused(oldProvider);
hex::unused(newProvider);
std::ignore = oldProvider;
std::ignore = newProvider;
RequestUpdateWindowTitle::post();
});

View File

@@ -185,7 +185,9 @@ namespace hex::plugin::builtin {
}
void IntelHexProvider::writeRaw(u64 offset, const void *buffer, size_t size) {
hex::unused(offset, buffer, size);
std::ignore = offset;
std::ignore = buffer;
std::ignore = size;
}
u64 IntelHexProvider::getActualSize() const {

View File

@@ -81,7 +81,7 @@ namespace hex::plugin::builtin {
};
auto read = process_vm_readv(m_processId, &local, 1, &remote, 1, 0);
hex::unused(read);
std::ignore = read;
#endif
}
void ProcessMemoryProvider::writeRaw(u64 address, const void *buffer, size_t size) {
@@ -107,7 +107,7 @@ namespace hex::plugin::builtin {
};
auto write = process_vm_writev(m_processId, &local, 1, &remote, 1, 0);
hex::unused(write);
std::ignore = write;
#endif
}

View File

@@ -28,7 +28,7 @@ namespace hex::plugin::builtin {
evaluator.setFunction(
"clear", [&](auto args) -> std::optional<long double> {
hex::unused(args);
std::ignore = args;
mathHistory.clear();
lastMathError.clear();

View File

@@ -60,7 +60,7 @@ namespace hex::plugin::builtin {
// Draw hex editor background highlights for bookmarks
ImHexApi::HexEditor::addBackgroundHighlightingProvider([this](u64 address, const u8* data, size_t size, bool) -> std::optional<color_t> {
hex::unused(data);
std::ignore = data;
// Check all bookmarks for potential overlaps with the current address
for (const auto &bookmark : *m_bookmarks) {
@@ -73,7 +73,7 @@ namespace hex::plugin::builtin {
// Draw hex editor tooltips for bookmarks
ImHexApi::HexEditor::addTooltipProvider([this](u64 address, const u8 *data, size_t size) {
hex::unused(data);
std::ignore = data;
// Loop over all bookmarks
for (const auto &[bookmark, editor] : *m_bookmarks) {

View File

@@ -21,7 +21,8 @@ namespace hex::plugin::builtin {
const static auto HighlightColor = [] { return (ImGuiExt::GetCustomColorU32(ImGuiCustomCol_FindHighlight) & 0x00FFFFFF) | 0x70000000; };
ImHexApi::HexEditor::addBackgroundHighlightingProvider([this](u64 address, const u8* data, size_t size, bool) -> std::optional<color_t> {
hex::unused(data, size);
std::ignore = data;
std::ignore = size;
if (m_searchTask.isRunning())
return { };
@@ -33,7 +34,8 @@ namespace hex::plugin::builtin {
});
ImHexApi::HexEditor::addTooltipProvider([this](u64 address, const u8* data, size_t size) {
hex::unused(data, size);
std::ignore = data;
std::ignore = size;
if (m_searchTask.isRunning())
return;

View File

@@ -44,7 +44,7 @@ namespace hex::plugin::builtin {
});
ImHexApi::HexEditor::addForegroundHighlightingProvider([this](u64 offset, const u8* buffer, size_t, bool) -> std::optional<color_t> {
hex::unused(buffer);
std::ignore = buffer;
if (!ImHexApi::Provider::isValid())
return std::nullopt;

View File

@@ -1535,7 +1535,7 @@ namespace hex::plugin::builtin {
auto mimeType = magic::getMIMEType(provider, 0, 100_KiB, true);
runtime.addPragma("MIME", [&mimeType, &foundCorrectType](const pl::PatternLanguage &runtime, const std::string &value) {
hex::unused(runtime);
std::ignore = runtime;
if (!magic::isValidMIMEType(value))
return false;
@@ -2191,7 +2191,8 @@ namespace hex::plugin::builtin {
});
ImHexApi::HexEditor::addBackgroundHighlightingProvider([this](u64 address, const u8 *data, size_t size, bool) -> std::optional<color_t> {
hex::unused(data, size);
std::ignore = data;
std::ignore = size;
if (m_runningEvaluators != 0)
return std::nullopt;
@@ -2232,7 +2233,8 @@ namespace hex::plugin::builtin {
});
ImHexApi::HexEditor::addTooltipProvider([this](u64 address, const u8 *data, size_t size) {
hex::unused(data, size);
std::ignore = data;
std::ignore = size;
if (TRY_LOCK(ContentRegistry::PatternLanguage::getRuntimeLock())) {
const auto &runtime = ContentRegistry::PatternLanguage::getRuntime();

View File

@@ -538,7 +538,7 @@ namespace hex::plugin::builtin {
// Clear project context if we go back to the welcome screen
EventProviderChanged::subscribe([](const hex::prv::Provider *oldProvider, const hex::prv::Provider *newProvider) {
hex::unused(oldProvider);
std::ignore = oldProvider;
if (newProvider == nullptr) {
ProjectFile::clearPath();
RequestUpdateWindowTitle::post();