ImHex-Patterns icon indicating copy to clipboard operation
ImHex-Patterns copied to clipboard

request: crc16 calculation in pattern editor

Open dl1mx opened this issue 11 months ago • 2 comments

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); };

dl1mx avatar Mar 12 '24 15:03 dl1mx

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());
        });

dl1mx avatar Mar 13 '24 07:03 dl1mx

Thank you. Yeah currently there's only CRC32 available in the standard library. I can add the other ones later

WerWolv avatar Mar 13 '24 07:03 WerWolv

crc8 too please.

LupusTheCanine avatar Jul 01 '24 21:07 LupusTheCanine