winevt_c 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1bac257f6ecb7f2f3cd697e067165f74ce990173f01746eb1899473cb859975f
4
- data.tar.gz: 83e7a12cb474e68fb03667b0be0a4b2ea02c950904d4e2aff6e4ec33e48b549d
3
+ metadata.gz: 643bcdf4d5b8c420f73bbb333ff5f43d3aaa49fa5e5c5387f9b56b226a17a95b
4
+ data.tar.gz: 3e1ac4f307bc238cc6fd3b6a1899d40d5906f73760fdab659a2b13155d4aeab0
5
5
  SHA512:
6
- metadata.gz: cb0746e7488a3af43daae3ac699900cd67bbcfd363f2806fe5ef12a40fa8bfa08da261ab825b7f65519462baea439b89341e81cbddb2a825e9d48917e6a4b970
7
- data.tar.gz: d7e69ecbc6e3e3c5b78e4f763f5c1c4509759bcc4b38db3637f8cec3600737a1b0aaceaf5f16b7d1244102ab9f46a29a9642f035e2ab78ca5dd1246160fbc6d1
6
+ metadata.gz: 14c3237a1fd9e278a1413a75736b75c4715daf9c4f58799bf1136784d3e9139a61a0eca41ba124ce5e740507cfc7a6bcb3c991cd31fd0b453ddcd263486aedf0
7
+ data.tar.gz: 45562eefcdac2d2214233ee8633b01f0f2eedd258690fc37dbdfef0aaec7b6ca863f66665f499f1039bff25c8b07d327eaf2d444baad09cb85c8ccea5be9246d
data/README.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  [![Build status](https://ci.appveyor.com/api/projects/status/hr3phv8ihvgc68oj/branch/master?svg=true)](https://ci.appveyor.com/project/cosmo0920/winevt-c/branch/master)
4
4
 
5
+ ## Prerequisites
6
+
7
+ * Windows Vista/Windows Server 2008 or later.
8
+ * gcc and g++ from MSYS2 for building C/C++ extension.
9
+ * Ruby 2.4 or later with MSYS2.
10
+
5
11
  ## Installation
6
12
 
7
13
  Add this line to your application's Gemfile:
@@ -12,11 +18,11 @@ gem 'winevt_c'
12
18
 
13
19
  And then execute:
14
20
 
15
- $ bundle
21
+ $ ridk exec bundle
16
22
 
17
23
  Or install it yourself as:
18
24
 
19
- $ gem install winevt_c
25
+ $ ridk exec gem install winevt_c
20
26
 
21
27
  ## Usage
22
28
 
@@ -80,16 +80,13 @@ static VALUE
80
80
  rb_winevt_bookmark_render(VALUE self)
81
81
  {
82
82
  WCHAR* wResult;
83
- char* result;
84
83
  struct WinevtBookmark *winevtBookmark;
85
84
  VALUE utf8str;
86
85
 
87
86
  TypedData_Get_Struct(self, struct WinevtBookmark, &rb_winevt_bookmark_type, winevtBookmark);
88
87
  wResult = render_event(winevtBookmark->bookmark, EvtRenderBookmark);
89
- result = wstr_to_mbstr(CP_UTF8, wResult, -1);
88
+ utf8str = wstr_to_rb_str(CP_UTF8, wResult, -1);
90
89
 
91
- utf8str = rb_utf8_str_new_cstr(result);
92
- free_allocated_mbstr(result);
93
90
  if (wResult != NULL)
94
91
  free(wResult);
95
92
 
@@ -27,6 +27,7 @@ extern "C" {
27
27
 
28
28
  char* wstr_to_mbstr(UINT cp, const WCHAR *wstr, int clen);
29
29
  void free_allocated_mbstr(const char* str);
30
+ VALUE wstr_to_rb_str(UINT cp, const WCHAR *wstr, int clen);
30
31
  WCHAR* render_event(EVT_HANDLE handle, DWORD flags);
31
32
  WCHAR* get_description(EVT_HANDLE handle);
32
33
  VALUE get_values(EVT_HANDLE handle);
@@ -43,7 +43,6 @@ rb_winevt_channel_each(VALUE self)
43
43
  EVT_HANDLE hChannels;
44
44
  struct WinevtChannel *winevtChannel;
45
45
  char *errBuf = NULL;
46
- char * result;
47
46
  LPWSTR buffer = NULL;
48
47
  LPWSTR temp = NULL;
49
48
  DWORD bufferSize = 0;
@@ -87,10 +86,7 @@ rb_winevt_channel_each(VALUE self)
87
86
  }
88
87
  }
89
88
 
90
- result = wstr_to_mbstr(CP_UTF8, buffer, -1);
91
-
92
- utf8str = rb_utf8_str_new_cstr(result);
93
- free_allocated_mbstr(result);
89
+ utf8str = wstr_to_rb_str(CP_UTF8, buffer, -1);
94
90
 
95
91
  rb_yield(utf8str);
96
92
  }
@@ -138,16 +138,13 @@ static VALUE
138
138
  rb_winevt_query_render(VALUE self)
139
139
  {
140
140
  WCHAR* wResult;
141
- char* result;
142
141
  struct WinevtQuery *winevtQuery;
143
142
  VALUE utf8str;
144
143
 
145
144
  TypedData_Get_Struct(self, struct WinevtQuery, &rb_winevt_query_type, winevtQuery);
146
145
  wResult = render_event(winevtQuery->event, EvtRenderEventXml);
147
- result = wstr_to_mbstr(CP_UTF8, wResult, -1);
146
+ utf8str = wstr_to_rb_str(CP_UTF8, wResult, -1);
148
147
 
149
- utf8str = rb_utf8_str_new_cstr(result);
150
- free_allocated_mbstr(result);
151
148
  if (wResult != NULL)
152
149
  free(wResult);
153
150
 
@@ -158,16 +155,12 @@ static VALUE
158
155
  rb_winevt_query_message(VALUE self)
159
156
  {
160
157
  WCHAR* wResult;
161
- char* result;
162
158
  struct WinevtQuery *winevtQuery;
163
159
  VALUE utf8str;
164
160
 
165
161
  TypedData_Get_Struct(self, struct WinevtQuery, &rb_winevt_query_type, winevtQuery);
166
162
  wResult = get_description(winevtQuery->event);
167
- result = wstr_to_mbstr(CP_UTF8, wResult, -1);
168
-
169
- utf8str = rb_utf8_str_new_cstr(result);
170
- free_allocated_mbstr(result);
163
+ utf8str = wstr_to_rb_str(CP_UTF8, wResult, -1);
171
164
 
172
165
  return utf8str;
173
166
  }
@@ -153,16 +153,13 @@ static VALUE
153
153
  rb_winevt_subscribe_render(VALUE self)
154
154
  {
155
155
  WCHAR* wResult;
156
- char* result;
157
156
  struct WinevtSubscribe *winevtSubscribe;
158
157
  VALUE utf8str;
159
158
 
160
159
  TypedData_Get_Struct(self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
161
160
  wResult = render_event(winevtSubscribe->event, EvtRenderEventXml);
162
- result = wstr_to_mbstr(CP_UTF8, wResult, -1);
161
+ utf8str = wstr_to_rb_str(CP_UTF8, wResult, -1);
163
162
 
164
- utf8str = rb_utf8_str_new_cstr(result);
165
- free_allocated_mbstr(result);
166
163
  if (wResult != NULL)
167
164
  free(wResult);
168
165
 
@@ -173,16 +170,12 @@ static VALUE
173
170
  rb_winevt_subscribe_message(VALUE self)
174
171
  {
175
172
  WCHAR* wResult;
176
- char* result;
177
173
  struct WinevtSubscribe *winevtSubscribe;
178
174
  VALUE utf8str;
179
175
 
180
176
  TypedData_Get_Struct(self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
181
177
  wResult = get_description(winevtSubscribe->event);
182
- result = wstr_to_mbstr(CP_UTF8, wResult, -1);
183
-
184
- utf8str = rb_utf8_str_new_cstr(result);
185
- free_allocated_mbstr(result);
178
+ utf8str = wstr_to_rb_str(CP_UTF8, wResult, -1);
186
179
 
187
180
  return utf8str;
188
181
  }
@@ -219,17 +212,13 @@ static VALUE
219
212
  rb_winevt_subscribe_get_bookmark(VALUE self)
220
213
  {
221
214
  WCHAR* wResult;
222
- char* result;
223
215
  struct WinevtSubscribe *winevtSubscribe;
224
216
  VALUE utf8str;
225
217
 
226
218
  TypedData_Get_Struct(self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
227
219
 
228
220
  wResult = render_event(winevtSubscribe->bookmark, EvtRenderBookmark);
229
- result = wstr_to_mbstr(CP_UTF8, wResult, -1);
230
-
231
- utf8str = rb_utf8_str_new_cstr(result);
232
- free_allocated_mbstr(result);
221
+ utf8str = wstr_to_rb_str(CP_UTF8, wResult, -1);
233
222
 
234
223
  return utf8str;
235
224
  }
@@ -7,9 +7,9 @@ char*
7
7
  wstr_to_mbstr(UINT cp, const WCHAR *wstr, int clen)
8
8
  {
9
9
  char *ptr;
10
- int len = WideCharToMultiByte(cp, 0, wstr, clen, NULL, 0, NULL, NULL);
11
- if (!(ptr = static_cast<char *>(xmalloc(len)))) return 0;
12
- WideCharToMultiByte(cp, 0, wstr, clen, ptr, len, NULL, NULL);
10
+ int len = WideCharToMultiByte(cp, 0, wstr, clen, nullptr, 0, nullptr, nullptr);
11
+ if (!(ptr = static_cast<char *>(xmalloc(len)))) return nullptr;
12
+ WideCharToMultiByte(cp, 0, wstr, clen, ptr, len, nullptr, nullptr);
13
13
 
14
14
  return ptr;
15
15
  }
@@ -20,9 +20,19 @@ void free_allocated_mbstr(const char* str)
20
20
  xfree((char *)str);
21
21
  }
22
22
 
23
+ VALUE
24
+ wstr_to_rb_str(UINT cp, const WCHAR *wstr, int clen)
25
+ {
26
+ int len = WideCharToMultiByte(cp, 0, wstr, clen, nullptr, 0, nullptr, nullptr);
27
+ VALUE str = rb_utf8_str_new(0, len);
28
+ WideCharToMultiByte(cp, 0, wstr, clen, RSTRING_PTR(str), len, nullptr, nullptr);
29
+
30
+ return str;
31
+ }
32
+
23
33
  WCHAR* render_event(EVT_HANDLE handle, DWORD flags)
24
34
  {
25
- PWSTR buffer = NULL;
35
+ PWSTR buffer = nullptr;
26
36
  ULONG bufferSize = 0;
27
37
  ULONG bufferSizeNeeded = 0;
28
38
  ULONG status, count;
@@ -34,7 +44,7 @@ WCHAR* render_event(EVT_HANDLE handle, DWORD flags)
34
44
  free(buffer);
35
45
  bufferSize = bufferSizeNeeded;
36
46
  buffer = static_cast<WCHAR *>(xmalloc(bufferSize));
37
- if (buffer == NULL) {
47
+ if (buffer == nullptr) {
38
48
  status = ERROR_OUTOFMEMORY;
39
49
  bufferSize = 0;
40
50
  rb_raise(rb_eWinevtQueryError, "Out of memory");
@@ -42,7 +52,7 @@ WCHAR* render_event(EVT_HANDLE handle, DWORD flags)
42
52
  }
43
53
  }
44
54
 
45
- if (EvtRender(NULL,
55
+ if (EvtRender(nullptr,
46
56
  handle,
47
57
  flags,
48
58
  bufferSize,
@@ -60,9 +70,9 @@ WCHAR* render_event(EVT_HANDLE handle, DWORD flags)
60
70
  FORMAT_MESSAGE_ALLOCATE_BUFFER |
61
71
  FORMAT_MESSAGE_FROM_SYSTEM |
62
72
  FORMAT_MESSAGE_IGNORE_INSERTS,
63
- NULL, status,
73
+ nullptr, status,
64
74
  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
65
- msgBuf, 0, NULL);
75
+ msgBuf, 0, nullptr);
66
76
 
67
77
  VALUE errmsg = rb_str_new2(msgBuf);
68
78
  LocalFree(msgBuf);
@@ -79,9 +89,9 @@ WCHAR* render_event(EVT_HANDLE handle, DWORD flags)
79
89
  }
80
90
 
81
91
  static std::wstring guid_to_wstr(const GUID& guid) {
82
- LPOLESTR p = NULL;
92
+ LPOLESTR p = nullptr;
83
93
  if (FAILED(StringFromCLSID(guid, &p))) {
84
- return NULL;
94
+ return nullptr;
85
95
  }
86
96
  std::wstring s(p);
87
97
  CoTaskMemFree(p);
@@ -96,12 +106,12 @@ VALUE get_values(EVT_HANDLE handle)
96
106
  DWORD status, propCount = 0;
97
107
  char *result;
98
108
  LPTSTR msgBuf;
99
- WCHAR* tmpWChar = NULL;
109
+ WCHAR* tmpWChar = nullptr;
100
110
  VALUE userValues = rb_ary_new();
101
111
 
102
112
  static PCWSTR eventProperties[] = { L"Event/EventData/Data[1]" };
103
- EVT_HANDLE renderContext = EvtCreateRenderContext(0, NULL, EvtRenderContextUser);
104
- if (renderContext == NULL) {
113
+ EVT_HANDLE renderContext = EvtCreateRenderContext(0, nullptr, EvtRenderContextUser);
114
+ if (renderContext == nullptr) {
105
115
  rb_raise(rb_eWinevtQueryError, "Failed to create renderContext");
106
116
  }
107
117
 
@@ -136,9 +146,9 @@ VALUE get_values(EVT_HANDLE handle)
136
146
  FORMAT_MESSAGE_ALLOCATE_BUFFER |
137
147
  FORMAT_MESSAGE_FROM_SYSTEM |
138
148
  FORMAT_MESSAGE_IGNORE_INSERTS,
139
- NULL, status,
149
+ nullptr, status,
140
150
  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
141
- msgBuf, 0, NULL);
151
+ msgBuf, 0, nullptr);
142
152
 
143
153
  VALUE errmsg = rb_str_new2(msgBuf);
144
154
  LocalFree(msgBuf);
@@ -146,11 +156,12 @@ VALUE get_values(EVT_HANDLE handle)
146
156
  rb_raise(rb_eWinevtQueryError, "ErrorCode: %lu\nError: %s\n", status, RSTRING_PTR(errmsg));
147
157
  }
148
158
 
149
- PEVT_VARIANT pRenderedValues = (PEVT_VARIANT)buffer.c_str();
159
+ PEVT_VARIANT pRenderedValues = reinterpret_cast<PEVT_VARIANT>(const_cast<WCHAR *>(buffer.c_str()));
150
160
  LARGE_INTEGER timestamp;
151
161
  SYSTEMTIME st;
152
162
  FILETIME ft;
153
- CHAR strTime[128];
163
+ std::string strTime;
164
+ std::string sResult;
154
165
  VALUE rbObj;
155
166
 
156
167
  for (int i = 0; i < propCount; i++) {
@@ -159,35 +170,34 @@ VALUE get_values(EVT_HANDLE handle)
159
170
  rb_ary_push(userValues, Qnil);
160
171
  break;
161
172
  case EvtVarTypeString:
162
- if (pRenderedValues[i].StringVal == NULL) {
173
+ if (pRenderedValues[i].StringVal == nullptr) {
163
174
  rb_ary_push(userValues, rb_utf8_str_new_cstr("(NULL)"));
164
175
  } else {
165
- result = wstr_to_mbstr(CP_UTF8, pRenderedValues[i].StringVal, -1);
166
- rb_ary_push(userValues, rb_utf8_str_new_cstr(result));
167
- free_allocated_mbstr(result);
176
+ rbObj = wstr_to_rb_str(CP_UTF8, pRenderedValues[i].StringVal, -1);
177
+ rb_ary_push(userValues, rbObj);
168
178
  }
169
179
  break;
170
180
  case EvtVarTypeAnsiString:
171
- if (pRenderedValues[i].AnsiStringVal == NULL) {
181
+ if (pRenderedValues[i].AnsiStringVal == nullptr) {
172
182
  rb_ary_push(userValues, rb_utf8_str_new_cstr("(NULL)"));
173
183
  } else {
174
- rb_ary_push(userValues, rb_utf8_str_new_cstr((char *)pRenderedValues[i].AnsiStringVal));
184
+ rb_ary_push(userValues, rb_utf8_str_new_cstr(const_cast<char *>(pRenderedValues[i].AnsiStringVal)));
175
185
  }
176
186
  break;
177
187
  case EvtVarTypeSByte:
178
- rbObj = INT2NUM((INT32)pRenderedValues[i].SByteVal);
188
+ rbObj = INT2NUM(static_cast<UINT32>(pRenderedValues[i].SByteVal));
179
189
  rb_ary_push(userValues, rbObj);
180
190
  break;
181
191
  case EvtVarTypeByte:
182
- rbObj = INT2NUM((UINT32)pRenderedValues[i].ByteVal);
192
+ rbObj = INT2NUM(static_cast<UINT32>(pRenderedValues[i].ByteVal));
183
193
  rb_ary_push(userValues, rbObj);
184
194
  break;
185
195
  case EvtVarTypeInt16:
186
- rbObj = INT2NUM((INT32)pRenderedValues[i].Int16Val);
196
+ rbObj = INT2NUM(static_cast<INT32>(pRenderedValues[i].Int16Val));
187
197
  rb_ary_push(userValues, rbObj);
188
198
  break;
189
199
  case EvtVarTypeUInt16:
190
- rbObj = UINT2NUM((UINT32)pRenderedValues[i].UInt16Val);
200
+ rbObj = UINT2NUM(static_cast<UINT32>(pRenderedValues[i].UInt16Val));
191
201
  rb_ary_push(userValues, rbObj);
192
202
  break;
193
203
  case EvtVarTypeInt32:
@@ -207,25 +217,23 @@ VALUE get_values(EVT_HANDLE handle)
207
217
  rb_ary_push(userValues, rbObj);
208
218
  break;
209
219
  case EvtVarTypeSingle:
210
- sprintf(result, "%f", pRenderedValues[i].SingleVal);
211
- rb_ary_push(userValues, rb_utf8_str_new_cstr(result));
212
- free_allocated_mbstr(result);
220
+ sprintf(&sResult[0], "%f", pRenderedValues[i].SingleVal);
221
+ rb_ary_push(userValues, rb_utf8_str_new_cstr(sResult.c_str()));
213
222
  break;
214
223
  case EvtVarTypeDouble:
215
- sprintf(result, "%lf", pRenderedValues[i].DoubleVal);
216
- rb_ary_push(userValues, rb_utf8_str_new_cstr(result));
224
+ sprintf(&sResult[0], "%lf", pRenderedValues[i].DoubleVal);
225
+ rb_ary_push(userValues, rb_utf8_str_new_cstr(sResult.c_str()));
217
226
  break;
218
227
  case EvtVarTypeBoolean:
219
228
  result = const_cast<char *>(pRenderedValues[i].BooleanVal ? "true" : "false");
220
229
  rb_ary_push(userValues, rb_utf8_str_new_cstr(result));
221
230
  break;
222
231
  case EvtVarTypeGuid:
223
- if (pRenderedValues[i].GuidVal != NULL) {
232
+ if (pRenderedValues[i].GuidVal != nullptr) {
224
233
  const GUID guid = *pRenderedValues[i].GuidVal;
225
234
  std::wstring wstr = guid_to_wstr(guid);
226
- result = wstr_to_mbstr(CP_UTF8, wstr.c_str(), -1);
227
- rb_ary_push(userValues, rb_utf8_str_new_cstr(result));
228
- free_allocated_mbstr(result);
235
+ rbObj = wstr_to_rb_str(CP_UTF8, wstr.c_str(), -1);
236
+ rb_ary_push(userValues, rbObj);
229
237
  } else {
230
238
  rb_ary_push(userValues, rb_utf8_str_new_cstr("?"));
231
239
  }
@@ -239,32 +247,31 @@ VALUE get_values(EVT_HANDLE handle)
239
247
  ft.dwHighDateTime = timestamp.HighPart;
240
248
  ft.dwLowDateTime = timestamp.LowPart;
241
249
  if (FileTimeToSystemTime( &ft, &st )) {
242
- sprintf(strTime, "%04d-%02d-%02d %02d:%02d:%02d.%dZ",
250
+ sprintf(&strTime[0], "%04d-%02d-%02d %02d:%02d:%02d.%dZ",
243
251
  st.wYear , st.wMonth , st.wDay ,
244
252
  st.wHour , st.wMinute , st.wSecond,
245
253
  st.wMilliseconds);
246
- rb_ary_push(userValues, rb_utf8_str_new_cstr(strTime));
254
+ rb_ary_push(userValues, rb_utf8_str_new_cstr(strTime.c_str()));
247
255
  } else {
248
256
  rb_ary_push(userValues, rb_utf8_str_new_cstr("?"));
249
257
  }
250
258
  break;
251
259
  case EvtVarTypeSysTime:
252
- if (pRenderedValues[i].SysTimeVal != NULL) {
260
+ if (pRenderedValues[i].SysTimeVal != nullptr) {
253
261
  st = *pRenderedValues[i].SysTimeVal;
254
- sprintf(strTime, "%04d-%02d-%02d %02d:%02d:%02d.%dZ",
262
+ sprintf(&strTime[0], "%04d-%02d-%02d %02d:%02d:%02d.%dZ",
255
263
  st.wYear , st.wMonth , st.wDay ,
256
264
  st.wHour , st.wMinute , st.wSecond,
257
265
  st.wMilliseconds);
258
- rb_ary_push(userValues, rb_utf8_str_new_cstr(strTime));
266
+ rb_ary_push(userValues, rb_utf8_str_new_cstr(strTime.c_str()));
259
267
  } else {
260
268
  rb_ary_push(userValues, rb_utf8_str_new_cstr("?"));
261
269
  }
262
270
  break;
263
271
  case EvtVarTypeSid:
264
272
  if (ConvertSidToStringSidW(pRenderedValues[i].SidVal, &tmpWChar)) {
265
- result = wstr_to_mbstr(CP_UTF8, tmpWChar, -1);
266
- rb_ary_push(userValues, rb_utf8_str_new_cstr(result));
267
- free_allocated_mbstr(result);
273
+ rbObj = wstr_to_rb_str(CP_UTF8, tmpWChar, -1);
274
+ rb_ary_push(userValues, rbObj);
268
275
  LocalFree(tmpWChar);
269
276
  } else {
270
277
  rb_ary_push(userValues, rb_utf8_str_new_cstr("?"));
@@ -281,12 +288,11 @@ VALUE get_values(EVT_HANDLE handle)
281
288
  rb_ary_push(userValues, rbObj);
282
289
  break;
283
290
  case EvtVarTypeEvtXml:
284
- if (pRenderedValues[i].XmlVal == NULL) {
291
+ if (pRenderedValues[i].XmlVal == nullptr) {
285
292
  rb_ary_push(userValues, rb_utf8_str_new_cstr("(NULL)"));
286
293
  } else {
287
- result = wstr_to_mbstr(CP_UTF8, pRenderedValues[i].XmlVal, -1);
288
- rb_ary_push(userValues, rb_utf8_str_new_cstr(result));
289
- free_allocated_mbstr(result);
294
+ rbObj = wstr_to_rb_str(CP_UTF8, pRenderedValues[i].XmlVal, -1);
295
+ rb_ary_push(userValues, rbObj);
290
296
  }
291
297
  break;
292
298
  default:
@@ -310,7 +316,7 @@ static std::wstring get_message(EVT_HANDLE hMetadata, EVT_HANDLE handle)
310
316
  LPVOID lpMsgBuf;
311
317
  std::wstring message(BUFSIZE, '\0');
312
318
 
313
- if (!EvtFormatMessage(hMetadata, handle, 0xffffffff, 0, NULL, EvtFormatMessageEvent, message.size(), &message[0], &bufferSizeNeeded)) {
319
+ if (!EvtFormatMessage(hMetadata, handle, 0xffffffff, 0, nullptr, EvtFormatMessageEvent, message.size(), &message[0], &bufferSizeNeeded)) {
314
320
  status = GetLastError();
315
321
 
316
322
  if (status != ERROR_EVT_UNRESOLVED_VALUE_INSERT) {
@@ -324,19 +330,19 @@ static std::wstring get_message(EVT_HANDLE hMetadata, EVT_HANDLE handle)
324
330
  if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
325
331
  FORMAT_MESSAGE_FROM_SYSTEM |
326
332
  FORMAT_MESSAGE_IGNORE_INSERTS,
327
- NULL,
333
+ nullptr,
328
334
  status,
329
335
  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
330
- (WCHAR *) &lpMsgBuf, 0, NULL) == 0)
336
+ reinterpret_cast<WCHAR *>(&lpMsgBuf), 0, nullptr) == 0)
331
337
  FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
332
338
  FORMAT_MESSAGE_FROM_SYSTEM |
333
339
  FORMAT_MESSAGE_IGNORE_INSERTS,
334
- NULL,
340
+ nullptr,
335
341
  status,
336
342
  MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
337
- (WCHAR *) &lpMsgBuf, 0, NULL);
343
+ reinterpret_cast<WCHAR *>(&lpMsgBuf), 0, nullptr);
338
344
 
339
- result = (WCHAR *)lpMsgBuf;
345
+ result = reinterpret_cast<WCHAR *>(lpMsgBuf);
340
346
  LocalFree(lpMsgBuf);
341
347
 
342
348
  goto cleanup;
@@ -351,7 +357,7 @@ static std::wstring get_message(EVT_HANDLE hMetadata, EVT_HANDLE handle)
351
357
  if (status == ERROR_INSUFFICIENT_BUFFER) {
352
358
  message.resize(bufferSizeNeeded);
353
359
 
354
- if(!EvtFormatMessage(hMetadata, handle, 0xffffffff, 0, NULL, EvtFormatMessageEvent, message.size(), &message[0], &bufferSizeNeeded)) {
360
+ if(!EvtFormatMessage(hMetadata, handle, 0xffffffff, 0, nullptr, EvtFormatMessageEvent, message.size(), &message[0], &bufferSizeNeeded)) {
355
361
  status = GetLastError();
356
362
 
357
363
  if (status != ERROR_EVT_UNRESOLVED_VALUE_INSERT) {
@@ -365,19 +371,19 @@ static std::wstring get_message(EVT_HANDLE hMetadata, EVT_HANDLE handle)
365
371
  if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
366
372
  FORMAT_MESSAGE_FROM_SYSTEM |
367
373
  FORMAT_MESSAGE_IGNORE_INSERTS,
368
- NULL,
374
+ nullptr,
369
375
  status,
370
376
  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
371
- (WCHAR *) &lpMsgBuf, 0, NULL) == 0)
377
+ reinterpret_cast<WCHAR *>(&lpMsgBuf), 0, nullptr) == 0)
372
378
  FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
373
379
  FORMAT_MESSAGE_FROM_SYSTEM |
374
380
  FORMAT_MESSAGE_IGNORE_INSERTS,
375
- NULL,
381
+ nullptr,
376
382
  status,
377
383
  MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
378
- (WCHAR *) &lpMsgBuf, 0, NULL);
384
+ reinterpret_cast<WCHAR *>(&lpMsgBuf), 0, nullptr);
379
385
 
380
- result = (WCHAR *)lpMsgBuf;
386
+ result = reinterpret_cast<WCHAR *>(lpMsgBuf);
381
387
  LocalFree(lpMsgBuf);
382
388
 
383
389
  goto cleanup;
@@ -407,11 +413,11 @@ WCHAR* get_description(EVT_HANDLE handle)
407
413
  ULONG status, count;
408
414
  std::wstring result;
409
415
  LPTSTR msgBuf;
410
- EVT_HANDLE hMetadata = NULL;
416
+ EVT_HANDLE hMetadata = nullptr;
411
417
 
412
418
  static PCWSTR eventProperties[] = {L"Event/System/Provider/@Name"};
413
419
  EVT_HANDLE renderContext = EvtCreateRenderContext(1, eventProperties, EvtRenderContextValues);
414
- if (renderContext == NULL) {
420
+ if (renderContext == nullptr) {
415
421
  rb_raise(rb_eWinevtQueryError, "Failed to create renderContext");
416
422
  }
417
423
 
@@ -432,9 +438,9 @@ WCHAR* get_description(EVT_HANDLE handle)
432
438
  FORMAT_MESSAGE_ALLOCATE_BUFFER |
433
439
  FORMAT_MESSAGE_FROM_SYSTEM |
434
440
  FORMAT_MESSAGE_IGNORE_INSERTS,
435
- NULL, status,
441
+ nullptr, status,
436
442
  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
437
- msgBuf, 0, NULL);
443
+ msgBuf, 0, nullptr);
438
444
 
439
445
  VALUE errmsg = rb_str_new2(msgBuf);
440
446
  LocalFree(msgBuf);
@@ -446,8 +452,8 @@ WCHAR* get_description(EVT_HANDLE handle)
446
452
  const PEVT_VARIANT values = reinterpret_cast<PEVT_VARIANT>(const_cast<WCHAR *>(buffer.c_str()));
447
453
 
448
454
  // Open publisher metadata
449
- hMetadata = EvtOpenPublisherMetadata(NULL, values[0].StringVal, NULL, MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), SORT_DEFAULT), 0);
450
- if (hMetadata == NULL) {
455
+ hMetadata = EvtOpenPublisherMetadata(nullptr, values[0].StringVal, nullptr, MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), SORT_DEFAULT), 0);
456
+ if (hMetadata == nullptr) {
451
457
  // When winevt_c cannot open metadata, then give up to obtain
452
458
  // message file and clean up immediately.
453
459
  goto cleanup;
@@ -1,3 +1,3 @@
1
1
  module Winevt
2
- VERSION = "0.4.4"
2
+ VERSION = "0.4.5"
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.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroshi Hatake
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-02 00:00:00.000000000 Z
11
+ date: 2019-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler