winevt_c 0.2.4-x64-mingw32 → 0.3.0-x64-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d672023362670f5f0a52991cb7cee6ccad756b099fea44854319e25d02fabfd5
4
- data.tar.gz: e739004257c5db401027c4f392c084e9ab69d843313d11e3349f2aa1bc9c5a2a
3
+ metadata.gz: 143e6fcaac67c8c04040b029480d9bbfbc71c572f212e13a63a360b814140296
4
+ data.tar.gz: 4224e2cbe5078ef310c625c52e8590aeaec33ba50d773ed2f449a2460cce899f
5
5
  SHA512:
6
- metadata.gz: f4f785f77ff6252d4cb98825c5d00b29c9ee6390dd33320aa77e6f7aaa725337cff33cec8b5ba9b7f66bc05b45eeb57557829a8fe1568aa2e26e5f749e8a1abd
7
- data.tar.gz: b9e871c40d73583ac5d6252d3db29136c9228c7376f251532a7e65df21719b11bda9ec4caa9c80162d7b50153f54fa07c189aa401dc6e3ca824cbdde70f97a3b
6
+ metadata.gz: 8ef6caaaf8c2f5f949226699f9029a21db7e04ba0784bb200ecd605b007c25387ceb578274c2880496b7e11ab83a09b3ffc09f2e220557cee158e862459563e9
7
+ data.tar.gz: 074657a3a9846105e5ca3ed4639bbc230aca3afea4609ac5097a44435c4e7ba6c0538987b89e3e43816b4dd8c4de26a04c216575c1ef6f1aafe4e5ddd78dcee9
@@ -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
 
@@ -24,6 +24,7 @@
24
24
  char* wstr_to_mbstr(UINT cp, const WCHAR *wstr, int clen);
25
25
  char* render_event(EVT_HANDLE handle, DWORD flags);
26
26
  char* get_description(EVT_HANDLE handle);
27
+ VALUE get_values(EVT_HANDLE handle);
27
28
 
28
29
  VALUE rb_cQuery;
29
30
  VALUE rb_cChannel;
@@ -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(2, rb_winevt_query_render(self), rb_winevt_query_message(self));
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(2, rb_winevt_subscribe_render(self), rb_winevt_subscribe_message(self));
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);
@@ -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
- hModule,
212
- eventId,
213
- 0, // Use current code page. Users must specify character encoding in Ruby side.
214
- descriptionBuffer,
215
- MAX_BUFFER,
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
Binary file
Binary file
Binary file
@@ -1,3 +1,3 @@
1
1
  module Winevt
2
- VERSION = "0.2.4"
2
+ VERSION = "0.3.0"
3
3
  end
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.2.4
4
+ version: 0.3.0
5
5
  platform: x64-mingw32
6
6
  authors:
7
7
  - Hiroshi Hatake
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-22 00:00:00.000000000 Z
11
+ date: 2019-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler