sys: Enable -Wall, -Wextra, -Werror and fix all warnings on all Platforms (#483)

* sys: Make ImHex compile with -Wall -Wextra -Werror

* sys: Fixed various build errors on Linux

* sys: Explicitly ignore return value of `system` function

* sys: More fixes for the warnings GitHub Actions enables somehow

* sys: More fixes

* sys: Remove -Werror again to see all GitHub Actions warnings

* sys: Hopefully fixed all remaining warnings

* sys: Added back -Werror

* git: Change windows icon in GitHub Actions
This commit is contained in:
WerWolv
2022-03-27 00:01:28 +01:00
committed by GitHub
parent 965207d688
commit 0462cc3d0c
69 changed files with 502 additions and 370 deletions

View File

@@ -73,3 +73,4 @@ endif()
add_compile_definitions(IMHEX_PROJECT_NAME="${PROJECT_NAME}")
set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Werror)

View File

@@ -60,7 +60,7 @@ namespace hex::plugin::builtin::prv {
void *m_mappedFile = nullptr;
size_t m_fileSize = 0;
struct stat m_fileStats = { 0 };
struct stat m_fileStats = { };
bool m_fileStatsValid = false;
bool m_emptyFile = false;

View File

@@ -25,7 +25,7 @@ namespace hex::plugin::builtin {
bool m_greyedOutZeros = true;
bool m_upperCaseHex = true;
int m_columnCount = 16;
u32 m_columnCount = 16;
};
}

View File

@@ -58,9 +58,12 @@ namespace hex {
struct Token {
TokenType type;
long double number;
Operator op;
BracketType bracketType;
union {
long double number;
Operator op;
BracketType bracketType;
};
std::string name;
std::vector<long double> arguments;
};

View File

@@ -77,7 +77,7 @@ namespace hex::plugin::builtin {
result += hex::format("{0:08X} ", col << 4);
for (u64 i = 0; i < 16; i++) {
if (col == (offset >> 4) && i < (offset & 0xF) || col == (end >> 4) && i > (end & 0xF))
if ((col == (offset >> 4) && i < (offset & 0xF)) || (col == (end >> 4) && i > (end & 0xF)))
result += " ";
else
result += hex::format("{0:02X} ", buffer[((col << 4) - offset) + i]);
@@ -90,7 +90,7 @@ namespace hex::plugin::builtin {
for (u64 i = 0; i < 16; i++) {
if (col == (offset >> 4) && i < (offset & 0xF) || col == (end >> 4) && i > (end & 0xF))
if ((col == (offset >> 4) && i < (offset & 0xF)) || (col == (end >> 4) && i > (end & 0xF)))
result += " ";
else {
u8 c = buffer[((col << 4) - offset) + i];
@@ -129,7 +129,7 @@ namespace hex::plugin::builtin {
result += hex::format(" <span class=\"offsetcolumn\">{0:08X}</span>&nbsp&nbsp<span class=\"hexcolumn\">", col << 4);
for (u64 i = 0; i < 16; i++) {
if (col == (offset >> 4) && i < (offset & 0xF) || col == (end >> 4) && i > (end & 0xF))
if ((col == (offset >> 4) && i < (offset & 0xF)) || (col == (end >> 4) && i > (end & 0xF)))
result += "&nbsp&nbsp ";
else
result += hex::format("{0:02X} ", buffer[((col << 4) - offset) + i]);
@@ -142,7 +142,7 @@ namespace hex::plugin::builtin {
for (u64 i = 0; i < 16; i++) {
if (col == (offset >> 4) && i < (offset & 0xF) || col == (end >> 4) && i > (end & 0xF))
if ((col == (offset >> 4) && i < (offset & 0xF)) || (col == (end >> 4) && i > (end & 0xF)))
result += "&nbsp";
else {
u8 c = buffer[((col << 4) - offset) + i];

View File

@@ -82,6 +82,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::string binary = "0b";
for (u8 i = 0; i < 8; i++)
binary += ((buffer[0] << i) & 0x80) == 0 ? '0' : '1';
@@ -91,6 +93,7 @@ namespace hex::plugin::builtin {
return binary;
};
}, [](std::string value, std::endian endian) -> std::vector<u8> {
hex::unused(endian);
if (value.starts_with("0b"))
value = value.substr(2);
@@ -113,6 +116,8 @@ namespace hex::plugin::builtin {
ContentRegistry::DataInspector::add("hex.builtin.inspector.u8", sizeof(u8),
[](auto buffer, auto endian, auto style) {
hex::unused(endian);
auto format = (style == Style::Decimal) ? "{0:d}" : ((style == Style::Hexadecimal) ? "0x{0:02X}" : "0o{0:03o}");
auto value = hex::format(format, *reinterpret_cast<u8 *>(buffer.data()));
@@ -209,6 +214,7 @@ namespace hex::plugin::builtin {
ContentRegistry::DataInspector::add("hex.builtin.inspector.float16", sizeof(u16),
[](auto buffer, auto endian, auto style) {
hex::unused(style);
auto value = hex::format("{0:G}", hex::changeEndianess(float16ToFloat32(*reinterpret_cast<u16 *>(buffer.data())), endian));
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
}
@@ -216,6 +222,8 @@ namespace hex::plugin::builtin {
ContentRegistry::DataInspector::add("hex.builtin.inspector.float", sizeof(float),
[](auto buffer, auto endian, auto style) {
hex::unused(style);
auto value = hex::format("{0:G}", hex::changeEndianess(*reinterpret_cast<float *>(buffer.data()), endian));
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
},
@@ -224,7 +232,12 @@ namespace hex::plugin::builtin {
ContentRegistry::DataInspector::add("hex.builtin.inspector.double", sizeof(double),
[](auto buffer, auto endian, auto style) {
auto value = hex::format("{0:G}", hex::changeEndianess(*reinterpret_cast<double *>(buffer.data()), endian));
hex::unused(style);
double result = 0;
std::memcpy(&result, buffer.data(), sizeof(double));
auto value = hex::format("{0:G}", hex::changeEndianess(result, endian));
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
},
stringToFloat<double>
@@ -232,6 +245,8 @@ namespace hex::plugin::builtin {
ContentRegistry::DataInspector::add("hex.builtin.inspector.long_double", sizeof(long double),
[](auto buffer, auto endian, auto style) {
hex::unused(style);
auto value = hex::format("{0:G}", hex::changeEndianess(*reinterpret_cast<long double *>(buffer.data()), endian));
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
},
@@ -240,10 +255,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);
auto value = makePrintable(*reinterpret_cast<char8_t *>(buffer.data()));
return [value] { ImGui::TextFormatted("'{0}'", value.c_str()); return value; };
},
[](const std::string &value, std::endian endian) -> std::vector<u8> {
hex::unused(endian);
if (value.length() > 1) return { };
return { u8(value[0]) };
@@ -252,6 +271,8 @@ namespace hex::plugin::builtin {
ContentRegistry::DataInspector::add("hex.builtin.inspector.wide", sizeof(wchar_t),
[](auto buffer, auto endian, auto style) {
hex::unused(style);
wchar_t wideChar = '\x00';
std::memcpy(&wideChar, buffer.data(), std::min(sizeof(wchar_t), buffer.size()));
@@ -278,6 +299,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);
char utf8Buffer[5] = { 0 };
char codepointString[5] = { 0 };
u32 codepoint = 0;
@@ -296,12 +319,14 @@ namespace hex::plugin::builtin {
ContentRegistry::DataInspector::add("hex.builtin.inspector.string", 1,
[](auto buffer, auto endian, auto style) {
Region currSelection = { 0 };
hex::unused(endian, style);
Region currSelection = { 0, 0 };
EventManager::post<QuerySelection>(currSelection);
constexpr static auto MaxStringLength = 32;
std::vector<u8> stringBuffer(std::min<ssize_t>(MaxStringLength, currSelection.size), 0x00);
std::vector<u8> stringBuffer(std::min<size_t>(MaxStringLength, currSelection.size), 0x00);
ImHexApi::Provider::get()->read(currSelection.address, stringBuffer.data(), stringBuffer.size());
auto value = hex::encodeByteString(stringBuffer);
@@ -313,6 +338,8 @@ namespace hex::plugin::builtin {
return [value, copyValue] { ImGui::TextFormatted("\"{0}\"", value.c_str()); return copyValue; };
},
[](const std::string &value, std::endian endian) -> std::vector<u8> {
hex::unused(endian);
return hex::decodeByteString(value);
}
);
@@ -320,6 +347,8 @@ namespace hex::plugin::builtin {
#if defined(OS_WINDOWS) && defined(ARCH_64_BIT)
ContentRegistry::DataInspector::add("hex.builtin.inspector.time32", sizeof(u32), [](auto buffer, auto endian, auto style) {
hex::unused(style);
auto endianAdjustedTime = hex::changeEndianess(*reinterpret_cast<u32 *>(buffer.data()), endian);
std::string value;
@@ -333,6 +362,8 @@ namespace hex::plugin::builtin {
});
ContentRegistry::DataInspector::add("hex.builtin.inspector.time64", sizeof(u64), [](auto buffer, auto endian, auto style) {
hex::unused(style);
auto endianAdjustedTime = hex::changeEndianess(*reinterpret_cast<u64 *>(buffer.data()), endian);
std::string value;
@@ -348,6 +379,8 @@ namespace hex::plugin::builtin {
#else
ContentRegistry::DataInspector::add("hex.builtin.inspector.time", sizeof(time_t), [](auto buffer, auto endian, auto style) {
hex::unused(style);
auto endianAdjustedTime = hex::changeEndianess(*reinterpret_cast<time_t *>(buffer.data()), endian);
std::string value;
@@ -363,7 +396,9 @@ namespace hex::plugin::builtin {
#endif
ContentRegistry::DataInspector::add("hex.builtin.inspector.guid", sizeof(GUID), [](auto buffer, auto endian, auto style) {
GUID guid = { 0 };
hex::unused(style);
GUID guid = { };
std::memcpy(&guid, buffer.data(), sizeof(GUID));
auto value = hex::format("{}{{{:08X}-{:04X}-{:04X}-{:02X}{:02X}-{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}}}",
(hex::changeEndianess(guid.data3, endian) >> 12) <= 5 && ((guid.data4[0] >> 4) >= 8 || (guid.data4[0] >> 4) == 0) ? "" : "Invalid ",
@@ -383,6 +418,8 @@ namespace hex::plugin::builtin {
});
ContentRegistry::DataInspector::add("hex.builtin.inspector.rgba8", sizeof(u32), [](auto buffer, auto endian, auto style) {
hex::unused(style);
ImColor value(hex::changeEndianess(*reinterpret_cast<u32 *>(buffer.data()), endian));
auto copyValue = hex::format("#{:02X}{:02X}{:02X}{:02X}", u8(0xFF * (value.Value.x)), u8(0xFF * (value.Value.y)), u8(0xFF * (value.Value.z)), u8(0xFF * (value.Value.w)));

View File

@@ -530,9 +530,9 @@ namespace hex::plugin::builtin {
auto from = this->getIntegerOnInput(1);
auto to = this->getIntegerOnInput(2);
if (from < 0 || from >= input.size())
if (from < 0 || static_cast<u64>(from) >= input.size())
throwNodeError("'from' input out of range");
if (to < 0 || from >= input.size())
if (to < 0 || static_cast<u64>(from) >= input.size())
throwNodeError("'to' input out of range");
if (to <= from)
throwNodeError("'to' input needs to be greater than 'from' input");

View File

@@ -75,12 +75,12 @@ namespace hex::plugin::builtin {
});
/* pack_size(...) */
ContentRegistry::PatternLanguage::addFunction(nsStd, "sizeof_pack", ParameterCount::atLeast(0), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStd, "sizeof_pack", ParameterCount::atLeast(0), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
return u128(params.size());
});
/* error(message) */
ContentRegistry::PatternLanguage::addFunction(nsStd, "error", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStd, "error", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
LogConsole::abortEvaluation(Token::literalToString(params[0], true));
return std::nullopt;
@@ -99,11 +99,15 @@ namespace hex::plugin::builtin {
/* base_address() */
ContentRegistry::PatternLanguage::addFunction(nsStdMem, "base_address", ParameterCount::none(), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
hex::unused(params);
return u128(ctx->getProvider()->getBaseAddress());
});
/* size() */
ContentRegistry::PatternLanguage::addFunction(nsStdMem, "size", ParameterCount::none(), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
hex::unused(params);
return u128(ctx->getProvider()->getActualSize());
});
@@ -185,14 +189,14 @@ namespace hex::plugin::builtin {
ContentRegistry::PatternLanguage::Namespace nsStdString = { "builtin", "std", "string" };
{
/* length(string) */
ContentRegistry::PatternLanguage::addFunction(nsStdString, "length", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdString, "length", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
auto string = Token::literalToString(params[0], false);
return u128(string.length());
});
/* at(string, index) */
ContentRegistry::PatternLanguage::addFunction(nsStdString, "at", ParameterCount::exactly(2), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdString, "at", ParameterCount::exactly(2), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
auto string = Token::literalToString(params[0], false);
auto index = Token::literalToSigned(params[1]);
@@ -213,7 +217,7 @@ namespace hex::plugin::builtin {
});
/* substr(string, pos, count) */
ContentRegistry::PatternLanguage::addFunction(nsStdString, "substr", ParameterCount::exactly(3), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdString, "substr", ParameterCount::exactly(3), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
auto string = Token::literalToString(params[0], false);
auto pos = Token::literalToUnsigned(params[1]);
auto size = Token::literalToUnsigned(params[2]);
@@ -225,7 +229,7 @@ namespace hex::plugin::builtin {
});
/* parse_int(string, base) */
ContentRegistry::PatternLanguage::addFunction(nsStdString, "parse_int", ParameterCount::exactly(2), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdString, "parse_int", ParameterCount::exactly(2), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
auto string = Token::literalToString(params[0], false);
auto base = Token::literalToUnsigned(params[1]);
@@ -233,7 +237,7 @@ namespace hex::plugin::builtin {
});
/* parse_float(string) */
ContentRegistry::PatternLanguage::addFunction(nsStdString, "parse_float", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdString, "parse_float", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
auto string = Token::literalToString(params[0], false);
return double(std::strtod(string.c_str(), nullptr));
@@ -243,7 +247,7 @@ namespace hex::plugin::builtin {
ContentRegistry::PatternLanguage::Namespace nsStdHttp = { "builtin", "std", "http" };
{
/* get(url) */
ContentRegistry::PatternLanguage::addDangerousFunction(nsStdHttp, "get", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addDangerousFunction(nsStdHttp, "get", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
const auto url = Token::literalToString(params[0], false);
hex::Net net;
@@ -258,7 +262,7 @@ namespace hex::plugin::builtin {
static std::map<u32, fs::File> openFiles;
/* open(path, mode) */
ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "open", ParameterCount::exactly(2), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "open", ParameterCount::exactly(2), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
const auto path = Token::literalToString(params[0], false);
const auto modeEnum = Token::literalToUnsigned(params[1]);
@@ -289,7 +293,7 @@ namespace hex::plugin::builtin {
});
/* close(file) */
ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "close", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "close", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
const auto file = Token::literalToUnsigned(params[0]);
if (!openFiles.contains(file))
@@ -301,7 +305,7 @@ namespace hex::plugin::builtin {
});
/* read(file, size) */
ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "read", ParameterCount::exactly(2), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "read", ParameterCount::exactly(2), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
const auto file = Token::literalToUnsigned(params[0]);
const auto size = Token::literalToUnsigned(params[1]);
@@ -312,7 +316,7 @@ namespace hex::plugin::builtin {
});
/* write(file, data) */
ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "write", ParameterCount::exactly(2), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "write", ParameterCount::exactly(2), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
const auto file = Token::literalToUnsigned(params[0]);
const auto data = Token::literalToString(params[1], true);
@@ -325,7 +329,7 @@ namespace hex::plugin::builtin {
});
/* seek(file, offset) */
ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "seek", ParameterCount::exactly(2), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "seek", ParameterCount::exactly(2), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
const auto file = Token::literalToUnsigned(params[0]);
const auto offset = Token::literalToUnsigned(params[1]);
@@ -338,7 +342,7 @@ namespace hex::plugin::builtin {
});
/* size(file) */
ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "size", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "size", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
const auto file = Token::literalToUnsigned(params[0]);
if (!openFiles.contains(file))
@@ -348,7 +352,7 @@ namespace hex::plugin::builtin {
});
/* resize(file, size) */
ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "resize", ParameterCount::exactly(2), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "resize", ParameterCount::exactly(2), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
const auto file = Token::literalToUnsigned(params[0]);
const auto size = Token::literalToUnsigned(params[1]);
@@ -361,7 +365,7 @@ namespace hex::plugin::builtin {
});
/* flush(file) */
ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "flush", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "flush", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
const auto file = Token::literalToUnsigned(params[0]);
if (!openFiles.contains(file))
@@ -373,7 +377,7 @@ namespace hex::plugin::builtin {
});
/* remove(file) */
ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "remove", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "remove", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
const auto file = Token::literalToUnsigned(params[0]);
if (!openFiles.contains(file))
@@ -389,126 +393,126 @@ namespace hex::plugin::builtin {
ContentRegistry::PatternLanguage::Namespace nsStdMath = { "builtin", "std", "math" };
{
/* floor(value) */
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "floor", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "floor", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
return std::floor(Token::literalToFloatingPoint(params[0]));
});
/* ceil(value) */
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "ceil", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "ceil", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
return std::ceil(Token::literalToFloatingPoint(params[0]));
});
/* round(value) */
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "round", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "round", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
return std::round(Token::literalToFloatingPoint(params[0]));
});
/* trunc(value) */
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "trunc", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "trunc", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
return std::trunc(Token::literalToFloatingPoint(params[0]));
});
/* log10(value) */
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "log10", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "log10", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
return std::log10(Token::literalToFloatingPoint(params[0]));
});
/* log2(value) */
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "log2", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "log2", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
return std::log2(Token::literalToFloatingPoint(params[0]));
});
/* ln(value) */
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "ln", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "ln", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
return std::log(Token::literalToFloatingPoint(params[0]));
});
/* fmod(x, y) */
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "fmod", ParameterCount::exactly(2), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "fmod", ParameterCount::exactly(2), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
return std::fmod(Token::literalToFloatingPoint(params[0]), Token::literalToFloatingPoint(params[1]));
});
/* pow(base, exp) */
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "pow", ParameterCount::exactly(2), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "pow", ParameterCount::exactly(2), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
return std::pow(Token::literalToFloatingPoint(params[0]), Token::literalToFloatingPoint(params[1]));
});
/* sqrt(value) */
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "sqrt", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "sqrt", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
return std::sqrt(Token::literalToFloatingPoint(params[0]));
});
/* cbrt(value) */
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "cbrt", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "cbrt", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
return std::cbrt(Token::literalToFloatingPoint(params[0]));
});
/* sin(value) */
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "sin", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "sin", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
return std::sin(Token::literalToFloatingPoint(params[0]));
});
/* cos(value) */
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "cos", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "cos", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
return std::cos(Token::literalToFloatingPoint(params[0]));
});
/* tan(value) */
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "tan", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "tan", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
return std::tan(Token::literalToFloatingPoint(params[0]));
});
/* asin(value) */
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "asin", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "asin", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
return std::asin(Token::literalToFloatingPoint(params[0]));
});
/* acos(value) */
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "acos", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "acos", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
return std::acos(Token::literalToFloatingPoint(params[0]));
});
/* atan(value) */
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "atan", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "atan", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
return std::atan(Token::literalToFloatingPoint(params[0]));
});
/* atan2(y, x) */
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "atan", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "atan", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
return std::atan2(Token::literalToFloatingPoint(params[0]), Token::literalToFloatingPoint(params[1]));
});
/* sinh(value) */
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "sinh", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "sinh", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
return std::sinh(Token::literalToFloatingPoint(params[0]));
});
/* cosh(value) */
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "cosh", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "cosh", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
return std::cosh(Token::literalToFloatingPoint(params[0]));
});
/* tanh(value) */
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "tanh", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "tanh", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
return std::tanh(Token::literalToFloatingPoint(params[0]));
});
/* asinh(value) */
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "asinh", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "asinh", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
return std::asinh(Token::literalToFloatingPoint(params[0]));
});
/* acosh(value) */
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "acosh", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "acosh", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
return std::acosh(Token::literalToFloatingPoint(params[0]));
});
/* atanh(value) */
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "atanh", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
ContentRegistry::PatternLanguage::addFunction(nsStdMath, "atanh", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
return std::atanh(Token::literalToFloatingPoint(params[0]));
});
}

View File

@@ -4,12 +4,12 @@
#include <hex/helpers/fmt.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/ui/imgui_imhex_extensions.h>
#include <bitset>
#include <filesystem>
#include <imgui.h>
#include <hex/ui/imgui_imhex_extensions.h>
#if defined(OS_LINUX)
#include <fcntl.h>
@@ -82,7 +82,7 @@ namespace hex::plugin::builtin::prv {
}
{
DISK_GEOMETRY_EX diskGeometry = { 0 };
DISK_GEOMETRY_EX diskGeometry = { };
DWORD bytesRead = 0;
if (DeviceIoControl(
this->m_diskHandle,
@@ -113,8 +113,11 @@ namespace hex::plugin::builtin::prv {
struct stat driveStat;
::stat(path.c_str(), &driveStat) == 0;
this->m_diskSize = driveStat.st_size;
if (::stat(path.c_str(), &driveStat) == 0)
this->m_diskSize = driveStat.st_size;
else
this->m_diskSize = 0;
this->m_sectorSize = 0;
this->m_diskHandle = ::open(path.c_str(), O_RDWR);
@@ -158,7 +161,7 @@ namespace hex::plugin::builtin::prv {
seekPosition.LowPart = (offset & 0xFFFF'FFFF) - (offset % this->m_sectorSize);
seekPosition.HighPart = offset >> 32;
if (this->m_sectorBufferAddress != seekPosition.QuadPart) {
if (this->m_sectorBufferAddress != static_cast<u64>(seekPosition.QuadPart)) {
::SetFilePointer(this->m_diskHandle, seekPosition.LowPart, &seekPosition.HighPart, FILE_BEGIN);
::ReadFile(this->m_diskHandle, this->m_sectorBuffer.data(), this->m_sectorBuffer.size(), &bytesRead, nullptr);
this->m_sectorBufferAddress = seekPosition.QuadPart;
@@ -177,7 +180,9 @@ namespace hex::plugin::builtin::prv {
if (this->m_sectorBufferAddress != seekPosition) {
::lseek(this->m_diskHandle, seekPosition, SEEK_SET);
::read(this->m_diskHandle, buffer, size);
if (::read(this->m_diskHandle, buffer, size) < 0)
break;
this->m_sectorBufferAddress = seekPosition;
}
@@ -231,7 +236,8 @@ namespace hex::plugin::builtin::prv {
std::memcpy(modifiedSectorBuffer.data() + ((offset - sectorBase) % this->m_sectorSize), reinterpret_cast<const u8 *>(buffer) + (startOffset - offset), currSize);
::lseek(this->m_diskHandle, sectorBase, SEEK_SET);
::write(this->m_diskHandle, modifiedSectorBuffer.data(), modifiedSectorBuffer.size());
if (::write(this->m_diskHandle, modifiedSectorBuffer.data(), modifiedSectorBuffer.size()) < 0)
break;
offset += currSize;
size -= currSize;
@@ -272,7 +278,7 @@ namespace hex::plugin::builtin::prv {
if (handle == INVALID_HANDLE_VALUE) continue;
VOLUME_DISK_EXTENTS diskExtents = { 0 };
VOLUME_DISK_EXTENTS diskExtents = { };
DWORD bytesRead = 0;
auto result = ::DeviceIoControl(
handle,
@@ -314,7 +320,7 @@ namespace hex::plugin::builtin::prv {
#else
if (ImGui::InputText("hex.builtin.provider.disk.selected_disk"_lang, 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

@@ -111,7 +111,7 @@ namespace hex::plugin::builtin::prv {
this->m_fileSize = file.getSize();
}
this->open();
(void)this->open();
}
void FileProvider::insert(u64 offset, size_t size) {
@@ -171,7 +171,7 @@ namespace hex::plugin::builtin::prv {
this->m_fileStatsValid = wstat(path.c_str(), &this->m_fileStats) == 0;
LARGE_INTEGER fileSize = { 0 };
LARGE_INTEGER fileSize = { };
this->m_file = reinterpret_cast<HANDLE>(CreateFileW(path.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr));
GetFileSizeEx(this->m_file, &fileSize);

View File

@@ -218,6 +218,7 @@ namespace hex::plugin::builtin::prv {
}
void GDBProvider::saveAs(const std::fs::path &path) {
hex::unused(path);
}
size_t GDBProvider::getActualSize() const {

View File

@@ -238,7 +238,7 @@ namespace hex::plugin::builtin {
ImGui::SameLine();
if (ImGui::IconButton(ICON_VS_FOLDER_OPENED, ImGui::GetStyleColorVec4(ImGuiCol_Text))) {
return fs::openFileBrowser("hex.builtin.setting.font.font_path", fs::DialogMode::Open, { {"TTF Font", "ttf"} },
return fs::openFileBrowser(fs::DialogMode::Open, { {"TTF Font", "ttf"} },
[&](const std::fs::path &path) {
fontPath = path.string();
setting = fontPath;
@@ -275,8 +275,10 @@ namespace hex::plugin::builtin {
ContentRegistry::Settings::addCategoryDescription(dirsSetting, "hex.builtin.setting.folders.description");
ContentRegistry::Settings::add(dirsSetting, dirsSetting, std::vector<std::string> {}, [](auto name, nlohmann::json &setting) {
hex::unused(name);
static std::vector<std::string> folders = setting;
static int currentItemIndex = 0;
static size_t currentItemIndex = 0;
if (!ImGui::BeginListBox("", ImVec2(-38, -FLT_MIN))) {
return false;
@@ -292,7 +294,7 @@ namespace hex::plugin::builtin {
ImGui::BeginGroup();
if (ImGui::IconButton(ICON_VS_NEW_FOLDER, ImGui::GetCustomColorVec4(ImGuiCustomCol_DescButton), ImVec2(30, 30))) {
fs::openFileBrowser("Select include folder", fs::DialogMode::Folder, {}, [&](const std::fs::path &path) {
fs::openFileBrowser(fs::DialogMode::Folder, {}, [&](const std::fs::path &path) {
auto pathStr = path.string();
if (std::find(folders.begin(), folders.end(), pathStr) == folders.end()) {

View File

@@ -142,6 +142,8 @@ namespace hex::plugin::builtin {
evaluator.setFunction(
"clear", [&](auto args) -> std::optional<long double> {
hex::unused(args);
mathHistory.clear();
lastMathError.clear();
mathEvaluator.getVariables().clear();
@@ -185,16 +187,16 @@ namespace hex::plugin::builtin {
2,
2);
return std::move(evaluator);
return evaluator;
}();
enum class MathDisplayType
{
enum class MathDisplayType : u8 {
Standard,
Scientific,
Engineering,
Programmer
} mathDisplayType;
} mathDisplayType = MathDisplayType::Standard;
if (ImGui::BeginTabBar("##mathFormatTabBar")) {
if (ImGui::BeginTabItem("hex.builtin.tools.format.standard"_lang)) {
mathDisplayType = MathDisplayType::Standard;
@@ -235,8 +237,10 @@ namespace hex::plugin::builtin {
if (ImGui::Button("CE", buttonSize)) mathInput.clear();
ImGui::SameLine();
if (ImGui::Button(ICON_FA_BACKSPACE, buttonSize)) mathInput.clear();
ImGui::SameLine();
ImGui::NewLine();
switch (mathDisplayType) {
case MathDisplayType::Standard:
case MathDisplayType::Scientific:
@@ -339,7 +343,7 @@ namespace hex::plugin::builtin {
ImGui::TableHeadersRow();
while (clipper.Step()) {
for (u64 i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
if (i == 0)
ImGui::PushStyleColor(ImGuiCol_Text, ImU32(ImColor(0xA5, 0x45, 0x45)));
@@ -438,7 +442,7 @@ namespace hex::plugin::builtin {
}
void drawBaseConverter() {
static char buffer[4][0xFFF] = { { '0' }, { '0' }, { '0' }, { '0' } };
static char buffer[4][0x1000] = { { '0' }, { '0' }, { '0' }, { '0' } };
static auto CharFilter = [](ImGuiInputTextCallbackData *data) -> int {
switch (*static_cast<u32 *>(data->UserData)) {
@@ -481,10 +485,15 @@ namespace hex::plugin::builtin {
auto base8String = hex::format("{0:#o}", number);
auto base2String = hex::toBinaryString(number);
std::strncpy(buffer[0], base10String.c_str(), sizeof(buffer[0]));
std::strncpy(buffer[1], base16String.c_str(), sizeof(buffer[1]));
std::strncpy(buffer[2], base8String.c_str(), sizeof(buffer[2]));
std::strncpy(buffer[3], base2String.c_str(), sizeof(buffer[3]));
std::strncpy(buffer[0], base10String.c_str(), sizeof(buffer[0]) - 1);
std::strncpy(buffer[1], base16String.c_str(), sizeof(buffer[1]) - 1);
std::strncpy(buffer[2], base8String.c_str(), sizeof(buffer[2]) - 1);
std::strncpy(buffer[3], base2String.c_str(), sizeof(buffer[3]) - 1);
buffer[0][0xFFF] = '\x00';
buffer[1][0xFFF] = '\x00';
buffer[2][0xFFF] = '\x00';
buffer[3][0xFFF] = '\x00';
};
u8 base = 10;
@@ -579,7 +588,7 @@ namespace hex::plugin::builtin {
ImGui::Header("hex.builtin.tools.file_uploader.control"_lang, true);
if (!uploading) {
if (ImGui::Button("hex.builtin.tools.file_uploader.upload"_lang)) {
fs::openFileBrowser("hex.builtin.tools.file_uploader.done"_lang, fs::DialogMode::Open, {}, [&](auto path) {
fs::openFileBrowser(fs::DialogMode::Open, {}, [&](auto path) {
uploadProcess = net.uploadFile("https://api.anonfiles.com/upload", path);
currFile = path;
});
@@ -678,7 +687,7 @@ namespace hex::plugin::builtin {
startSearch = ImGui::InputText("##search", searchString, ImGuiInputTextFlags_EnterReturnsTrue);
ImGui::SameLine();
ImGui::BeginDisabled(searchProcess.valid() && searchProcess.wait_for(0s) != std::future_status::ready || searchString.empty());
ImGui::BeginDisabled((searchProcess.valid() && searchProcess.wait_for(0s) != std::future_status::ready) || searchString.empty());
startSearch = ImGui::Button("hex.builtin.tools.wiki_explain.search"_lang) || startSearch;
ImGui::EndDisabled();
@@ -744,7 +753,7 @@ namespace hex::plugin::builtin {
ImGui::InputText("##path", selectedFile);
ImGui::SameLine();
if (ImGui::Button("...")) {
fs::openFileBrowser("hex.builtin.tools.file_tools.shredder.picker"_lang, fs::DialogMode::Open, {}, [](const auto &path) {
fs::openFileBrowser(fs::DialogMode::Open, {}, [](const auto &path) {
selectedFile = path.string();
});
}
@@ -886,7 +895,7 @@ namespace hex::plugin::builtin {
ImGui::InputText("##path", selectedFile);
ImGui::SameLine();
if (ImGui::Button("...##input")) {
fs::openFileBrowser("hex.builtin.tools.file_tools.splitter.picker.input"_lang, fs::DialogMode::Open, {}, [](const auto &path) {
fs::openFileBrowser(fs::DialogMode::Open, {}, [](const auto &path) {
selectedFile = path.string();
});
}
@@ -896,7 +905,7 @@ namespace hex::plugin::builtin {
ImGui::InputText("##base_path", baseOutputPath);
ImGui::SameLine();
if (ImGui::Button("...##output")) {
fs::openFileBrowser("hex.builtin.tools.file_tools.splitter.picker.output"_lang, fs::DialogMode::Save, {}, [](const auto &path) {
fs::openFileBrowser(fs::DialogMode::Save, {}, [](const auto &path) {
baseOutputPath = path.string();
});
}
@@ -979,7 +988,7 @@ namespace hex::plugin::builtin {
static bool combining = false;
static std::vector<std::string> files;
static auto outputPath = [] { std::string s; s.reserve(0x1000); return s; }();
static i32 selectedIndex;
static u32 selectedIndex;
if (ImGui::BeginTable("files_table", 2, ImGuiTableFlags_SizingStretchProp)) {
ImGui::TableSetupColumn("file list", ImGuiTableColumnFlags_NoHeaderLabel, 10);
@@ -989,7 +998,7 @@ namespace hex::plugin::builtin {
if (ImGui::BeginListBox("##files", { -FLT_MIN, 10 * ImGui::GetTextLineHeightWithSpacing() })) {
i32 index = 0;
u32 index = 0;
for (auto &file : files) {
if (ImGui::Selectable(std::fs::path(file).filename().string().c_str(), index == selectedIndex))
selectedIndex = index;
@@ -1025,7 +1034,7 @@ namespace hex::plugin::builtin {
ImGui::BeginDisabled(combining);
{
if (ImGui::Button("hex.builtin.tools.file_tools.combiner.add"_lang)) {
fs::openFileBrowser("hex.builtin.tools.file_tools.combiner.add.picker"_lang, fs::DialogMode::Open, {}, [](const auto &path) {
fs::openFileBrowser(fs::DialogMode::Open, {}, [](const auto &path) {
files.push_back(path.string());
});
}
@@ -1049,7 +1058,7 @@ namespace hex::plugin::builtin {
ImGui::InputText("##output_path", outputPath);
ImGui::SameLine();
if (ImGui::Button("...")) {
fs::openFileBrowser("hex.builtin.tools.file_tools.combiner.output.picker"_lang, fs::DialogMode::Save, {}, [](const auto &path) {
fs::openFileBrowser(fs::DialogMode::Save, {}, [](const auto &path) {
outputPath = path.string();
});
}

View File

@@ -105,7 +105,7 @@ namespace hex::plugin::builtin {
// Save file as
ImGui::Disabled([&provider] {
if (ImGui::ToolBarButton(ICON_VS_SAVE_AS, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarBlue)))
fs::openFileBrowser("hex.builtin.view.hex_editor.save_as"_lang, fs::DialogMode::Save, {}, [&provider](auto path) {
fs::openFileBrowser(fs::DialogMode::Save, {}, [&provider](auto path) {
provider->saveAs(path);
});
},
@@ -118,7 +118,7 @@ namespace hex::plugin::builtin {
// Create bookmark
ImGui::Disabled([] {
if (ImGui::ToolBarButton(ICON_VS_BOOKMARK, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarGreen))) {
Region region = { 0 };
Region region = { };
EventManager::post<QuerySelection>(region);
ImHexApi::Bookmarks::add(region.address, region.size, {}, {});
@@ -141,7 +141,7 @@ namespace hex::plugin::builtin {
ImGui::SetNextItemWidth(200_scaled);
if (ImGui::BeginCombo("", preview.c_str())) {
for (int i = 0; i < providers.size(); i++) {
for (size_t i = 0; i < providers.size(); i++) {
if (ImGui::Selectable(providers[i]->getName().c_str())) {
ImHexApi::Provider::setCurrentProvider(i);
}

View File

@@ -128,7 +128,7 @@ namespace hex::plugin::builtin {
clipper.Begin(this->m_filterIndices.size());
while (clipper.Step()) {
for (u64 i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
auto &constant = this->m_constants[this->m_filterIndices[i]];
ImGui::TableNextRow();
ImGui::TableNextColumn();

View File

@@ -42,6 +42,8 @@ namespace hex::plugin::builtin {
});
EventManager::subscribe<EventFileLoaded>(this, [this](const std::fs::path &path) {
hex::unused(path);
for (auto &node : this->m_nodes) {
node->setCurrentOverlay(nullptr);
}
@@ -56,7 +58,7 @@ namespace hex::plugin::builtin {
bool providerValid = ImHexApi::Provider::isValid();
if (ImGui::MenuItem("hex.builtin.view.data_processor.menu.file.load_processor"_lang, nullptr, false, providerValid)) {
fs::openFileBrowser("hex.builtin.view.data_processor.menu.file.load_processor"_lang, fs::DialogMode::Open, { {"hex.builtin.view.data_processor.name"_lang, "hexnode"} },
fs::openFileBrowser(fs::DialogMode::Open, { {"hex.builtin.view.data_processor.name"_lang, "hexnode"} },
[this](const std::fs::path &path) {
fs::File file(path, fs::File::Mode::Read);
if (file.isValid())
@@ -65,7 +67,7 @@ namespace hex::plugin::builtin {
}
if (ImGui::MenuItem("hex.builtin.view.data_processor.menu.file.save_processor"_lang, nullptr, false, !this->m_nodes.empty() && providerValid)) {
fs::openFileBrowser("hex.builtin.view.data_processor.menu.file.save_processor"_lang, fs::DialogMode::Save, { {"hex.builtin.view.data_processor.name"_lang, "hexnode"} },
fs::openFileBrowser(fs::DialogMode::Save, { {"hex.builtin.view.data_processor.name"_lang, "hexnode"} },
[this](const std::fs::path &path) {
fs::File file(path, fs::File::Mode::Create);
if (file.isValid())
@@ -114,7 +116,7 @@ namespace hex::plugin::builtin {
}
void ViewDataProcessor::eraseNodes(const std::vector<int> &ids) {
for (const int id : ids) {
for (u32 id : ids) {
auto node = std::find_if(this->m_nodes.begin(), this->m_nodes.end(), [&id](auto node) { return node->getId() == id; });
for (auto &attr : (*node)->getAttributes()) {
@@ -127,7 +129,7 @@ namespace hex::plugin::builtin {
}
}
for (const int id : ids) {
for (u32 id : ids) {
auto node = std::find_if(this->m_nodes.begin(), this->m_nodes.end(), [&id](auto node) { return node->getId() == id; });
std::erase_if(this->m_endNodes, [&id](auto node) { return node->getId() == id; });
@@ -275,7 +277,7 @@ namespace hex::plugin::builtin {
{
int nodeId;
if (ImNodes::IsNodeHovered(&nodeId) && this->m_currNodeError.has_value() && this->m_currNodeError->first->getId() == nodeId) {
if (ImNodes::IsNodeHovered(&nodeId) && this->m_currNodeError.has_value() && this->m_currNodeError->first->getId() == static_cast<u32>(nodeId)) {
ImGui::BeginTooltip();
ImGui::TextUnformatted("hex.builtin.common.error"_lang);
ImGui::Separator();
@@ -305,6 +307,7 @@ namespace hex::plugin::builtin {
ImNodesPinShape pinShape;
switch (attribute.getType()) {
default:
case dp::Attribute::Type::Integer:
pinShape = ImNodesPinShape_Circle;
break;
@@ -366,9 +369,9 @@ namespace hex::plugin::builtin {
dp::Attribute *fromAttr, *toAttr;
for (auto &node : this->m_nodes) {
for (auto &attribute : node->getAttributes()) {
if (attribute.getId() == from)
if (attribute.getId() == static_cast<u32>(from))
fromAttr = &attribute;
else if (attribute.getId() == to)
else if (attribute.getId() == static_cast<u32>(to))
toAttr = &attribute;
}
}

View File

@@ -50,7 +50,7 @@ namespace hex::plugin::builtin {
ImGui::SetNextItemWidth(200_scaled);
if (ImGui::BeginCombo("", preview.c_str())) {
for (int i = 0; i < providers.size(); i++) {
for (size_t i = 0; i < providers.size(); i++) {
if (ImGui::Selectable(providers[i]->getName().c_str())) {
provider = i;
}
@@ -130,7 +130,8 @@ namespace hex::plugin::builtin {
ImGui::TableNextColumn();
auto other = !curr;
std::optional<ImVec2> lastHighlightEnd;
bool hasLastHighlight = false;
ImVec2 lastHighlightEnd = { };
for (i64 col = 0; col < lineInfo[curr].validBytes; col++) {
auto pos = ImGui::GetCursorScreenPos();
@@ -162,10 +163,15 @@ namespace hex::plugin::builtin {
// Draw highlighting
if (highlightColor.has_value()) {
drawList->AddRectFilled(lastHighlightEnd.value_or(pos), pos + highlightSize, highlightColor.value());
if (hasLastHighlight)
drawList->AddRectFilled(lastHighlightEnd, pos + highlightSize, highlightColor.value());
else
drawList->AddRectFilled(pos, pos + highlightSize, highlightColor.value());
hasLastHighlight = true;
lastHighlightEnd = pos + ImVec2((glyphWidth - 1) * 2, 0);
} else {
lastHighlightEnd.reset();
hasLastHighlight = false;
}
}
}
@@ -217,7 +223,7 @@ namespace hex::plugin::builtin {
// Draw diff lines
while (clipper.Step()) {
for (u64 row = clipper.DisplayStart; row < clipper.DisplayEnd; row++) {
for (int row = clipper.DisplayStart; row < clipper.DisplayEnd; row++) {
ImGui::TableNextRow();
drawDiffLine({ this->m_providerA, this->m_providerB }, row);
}

View File

@@ -71,7 +71,7 @@ namespace hex::plugin::builtin {
u64 usedBytes = 0;
for (u32 i = 0; i < instructionCount; i++) {
const auto &instr = instructions[i];
Disassembly disassembly = { 0 };
Disassembly disassembly = { };
disassembly.address = instr.address;
disassembly.offset = this->m_codeRegion[0] + address + usedBytes;
disassembly.size = instr.size;
@@ -169,7 +169,7 @@ namespace hex::plugin::builtin {
static bool microMode;
ImGui::Checkbox("hex.builtin.view.disassembler.mips.micro"_lang, &microMode);
this->m_mode = cs_mode(mode | (microMode ? CS_MODE_MICRO : 0));
this->m_mode = cs_mode(mode | (microMode ? CS_MODE_MICRO : cs_mode(0)));
}
break;
case Architecture::X86:
@@ -198,7 +198,7 @@ namespace hex::plugin::builtin {
static bool booke = false;
ImGui::Checkbox("hex.builtin.view.disassembler.ppc.booke"_lang, &booke);
this->m_mode = cs_mode(mode | (qpx ? CS_MODE_QPX : 0) | (spe ? CS_MODE_SPE : 0) | (booke ? CS_MODE_BOOKE : 0));
this->m_mode = cs_mode(mode | (qpx ? CS_MODE_QPX : cs_mode(0)) | (spe ? CS_MODE_SPE : cs_mode(0)) | (booke ? CS_MODE_BOOKE : cs_mode(0)));
}
break;
case Architecture::SPARC:
@@ -206,7 +206,7 @@ namespace hex::plugin::builtin {
static bool v9Mode = false;
ImGui::Checkbox("hex.builtin.view.disassembler.sparc.v9"_lang, &v9Mode);
this->m_mode = cs_mode(v9Mode ? CS_MODE_V9 : 0);
this->m_mode = cs_mode(v9Mode ? CS_MODE_V9 : cs_mode(0));
}
break;
case Architecture::RISCV:
@@ -219,7 +219,7 @@ namespace hex::plugin::builtin {
static bool compressed = false;
ImGui::Checkbox("hex.builtin.view.disassembler.riscv.compressed"_lang, &compressed);
this->m_mode = cs_mode(mode | (compressed ? CS_MODE_RISCVC : 0));
this->m_mode = cs_mode(mode | (compressed ? CS_MODE_RISCVC : cs_mode(0)));
}
break;
case Architecture::M68K:
@@ -351,7 +351,7 @@ namespace hex::plugin::builtin {
ImGui::TableHeadersRow();
while (clipper.Step()) {
for (u64 i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
const auto &instruction = this->m_disassembly[i];
ImGui::TableNextRow();
ImGui::TableNextColumn();

View File

@@ -34,7 +34,7 @@ namespace hex::plugin::builtin {
template<size_t Size>
static void formatBigHexInt(std::array<u8, Size> dataArray, char *buffer, size_t bufferSize) {
for (int i = 0; i < dataArray.size(); i++)
for (size_t i = 0; i < dataArray.size(); i++)
snprintf(buffer + 2 * i, bufferSize - 2 * i, "%02X", dataArray[i]);
}
@@ -64,8 +64,8 @@ namespace hex::plugin::builtin {
ImGui::Separator();
if (ImGui::BeginCombo("hex.builtin.view.hashes.function"_lang, hashFunctionNames[this->m_currHashFunction].second, 0)) {
for (int i = 0; i < hashFunctionNames.size(); i++) {
bool is_selected = (this->m_currHashFunction == i);
for (size_t i = 0; i < hashFunctionNames.size(); i++) {
bool is_selected = (static_cast<size_t>(this->m_currHashFunction) == i);
if (ImGui::Selectable(hashFunctionNames[i].second, is_selected))
this->m_currHashFunction = i;
if (is_selected)

View File

@@ -39,7 +39,7 @@ namespace hex::plugin::builtin {
return true;
});
this->m_memoryEditor.ReadFn = [](const ImU8 *data, size_t off) -> ImU8 {
this->m_memoryEditor.ReadFn = [](const ImU8 *, size_t off) -> ImU8 {
auto provider = ImHexApi::Provider::get();
if (!provider->isAvailable() || !provider->isReadable())
return 0x00;
@@ -50,7 +50,7 @@ namespace hex::plugin::builtin {
return byte;
};
this->m_memoryEditor.WriteFn = [](ImU8 *data, size_t off, ImU8 d) -> void {
this->m_memoryEditor.WriteFn = [](ImU8 *, size_t off, ImU8 d) -> void {
auto provider = ImHexApi::Provider::get();
if (!provider->isAvailable() || !provider->isWritable())
return;
@@ -269,7 +269,7 @@ namespace hex::plugin::builtin {
}
static void saveAs() {
fs::openFileBrowser("hex.builtin.view.hex_editor.save_as"_lang, fs::DialogMode::Save, {}, [](const auto &path) {
fs::openFileBrowser(fs::DialogMode::Save, {}, [](const auto &path) {
ImHexApi::Provider::get()->saveAs(path);
});
}
@@ -299,7 +299,7 @@ namespace hex::plugin::builtin {
ImGui::InputText("##nolabel", this->m_loaderScriptScriptPath.data(), this->m_loaderScriptScriptPath.length(), ImGuiInputTextFlags_ReadOnly);
ImGui::SameLine();
if (ImGui::Button("hex.builtin.view.hex_editor.script.script"_lang)) {
fs::openFileBrowser("hex.builtin.view.hex_editor.script.script.title"_lang, fs::DialogMode::Open, { {"Python Script", "py"} },
fs::openFileBrowser(fs::DialogMode::Open, { {"Python Script", "py"} },
[this](const auto &path) {
this->m_loaderScriptScriptPath = path.string();
});
@@ -307,7 +307,7 @@ namespace hex::plugin::builtin {
ImGui::InputText("##nolabel", this->m_loaderScriptFilePath.data(), this->m_loaderScriptFilePath.length(), ImGuiInputTextFlags_ReadOnly);
ImGui::SameLine();
if (ImGui::Button("hex.builtin.view.hex_editor.script.file"_lang)) {
fs::openFileBrowser("hex.builtin.view.hex_editor.script.file.title"_lang, fs::DialogMode::Open, {}, [this](const auto &path) {
fs::openFileBrowser(fs::DialogMode::Open, {}, [this](const auto &path) {
this->m_loaderScriptFilePath = path.string();
});
}
@@ -801,7 +801,7 @@ namespace hex::plugin::builtin {
ImGui::Separator();
bool bytesSelected = this->m_memoryEditor.DataPreviewAddr != -1 && this->m_memoryEditor.DataPreviewAddrEnd != -1;
bool bytesSelected = this->m_memoryEditor.DataPreviewAddr != static_cast<size_t>(-1) && this->m_memoryEditor.DataPreviewAddrEnd != static_cast<size_t>(-1);
if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.edit.copy"_lang, "CTRL + C", false, bytesSelected))
this->copyBytes();
@@ -834,7 +834,9 @@ 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)) {
if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.edit.bookmark"_lang, nullptr, false,
this->m_memoryEditor.DataPreviewAddr != static_cast<size_t>(-1) && this->m_memoryEditor.DataPreviewAddrEnd != static_cast<size_t>(-1)))
{
auto base = provider->getBaseAddress();
size_t start = base + std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd);
@@ -898,7 +900,7 @@ namespace hex::plugin::builtin {
EventManager::subscribe<RequestOpenWindow>(this, [this](const std::string &name) {
if (name == "Create File") {
fs::openFileBrowser("hex.builtin.view.hex_editor.create_file"_lang, fs::DialogMode::Save, {}, [this](const auto &path) {
fs::openFileBrowser(fs::DialogMode::Save, {}, [this](const auto &path) {
fs::File file(path, fs::File::Mode::Create);
if (!file.isValid()) {
@@ -912,12 +914,12 @@ namespace hex::plugin::builtin {
this->getWindowOpenState() = true;
});
} else if (name == "Open File") {
fs::openFileBrowser("hex.builtin.view.hex_editor.open_file"_lang, fs::DialogMode::Open, {}, [this](const auto &path) {
fs::openFileBrowser(fs::DialogMode::Open, {}, [this](const auto &path) {
EventManager::post<RequestOpenFile>(path);
this->getWindowOpenState() = true;
});
} else if (name == "Open Project") {
fs::openFileBrowser("hex.builtin.view.hex_editor.open_project"_lang, fs::DialogMode::Open, { {"Project File", "hexproj"} },
fs::openFileBrowser(fs::DialogMode::Open, { {"Project File", "hexproj"} },
[this](const auto &path) {
ProjectFile::load(path);
this->getWindowOpenState() = true;
@@ -1033,7 +1035,7 @@ namespace hex::plugin::builtin {
});
ShortcutManager::addShortcut(this, CTRL + Keys::O, [] {
fs::openFileBrowser("hex.builtin.view.hex_editor.open_file"_lang, fs::DialogMode::Open, {}, [](const auto &path) {
fs::openFileBrowser(fs::DialogMode::Open, {}, [](const auto &path) {
EventManager::post<RequestOpenFile>(path);
});
});
@@ -1092,7 +1094,7 @@ namespace hex::plugin::builtin {
bool providerValid = ImHexApi::Provider::isValid();
if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.file.open_project"_lang, "")) {
fs::openFileBrowser("hex.builtin.view.hex_editor.menu.file.open_project"_lang, fs::DialogMode::Open, { {"Project File", "hexproj"}
fs::openFileBrowser(fs::DialogMode::Open, { {"Project File", "hexproj"}
},
[](const auto &path) {
ProjectFile::load(path);
@@ -1101,7 +1103,7 @@ namespace hex::plugin::builtin {
if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.file.save_project"_lang, "", false, providerValid && provider->isWritable())) {
if (ProjectFile::getProjectFilePath() == "") {
fs::openFileBrowser("hex.builtin.view.hex_editor.save_project"_lang, fs::DialogMode::Save, { {"Project File", "hexproj"}
fs::openFileBrowser(fs::DialogMode::Save, { {"Project File", "hexproj"}
},
[](std::fs::path path) {
if (path.extension() != ".hexproj") {
@@ -1142,7 +1144,7 @@ namespace hex::plugin::builtin {
if (ImGui::BeginMenu("hex.builtin.view.hex_editor.menu.file.import"_lang)) {
if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.file.import.base64"_lang)) {
fs::openFileBrowser("hex.builtin.view.hex_editor.menu.file.import.base64"_lang, fs::DialogMode::Open, {}, [this](const auto &path) {
fs::openFileBrowser(fs::DialogMode::Open, {}, [this](const auto &path) {
fs::File file(path, fs::File::Mode::Read);
if (!file.isValid()) {
View::showErrorPopup("hex.builtin.view.hex_editor.error.open"_lang);
@@ -1167,7 +1169,7 @@ namespace hex::plugin::builtin {
if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.file.import.ips"_lang, nullptr, false, !this->m_processingImportExport)) {
fs::openFileBrowser("hex.builtin.view.hex_editor.open_file"_lang, fs::DialogMode::Open, {}, [this](const auto &path) {
fs::openFileBrowser(fs::DialogMode::Open, {}, [this](const auto &path) {
this->m_processingImportExport = true;
std::thread([this, path] {
auto task = ImHexApi::Tasks::createTask("hex.builtin.view.hex_editor.processing", 0);
@@ -1195,7 +1197,7 @@ namespace hex::plugin::builtin {
}
if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.file.import.ips32"_lang, nullptr, false, !this->m_processingImportExport)) {
fs::openFileBrowser("hex.builtin.view.hex_editor.open_file"_lang, fs::DialogMode::Open, {}, [this](const auto &path) {
fs::openFileBrowser(fs::DialogMode::Open, {}, [this](const auto &path) {
this->m_processingImportExport = true;
std::thread([this, path] {
auto task = ImHexApi::Tasks::createTask("hex.builtin.view.hex_editor.processing", 0);
@@ -1250,7 +1252,7 @@ namespace hex::plugin::builtin {
this->m_processingImportExport = false;
ImHexApi::Tasks::doLater([this] {
fs::openFileBrowser("hex.builtin.view.hex_editor.menu.file.export.title"_lang, fs::DialogMode::Save, {}, [this](const auto &path) {
fs::openFileBrowser(fs::DialogMode::Save, {}, [this](const auto &path) {
auto file = fs::File(path, fs::File::Mode::Create);
if (!file.isValid()) {
View::showErrorPopup("hex.builtin.view.hex_editor.error.create"_lang);
@@ -1279,7 +1281,7 @@ namespace hex::plugin::builtin {
this->m_processingImportExport = false;
ImHexApi::Tasks::doLater([this] {
fs::openFileBrowser("hex.builtin.view.hex_editor.menu.file.export.title"_lang, fs::DialogMode::Save, {}, [this](const auto &path) {
fs::openFileBrowser(fs::DialogMode::Save, {}, [this](const auto &path) {
auto file = fs::File(path, fs::File::Mode::Create);
if (!file.isValid()) {
View::showErrorPopup("hex.builtin.view.hex_editor.error.create"_lang);

View File

@@ -9,6 +9,7 @@
#include <cstring>
#include <cmath>
#include <cinttypes>
#include <filesystem>
#include <numeric>
#include <span>
@@ -156,7 +157,7 @@ namespace hex::plugin::builtin {
if (this->m_dataValid) {
ImGui::LabelText("hex.builtin.view.information.region"_lang, "0x%llx - 0x%llx", this->m_analyzedRegion.first, this->m_analyzedRegion.second);
ImGui::LabelText("hex.builtin.view.information.region"_lang, "%s", hex::format("0x{:X} - 0x{:X}", this->m_analyzedRegion.first, this->m_analyzedRegion.second).c_str());
ImGui::NewLine();

View File

@@ -3,7 +3,6 @@
#include <hex/pattern_language/preprocessor.hpp>
#include <hex/pattern_language/patterns/pattern.hpp>
#include <hex/pattern_language/ast/ast_node.hpp>
#include <hex/pattern_language/ast/ast_node_variable_decl.hpp>
#include <hex/pattern_language/ast/ast_node_type_decl.hpp>
#include <hex/pattern_language/ast/ast_node_builtin_type.hpp>
@@ -101,6 +100,8 @@ namespace hex::plugin::builtin {
});
EventManager::subscribe<EventFileLoaded>(this, [this](const std::fs::path &path) {
hex::unused(path);
if (!ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.auto_load_patterns", 1))
return;
@@ -217,7 +218,7 @@ namespace hex::plugin::builtin {
}
if (ImGui::MenuItem("hex.builtin.view.pattern_editor.menu.file.save_pattern"_lang, nullptr, false, providerValid)) {
fs::openFileBrowser("hex.builtin.view.pattern_editor.menu.file.save_pattern"_lang, fs::DialogMode::Save, { {"Pattern", "hexpat"} },
fs::openFileBrowser(fs::DialogMode::Save, { {"Pattern", "hexpat"} },
[this](const auto &path) {
fs::File file(path, fs::File::Mode::Create);
@@ -379,7 +380,7 @@ namespace hex::plugin::builtin {
if (ImGui::BeginChild("##console", size, true, ImGuiWindowFlags_AlwaysVerticalScrollbar | ImGuiWindowFlags_HorizontalScrollbar)) {
ImGuiListClipper clipper(this->m_console.size());
while (clipper.Step())
for (u64 i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
const auto &[level, message] = this->m_console[i];
switch (level) {
@@ -639,7 +640,8 @@ namespace hex::plugin::builtin {
PatternVariable variable = {
.inVariable = variableDecl->isInVariable(),
.outVariable = variableDecl->isOutVariable(),
.type = builtinType->getType()
.type = builtinType->getType(),
.value = { }
};
if (variable.inVariable || variable.outVariable) {

View File

@@ -81,7 +81,7 @@ namespace hex::plugin::builtin {
if (buffer[i] >= ' ' && buffer[i] <= '~' && offset < provider->getActualSize() - 1)
foundCharacters++;
else {
if (foundCharacters >= this->m_minimumLength) {
if (foundCharacters >= static_cast<u32>(this->m_minimumLength)) {
FoundString foundString = {
offset + i - foundCharacters + provider->getBaseAddress(),
foundCharacters
@@ -212,7 +212,7 @@ namespace hex::plugin::builtin {
clipper.Begin(this->m_filterIndices.size());
while (clipper.Step()) {
for (u64 i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
auto &foundString = this->m_foundStrings[this->m_filterIndices[i]];
auto string = readString(foundString);

View File

@@ -2,18 +2,14 @@
#include <hex/api/content_registry.hpp>
#include <hex/providers/provider.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/helpers/file.hpp>
#include <hex/helpers/fs.hpp>
#include <hex/helpers/logger.hpp>
#include <yara.h>
#include <filesystem>
#include <thread>
#include <hex/helpers/fs.hpp>
namespace hex::plugin::builtin {
ViewYara::ViewYara() : View("hex.builtin.view.yara.name") {
@@ -94,7 +90,7 @@ namespace hex::plugin::builtin {
clipper.Begin(this->m_matches.size());
while (clipper.Step()) {
for (u32 i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
auto &[identifier, variableName, address, size, wholeDataMatch, highlightId] = this->m_matches[i];
ImGui::TableNextRow();
ImGui::TableNextColumn();
@@ -133,7 +129,7 @@ namespace hex::plugin::builtin {
if (ImGui::BeginChild("##console", consoleSize, true, ImGuiWindowFlags_AlwaysVerticalScrollbar | ImGuiWindowFlags_HorizontalScrollbar)) {
ImGuiListClipper clipper(this->m_consoleMessages.size());
while (clipper.Step())
for (u64 i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
const auto &message = this->m_consoleMessages[i];
if (ImGui::Selectable(message.c_str()))
@@ -189,7 +185,7 @@ namespace hex::plugin::builtin {
yr_compiler_set_include_callback(
compiler,
[](const char *includeName, const char *callingRuleFileName, const char *callingRuleNamespace, void *userData) -> const char * {
[](const char *includeName, const char *, const char *, void *userData) -> const char * {
auto currFilePath = static_cast<const char *>(userData);
fs::File file((std::fs::path(currFilePath).parent_path() / includeName).string(), fs::File::Mode::Read);
@@ -204,6 +200,8 @@ namespace hex::plugin::builtin {
return buffer;
},
[](const char *ptr, void *userData) {
hex::unused(userData);
delete[] ptr;
},
this->m_rules[this->m_selectedRule].second.data());
@@ -257,6 +255,8 @@ namespace hex::plugin::builtin {
return context.buffer.data();
};
iterator.file_size = [](auto *iterator) -> u64 {
hex::unused(iterator);
return ImHexApi::Provider::get()->getActualSize();
};
@@ -310,11 +310,11 @@ namespace hex::plugin::builtin {
if (rule->strings != nullptr) {
yr_rule_strings_foreach(rule, string) {
yr_string_matches_foreach(context, string, match) {
results.newMatches.push_back({ rule->identifier, string->identifier, u64(match->offset), size_t(match->match_length), false });
results.newMatches.push_back({ rule->identifier, string->identifier, u64(match->offset), size_t(match->match_length), false, 0 });
}
}
} else {
results.newMatches.push_back({ rule->identifier, "", 0, 0, true });
results.newMatches.push_back({ rule->identifier, "", 0, 0, true, 0 });
}
}
break;

View File

@@ -200,7 +200,7 @@ namespace hex::plugin::builtin {
clipper.Begin(plugins.size());
while (clipper.Step()) {
for (u64 i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
const auto &plugin = plugins[i];
ImGui::TableNextRow();
@@ -420,7 +420,7 @@ namespace hex::plugin::builtin {
ContentRegistry::Interface::addMenuItem("hex.builtin.menu.file", 1050, [&] {
if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.file.open_file"_lang, "CTRL + O")) {
fs::openFileBrowser("hex.builtin.view.hex_editor.open_file"_lang, fs::DialogMode::Open, {}, [](const auto &path) {
fs::openFileBrowser(fs::DialogMode::Open, {}, [](const auto &path) {
EventManager::post<RequestOpenFile>(path);
});
}

View File

@@ -58,7 +58,7 @@ namespace hex {
if (currToken.type == TokenType::Number || currToken.type == TokenType::Variable || currToken.type == TokenType::Function)
outputQueue.push(currToken);
else if (currToken.type == TokenType::Operator) {
while ((!operatorStack.empty()) && (operatorStack.top().type == TokenType::Operator && currToken.type == TokenType::Operator && (comparePrecedence(operatorStack.top().op, currToken.op) > 0) || (comparePrecedence(operatorStack.top().op, currToken.op) == 0 && isLeftAssociative(currToken.op))) && operatorStack.top().type != TokenType::Bracket) {
while ((!operatorStack.empty()) && ((operatorStack.top().type == TokenType::Operator && currToken.type == TokenType::Operator && (comparePrecedence(operatorStack.top().op, currToken.op) > 0)) || (comparePrecedence(operatorStack.top().op, currToken.op) == 0 && isLeftAssociative(currToken.op))) && operatorStack.top().type != TokenType::Bracket) {
outputQueue.push(operatorStack.top());
operatorStack.pop();
}
@@ -109,12 +109,12 @@ namespace hex {
number = std::strtoull(pos, &pos, 0);
}
inputQueue.push(Token { .type = TokenType::Number, .number = number });
inputQueue.push(Token { .type = TokenType::Number, .number = number, .name = "", .arguments = { } });
} else if (*pos == '(') {
inputQueue.push(Token { .type = TokenType::Bracket, .bracketType = BracketType::Left });
inputQueue.push(Token { .type = TokenType::Bracket, .bracketType = BracketType::Left, .name = "", .arguments = { } });
pos++;
} else if (*pos == ')') {
inputQueue.push(Token { .type = TokenType::Bracket, .bracketType = BracketType::Right });
inputQueue.push(Token { .type = TokenType::Bracket, .bracketType = BracketType::Right, .name = "", .arguments = { } });
pos++;
} else if (std::isspace(*pos)) {
pos++;
@@ -122,7 +122,7 @@ namespace hex {
auto [op, width] = toOperator(pos);
if (op != Operator::Invalid) {
inputQueue.push(Token { .type = TokenType::Operator, .op = op });
inputQueue.push(Token { .type = TokenType::Operator, .op = op, .name = "", .arguments = { } });
pos += width;
} else {
Token token;

View File

@@ -26,4 +26,5 @@ if (WIN32)
endif()
add_compile_definitions(IMHEX_PROJECT_NAME="${PROJECT_NAME}")
set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Werror)

View File

@@ -37,5 +37,6 @@ if (WIN32)
add_compile_definitions(IMHEX_PROJECT_NAME="${PROJECT_NAME}")
set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Werror)
endif ()

View File

@@ -1,7 +1,6 @@
#include <hex/api/content_registry.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/helpers/fmt.hpp>
#include <windows.h>
#include <psapi.h>
@@ -14,18 +13,6 @@
namespace hex::plugin::windows {
static ULONGLONG subtractTimes(const FILETIME &left, const FILETIME &right) {
LARGE_INTEGER a, b;
a.LowPart = left.dwLowDateTime;
a.HighPart = left.dwHighDateTime;
b.LowPart = right.dwLowDateTime;
b.HighPart = right.dwHighDateTime;
return a.QuadPart - b.QuadPart;
}
void addTitleBarButtons() {
#if defined(DEBUG)
ContentRegistry::Interface::addTitleBarButton(ICON_VS_DEBUG, "hex.windows.title_bar_button.debug_build", []{
@@ -59,15 +46,17 @@ namespace hex::plugin::windows {
static u32 numProcessors;
static HANDLE self = GetCurrentProcess();
FILETIME ftime, fsys, fuser;
ULARGE_INTEGER now, sys, user;
{
FILETIME ftime, fsys, fuser;
GetSystemTimeAsFileTime(&ftime);
memcpy(&now, &ftime, sizeof(FILETIME));
GetSystemTimeAsFileTime(&ftime);
memcpy(&now, &ftime, sizeof(FILETIME));
GetProcessTimes(self, &ftime, &ftime, &fsys, &fuser);
memcpy(&sys, &fsys, sizeof(FILETIME));
memcpy(&user, &fuser, sizeof(FILETIME));
GetProcessTimes(self, &ftime, &ftime, &fsys, &fuser);
memcpy(&sys, &fsys, sizeof(FILETIME));
memcpy(&user, &fuser, sizeof(FILETIME));
}
if (lastCPU.QuadPart == 0) {
SYSTEM_INFO sysInfo;

View File

@@ -40,6 +40,8 @@ namespace hex::plugin::windows {
ImGui::Combo(
"hex.windows.view.tty_console.baud"_lang, &this->m_selectedBaudRate, [](void *data, int idx, const char **out_text) -> bool {
hex::unused(data);
*out_text = ViewTTYConsole::BaudRates[idx];
return true;
},
@@ -48,6 +50,7 @@ namespace hex::plugin::windows {
ImGui::Combo(
"hex.windows.view.tty_console.num_bits"_lang, &this->m_selectedNumBits, [](void *data, int idx, const char **out_text) -> bool {
hex::unused(data);
*out_text = ViewTTYConsole::NumBits[idx];
return true;
},
@@ -56,6 +59,7 @@ namespace hex::plugin::windows {
ImGui::Combo(
"hex.windows.view.tty_console.stop_bits"_lang, &this->m_selectedStopBits, [](void *data, int idx, const char **out_text) -> bool {
hex::unused(data);
*out_text = ViewTTYConsole::StopBits[idx];
return true;
},
@@ -64,6 +68,7 @@ namespace hex::plugin::windows {
ImGui::Combo(
"hex.windows.view.tty_console.parity_bits"_lang, &this->m_selectedParityBits, [](void *data, int idx, const char **out_text) -> bool {
hex::unused(data);
*out_text = ViewTTYConsole::ParityBits[idx];
return true;
},
@@ -113,12 +118,12 @@ namespace hex::plugin::windows {
while (clipper.Step()) {
std::scoped_lock lock(this->m_receiveBufferMutex);
for (u32 i = clipper.DisplayStart + 1; i < clipper.DisplayEnd; i++) {
for (int i = clipper.DisplayStart + 1; i < clipper.DisplayEnd; i++) {
ImGui::TextUnformatted(this->m_receiveDataBuffer.data() + this->m_wrapPositions[i - 1], this->m_receiveDataBuffer.data() + this->m_wrapPositions[i]);
}
if (!this->m_receiveDataBuffer.empty() && !this->m_wrapPositions.empty())
if (clipper.DisplayEnd >= this->m_wrapPositions.size() - 1)
if (static_cast<size_t>(clipper.DisplayEnd) >= this->m_wrapPositions.size() - 1)
ImGui::TextUnformatted(this->m_receiveDataBuffer.data() + this->m_wrapPositions.back());
if (this->m_shouldAutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY()) {
@@ -182,7 +187,7 @@ namespace hex::plugin::windows {
}
bool ViewTTYConsole::connect() {
if (this->m_comPorts.empty() || this->m_selectedPort >= this->m_comPorts.size()) {
if (this->m_comPorts.empty() || static_cast<size_t>(this->m_selectedPort) >= this->m_comPorts.size()) {
View::showErrorPopup("hex.windows.view.tty_console.no_available_port"_lang);
return true; // If false, connect_error error popup will override this error popup
}
@@ -231,7 +236,7 @@ namespace hex::plugin::windows {
this->m_receiveThread = std::jthread([this](const std::stop_token &token) {
bool waitingOnRead = false;
OVERLAPPED overlapped = { 0 };
OVERLAPPED overlapped = { };
overlapped.hEvent = ::CreateEvent(nullptr, true, false, nullptr);
ON_SCOPE_EXIT { ::CloseHandle(&overlapped); };
@@ -298,7 +303,7 @@ namespace hex::plugin::windows {
return;
auto transmitThread = std::thread([&, this] {
OVERLAPPED overlapped = { 0 };
OVERLAPPED overlapped = { };
overlapped.hEvent = ::CreateEvent(nullptr, true, false, nullptr);
ON_SCOPE_EXIT { ::CloseHandle(&overlapped); };