win32-eventlog 0.4.6 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +11 -0
- data/README +2 -2
- data/doc/tutorial.txt +24 -27
- data/lib/win32/eventlog.rb +253 -108
- data/test/tc_eventlog.rb +1 -1
- data/win32-eventlog.gemspec +1 -1
- metadata +52 -45
data/CHANGES
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
= 0.4.7 - 8-Dec-2008
|
2
|
+
* Fixed a bug where you couldn't write to custom (parent) event sources.
|
3
|
+
Thanks go to Tim Uckun for the spot.
|
4
|
+
* Now handles ParameterMessageFiles, both in the EventLog.add_event_source
|
5
|
+
method and in terms of getting event descriptions properly. Thanks go to
|
6
|
+
botp for spotting the description problem.
|
7
|
+
* The EventLog.open_backup method handles a block the same way that the
|
8
|
+
EventLog.open method does.
|
9
|
+
* The EventLog.add_event_source now returns the creation disposition
|
10
|
+
instead of self.
|
11
|
+
|
1
12
|
= 0.4.6 - 27-Aug-2007
|
2
13
|
* Reading event logs is now approximately 5-7 times faster!
|
3
14
|
* Fixed a potential bug where, in rare cases, event descriptions could be
|
data/README
CHANGED
@@ -50,8 +50,8 @@
|
|
50
50
|
them somewhere on your system.
|
51
51
|
|
52
52
|
= Known Issues
|
53
|
-
|
54
|
-
|
53
|
+
None known. Please file any bug reports on the project page at
|
54
|
+
http://www.rubyforge.org/projects/win32utils.
|
55
55
|
|
56
56
|
= License
|
57
57
|
Ruby's
|
data/doc/tutorial.txt
CHANGED
@@ -4,9 +4,6 @@ strings for each event identifier, event category, and parameter. Register
|
|
4
4
|
these files in the EventMessageFile, CategoryMessageFile, and
|
5
5
|
ParameterMessageFile registry values for the event source.
|
6
6
|
|
7
|
-
Note: ParameterMessageFiles are not yet supported in the add_event_source
|
8
|
-
method and probably won't be unless requested.
|
9
|
-
|
10
7
|
You can create one message file that contains descriptions for the event
|
11
8
|
identifiers, categories, and parameters, or create three separate message
|
12
9
|
files. Several applications can share the same message file.
|
@@ -49,21 +46,21 @@ command line utilities. Follow these steps:
|
|
49
46
|
2) rc -r -fo filename.res filename.rc
|
50
47
|
3) link -dll -noentry -out:filename.dll filename.res
|
51
48
|
|
52
|
-
Your other option is to use the win32-mc
|
53
|
-
for the above commands, and is included with this
|
49
|
+
Your other option is to use the win32-mc library, which is a simple wrapper
|
50
|
+
for the above commands, and is included with this library. You now have a
|
54
51
|
dll that you can associate with your event source (i.e. the one you associate
|
55
52
|
with your application). You can also take a look at the C header file that
|
56
53
|
.mc generates and use that in your own extensions if you like.
|
57
54
|
|
58
55
|
After this you'll need to register your event source and associate the .dll
|
59
|
-
file with it. To do that, use the EventLog.add_event_source method.
|
60
|
-
to
|
56
|
+
file with it. To do that, use the EventLog.add_event_source method. Be sure
|
57
|
+
to specify the number of categories manually - it is not calculated
|
61
58
|
automatically by the OS.
|
62
59
|
|
63
60
|
Returning to the .mc file, the example I used actually creates two categories,
|
64
61
|
"error" and "warning", and one event message. The numbers you assign here
|
65
62
|
create corresponding (though not identical) values in the header file that
|
66
|
-
is generated.
|
63
|
+
is generated. It is the values found in the header file that you pass to the
|
67
64
|
EventLog#report_event method for the category or event id. Here's the
|
68
65
|
relevant data from the foo.h file (using foo.mc above):
|
69
66
|
|
@@ -76,46 +73,46 @@ In the case of categories, that number is the name number that shows up in the
|
|
76
73
|
is the text that shows up in the event description.
|
77
74
|
|
78
75
|
The "data" field is what replaces "%1" as an actual text string in the event
|
79
|
-
log, sort of like a printf
|
76
|
+
log, sort of like a printf format specifier, except that it's always a string.
|
80
77
|
|
81
78
|
= Registering an event source
|
82
|
-
First, create the .dll file from the .mc file.
|
83
|
-
for an event source we'll call "foo".
|
79
|
+
First, create the .dll file from the .mc file. Then register that .dll file
|
80
|
+
for an event source we'll call "foo". You can name the .dll file anything
|
84
81
|
you like, but for sanity's sake I recommend keeping the same as the event
|
85
82
|
source name.
|
86
83
|
|
87
|
-
require
|
84
|
+
require 'win32/eventlog'
|
88
85
|
include Win32
|
89
86
|
|
90
|
-
dll_file =
|
87
|
+
dll_file = 'c:\\wherever\\foo.dll'
|
91
88
|
|
92
89
|
EventLog.add_event_source(
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
90
|
+
:source => 'Application',
|
91
|
+
:key_name => 'foo',
|
92
|
+
:category_count => 2,
|
93
|
+
:event_message_file => dll_file,
|
94
|
+
:category_message_file => dll_file
|
98
95
|
)
|
99
96
|
|
100
|
-
After you run this, you can run regedit and see that your event source has
|
101
|
-
been inserted into the registry.
|
97
|
+
After you run this, you can run 'regedit' and see that your event source has
|
98
|
+
been inserted into the registry. You can find it under:
|
102
99
|
|
103
100
|
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Application.
|
104
101
|
|
105
102
|
= Writing to the event source
|
106
|
-
Now that our event source
|
103
|
+
Now that our event source 'foo' is registered, we can begin writing event
|
107
104
|
log data for it. Here's an example of how you use it:
|
108
105
|
|
109
|
-
require
|
106
|
+
require 'win32/eventlog'
|
110
107
|
include Win32
|
111
108
|
|
112
|
-
EventLog.open(
|
109
|
+
EventLog.open('Application') do |log|
|
113
110
|
log.report_event(
|
114
|
-
:source =>
|
111
|
+
:source => 'foo',
|
115
112
|
:event_type => EventLog::WARN,
|
116
|
-
:category =>
|
117
|
-
:event_id =>
|
118
|
-
:data =>
|
113
|
+
:category => '0x00000002L'.hex,
|
114
|
+
:event_id => '0x00000003L'.hex,
|
115
|
+
:data => 'I'm warning you!'
|
119
116
|
)
|
120
117
|
end
|
121
118
|
|
data/lib/win32/eventlog.rb
CHANGED
@@ -37,7 +37,7 @@ module Win32
|
|
37
37
|
extend Windows::Error
|
38
38
|
extend Windows::Registry
|
39
39
|
|
40
|
-
VERSION = '0.4.
|
40
|
+
VERSION = '0.4.7'
|
41
41
|
|
42
42
|
# Aliased read flags
|
43
43
|
FORWARDS_READ = EVENTLOG_FORWARDS_READ
|
@@ -130,7 +130,7 @@ module Win32
|
|
130
130
|
# Nearly identical to EventLog.open, except that the source is a backup
|
131
131
|
# file and not an event source (and there is no default).
|
132
132
|
#
|
133
|
-
def self.open_backup(file, source = 'Application', server = nil)
|
133
|
+
def self.open_backup(file, source = 'Application', server = nil, &block)
|
134
134
|
@file = file
|
135
135
|
@source = source
|
136
136
|
@server = server
|
@@ -139,18 +139,23 @@ module Win32
|
|
139
139
|
raise TypeError unless @file.is_a?(String)
|
140
140
|
raise TypeError unless @source.is_a?(String)
|
141
141
|
raise TypeError unless @server.is_a?(String) if @server
|
142
|
-
|
143
|
-
self.new(source, server, file)
|
142
|
+
|
143
|
+
self.new(source, server, file, &block)
|
144
144
|
end
|
145
145
|
|
146
|
-
# Adds an event source to the registry.
|
146
|
+
# Adds an event source to the registry. Returns the disposition, which
|
147
|
+
# is either REG_CREATED_NEW_KEY (1) or REG_OPENED_EXISTING_KEY (2).
|
148
|
+
#
|
149
|
+
# The following are valid keys:
|
147
150
|
#
|
148
|
-
# * source
|
149
|
-
# * key_name
|
150
|
-
# * category_count
|
151
|
-
# * event_message_file
|
152
|
-
# * category_message_file
|
153
|
-
# *
|
151
|
+
# * source # Source name. Set to "Application" by default
|
152
|
+
# * key_name # Name stored as the registry key
|
153
|
+
# * category_count # Number of supported (custom) categories
|
154
|
+
# * event_message_file # File (dll) that defines events
|
155
|
+
# * category_message_file # File (dll) that defines categories
|
156
|
+
# * parameter_message_file # File (dll) that contains values for
|
157
|
+
# variables in the event description.
|
158
|
+
# * supported_types # See the 'event types' constants
|
154
159
|
#
|
155
160
|
# Of these keys, only +key_name+ is mandatory. An ArgumentError is
|
156
161
|
# raised if you attempt to use an invalid key. If +supported_types+
|
@@ -165,10 +170,8 @@ module Win32
|
|
165
170
|
def self.add_event_source(args)
|
166
171
|
raise TypeError unless args.is_a?(Hash)
|
167
172
|
|
168
|
-
hkey = [0].pack('L')
|
169
|
-
|
170
173
|
valid_keys = %w/source key_name category_count event_message_file
|
171
|
-
category_message_file supported_types/
|
174
|
+
category_message_file parameter_message_file supported_types/
|
172
175
|
|
173
176
|
key_base = "SYSTEM\\CurrentControlSet\\Services\\EventLog\\"
|
174
177
|
|
@@ -192,13 +195,69 @@ module Win32
|
|
192
195
|
raise Error, 'no event_type specified'
|
193
196
|
end
|
194
197
|
|
195
|
-
|
198
|
+
hkey = [0].pack('L')
|
199
|
+
key = key_base + hash['source']
|
200
|
+
|
201
|
+
disposition = [0].pack('L')
|
202
|
+
|
203
|
+
rv = RegCreateKeyEx(
|
204
|
+
HKEY_LOCAL_MACHINE,
|
205
|
+
key,
|
206
|
+
0,
|
207
|
+
nil,
|
208
|
+
REG_OPTION_NON_VOLATILE,
|
209
|
+
KEY_WRITE,
|
210
|
+
nil,
|
211
|
+
hkey,
|
212
|
+
disposition
|
213
|
+
)
|
214
|
+
|
215
|
+
if rv != ERROR_SUCCESS
|
216
|
+
error = 'RegCreateKeyEx() failed: ' + get_last_error
|
217
|
+
raise Error, error
|
218
|
+
end
|
219
|
+
|
220
|
+
hkey = hkey.unpack('L')[0]
|
221
|
+
data = "%SystemRoot%\\System32\\config\\#{hash['source']}.evt"
|
196
222
|
|
197
|
-
|
198
|
-
|
223
|
+
rv = RegSetValueEx(
|
224
|
+
hkey,
|
225
|
+
'File',
|
226
|
+
0,
|
227
|
+
REG_EXPAND_SZ,
|
228
|
+
data,
|
229
|
+
data.size
|
230
|
+
)
|
231
|
+
|
232
|
+
if rv != ERROR_SUCCESS
|
233
|
+
error = 'RegSetValueEx() failed: ', get_last_error
|
234
|
+
RegCloseKey(hkey)
|
199
235
|
raise Error, error
|
200
236
|
end
|
201
237
|
|
238
|
+
RegCloseKey(hkey)
|
239
|
+
|
240
|
+
hkey = [0].pack('L')
|
241
|
+
key = key_base << hash['source'] << "\\" << hash['key_name']
|
242
|
+
|
243
|
+
disposition = [0].pack('L')
|
244
|
+
|
245
|
+
rv = RegCreateKeyEx(
|
246
|
+
HKEY_LOCAL_MACHINE,
|
247
|
+
key,
|
248
|
+
0,
|
249
|
+
nil,
|
250
|
+
REG_OPTION_NON_VOLATILE,
|
251
|
+
KEY_WRITE,
|
252
|
+
nil,
|
253
|
+
hkey,
|
254
|
+
disposition
|
255
|
+
)
|
256
|
+
|
257
|
+
if rv != ERROR_SUCCESS
|
258
|
+
raise Error, 'RegCreateKeyEx() failed: ' + get_last_error
|
259
|
+
end
|
260
|
+
|
202
261
|
hkey = hkey.unpack('L')[0]
|
203
262
|
|
204
263
|
if hash['category_count']
|
@@ -214,7 +273,7 @@ module Win32
|
|
214
273
|
)
|
215
274
|
|
216
275
|
if rv != ERROR_SUCCESS
|
217
|
-
error = 'RegSetValueEx() failed: '
|
276
|
+
error = 'RegSetValueEx() failed: ' + get_last_error
|
218
277
|
RegCloseKey(hkey)
|
219
278
|
raise Error, error
|
220
279
|
end
|
@@ -233,7 +292,7 @@ module Win32
|
|
233
292
|
)
|
234
293
|
|
235
294
|
if rv != ERROR_SUCCESS
|
236
|
-
error = 'RegSetValueEx() failed: '
|
295
|
+
error = 'RegSetValueEx() failed: ' + get_last_error
|
237
296
|
RegCloseKey(hkey)
|
238
297
|
raise Error, error
|
239
298
|
end
|
@@ -252,12 +311,31 @@ module Win32
|
|
252
311
|
)
|
253
312
|
|
254
313
|
if rv != ERROR_SUCCESS
|
255
|
-
error = 'RegSetValueEx() failed: '
|
314
|
+
error = 'RegSetValueEx() failed: ' + get_last_error
|
256
315
|
RegCloseKey(hkey)
|
257
316
|
raise Error, error
|
258
317
|
end
|
259
318
|
end
|
260
319
|
|
320
|
+
if hash['parameter_message_file']
|
321
|
+
data = File.expand_path(hash['parameter_message_file'])
|
322
|
+
|
323
|
+
rv = RegSetValueEx(
|
324
|
+
hkey,
|
325
|
+
'ParameterMessageFile',
|
326
|
+
0,
|
327
|
+
REG_EXPAND_SZ,
|
328
|
+
data,
|
329
|
+
data.size
|
330
|
+
)
|
331
|
+
|
332
|
+
if rv != ERROR_SUCCESS
|
333
|
+
error = 'RegSetValueEx() failed: ' + get_last_error
|
334
|
+
RegCloseKey(hkey)
|
335
|
+
raise Error, error
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
261
339
|
data = [hash['supported_types']].pack('L')
|
262
340
|
rv = RegSetValueEx(
|
263
341
|
hkey,
|
@@ -269,13 +347,14 @@ module Win32
|
|
269
347
|
)
|
270
348
|
|
271
349
|
if rv != ERROR_SUCCESS
|
272
|
-
error = 'RegSetValueEx() failed: '
|
350
|
+
error = 'RegSetValueEx() failed: ' + get_last_error
|
273
351
|
RegCloseKey(hkey)
|
274
352
|
raise Error, error
|
275
353
|
end
|
276
354
|
|
277
355
|
RegCloseKey(hkey)
|
278
|
-
|
356
|
+
|
357
|
+
disposition.unpack('L')[0]
|
279
358
|
end
|
280
359
|
|
281
360
|
# Backs up the event log to +file+. Note that you cannot backup to
|
@@ -429,9 +508,6 @@ module Win32
|
|
429
508
|
end
|
430
509
|
end
|
431
510
|
|
432
|
-
# EventLog#read(flags=nil, offset=0)
|
433
|
-
# EventLog#read(flags=nil, offset=0){ |log| ... }
|
434
|
-
#
|
435
511
|
# Iterates over each record in the event log, yielding a EventLogStruct
|
436
512
|
# for each record. The offset value is only used when used in
|
437
513
|
# conjunction with the EventLog::SEEK_READ flag. Otherwise, it is
|
@@ -445,17 +521,17 @@ module Win32
|
|
445
521
|
#
|
446
522
|
# The EventLogStruct struct contains the following members:
|
447
523
|
#
|
448
|
-
# record_number # Fixnum
|
449
|
-
# time_generated # Time
|
450
|
-
# time_written # Time
|
451
|
-
# event_id # Fixnum
|
452
|
-
# event_type # String
|
453
|
-
# category # String
|
454
|
-
# source # String
|
455
|
-
# computer # String
|
456
|
-
# user # String or nil
|
457
|
-
# description # String or nil
|
458
|
-
# string_inserts # An array of Strings or nil
|
524
|
+
# * record_number # Fixnum
|
525
|
+
# * time_generated # Time
|
526
|
+
# * time_written # Time
|
527
|
+
# * event_id # Fixnum
|
528
|
+
# * event_type # String
|
529
|
+
# * category # String
|
530
|
+
# * source # String
|
531
|
+
# * computer # String
|
532
|
+
# * user # String or nil
|
533
|
+
# * description # String or nil
|
534
|
+
# * string_inserts # An array of Strings or nil
|
459
535
|
#
|
460
536
|
# If no block is given the method returns an array of EventLogStruct's.
|
461
537
|
#
|
@@ -547,25 +623,23 @@ module Win32
|
|
547
623
|
end
|
548
624
|
}
|
549
625
|
end
|
550
|
-
|
551
|
-
# EventLog#report_event(key => value, ...)
|
552
|
-
#
|
626
|
+
|
553
627
|
# Writes an event to the event log. The following are valid keys:
|
554
628
|
#
|
555
|
-
# source
|
556
|
-
# event_id
|
557
|
-
# category
|
558
|
-
# data
|
559
|
-
# event_type
|
629
|
+
# * source # Event log source name. Defaults to "Application"
|
630
|
+
# * event_id # Event ID (defined in event message file)
|
631
|
+
# * category # Event category (defined in category message file)
|
632
|
+
# * data # String that is written to the log
|
633
|
+
# * event_type # Type of event, e.g. EventLog::ERROR, etc.
|
560
634
|
#
|
561
|
-
# The +event_type+ keyword is the only mandatory keyword.
|
562
|
-
# optional.
|
635
|
+
# The +event_type+ keyword is the only mandatory keyword. The others are
|
636
|
+
# optional. Although the +source+ defaults to "Application", I
|
563
637
|
# recommend that you create an application specific event source and use
|
564
|
-
# that instead.
|
638
|
+
# that instead. See the 'EventLog.add_event_source' method for more
|
565
639
|
# details.
|
566
640
|
#
|
567
641
|
# The +event_id+ and +category+ values are defined in the message
|
568
|
-
# file(s) that you created for your application.
|
642
|
+
# file(s) that you created for your application. See the tutorial.txt
|
569
643
|
# file for more details on how to create a message file.
|
570
644
|
#
|
571
645
|
# An ArgumentError is raised if you attempt to use an invalid key.
|
@@ -678,66 +752,6 @@ module Win32
|
|
678
752
|
struct
|
679
753
|
end
|
680
754
|
|
681
|
-
# Private method that gets the string inserts (Array) and the full
|
682
|
-
# event description (String) based on data from the EVENTLOGRECORD
|
683
|
-
# buffer.
|
684
|
-
#
|
685
|
-
def get_description(rec, event_source, lkey)
|
686
|
-
str = rec[rec[36,4].unpack('L')[0] .. -1]
|
687
|
-
num = rec[26,2].unpack('S')[0] # NumStrings
|
688
|
-
hkey = [0].pack('L')
|
689
|
-
key = BASE_KEY + "#{@source}\\#{event_source}"
|
690
|
-
buf = 0.chr * 1024
|
691
|
-
va_list = nil
|
692
|
-
|
693
|
-
if num == 0
|
694
|
-
va_list_ptr = 0.chr * 4
|
695
|
-
else
|
696
|
-
va_list = str.unpack('Z*' * num)
|
697
|
-
va_list_ptr = va_list.map{ |x|
|
698
|
-
[x + 0.chr].pack('P').unpack('L')[0]
|
699
|
-
}.pack('L*')
|
700
|
-
end
|
701
|
-
|
702
|
-
if RegOpenKeyEx(lkey, key, 0, KEY_READ, hkey) == 0
|
703
|
-
value = 'EventMessageFile'
|
704
|
-
file = 0.chr * MAX_SIZE
|
705
|
-
hkey = hkey.unpack('L')[0]
|
706
|
-
size = [file.length].pack('L')
|
707
|
-
|
708
|
-
if RegQueryValueEx(hkey, value, 0, 0, file, size) == 0
|
709
|
-
file = file.nstrip
|
710
|
-
exe = 0.chr * MAX_SIZE
|
711
|
-
|
712
|
-
ExpandEnvironmentStrings(file, exe, exe.size)
|
713
|
-
exe = exe.nstrip
|
714
|
-
|
715
|
-
exe.split(';').each{ |file|
|
716
|
-
hmodule = LoadLibraryEx(file, 0, DONT_RESOLVE_DLL_REFERENCES)
|
717
|
-
event_id = rec[20,4].unpack('L')[0]
|
718
|
-
if hmodule != 0
|
719
|
-
FormatMessage(
|
720
|
-
FORMAT_MESSAGE_FROM_HMODULE |
|
721
|
-
FORMAT_MESSAGE_ARGUMENT_ARRAY,
|
722
|
-
hmodule,
|
723
|
-
event_id,
|
724
|
-
0,
|
725
|
-
buf,
|
726
|
-
buf.size,
|
727
|
-
va_list_ptr
|
728
|
-
)
|
729
|
-
|
730
|
-
FreeLibrary(hmodule)
|
731
|
-
break if buf.nstrip != "" # All messages read
|
732
|
-
end
|
733
|
-
}
|
734
|
-
end
|
735
|
-
|
736
|
-
RegCloseKey(hkey)
|
737
|
-
end
|
738
|
-
[va_list, buf.strip]
|
739
|
-
end
|
740
|
-
|
741
755
|
# Private method that retrieves the user name based on data in the
|
742
756
|
# EVENTLOGRECORD buffer.
|
743
757
|
#
|
@@ -785,5 +799,136 @@ module Win32
|
|
785
799
|
nil
|
786
800
|
end
|
787
801
|
end
|
802
|
+
|
803
|
+
# Private method that gets the string inserts (Array) and the full
|
804
|
+
# event description (String) based on data from the EVENTLOGRECORD
|
805
|
+
# buffer.
|
806
|
+
#
|
807
|
+
def get_description(rec, event_source, lkey)
|
808
|
+
str = rec[rec[36,4].unpack('L')[0] .. -1]
|
809
|
+
num = rec[26,2].unpack('S')[0] # NumStrings
|
810
|
+
hkey = [0].pack('L')
|
811
|
+
key = BASE_KEY + "#{@source}\\#{event_source}"
|
812
|
+
buf = 0.chr * 8192
|
813
|
+
va_list = va_list0 = (num == 0) ? [] : str.unpack('Z*' * num)
|
814
|
+
|
815
|
+
if RegOpenKeyEx(lkey, key, 0, KEY_READ, hkey) == 0
|
816
|
+
value = 'ParameterMessageFile'
|
817
|
+
file = 0.chr * MAX_SIZE
|
818
|
+
hkey = hkey.unpack('L')[0]
|
819
|
+
size = [ file.length].pack('L')
|
820
|
+
|
821
|
+
if RegQueryValueEx(hkey, value, 0, 0, file, size) == 0
|
822
|
+
file = file.nstrip
|
823
|
+
exe = 0.chr * MAX_SIZE
|
824
|
+
ExpandEnvironmentStrings(file, exe, exe.size)
|
825
|
+
exe = exe.nstrip
|
826
|
+
|
827
|
+
va_list = va_list0.map{ |v|
|
828
|
+
va = v
|
829
|
+
|
830
|
+
v.scan(/%%(\d+)/).uniq.each{ |x|
|
831
|
+
exe.split(';').each{ |file|
|
832
|
+
hmodule = LoadLibraryEx(
|
833
|
+
file,
|
834
|
+
0,
|
835
|
+
DONT_RESOLVE_DLL_REFERENCES
|
836
|
+
)
|
837
|
+
|
838
|
+
if hmodule != 0
|
839
|
+
FormatMessage(
|
840
|
+
FORMAT_MESSAGE_FROM_HMODULE |
|
841
|
+
FORMAT_MESSAGE_ARGUMENT_ARRAY,
|
842
|
+
hmodule,
|
843
|
+
x.first.to_i,
|
844
|
+
0,
|
845
|
+
buf,
|
846
|
+
buf.size,
|
847
|
+
v
|
848
|
+
)
|
849
|
+
FreeLibrary(hmodule)
|
850
|
+
break if buf.nstrip != ""
|
851
|
+
end
|
852
|
+
}
|
853
|
+
va = va.gsub("%%#{x.first}", buf.nstrip)
|
854
|
+
}
|
855
|
+
va
|
856
|
+
}
|
857
|
+
end
|
858
|
+
|
859
|
+
value = 'EventMessageFile'
|
860
|
+
file = 0.chr * MAX_SIZE
|
861
|
+
size = [file.length].pack('L')
|
862
|
+
|
863
|
+
if RegQueryValueEx(hkey, value, 0, 0, file, size) == 0
|
864
|
+
file = file.nstrip
|
865
|
+
exe = 0.chr * MAX_SIZE
|
866
|
+
|
867
|
+
ExpandEnvironmentStrings(file, exe, exe.size)
|
868
|
+
exe = exe.nstrip
|
869
|
+
|
870
|
+
# Try to retrieve message *without* expanding the inserts yet
|
871
|
+
exe.split(';').each{ |file|
|
872
|
+
hmodule = LoadLibraryEx(file, 0, DONT_RESOLVE_DLL_REFERENCES)
|
873
|
+
event_id = rec[20,4].unpack('L')[0]
|
874
|
+
|
875
|
+
if hmodule != 0
|
876
|
+
FormatMessage(
|
877
|
+
FORMAT_MESSAGE_FROM_HMODULE |
|
878
|
+
FORMAT_MESSAGE_IGNORE_INSERTS,
|
879
|
+
hmodule,
|
880
|
+
event_id,
|
881
|
+
0,
|
882
|
+
buf,
|
883
|
+
buf.size,
|
884
|
+
nil
|
885
|
+
)
|
886
|
+
|
887
|
+
FreeLibrary(hmodule)
|
888
|
+
break if buf.nstrip != "" # All messages read
|
889
|
+
end
|
890
|
+
}
|
891
|
+
|
892
|
+
buf = 0.chr * 8192 # Reset the buffer
|
893
|
+
|
894
|
+
# Determine higest %n insert number
|
895
|
+
max_insert = [num,buf.nstrip.scan(/%(\d+)/).map{|x|x[0].to_i}.max].compact.max
|
896
|
+
|
897
|
+
# Insert dummy strings not provided by caller
|
898
|
+
((num+1)..(max_insert)).each{ |x| va_list.push("%#{x}") }
|
899
|
+
|
900
|
+
if num == 0
|
901
|
+
va_list_ptr = 0.chr * 4
|
902
|
+
else
|
903
|
+
va_list_ptr = va_list.map{ |x|
|
904
|
+
[x + 0.chr].pack('P').unpack('L')[0]
|
905
|
+
}.pack('L*')
|
906
|
+
end
|
907
|
+
|
908
|
+
exe.split(';').each{ |file|
|
909
|
+
hmodule = LoadLibraryEx(file, 0, DONT_RESOLVE_DLL_REFERENCES)
|
910
|
+
event_id = rec[20,4].unpack('L')[0]
|
911
|
+
|
912
|
+
if hmodule != 0
|
913
|
+
FormatMessage(
|
914
|
+
FORMAT_MESSAGE_FROM_HMODULE |
|
915
|
+
FORMAT_MESSAGE_ARGUMENT_ARRAY,
|
916
|
+
hmodule,
|
917
|
+
event_id,
|
918
|
+
0,
|
919
|
+
buf,
|
920
|
+
buf.size,
|
921
|
+
va_list_ptr
|
922
|
+
)
|
923
|
+
|
924
|
+
FreeLibrary(hmodule)
|
925
|
+
break if buf.nstrip != "" # All messages read
|
926
|
+
end
|
927
|
+
}
|
928
|
+
end
|
929
|
+
RegCloseKey(hkey)
|
930
|
+
end
|
931
|
+
[va_list0, buf.strip]
|
932
|
+
end
|
788
933
|
end
|
789
934
|
end
|
data/test/tc_eventlog.rb
CHANGED
data/win32-eventlog.gemspec
CHANGED
@@ -2,7 +2,7 @@ require "rubygems"
|
|
2
2
|
|
3
3
|
spec = Gem::Specification.new do |gem|
|
4
4
|
gem.name = "win32-eventlog"
|
5
|
-
gem.version = "0.4.
|
5
|
+
gem.version = "0.4.7"
|
6
6
|
gem.author = "Daniel J. Berger"
|
7
7
|
gem.email = "djberg96@gmail.com"
|
8
8
|
gem.homepage = "http://www.rubyforge.org/projects/win32utils"
|
metadata
CHANGED
@@ -1,33 +1,37 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: win32-eventlog
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.4.
|
7
|
-
date: 2007-08-27 00:00:00 -06:00
|
8
|
-
summary: Interface for the MS Windows Event Log.
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: djberg96@gmail.com
|
12
|
-
homepage: http://www.rubyforge.org/projects/win32utils
|
13
|
-
rubyforge_project:
|
14
|
-
description: Interface for the MS Windows Event Log.
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: 0.4.7
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Daniel J. Berger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2007-12-08 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: windows-pr
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.5.0
|
23
|
+
version:
|
24
|
+
description: Interface for the MS Windows Event Log.
|
25
|
+
email: djberg96@gmail.com
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- README
|
32
|
+
- CHANGES
|
33
|
+
- MANIFEST
|
34
|
+
- doc/tutorial.txt
|
31
35
|
files:
|
32
36
|
- lib/win32/eventlog.rb
|
33
37
|
- lib/win32/mc.rb
|
@@ -48,28 +52,31 @@ files:
|
|
48
52
|
- test
|
49
53
|
- win32-eventlog.gemspec
|
50
54
|
- doc/tutorial.txt
|
51
|
-
|
52
|
-
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://www.rubyforge.org/projects/win32utils
|
57
|
+
post_install_message:
|
53
58
|
rdoc_options: []
|
54
59
|
|
55
|
-
|
56
|
-
-
|
57
|
-
|
58
|
-
|
59
|
-
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
version:
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: "0"
|
73
|
+
version:
|
64
74
|
requirements: []
|
65
75
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: 0.5.0
|
75
|
-
version:
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 0.9.5
|
78
|
+
signing_key:
|
79
|
+
specification_version: 2
|
80
|
+
summary: Interface for the MS Windows Event Log.
|
81
|
+
test_files:
|
82
|
+
- test/ts_all.rb
|