win32-eventlog 0.6.0 → 0.6.1

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
  SHA1:
3
- metadata.gz: ceb5a13af0deadb88315e89d570a5f1aa2c79f27
4
- data.tar.gz: 7b5687780d298adefe46bdd3c8f5216947cc3052
3
+ metadata.gz: 88fd3143cff77fa6e55e35cd8e3f33f4ec03b887
4
+ data.tar.gz: b9532c5facf8c98af6c3072f679b98dcc49f2856
5
5
  SHA512:
6
- metadata.gz: c43100375b65b7b42eb8f571eb603dda0ecfcad79d4aa1936bd007feef87b7c8f7d03badddbb2e4dfb321919d1c9012d5abc5c34601d3a1f87d8be6a813e0c00
7
- data.tar.gz: 34ad5d018e864eec47b0af9a936fa0248f35a2c0d0d0795c5e90bb1512817324dbcc3b7705390270376242d1315f457a495a2f7a0ab62c94eb0bf6a8cddd19a0
6
+ metadata.gz: c128e20a50648bc052ab926e32c06f46702a75f76040db23f4480a04450e17211927fa4054a99ac049e724951dcc45104df3847500d92ff96d0e692191201c0d
7
+ data.tar.gz: c513a361ef15f70f887433ff9cc6ebd32a630e2f71f96a752ff2bd77f06fb9a01f027b395048ef5c9816cbfb5dd6cbb3b48df96f0dfaf4231f9e882830fd4b06
data/CHANGES CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.6.1 - 1-Jun-2014
2
+ * Added the read_last_event instance method. This was already in the code as
3
+ as a private method but it is now public.
4
+ * Removed some intermediate variables and properly re-use some memory pointers
5
+ to be more memory efficient.
6
+ * Changed File.exists? to File.exist? everywhere to avoid warnings in Ruby 2.1.
7
+
1
8
  == 0.6.0 - 13-Jan-2014
2
9
  * Now assumes Windows Vista or later and Ruby 1.9.1 or later.
3
10
  * The code base has been converted to use FFI, and now works with JRuby.
data/README CHANGED
@@ -59,11 +59,12 @@
59
59
  system.
60
60
 
61
61
  == Known Issues
62
- JRuby users may need to increase their heap space.
62
+ * JRuby users may need to increase their heap space.
63
+ * JRuby x64 suffers from a bug that currently makes this library unusable.
64
+ See https://github.com/jruby/jruby/issues/1718.
63
65
 
64
66
  Please file any bug reports on the project page at
65
- http://github.com/djberg96/win32-eventlog or
66
- http://www.rubyforge.org/projects/win32utils.
67
+ http://github.com/djberg96/win32-eventlog.
67
68
 
68
69
  == License
69
70
  Artistic 2.0
@@ -17,10 +17,13 @@ sleep 1
17
17
 
18
18
  el = EventLog.new("Application")
19
19
  el.read{ |log|
20
- p log
20
+ #p log.description if !log.description.empty?
21
+ p log
21
22
  }
23
+ #p el.read_last_event
22
24
  el.close
23
25
 
26
+ =begin
24
27
  EventLog.read("Application"){ |log|
25
28
  p log
26
29
  puts
@@ -81,4 +84,5 @@ e4.read{ |elr|
81
84
  puts "Finished reading backup file"
82
85
  e4.close
83
86
 
84
- File.delete(backup_file)
87
+ File.delete(backup_file)
88
+ =end
@@ -1,6 +1,6 @@
1
- require File.join(File.dirname(__FILE__), 'windows', 'constants')
2
- require File.join(File.dirname(__FILE__), 'windows', 'structs')
3
- require File.join(File.dirname(__FILE__), 'windows', 'functions')
1
+ require_relative 'windows/constants'
2
+ require_relative 'windows/structs'
3
+ require_relative 'windows/functions'
4
4
 
5
5
  # The Win32 module serves as a namespace only.
6
6
  module Win32
@@ -18,7 +18,7 @@ module Win32
18
18
  class Error < StandardError; end
19
19
 
20
20
  # The version of the win32-eventlog library
21
- VERSION = '0.6.0'
21
+ VERSION = '0.6.1'
22
22
 
23
23
  # The log is read in chronological order, i.e. oldest to newest.
24
24
  FORWARDS_READ = EVENTLOG_FORWARDS_READ
@@ -564,23 +564,16 @@ module Win32
564
564
  struct = EventLogStruct.new
565
565
  record = EVENTLOGRECORD.new(buf)
566
566
 
567
- event_source = buf.read_bytes(buf.size)[56..-1][/^[^\0]*/]
568
- computer = buf.read_bytes(buf.size)[56 + event_source.length + 1..-1][/^[^\0]*/]
569
- user = get_user(record)
570
-
571
- strings, desc = get_description(buf, event_source, lkey)
572
-
573
- struct.source = event_source
574
- struct.computer = computer
567
+ struct.source = buf.read_bytes(buf.size)[56..-1][/^[^\0]*/]
568
+ struct.computer = buf.read_bytes(buf.size)[56 + struct.source.length + 1..-1][/^[^\0]*/]
575
569
  struct.record_number = record[:RecordNumber]
576
570
  struct.time_generated = Time.at(record[:TimeGenerated])
577
571
  struct.time_written = Time.at(record[:TimeWritten])
578
572
  struct.event_id = record[:EventID] & 0x0000FFFF
579
573
  struct.event_type = get_event_type(record[:EventType])
580
- struct.user = user
574
+ struct.user = get_user(record)
581
575
  struct.category = record[:EventCategory]
582
- struct.string_inserts = strings
583
- struct.description = desc
576
+ struct.string_inserts, struct.description = get_description(buf, struct.source, lkey)
584
577
 
585
578
  struct.freeze # This is read-only information
586
579
 
@@ -727,11 +720,9 @@ module Win32
727
720
 
728
721
  alias :write :report_event
729
722
 
730
- private
731
-
732
- # A private method that reads the last event log record.
723
+ # Reads the last event record.
733
724
  #
734
- def read_last_event(handle=@handle, source=@source, server=@server)
725
+ def read_last_event
735
726
  buf = FFI::MemoryPointer.new(:char, BUFFER_SIZE)
736
727
  read = FFI::MemoryPointer.new(:ulong)
737
728
  needed = FFI::MemoryPointer.new(:ulong)
@@ -761,30 +752,25 @@ module Win32
761
752
 
762
753
  record = EVENTLOGRECORD.new(buf)
763
754
 
764
- event_source = buf.read_bytes(buf.size)[56..-1][/^[^\0]*/]
765
- computer = buf.read_bytes(buf.size)[56 + event_source.length + 1..-1][/^[^\0]*/]
766
- event_type = get_event_type(record[:EventType])
767
- user = get_user(record)
768
- strings, desc = get_description(buf, event_source, lkey)
769
-
770
755
  struct = EventLogStruct.new
771
- struct.source = event_source
772
- struct.computer = computer
756
+ struct.source = buf.read_bytes(buf.size)[56..-1][/^[^\0]*/]
757
+ struct.computer = buf.read_bytes(buf.size)[56 + struct.source.length + 1..-1][/^[^\0]*/]
773
758
  struct.record_number = record[:RecordNumber]
774
759
  struct.time_generated = Time.at(record[:TimeGenerated])
775
760
  struct.time_written = Time.at(record[:TimeWritten])
776
761
  struct.event_id = record[:EventID] & 0x0000FFFF
777
- struct.event_type = event_type
778
- struct.user = user
762
+ struct.event_type = get_event_type(record[:EventType])
763
+ struct.user = get_user(record)
779
764
  struct.category = record[:EventCategory]
780
- struct.string_inserts = strings
781
- struct.description = desc
765
+ struct.string_inserts, struct.description = get_description(buf, struct.source, lkey)
782
766
 
783
767
  struct.freeze # This is read-only information
784
768
 
785
769
  struct
786
770
  end
787
771
 
772
+ private
773
+
788
774
  # Private method that retrieves the user name based on data in the
789
775
  # EVENTLOGRECORD buffer.
790
776
  #
@@ -861,73 +847,75 @@ module Win32
861
847
  hkey = hkey.read_pointer.to_i
862
848
  value = 'providerGuid'
863
849
 
864
- guid = FFI::MemoryPointer.new(:char, MAX_SIZE)
865
- size = FFI::MemoryPointer.new(:ulong)
850
+ guid_ptr = FFI::MemoryPointer.new(:char, MAX_SIZE)
851
+ size_ptr = FFI::MemoryPointer.new(:ulong)
866
852
 
867
- size.write_ulong(guid.size)
853
+ size_ptr.write_ulong(guid_ptr.size)
868
854
 
869
- if RegQueryValueEx(hkey, value, nil, nil, guid, size) == 0
870
- guid = guid.read_string
855
+ if RegQueryValueEx(hkey, value, nil, nil, guid_ptr, size_ptr) == 0
856
+ guid = guid_ptr.read_string
871
857
  hkey2 = FFI::MemoryPointer.new(:uintptr_t)
872
858
  key = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WINEVT\\Publishers\\#{guid}"
873
859
 
860
+ guid_ptr.free
861
+
874
862
  if RegOpenKeyEx(lkey, key, 0, KEY_READ|0x100, hkey2) == 0
875
863
  hkey2 = hkey2.read_pointer.to_i
876
864
 
877
865
  value = 'ParameterMessageFile'
878
- file = FFI::MemoryPointer.new(:char, MAX_SIZE)
879
- size = FFI::MemoryPointer.new(:ulong)
880
-
881
- size.write_ulong(file.size)
866
+ file_ptr = FFI::MemoryPointer.new(:char, MAX_SIZE)
867
+ size_ptr.clear.write_ulong(file_ptr.size)
882
868
 
883
- if RegQueryValueEx(hkey2, value, nil, nil, file, size) == 0
884
- file = file.read_string
869
+ if RegQueryValueEx(hkey2, value, nil, nil, file_ptr, size_ptr) == 0
870
+ file = file_ptr.read_string
885
871
  exe = FFI::MemoryPointer.new(:char, MAX_SIZE)
886
872
  ExpandEnvironmentStrings(file, exe, exe.size)
887
873
  param_exe = exe.read_string
888
874
  end
889
875
 
890
876
  value = 'MessageFileName'
891
- file = FFI::MemoryPointer.new(:char, MAX_SIZE)
892
- size = FFI::MemoryPointer.new(:ulong)
893
877
 
894
- size.write_ulong(file.size)
878
+ file_ptr.clear
879
+ size_ptr.clear.write_ulong(file_ptr.size)
895
880
 
896
- if RegQueryValueEx(hkey2, value, nil, nil, file, size) == 0
897
- file = file.read_string
881
+ if RegQueryValueEx(hkey2, value, nil, nil, file_ptr, size_ptr) == 0
882
+ file = file_ptr.read_string
898
883
  exe = FFI::MemoryPointer.new(:char, MAX_SIZE)
899
884
  ExpandEnvironmentStrings(file, exe, exe.size)
900
885
  message_exe = exe.read_string
901
886
  end
902
887
 
903
888
  RegCloseKey(hkey2)
889
+
890
+ file_ptr.free
891
+ size_ptr.free
904
892
  end
905
893
  else
906
894
  value = 'ParameterMessageFile'
907
- file = FFI::MemoryPointer.new(:char, MAX_SIZE)
908
- size = FFI::MemoryPointer.new(:ulong)
909
-
910
- size.write_ulong(file.size)
895
+ file_ptr = FFI::MemoryPointer.new(:char, MAX_SIZE)
896
+ size_ptr.clear.write_ulong(file_ptr.size)
911
897
 
912
- if RegQueryValueEx(hkey, value, nil, nil, file, size) == 0
913
- file = file.read_string
898
+ if RegQueryValueEx(hkey, value, nil, nil, file_ptr, size_ptr) == 0
899
+ file = file_ptr.read_string
914
900
  exe = FFI::MemoryPointer.new(:char, MAX_SIZE)
915
901
  ExpandEnvironmentStrings(file, exe, exe.size)
916
902
  param_exe = exe.read_string
917
903
  end
918
904
 
919
905
  value = 'EventMessageFile'
920
- file = FFI::MemoryPointer.new(:char, MAX_SIZE)
921
- size = FFI::MemoryPointer.new(:ulong)
922
906
 
923
- size.write_ulong(file.size)
907
+ file_ptr.clear
908
+ size_ptr.clear.write_ulong(file_ptr.size)
924
909
 
925
- if RegQueryValueEx(hkey, value, nil, nil, file, size) == 0
926
- file = file.read_string
910
+ if RegQueryValueEx(hkey, value, nil, nil, file_ptr, size_ptr) == 0
911
+ file = file_ptr.read_string
927
912
  exe = FFI::MemoryPointer.new(:char, MAX_SIZE)
928
913
  ExpandEnvironmentStrings(file, exe, exe.size)
929
914
  message_exe = exe.read_string
930
915
  end
916
+
917
+ file_ptr.free
918
+ size_ptr.free
931
919
  end
932
920
 
933
921
  RegCloseKey(hkey)
@@ -959,8 +947,8 @@ module Win32
959
947
  ExpandEnvironmentStrings(file, exe, exe.size)
960
948
  param_exe = exe.read_string
961
949
 
962
- buf2 = FFI::MemoryPointer.new(:char, 8192)
963
- val = FFI::MemoryPointer.new(:ulong)
950
+ buf2.clear
951
+ val.clear
964
952
 
965
953
  bool = EvtGetPublisherMetadataProperty(
966
954
  pubMetadata,
@@ -975,10 +963,15 @@ module Win32
975
963
  raise SystemCallError.new('EvtGetPublisherMetadataProperty', FFI.errno)
976
964
  end
977
965
 
966
+ exe.clear
967
+
978
968
  file = buf2.read_string[16..-1]
979
- exe = FFI::MemoryPointer.new(:char, MAX_SIZE)
980
969
  ExpandEnvironmentStrings(file, exe, exe.size)
981
970
  message_exe = exe.read_string
971
+
972
+ buf2.free
973
+ val.free
974
+ exe.free
982
975
  end
983
976
  ensure
984
977
  EvtClose(pubMetadata) if pubMetadata
@@ -1034,7 +1027,7 @@ module Win32
1034
1027
  end
1035
1028
 
1036
1029
  if message_exe != nil
1037
- buf = FFI::MemoryPointer.new(:char, 8192) # Reset the buffer
1030
+ buf.clear
1038
1031
 
1039
1032
  # Try to retrieve message *without* expanding the inserts yet
1040
1033
  message_exe.split(';').each{ |lfile|
data/lib/win32/mc.rb CHANGED
@@ -57,7 +57,7 @@ module Win32
57
57
  #
58
58
  def create_res_file
59
59
  rc_file = File.basename(@mc_file, '.mc') + '.rc'
60
- unless File.exists?(rc_file)
60
+ unless File.exist?(rc_file)
61
61
  raise MC::Error, "No .rc file found: #{@rc_file}"
62
62
  end
63
63
  system("rc -r -fo #{@res_file} #{rc_file}")
@@ -68,7 +68,7 @@ module Win32
68
68
  # found.
69
69
  #
70
70
  def create_dll_file
71
- unless File.exists?(@res_file)
71
+ unless File.exist?(@res_file)
72
72
  raise MC::Error, "No .res file found: #{@res_file}"
73
73
  end
74
74
  system("link -dll -noentry -out:#{@dll_file} #{@res_file}")
@@ -92,7 +92,7 @@ module Win32
92
92
 
93
93
  %w[.h .rc .res].each do |ext|
94
94
  file = base + ext
95
- File.delete(file) if File.exists?(file)
95
+ File.delete(file) if File.exist?(file)
96
96
  end
97
97
 
98
98
  Dir["MSG*.bin"].each do |binfile|
@@ -25,7 +25,7 @@ class TC_Win32_EventLog < Test::Unit::TestCase
25
25
  end
26
26
 
27
27
  test "version constant is set to expected value" do
28
- assert_equal('0.6.0', EventLog::VERSION)
28
+ assert_equal('0.6.1', EventLog::VERSION)
29
29
  end
30
30
 
31
31
  test "constructor basic functionality" do
@@ -77,7 +77,7 @@ class TC_Win32_EventLog < Test::Unit::TestCase
77
77
 
78
78
  test "backup works as expected" do
79
79
  assert_nothing_raised{ @log.backup(@bakfile) }
80
- assert(File.exists?(@bakfile))
80
+ assert(File.exist?(@bakfile))
81
81
  end
82
82
 
83
83
  test "backup method fails if backup file already exists" do
@@ -167,6 +167,15 @@ class TC_Win32_EventLog < Test::Unit::TestCase
167
167
  assert_raises(ArgumentError){ @log.read(nil, 500, 'foo') }
168
168
  end
169
169
 
170
+ test "read_last_event method basic functionality" do
171
+ assert_respond_to(@log, :read_last_event)
172
+ assert_nothing_raised{ @log.read_last_event }
173
+ end
174
+
175
+ test "read_last_event returns the expected results" do
176
+ assert_kind_of(Win32::EventLog::EventLogStruct, @log.read_last_event)
177
+ end
178
+
170
179
  test "seek_read flag plus forwards_read flag works as expected" do
171
180
  flags = EventLog::SEEK_READ | EventLog::FORWARDS_READ
172
181
  assert_nothing_raised{ @last = @log.read[-10].record_number }
@@ -298,7 +307,7 @@ class TC_Win32_EventLog < Test::Unit::TestCase
298
307
 
299
308
  def teardown
300
309
  @log.close rescue nil
301
- File.delete(@bakfile) if File.exists?(@bakfile)
310
+ File.delete(@bakfile) if File.exist?(@bakfile)
302
311
  @logfile = nil
303
312
  @records = nil
304
313
  @last = nil
data/test/test_mc.rb CHANGED
@@ -53,7 +53,7 @@ class TC_Win32_MC < Test::Unit::TestCase
53
53
 
54
54
  def teardown
55
55
  @mc = nil
56
- File.delete('foo.dll') if File.exists?('foo.dll')
56
+ File.delete('foo.dll') if File.exist?('foo.dll')
57
57
  end
58
58
 
59
59
  def self.shutdown
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'win32-eventlog'
5
- spec.version = '0.6.0'
5
+ spec.version = '0.6.1'
6
6
  spec.authors = ['Daniel J. Berger', 'Park Heesob']
7
7
  spec.license = 'Artistic 2.0'
8
8
  spec.email = 'djberg96@gmail.com'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: win32-eventlog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -9,62 +9,62 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-13 00:00:00.000000000 Z
12
+ date: 2014-06-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '>='
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - '>='
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: test-unit
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '>='
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rake
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - '>='
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - '>='
53
+ - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: ptools
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - '>='
60
+ - - ">="
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - '>='
67
+ - - ">="
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  description: |2
@@ -113,17 +113,17 @@ require_paths:
113
113
  - lib
114
114
  required_ruby_version: !ruby/object:Gem::Requirement
115
115
  requirements:
116
- - - '>='
116
+ - - ">="
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
119
  required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  requirements:
121
- - - '>='
121
+ - - ">="
122
122
  - !ruby/object:Gem::Version
123
123
  version: '0'
124
124
  requirements: []
125
125
  rubyforge_project: win32utils
126
- rubygems_version: 2.2.1
126
+ rubygems_version: 2.2.2
127
127
  signing_key:
128
128
  specification_version: 4
129
129
  summary: Interface for the MS Windows Event Log.