krabsetw icon indicating copy to clipboard operation
krabsetw copied to clipboard

parse<boolean> is identified as UINT8

Open Gabriele91 opened this issue 3 years ago • 4 comments

Hi there,

I have a problem regarding parse<T> for boolean type. Indeed it is identified as UINT8 instead of BOOLEAN (or BOOL), thus throw_if_invalid raises an exception: image

I guess it happens because in c++ boolean is an unsigned char instead of int (it is also true for bool). I think could be nice a specialized template for the boolean type, in order to avoid this problem.

Gabriele91 avatar Sep 08 '21 08:09 Gabriele91

Update, It is also true for the BOOL type, which is classified as INT32 instead of BOOLEAN: image I guess a workaround is a struct krabs::boolean like the krabs::hex32/64 ones.

Gabriele91 avatar Sep 08 '21 08:09 Gabriele91

This is my workaround and it works fine, for me.

namespace krabs
{
    struct boolean
    {
        int value;
    };

    namespace debug
    {
        template <>
        inline void assert_valid_assignment<boolean>(const std::wstring&, const property_info& info)
        {
            auto actual = (_TDH_IN_TYPE)info.pEventPropertyInfo_->nonStructType.InType;
            if (actual != TDH_INTYPE_BOOLEAN) {
                throw std::runtime_error("Requested a boolean value from non-boolean property");
            }
        }
    }
}

Gabriele91 avatar Sep 08 '21 08:09 Gabriele91

Nope, the issue is visible in the first image, the specialized template classifies it as UINT8 instead of boolean (TDH_INTYPE_BOOLEAN). This raises the exception.

Gabriele91 avatar Oct 06 '21 17:10 Gabriele91

@Gabriele91 nice find! #148 added support for boolean including an appropriate assert_valid_assignment specialization, but it's possible that we missed something. Would you be willing to share a minimal repro that I can test with?

swannman avatar Oct 08 '21 15:10 swannman