winevt_c 0.2.4-x86-mingw32 → 0.3.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/winevt/extconf.rb +3 -1
- data/ext/winevt/winevt_c.h +1 -0
- data/ext/winevt/winevt_query.c +14 -1
- data/ext/winevt/winevt_subscribe.c +14 -1
- data/ext/winevt/winevt_utils.c +184 -5
- data/lib/winevt/2.4/winevt.so +0 -0
- data/lib/winevt/2.5/winevt.so +0 -0
- data/lib/winevt/2.6/winevt.so +0 -0
- data/lib/winevt/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec281ab900bda5f04c90ce925feb586e29baa7765b92c523054f99dad40874d4
|
4
|
+
data.tar.gz: 74c01f7f85c5d3d26364883ceba104d1640a286736a654a079e9dbe7198a8186
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d92bdbd2c84912e045678c8bff2cf6dfa08dac8472147e68c57a3ac6f5d87d1020fdbeed5a279b999ae50282909569edb5777790bcb20fd62ae9df3111114bb
|
7
|
+
data.tar.gz: d5e37e9b7066db2b79e26ac89ebd43d92694640a0eeb7a8a9c0e18aa82b34d040bb217a74dca725710fd6ab6941381c1d98c2d4cfd3f2461f3e3ffcf052d1107
|
data/ext/winevt/extconf.rb
CHANGED
@@ -12,8 +12,10 @@ dir_config("winevt", includedir, libdir)
|
|
12
12
|
|
13
13
|
have_library("wevtapi")
|
14
14
|
have_func("EvtQuery", "winevt.h")
|
15
|
+
have_library("advapi32")
|
16
|
+
have_library("ole32")
|
15
17
|
|
16
|
-
$LDFLAGS << " -lwevtapi"
|
18
|
+
$LDFLAGS << " -lwevtapi -ladvapi32 -lole32"
|
17
19
|
$CFLAGS << " -std=c99 -fPIC -fms-extensions "
|
18
20
|
# $CFLAGS << " -g -O0"
|
19
21
|
|
data/ext/winevt/winevt_c.h
CHANGED
data/ext/winevt/winevt_query.c
CHANGED
@@ -159,6 +159,15 @@ rb_winevt_query_message(VALUE self)
|
|
159
159
|
return rb_utf8_str_new_cstr(result);
|
160
160
|
}
|
161
161
|
|
162
|
+
static VALUE
|
163
|
+
rb_winevt_query_string_inserts(VALUE self)
|
164
|
+
{
|
165
|
+
struct WinevtQuery *winevtQuery;
|
166
|
+
|
167
|
+
TypedData_Get_Struct(self, struct WinevtQuery, &rb_winevt_query_type, winevtQuery);
|
168
|
+
return get_values(winevtQuery->event);
|
169
|
+
}
|
170
|
+
|
162
171
|
static DWORD
|
163
172
|
get_evt_seek_flag_from_cstr(char* flag_str)
|
164
173
|
{
|
@@ -221,7 +230,10 @@ rb_winevt_query_each(VALUE self)
|
|
221
230
|
TypedData_Get_Struct(self, struct WinevtQuery, &rb_winevt_query_type, winevtQuery);
|
222
231
|
|
223
232
|
while (rb_winevt_query_next(self)) {
|
224
|
-
rb_yield_values(
|
233
|
+
rb_yield_values(3,
|
234
|
+
rb_winevt_query_render(self),
|
235
|
+
rb_winevt_query_message(self),
|
236
|
+
rb_winevt_query_string_inserts(self));
|
225
237
|
}
|
226
238
|
|
227
239
|
return Qnil;
|
@@ -236,6 +248,7 @@ void Init_winevt_query(VALUE rb_cEventLog)
|
|
236
248
|
rb_define_method(rb_cQuery, "next", rb_winevt_query_next, 0);
|
237
249
|
rb_define_method(rb_cQuery, "render", rb_winevt_query_render, 0);
|
238
250
|
rb_define_method(rb_cQuery, "message", rb_winevt_query_message, 0);
|
251
|
+
rb_define_method(rb_cQuery, "string_inserts", rb_winevt_query_string_inserts, 0);
|
239
252
|
rb_define_method(rb_cQuery, "seek", rb_winevt_query_seek, 1);
|
240
253
|
rb_define_method(rb_cQuery, "offset", rb_winevt_query_get_offset, 0);
|
241
254
|
rb_define_method(rb_cQuery, "offset=", rb_winevt_query_set_offset, 1);
|
@@ -174,6 +174,15 @@ rb_winevt_subscribe_message(VALUE self)
|
|
174
174
|
return rb_utf8_str_new_cstr(result);
|
175
175
|
}
|
176
176
|
|
177
|
+
static VALUE
|
178
|
+
rb_winevt_subscribe_string_inserts(VALUE self)
|
179
|
+
{
|
180
|
+
struct WinevtSubscribe *winevtSubscribe;
|
181
|
+
|
182
|
+
TypedData_Get_Struct(self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
|
183
|
+
return get_values(winevtSubscribe->event);
|
184
|
+
}
|
185
|
+
|
177
186
|
static VALUE
|
178
187
|
rb_winevt_subscribe_each(VALUE self)
|
179
188
|
{
|
@@ -184,7 +193,10 @@ rb_winevt_subscribe_each(VALUE self)
|
|
184
193
|
TypedData_Get_Struct(self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
|
185
194
|
|
186
195
|
while (rb_winevt_subscribe_next(self)) {
|
187
|
-
rb_yield_values(
|
196
|
+
rb_yield_values(3,
|
197
|
+
rb_winevt_subscribe_render(self),
|
198
|
+
rb_winevt_subscribe_message(self),
|
199
|
+
rb_winevt_subscribe_string_inserts(self));
|
188
200
|
}
|
189
201
|
|
190
202
|
return Qnil;
|
@@ -213,6 +225,7 @@ void Init_winevt_subscribe(VALUE rb_cEventLog)
|
|
213
225
|
rb_define_method(rb_cSubscribe, "next", rb_winevt_subscribe_next, 0);
|
214
226
|
rb_define_method(rb_cSubscribe, "render", rb_winevt_subscribe_render, 0);
|
215
227
|
rb_define_method(rb_cSubscribe, "message", rb_winevt_subscribe_message, 0);
|
228
|
+
rb_define_method(rb_cSubscribe, "string_inserts", rb_winevt_subscribe_string_inserts, 0);
|
216
229
|
rb_define_method(rb_cSubscribe, "each", rb_winevt_subscribe_each, 0);
|
217
230
|
rb_define_method(rb_cSubscribe, "bookmark", rb_winevt_subscribe_get_bookmark, 0);
|
218
231
|
rb_define_method(rb_cSubscribe, "tail?", rb_winevt_subscribe_tail_p, 0);
|
data/ext/winevt/winevt_utils.c
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
#include <winevt_c.h>
|
2
|
+
#include <sddl.h>
|
3
|
+
#include <stdlib.h>
|
2
4
|
|
3
5
|
char*
|
4
6
|
wstr_to_mbstr(UINT cp, const WCHAR *wstr, int clen)
|
@@ -69,6 +71,183 @@ char* render_event(EVT_HANDLE handle, DWORD flags)
|
|
69
71
|
return result;
|
70
72
|
}
|
71
73
|
|
74
|
+
VALUE get_values(EVT_HANDLE handle)
|
75
|
+
{
|
76
|
+
PWSTR buffer = NULL;
|
77
|
+
ULONG bufferSize = 0;
|
78
|
+
ULONG bufferSizeNeeded = 0;
|
79
|
+
DWORD status, propCount = 0;
|
80
|
+
char *result = "";
|
81
|
+
LPTSTR msgBuf;
|
82
|
+
WCHAR* tmpWChar = NULL;
|
83
|
+
VALUE userValues = rb_ary_new();
|
84
|
+
|
85
|
+
static PCWSTR eventProperties[] = { L"Event/EventData/Data[1]" };
|
86
|
+
EVT_HANDLE renderContext = EvtCreateRenderContext(0, NULL, EvtRenderContextUser);
|
87
|
+
if (renderContext == NULL) {
|
88
|
+
rb_raise(rb_eWinevtQueryError, "Failed to create renderContext");
|
89
|
+
}
|
90
|
+
|
91
|
+
do {
|
92
|
+
if (bufferSizeNeeded > bufferSize) {
|
93
|
+
free(buffer);
|
94
|
+
bufferSize = bufferSizeNeeded;
|
95
|
+
buffer = malloc(bufferSize);
|
96
|
+
if (buffer == NULL) {
|
97
|
+
status = ERROR_OUTOFMEMORY;
|
98
|
+
bufferSize = 0;
|
99
|
+
rb_raise(rb_eWinevtQueryError, "Out of memory");
|
100
|
+
break;
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
if (EvtRender(renderContext,
|
105
|
+
handle,
|
106
|
+
EvtRenderEventValues,
|
107
|
+
bufferSize,
|
108
|
+
buffer,
|
109
|
+
&bufferSizeNeeded,
|
110
|
+
&propCount) != FALSE) {
|
111
|
+
status = ERROR_SUCCESS;
|
112
|
+
} else {
|
113
|
+
status = GetLastError();
|
114
|
+
}
|
115
|
+
} while (status == ERROR_INSUFFICIENT_BUFFER);
|
116
|
+
|
117
|
+
if (status != ERROR_SUCCESS) {
|
118
|
+
FormatMessage(
|
119
|
+
FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
120
|
+
FORMAT_MESSAGE_FROM_SYSTEM |
|
121
|
+
FORMAT_MESSAGE_IGNORE_INSERTS,
|
122
|
+
NULL, status,
|
123
|
+
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
124
|
+
&msgBuf, 0, NULL);
|
125
|
+
result = wstr_to_mbstr(CP_ACP, msgBuf, -1);
|
126
|
+
|
127
|
+
rb_raise(rb_eWinevtQueryError, "ErrorCode: %d\nError: %s\n", status, result);
|
128
|
+
}
|
129
|
+
|
130
|
+
PEVT_VARIANT pRenderedValues = (PEVT_VARIANT)buffer;
|
131
|
+
LARGE_INTEGER timestamp;
|
132
|
+
SYSTEMTIME st;
|
133
|
+
FILETIME ft;
|
134
|
+
CHAR strTime[128];
|
135
|
+
VALUE rbObj;
|
136
|
+
|
137
|
+
for (int i = 0; i < propCount; i++) {
|
138
|
+
switch (pRenderedValues[i].Type) {
|
139
|
+
case EvtVarTypeString:
|
140
|
+
if (pRenderedValues[i].StringVal == NULL) {
|
141
|
+
rb_ary_push(userValues, rb_utf8_str_new_cstr("(NULL)"));
|
142
|
+
} else {
|
143
|
+
result = wstr_to_mbstr(CP_UTF8, pRenderedValues[i].StringVal, -1);
|
144
|
+
rb_ary_push(userValues, rb_utf8_str_new_cstr(result));
|
145
|
+
}
|
146
|
+
break;
|
147
|
+
case EvtVarTypeAnsiString:
|
148
|
+
if (pRenderedValues[i].AnsiStringVal == NULL) {
|
149
|
+
rb_ary_push(userValues, rb_utf8_str_new_cstr("(NULL)"));
|
150
|
+
} else {
|
151
|
+
rb_ary_push(userValues, rb_utf8_str_new_cstr((char *)pRenderedValues[i].AnsiStringVal));
|
152
|
+
}
|
153
|
+
break;
|
154
|
+
case EvtVarTypeSByte:
|
155
|
+
rbObj = INT2NUM((INT32)pRenderedValues[i].SByteVal);
|
156
|
+
rb_ary_push(userValues, rbObj);
|
157
|
+
break;
|
158
|
+
case EvtVarTypeByte:
|
159
|
+
rbObj = INT2NUM((UINT32)pRenderedValues[i].ByteVal);
|
160
|
+
rb_ary_push(userValues, rbObj);
|
161
|
+
break;
|
162
|
+
case EvtVarTypeInt16:
|
163
|
+
rbObj = INT2NUM((INT32)pRenderedValues[i].Int16Val);
|
164
|
+
rb_ary_push(userValues, rbObj);
|
165
|
+
break;
|
166
|
+
case EvtVarTypeUInt16:
|
167
|
+
rbObj = UINT2NUM((UINT32)pRenderedValues[i].UInt16Val);
|
168
|
+
rb_ary_push(userValues, rbObj);
|
169
|
+
break;
|
170
|
+
case EvtVarTypeInt32:
|
171
|
+
rbObj = INT2NUM(pRenderedValues[i].Int32Val);
|
172
|
+
rb_ary_push(userValues, rbObj);
|
173
|
+
break;
|
174
|
+
case EvtVarTypeUInt32:
|
175
|
+
rbObj = UINT2NUM(pRenderedValues[i].UInt32Val);
|
176
|
+
rb_ary_push(userValues, rbObj);
|
177
|
+
break;
|
178
|
+
case EvtVarTypeInt64:
|
179
|
+
rbObj = LONG2NUM(pRenderedValues[i].Int64Val);
|
180
|
+
rb_ary_push(userValues, rbObj);
|
181
|
+
break;
|
182
|
+
case EvtVarTypeUInt64:
|
183
|
+
rbObj = ULONG2NUM(pRenderedValues[i].UInt64Val);
|
184
|
+
rb_ary_push(userValues, rbObj);
|
185
|
+
break;
|
186
|
+
case EvtVarTypeSingle:
|
187
|
+
sprintf(result, "%f", pRenderedValues[i].SingleVal);
|
188
|
+
rb_ary_push(userValues, rb_utf8_str_new_cstr(result));
|
189
|
+
break;
|
190
|
+
case EvtVarTypeDouble:
|
191
|
+
sprintf(result, "%lf", pRenderedValues[i].DoubleVal);
|
192
|
+
rb_ary_push(userValues, rb_utf8_str_new_cstr(result));
|
193
|
+
break;
|
194
|
+
case EvtVarTypeBoolean:
|
195
|
+
result = pRenderedValues[i].BooleanVal ? "true" : "false";
|
196
|
+
rb_ary_push(userValues, rb_utf8_str_new_cstr(result));
|
197
|
+
break;
|
198
|
+
case EvtVarTypeHexInt32:
|
199
|
+
rbObj = ULONG2NUM(pRenderedValues[i].UInt32Val);
|
200
|
+
rbObj = rb_sprintf("%#x", rbObj);
|
201
|
+
rb_ary_push(userValues, rbObj);
|
202
|
+
break;
|
203
|
+
case EvtVarTypeHexInt64:
|
204
|
+
rbObj = ULONG2NUM(pRenderedValues[i].UInt64Val);
|
205
|
+
rbObj = rb_sprintf("%#x", rbObj);
|
206
|
+
rb_ary_push(userValues, rbObj);
|
207
|
+
break;
|
208
|
+
case EvtVarTypeGuid:
|
209
|
+
if (pRenderedValues[i].GuidVal != NULL) {
|
210
|
+
StringFromCLSID(pRenderedValues[i].GuidVal, &tmpWChar);
|
211
|
+
result = wstr_to_mbstr(CP_UTF8, tmpWChar, -1);
|
212
|
+
rb_ary_push(userValues, rb_utf8_str_new_cstr(result));
|
213
|
+
} else {
|
214
|
+
rb_ary_push(userValues, rb_utf8_str_new_cstr("?"));
|
215
|
+
}
|
216
|
+
break;
|
217
|
+
case EvtVarTypeSid:
|
218
|
+
if (ConvertSidToStringSidW(pRenderedValues[i].SidVal, &tmpWChar)) {
|
219
|
+
result = wstr_to_mbstr(CP_UTF8, tmpWChar, -1);
|
220
|
+
rb_ary_push(userValues, rb_utf8_str_new_cstr(result));
|
221
|
+
} else {
|
222
|
+
rb_ary_push(userValues, rb_utf8_str_new_cstr("?"));
|
223
|
+
}
|
224
|
+
break;
|
225
|
+
case EvtVarTypeFileTime:
|
226
|
+
timestamp.QuadPart = pRenderedValues[i].FileTimeVal;
|
227
|
+
ft.dwHighDateTime = timestamp.HighPart;
|
228
|
+
ft.dwLowDateTime = timestamp.LowPart;
|
229
|
+
if (FileTimeToSystemTime( &ft, &st )) {
|
230
|
+
sprintf(strTime, "%04d-%02d-%02d %02d:%02d:%02d.%dZ",
|
231
|
+
st.wYear , st.wMonth , st.wDay ,
|
232
|
+
st.wHour , st.wMinute , st.wSecond,
|
233
|
+
st.wMilliseconds);
|
234
|
+
rb_ary_push(userValues, rb_utf8_str_new_cstr(strTime));
|
235
|
+
} else {
|
236
|
+
rb_ary_push(userValues, rb_utf8_str_new_cstr("?"));
|
237
|
+
}
|
238
|
+
break;
|
239
|
+
default:
|
240
|
+
rb_ary_push(userValues, rb_utf8_str_new_cstr("?"));
|
241
|
+
break;
|
242
|
+
}
|
243
|
+
}
|
244
|
+
|
245
|
+
if (buffer)
|
246
|
+
free(buffer);
|
247
|
+
|
248
|
+
return userValues;
|
249
|
+
}
|
250
|
+
|
72
251
|
char* get_description(EVT_HANDLE handle)
|
73
252
|
{
|
74
253
|
#define MAX_BUFFER 65535
|
@@ -208,11 +387,11 @@ char* get_description(EVT_HANDLE handle)
|
|
208
387
|
DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE);
|
209
388
|
|
210
389
|
if(!FormatMessageW(FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS,
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
390
|
+
hModule,
|
391
|
+
eventId,
|
392
|
+
0, // Use current code page. Users must specify character encoding in Ruby side.
|
393
|
+
descriptionBuffer,
|
394
|
+
MAX_BUFFER,
|
216
395
|
NULL)) {
|
217
396
|
if (ERROR_MR_MID_NOT_FOUND == GetLastError()) {
|
218
397
|
// clear buffer
|
data/lib/winevt/2.4/winevt.so
CHANGED
Binary file
|
data/lib/winevt/2.5/winevt.so
CHANGED
Binary file
|
data/lib/winevt/2.6/winevt.so
CHANGED
Binary file
|
data/lib/winevt/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: winevt_c
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: x86-mingw32
|
6
6
|
authors:
|
7
7
|
- Hiroshi Hatake
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|