ImHex-Patterns
ImHex-Patterns copied to clipboard
request: crc16 calculation in pattern editor
I like to get the crc16 calculation available in the pattern editor. Only crc32 is available at the moment. Adding the follwing code to hash.pat is not working: fn crc16(ref auto pattern, u16 init, u16 poly, u16 xorout, bool reflect_in, bool reflect_out) { return builtin::std::hash::crc16(pattern, init, poly, xorout, reflect_in, reflect_out); };
Seems that the code in project Pattern Language needs to be edited also with something like that in hash.cpp:
/* crc16(pattern, init, poly, xorout, reflect_in, reflect_out) */
runtime.addFunction(nsStdHash, "crc16", FunctionParameterCount::exactly(6), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
wolv::util::unused(ctx);
auto pattern = params[0].toPattern();
auto init = params[1].toUnsigned();
auto poly = params[2].toUnsigned();
auto xorout = params[3].toUnsigned();
auto reflectIn = params[4].toUnsigned();
auto reflectOut = params[5].toUnsigned();
wolv::hash::Crc<16> crc(poly, init, xorout, reflectIn, reflectOut);
crc.process(pattern->getBytes());
return u128(crc.getResult());
});
Thank you. Yeah currently there's only CRC32 available in the standard library. I can add the other ones later
crc8 too please.