Skip to content

Commit 9bcea01

Browse files
authored
Merge pull request #40 from fluent-plugins-nursery/support-binary-type-string-inserts-decoding
utils: Support Binary type of string inserts decoding
2 parents a34c933 + 1d803aa commit 9bcea01

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

ext/winevt/winevt_utils.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,36 @@ guid_to_wstr(const GUID& guid)
129129
return s;
130130
}
131131

132+
static VALUE
133+
make_displayable_binary_string(PBYTE bin, size_t length)
134+
{
135+
const char *HEX_TABLE = "0123456789ABCDEF";
136+
CHAR *buffer;
137+
int size = length * 2 + 1;
138+
size_t i, j;
139+
unsigned int idx = 0;
140+
VALUE vbuffer;
141+
142+
if (length == 0) {
143+
return rb_str_new2("(NULL)");
144+
}
145+
146+
buffer = ALLOCV_N(CHAR, vbuffer, size);
147+
148+
for (i = 0; i < length; i++) {
149+
for (j = 0; j < 2; j++) {
150+
idx = (unsigned int)(bin[i] >> (j * 4) & 0x0F);
151+
buffer[2*i+(1-j)] = HEX_TABLE[idx];
152+
}
153+
}
154+
buffer[size - 1] = '\0';
155+
156+
VALUE str = rb_str_new2(buffer);
157+
ALLOCV_END(vbuffer);
158+
159+
return str;
160+
}
161+
132162
static VALUE
133163
extract_user_evt_variants(PEVT_VARIANT pRenderedValues, DWORD propCount)
134164
{
@@ -302,6 +332,14 @@ extract_user_evt_variants(PEVT_VARIANT pRenderedValues, DWORD propCount)
302332
rb_ary_push(userValues, rbObj);
303333
}
304334
break;
335+
case EvtVarTypeBinary:
336+
if (pRenderedValues[i].BinaryVal == nullptr) {
337+
rb_ary_push(userValues, rb_utf8_str_new_cstr("(NULL)"));
338+
} else {
339+
rbObj = make_displayable_binary_string(pRenderedValues[i].BinaryVal, pRenderedValues[i].Count);
340+
rb_ary_push(userValues, rbObj);
341+
}
342+
break;
305343
default:
306344
rb_ary_push(userValues, rb_utf8_str_new_cstr("?"));
307345
break;

0 commit comments

Comments
 (0)