winevt_c 0.1.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5cf95319c95243ca432d01b7a5b386603b3d1e100eb873f791e56e1e014cb49b
4
+ data.tar.gz: 74e6d59960089642a685771ba71562f68424ee1836dd3641576cdad79fc37ab1
5
+ SHA512:
6
+ metadata.gz: a1b809b0b7c612aed9b8e76c90e8d4d0ee326c79da950ba10a2c35f058fdaf88b22367dafdefac267023b02fed8ea97dc815d329c88fc95d25cb9ef006b45b9a
7
+ data.tar.gz: cf97a89b5b0c42bde5b90fb3ed5faef71430ce56ad58987c3ed7b364ccfe96b545d95e38aaf7ae8916a4e39425d54846fedfa6de8c99b871e7b60f4ec1444cc5
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /Gemfile.lock
10
+ /vendor/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in winevt_c.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # winevt_c
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'winevt_c'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install winevt_c
18
+
19
+ ## Usage
20
+
21
+ Usage examples are found in [example directory](example).
22
+ ## Development
23
+
24
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
25
+
26
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
27
+
28
+ ## Contributing
29
+
30
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cosmo0920/winevt_c.
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require "rake/testtask"
5
+ require 'rake_compiler_dock'
6
+ require 'rake/clean'
7
+
8
+ Rake::TestTask.new(:test) do |t|
9
+ t.libs << "test"
10
+ t.libs << "lib"
11
+ t.test_files = FileList["test/**/test_*.rb"]
12
+ end
13
+
14
+ require "rake/extensiontask"
15
+
16
+ spec = eval File.read("winevt_c.gemspec")
17
+
18
+ Rake::ExtensionTask.new("winevt", spec) do |ext|
19
+ ext.ext_dir = 'ext/winevt'
20
+ ext.cross_compile = true
21
+ ext.lib_dir = File.join(*['lib', 'winevt', ENV['FAT_DIR']].compact)
22
+ # cross_platform names are of MRI's platform name
23
+ ext.cross_platform = ['x86-mingw32', 'x64-mingw32']
24
+ end
25
+
26
+ desc 'Build gems for Windows per rake-compiler-dock'
27
+ task 'gem:native' do
28
+ # See RUBY_CC_VERSION in https://github.com/rake-compiler/rake-compiler-dock/blob/master/Dockerfile.mri
29
+ RakeCompilerDock.sh <<-EOS
30
+ bundle --local
31
+ bundle exec rake cross native gem RUBY_CC_VERSION=2.4.0:2.5.0:2.6.0
32
+ EOS
33
+ end
34
+
35
+ CLEAN.include('lib/winevt/winevt.*')
36
+
37
+ task :default => [:clobber, :compile, :test]
data/appveyor.yml ADDED
@@ -0,0 +1,26 @@
1
+ version: '{build}'
2
+
3
+ # init:
4
+ # - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
5
+
6
+ install:
7
+ - SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
8
+ - ruby --version
9
+ - gem --version
10
+ - bundle --version
11
+ - bundle install
12
+ - ridk.cmd exec bundle exec rake compile
13
+ build: off
14
+ test_script:
15
+ # - bundle exec rake test
16
+ - bundle exec rake test TESTOPTS=-v
17
+
18
+ # https://www.appveyor.com/docs/installed-software/#ruby
19
+ environment:
20
+ matrix:
21
+ - ruby_version: "26-x64"
22
+ - ruby_version: "26"
23
+ - ruby_version: "25-x64"
24
+ - ruby_version: "25"
25
+ - ruby_version: "24-x64"
26
+ - ruby_version: "24"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "winevt"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,9 @@
1
+ require 'winevt'
2
+
3
+ @query = Winevt::EventLog::Query.new("Application", "*[System[(Level <= 3) and TimeCreated[timediff(@SystemTime) <= 86400000]]]")
4
+ @bookmark = Winevt::EventLog::Bookmark.new
5
+ @query.each do |xml|
6
+ @bookmark.update(@query)
7
+ end
8
+
9
+ puts @bookmark.render
@@ -0,0 +1,7 @@
1
+ require 'winevt'
2
+
3
+ @query = Winevt::EventLog::Query.new("Application", "*[System[(Level <= 3) and TimeCreated[timediff(@SystemTime) <= 86400000]]]")
4
+
5
+ @query.each do |eventlog|
6
+ puts eventlog
7
+ end
@@ -0,0 +1,14 @@
1
+ require 'winevt'
2
+
3
+ @subscribe = Winevt::EventLog::Subscribe.new
4
+ @subscribe.tail = true
5
+ @subscribe.subscribe("Application", "*[System[(Level <= 4) and TimeCreated[timediff(@SystemTime) <= 86400000]]]")
6
+ while (1) do
7
+ if @subscribe.next
8
+ puts @subscribe.render
9
+ else
10
+ printf(".")
11
+ sleep(1)
12
+ end
13
+ end
14
+ puts @subscribe.bookmark
@@ -0,0 +1,20 @@
1
+ require "mkmf"
2
+ require "rbconfig"
3
+
4
+ if RbConfig::CONFIG['host_os'] =~ /mingw/
5
+ $CFLAGS << ' -fno-omit-frame-pointer'
6
+ end
7
+
8
+ libdir = RbConfig::CONFIG["libdir"]
9
+ includedir = RbConfig::CONFIG["includedir"]
10
+
11
+ dir_config("winevt", includedir, libdir)
12
+
13
+ have_library("wevtapi")
14
+ have_func("EvtQuery", "winevt.h")
15
+
16
+ $LDFLAGS << " -lwevtapi"
17
+ $CFLAGS << " -std=c99 -fPIC -fms-extensions "
18
+ # $CFLAGS << " -g -O0"
19
+
20
+ create_makefile("winevt/winevt")
@@ -0,0 +1,746 @@
1
+ #include <ruby.h>
2
+ #include <ruby/encoding.h>
3
+
4
+ #ifdef __GNUC__
5
+ # include <w32api.h>
6
+ # define MINIMUM_WINDOWS_VERSION WindowsVista
7
+ #else /* __GNUC__ */
8
+ # define MINIMUM_WINDOWS_VERSION 0x0600 /* Vista */
9
+ #endif /* __GNUC__ */
10
+
11
+ #ifdef _WIN32_WINNT
12
+ # undef WIN32_WINNT
13
+ #endif /* WIN32_WINNT */
14
+ #define _WIN32_WINNT MINIMUM_WINDOWS_VERSION
15
+
16
+ #include <winevt.h>
17
+ #define EventQuery(object) ((struct WinevtQuery *)DATA_PTR(object))
18
+ #define EventBookMark(object) ((struct WinevtBookmark *)DATA_PTR(object))
19
+ #define EventChannel(object) ((struct WinevtChannel *)DATA_PTR(object))
20
+
21
+ VALUE rb_mWinevt;
22
+ VALUE rb_cEventLog;
23
+ VALUE rb_cSubscribe;
24
+ VALUE rb_cChannel;
25
+ VALUE rb_cQuery;
26
+ VALUE rb_cBookmark;
27
+ VALUE rb_eWinevtQueryError;
28
+
29
+ static ID id_call;
30
+ static void channel_free(void *ptr);
31
+ static void subscribe_free(void *ptr);
32
+ static void query_free(void *ptr);
33
+ static void bookmark_free(void *ptr);
34
+ static char* render_event(EVT_HANDLE handle, DWORD flags);
35
+ static DWORD WINAPI SubscriptionCallback(EVT_SUBSCRIBE_NOTIFY_ACTION action, PVOID pContext, EVT_HANDLE hEvent);
36
+
37
+ static const rb_data_type_t rb_winevt_channel_type = {
38
+ "winevt/channel", {
39
+ 0, channel_free, 0,
40
+ }, NULL, NULL,
41
+ RUBY_TYPED_FREE_IMMEDIATELY
42
+ };
43
+
44
+ struct WinevtChannel {
45
+ EVT_HANDLE channels;
46
+ };
47
+
48
+ static const rb_data_type_t rb_winevt_query_type = {
49
+ "winevt/query", {
50
+ 0, query_free, 0,
51
+ }, NULL, NULL,
52
+ RUBY_TYPED_FREE_IMMEDIATELY
53
+ };
54
+
55
+ struct WinevtQuery {
56
+ EVT_HANDLE query;
57
+ EVT_HANDLE event;
58
+ ULONG count;
59
+ LONG offset;
60
+ LONG timeout;
61
+ };
62
+
63
+ static const rb_data_type_t rb_winevt_bookmark_type = {
64
+ "winevt/bookmark", {
65
+ 0, bookmark_free, 0,
66
+ }, NULL, NULL,
67
+ RUBY_TYPED_FREE_IMMEDIATELY
68
+ };
69
+
70
+ struct WinevtBookmark {
71
+ EVT_HANDLE bookmark;
72
+ ULONG count;
73
+ };
74
+
75
+ static const rb_data_type_t rb_winevt_subscribe_type = {
76
+ "winevt/subscribe", {
77
+ 0, subscribe_free, 0,
78
+ }, NULL, NULL,
79
+ RUBY_TYPED_FREE_IMMEDIATELY
80
+ };
81
+
82
+ struct WinevtSubscribe {
83
+ HANDLE signalEvent;
84
+ EVT_HANDLE subscription;
85
+ EVT_HANDLE bookmark;
86
+ EVT_HANDLE event;
87
+ DWORD flags;
88
+ BOOL tailing;
89
+ };
90
+
91
+ static void
92
+ channel_free(void *ptr)
93
+ {
94
+ struct WinevtChannel *winevtChannel = (struct WinevtChannel *)ptr;
95
+ if (winevtChannel->channels)
96
+ EvtClose(winevtChannel->channels);
97
+
98
+ xfree(ptr);
99
+ }
100
+
101
+ static VALUE
102
+ rb_winevt_channel_alloc(VALUE klass)
103
+ {
104
+ VALUE obj;
105
+ struct WinevtChannel *winevtChannel;
106
+ obj = TypedData_Make_Struct(klass,
107
+ struct WinevtChannel,
108
+ &rb_winevt_channel_type,
109
+ winevtChannel);
110
+ return obj;
111
+ }
112
+
113
+ static VALUE
114
+ rb_winevt_channel_initialize(VALUE klass)
115
+ {
116
+ return Qnil;
117
+ }
118
+
119
+ static VALUE
120
+ rb_winevt_channel_each(VALUE self)
121
+ {
122
+ EVT_HANDLE hChannels;
123
+ struct WinevtChannel *winevtChannel;
124
+ char *errBuf;
125
+ char * result;
126
+ LPWSTR buffer = NULL;
127
+ LPWSTR temp = NULL;
128
+ DWORD bufferSize = 0;
129
+ DWORD bufferUsed = 0;
130
+ DWORD status = ERROR_SUCCESS;
131
+ ULONG len;
132
+
133
+ RETURN_ENUMERATOR(self, 0, 0);
134
+
135
+ TypedData_Get_Struct(self, struct WinevtChannel, &rb_winevt_channel_type, winevtChannel);
136
+
137
+ hChannels = EvtOpenChannelEnum(NULL, 0);
138
+
139
+ if (hChannels) {
140
+ winevtChannel->channels = hChannels;
141
+ } else {
142
+ sprintf(errBuf, "Failed to enumerate channels with %s\n", GetLastError());
143
+ rb_raise(rb_eRuntimeError, errBuf);
144
+ }
145
+
146
+ while (1) {
147
+ if (!EvtNextChannelPath(winevtChannel->channels, bufferSize, buffer, &bufferUsed)) {
148
+ status = GetLastError();
149
+
150
+ if (ERROR_NO_MORE_ITEMS == status) {
151
+ break;
152
+ } else if (ERROR_INSUFFICIENT_BUFFER == status) {
153
+ bufferSize = bufferUsed;
154
+ temp = (LPWSTR)realloc(buffer, bufferSize * sizeof(WCHAR));
155
+ if (temp) {
156
+ buffer = temp;
157
+ temp = NULL;
158
+ EvtNextChannelPath(winevtChannel->channels, bufferSize, buffer, &bufferUsed);
159
+ } else {
160
+ status = ERROR_OUTOFMEMORY;
161
+ rb_raise(rb_eRuntimeError, "realloc failed");
162
+ }
163
+ } else {
164
+ sprintf(errBuf, "EvtNextChannelPath failed with %lu.\n", status);
165
+ rb_raise(rb_eRuntimeError, errBuf);
166
+ }
167
+ }
168
+
169
+ len = WideCharToMultiByte(CP_UTF8, 0, buffer, -1, NULL, 0, NULL, NULL);
170
+ if (!(result = malloc(len))) return "";
171
+ WideCharToMultiByte(CP_UTF8, 0, buffer, -1, result, len, NULL, NULL);
172
+
173
+ rb_yield(rb_str_new2(result));
174
+ }
175
+
176
+ return Qnil;
177
+ }
178
+
179
+ static void
180
+ subscribe_free(void *ptr)
181
+ {
182
+ struct WinevtSubscribe *winevtSubscribe = (struct WinevtSubscribe *)ptr;
183
+ if (winevtSubscribe->signalEvent)
184
+ CloseHandle(winevtSubscribe->signalEvent);
185
+
186
+ if (winevtSubscribe->subscription)
187
+ EvtClose(winevtSubscribe->subscription);
188
+
189
+ if (winevtSubscribe->bookmark)
190
+ EvtClose(winevtSubscribe->bookmark);
191
+
192
+ if (winevtSubscribe->event)
193
+ EvtClose(winevtSubscribe->event);
194
+
195
+ xfree(ptr);
196
+ }
197
+
198
+ static VALUE
199
+ rb_winevt_subscribe_alloc(VALUE klass)
200
+ {
201
+ VALUE obj;
202
+ struct WinevtSubscribe *winevtSubscribe;
203
+ obj = TypedData_Make_Struct(klass,
204
+ struct WinevtSubscribe,
205
+ &rb_winevt_subscribe_type,
206
+ winevtSubscribe);
207
+ return obj;
208
+ }
209
+
210
+ static VALUE
211
+ rb_winevt_subscribe_initialize(VALUE self)
212
+ {
213
+ return Qnil;
214
+ }
215
+
216
+ static VALUE
217
+ rb_winevt_subscribe_set_tail(VALUE self, VALUE rb_tailing_p)
218
+ {
219
+ struct WinevtSubscribe *winevtSubscribe;
220
+
221
+ TypedData_Get_Struct(self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
222
+
223
+ winevtSubscribe->tailing = RTEST(rb_tailing_p);
224
+
225
+ return Qnil;
226
+ }
227
+
228
+ static VALUE
229
+ rb_winevt_subscribe_tail_p(VALUE self, VALUE rb_flag)
230
+ {
231
+ struct WinevtSubscribe *winevtSubscribe;
232
+
233
+ TypedData_Get_Struct(self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
234
+
235
+ return winevtSubscribe->tailing ? Qtrue : Qfalse;
236
+ }
237
+
238
+ static VALUE
239
+ rb_winevt_subscribe_subscribe(int argc, VALUE argv, VALUE self)
240
+ {
241
+ VALUE rb_path, rb_query, rb_bookmark;
242
+ EVT_HANDLE hSubscription = NULL, hBookmark = NULL;
243
+ HANDLE hSignalEvent;
244
+ DWORD len, flags;
245
+ VALUE wpathBuf, wqueryBuf;
246
+ PWSTR path, query;
247
+ DWORD status = ERROR_SUCCESS;
248
+ struct WinevtBookmark *winevtBookmark;
249
+ struct WinevtSubscribe *winevtSubscribe;
250
+
251
+ hSignalEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
252
+
253
+ TypedData_Get_Struct(self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
254
+
255
+ rb_scan_args(argc, argv, "21", &rb_path, &rb_query, &rb_bookmark);
256
+ Check_Type(rb_path, T_STRING);
257
+ Check_Type(rb_query, T_STRING);
258
+
259
+ if (rb_obj_is_kind_of(rb_bookmark, rb_cBookmark)) {
260
+ hBookmark = EventBookMark(rb_bookmark)->bookmark;
261
+ }
262
+
263
+ // path : To wide char
264
+ len = MultiByteToWideChar(CP_UTF8, 0, RSTRING_PTR(rb_path), RSTRING_LEN(rb_path), NULL, 0);
265
+ path = ALLOCV_N(WCHAR, wpathBuf, len+1);
266
+ MultiByteToWideChar(CP_UTF8, 0, RSTRING_PTR(rb_path), RSTRING_LEN(rb_path), path, len);
267
+ path[len] = L'\0';
268
+
269
+ // query : To wide char
270
+ len = MultiByteToWideChar(CP_UTF8, 0, RSTRING_PTR(rb_query), RSTRING_LEN(rb_query), NULL, 0);
271
+ query = ALLOCV_N(WCHAR, wqueryBuf, len+1);
272
+ MultiByteToWideChar(CP_UTF8, 0, RSTRING_PTR(rb_query), RSTRING_LEN(rb_query), query, len);
273
+ query[len] = L'\0';
274
+
275
+ if (hBookmark){
276
+ flags |= EvtSubscribeStartAfterBookmark;
277
+ } else if (winevtSubscribe->tailing) {
278
+ flags |= EvtSubscribeToFutureEvents;
279
+ } else {
280
+ flags |= EvtSubscribeStartAtOldestRecord;
281
+ }
282
+
283
+ hSubscription = EvtSubscribe(NULL, hSignalEvent, path, query, hBookmark, NULL, NULL, flags);
284
+
285
+ winevtSubscribe->signalEvent = hSignalEvent;
286
+ winevtSubscribe->subscription = hSubscription;
287
+ if (hBookmark) {
288
+ winevtSubscribe->bookmark = hBookmark;
289
+ } else {
290
+ winevtSubscribe->bookmark = EvtCreateBookmark(NULL);
291
+ }
292
+
293
+ status = GetLastError();
294
+
295
+ if (status == ERROR_SUCCESS)
296
+ return Qtrue;
297
+
298
+ return Qfalse;
299
+ }
300
+
301
+ static VALUE
302
+ rb_winevt_subscribe_next(VALUE self)
303
+ {
304
+ EVT_HANDLE event;
305
+ ULONG count;
306
+ struct WinevtSubscribe *winevtSubscribe;
307
+
308
+ TypedData_Get_Struct(self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
309
+
310
+ if (EvtNext(winevtSubscribe->subscription, 1, &event, INFINITE, 0, &count) != FALSE) {
311
+ winevtSubscribe->event = event;
312
+ EvtUpdateBookmark(winevtSubscribe->bookmark, winevtSubscribe->event);
313
+
314
+ return Qtrue;
315
+ }
316
+
317
+ return Qfalse;
318
+ }
319
+
320
+ static VALUE
321
+ rb_winevt_subscribe_render(VALUE self)
322
+ {
323
+ char* result;
324
+ struct WinevtSubscribe *winevtSubscribe;
325
+
326
+ TypedData_Get_Struct(self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
327
+ result = render_event(winevtSubscribe->event, EvtRenderEventXml);
328
+
329
+ return rb_str_new2(result);
330
+ }
331
+
332
+ static VALUE
333
+ rb_winevt_subscribe_each(VALUE self)
334
+ {
335
+ struct WinevtSubscribe *winevtSubscribe;
336
+
337
+ RETURN_ENUMERATOR(self, 0, 0);
338
+
339
+ TypedData_Get_Struct(self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
340
+
341
+ while (rb_winevt_subscribe_next(self)) {
342
+ rb_yield(rb_winevt_subscribe_render(self));
343
+ }
344
+
345
+ return Qnil;
346
+ }
347
+
348
+ static VALUE
349
+ rb_winevt_subscribe_get_bookmark(VALUE self)
350
+ {
351
+ char* result;
352
+ struct WinevtSubscribe *winevtSubscribe;
353
+
354
+ TypedData_Get_Struct(self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
355
+
356
+ result = render_event(winevtSubscribe->bookmark, EvtRenderBookmark);
357
+
358
+ return rb_str_new2(result);
359
+ }
360
+
361
+ static void
362
+ bookmark_free(void *ptr)
363
+ {
364
+ struct WinevtBookmark *winevtBookmark = (struct WinevtBookmark *)ptr;
365
+ if (winevtBookmark->bookmark)
366
+ EvtClose(winevtBookmark->bookmark);
367
+
368
+ xfree(ptr);
369
+ }
370
+
371
+ static VALUE
372
+ rb_winevt_bookmark_alloc(VALUE klass)
373
+ {
374
+ VALUE obj;
375
+ struct WinevtBookmark *winevtBookmark;
376
+ obj = TypedData_Make_Struct(klass,
377
+ struct WinevtBookmark,
378
+ &rb_winevt_bookmark_type,
379
+ winevtBookmark);
380
+ return obj;
381
+ }
382
+
383
+ static VALUE
384
+ rb_winevt_bookmark_initialize(int argc, VALUE *argv, VALUE self)
385
+ {
386
+ PWSTR bookmarkXml;
387
+ VALUE wbookmarkXmlBuf;
388
+ DWORD len;
389
+ struct WinevtBookmark *winevtBookmark;
390
+
391
+ TypedData_Get_Struct(self, struct WinevtBookmark, &rb_winevt_bookmark_type, winevtBookmark);
392
+
393
+ if (argc == 0) {
394
+ winevtBookmark->bookmark = EvtCreateBookmark(NULL);
395
+ } else if (argc == 1) {
396
+ VALUE rb_bookmarkXml;
397
+ rb_scan_args(argc, argv, "10", &rb_bookmarkXml);
398
+ Check_Type(rb_bookmarkXml, T_STRING);
399
+
400
+ // bookmarkXml : To wide char
401
+ len = MultiByteToWideChar(CP_UTF8, 0, RSTRING_PTR(rb_bookmarkXml), RSTRING_LEN(rb_bookmarkXml), NULL, 0);
402
+ bookmarkXml = ALLOCV_N(WCHAR, wbookmarkXmlBuf, len+1);
403
+ MultiByteToWideChar(CP_UTF8, 0, RSTRING_PTR(rb_bookmarkXml), RSTRING_LEN(rb_bookmarkXml), bookmarkXml, len);
404
+ bookmarkXml[len] = L'\0';
405
+ winevtBookmark->bookmark = EvtCreateBookmark(bookmarkXml);
406
+ ALLOCV_END(wbookmarkXmlBuf);
407
+ }
408
+
409
+ return Qnil;
410
+ }
411
+
412
+ static VALUE
413
+ rb_winevt_bookmark_update(VALUE self, VALUE event)
414
+ {
415
+ struct WinevtQuery *winevtQuery;
416
+ struct WinevtBookmark *winevtBookmark;
417
+
418
+ winevtQuery = EventQuery(event);
419
+
420
+ TypedData_Get_Struct(self, struct WinevtBookmark, &rb_winevt_bookmark_type, winevtBookmark);
421
+
422
+ if(EvtUpdateBookmark(winevtBookmark->bookmark, winevtQuery->event))
423
+ return Qtrue;
424
+
425
+ return Qfalse;
426
+ }
427
+
428
+ static VALUE
429
+ rb_winevt_bookmark_render(VALUE self)
430
+ {
431
+ char* result;
432
+ struct WinevtBookmark *winevtBookmark;
433
+
434
+ TypedData_Get_Struct(self, struct WinevtBookmark, &rb_winevt_bookmark_type, winevtBookmark);
435
+
436
+ result = render_event(winevtBookmark->bookmark, EvtRenderBookmark);
437
+
438
+ return rb_str_new2(result);
439
+ }
440
+
441
+ static void
442
+ query_free(void *ptr)
443
+ {
444
+ struct WinevtQuery *winevtQuery = (struct WinevtQuery *)ptr;
445
+ if (winevtQuery->query)
446
+ EvtClose(winevtQuery->query);
447
+
448
+ if (winevtQuery->event)
449
+ EvtClose(winevtQuery->event);
450
+
451
+ xfree(ptr);
452
+ }
453
+
454
+ static VALUE
455
+ rb_winevt_query_alloc(VALUE klass)
456
+ {
457
+ VALUE obj;
458
+ struct WinevtQuery *winevtQuery;
459
+ obj = TypedData_Make_Struct(klass,
460
+ struct WinevtQuery,
461
+ &rb_winevt_query_type,
462
+ winevtQuery);
463
+ return obj;
464
+ }
465
+
466
+ static VALUE
467
+ rb_winevt_query_initialize(VALUE self, VALUE channel, VALUE xpath)
468
+ {
469
+ PWSTR evtChannel, evtXPath;
470
+ struct WinevtQuery *winevtQuery;
471
+ DWORD len;
472
+ VALUE wchannelBuf, wpathBuf;
473
+
474
+ Check_Type(channel, T_STRING);
475
+ Check_Type(xpath, T_STRING);
476
+
477
+ // channel : To wide char
478
+ len = MultiByteToWideChar(CP_UTF8, 0, RSTRING_PTR(channel), RSTRING_LEN(channel), NULL, 0);
479
+ evtChannel = ALLOCV_N(WCHAR, wchannelBuf, len+1);
480
+ MultiByteToWideChar(CP_UTF8, 0, RSTRING_PTR(channel), RSTRING_LEN(channel), evtChannel, len);
481
+ evtChannel[len] = L'\0';
482
+
483
+ // xpath : To wide char
484
+ len = MultiByteToWideChar(CP_UTF8, 0, RSTRING_PTR(xpath), RSTRING_LEN(xpath), NULL, 0);
485
+ evtXPath = ALLOCV_N(WCHAR, wpathBuf, len+1);
486
+ MultiByteToWideChar(CP_UTF8, 0, RSTRING_PTR(xpath), RSTRING_LEN(xpath), evtXPath, len);
487
+ evtXPath[len] = L'\0';
488
+
489
+ TypedData_Get_Struct(self, struct WinevtQuery, &rb_winevt_query_type, winevtQuery);
490
+
491
+ winevtQuery->query = EvtQuery(NULL, evtChannel, evtXPath,
492
+ EvtQueryChannelPath | EvtQueryTolerateQueryErrors);
493
+ winevtQuery->offset = 0L;
494
+ winevtQuery->timeout = 0L;
495
+
496
+ ALLOCV_END(wchannelBuf);
497
+ ALLOCV_END(wpathBuf);
498
+
499
+ return Qnil;
500
+ }
501
+
502
+ static VALUE
503
+ rb_winevt_query_get_offset(VALUE self, VALUE offset)
504
+ {
505
+ struct WinevtQuery *winevtQuery;
506
+
507
+ TypedData_Get_Struct(self, struct WinevtQuery, &rb_winevt_query_type, winevtQuery);
508
+
509
+ return LONG2NUM(winevtQuery->offset);
510
+ }
511
+
512
+ static VALUE
513
+ rb_winevt_query_set_offset(VALUE self, VALUE offset)
514
+ {
515
+ struct WinevtQuery *winevtQuery;
516
+
517
+ TypedData_Get_Struct(self, struct WinevtQuery, &rb_winevt_query_type, winevtQuery);
518
+
519
+ winevtQuery->offset = NUM2LONG(offset);
520
+
521
+ return Qnil;
522
+ }
523
+
524
+ static VALUE
525
+ rb_winevt_query_get_timeout(VALUE self, VALUE timeout)
526
+ {
527
+ struct WinevtQuery *winevtQuery;
528
+
529
+ TypedData_Get_Struct(self, struct WinevtQuery, &rb_winevt_query_type, winevtQuery);
530
+
531
+ return LONG2NUM(winevtQuery->timeout);
532
+ }
533
+
534
+ static VALUE
535
+ rb_winevt_query_set_timeout(VALUE self, VALUE timeout)
536
+ {
537
+ struct WinevtQuery *winevtQuery;
538
+
539
+ TypedData_Get_Struct(self, struct WinevtQuery, &rb_winevt_query_type, winevtQuery);
540
+
541
+ winevtQuery->timeout = NUM2LONG(timeout);
542
+
543
+ return Qnil;
544
+ }
545
+
546
+ static VALUE
547
+ rb_winevt_query_next(VALUE self)
548
+ {
549
+ EVT_HANDLE event;
550
+ ULONG count;
551
+ struct WinevtQuery *winevtQuery;
552
+
553
+ TypedData_Get_Struct(self, struct WinevtQuery, &rb_winevt_query_type, winevtQuery);
554
+
555
+ if (EvtNext(winevtQuery->query, 1, &event, INFINITE, 0, &count) != FALSE) {
556
+ winevtQuery->event = event;
557
+ winevtQuery->count = count;
558
+
559
+ return Qtrue;
560
+ }
561
+
562
+ return Qfalse;
563
+ }
564
+
565
+ static char* render_event(EVT_HANDLE handle, DWORD flags)
566
+ {
567
+ PWSTR buffer = NULL;
568
+ ULONG bufferSize = 0;
569
+ ULONG bufferSizeNeeded = 0;
570
+ EVT_HANDLE event;
571
+ ULONG len, status, count;
572
+ char* errBuf;
573
+ char* result;
574
+ LPTSTR msgBuf;
575
+
576
+ do {
577
+ if (bufferSizeNeeded > bufferSize) {
578
+ free(buffer);
579
+ bufferSize = bufferSizeNeeded;
580
+ buffer = malloc(bufferSize);
581
+ if (buffer == NULL) {
582
+ status = ERROR_OUTOFMEMORY;
583
+ bufferSize = 0;
584
+ rb_raise(rb_eWinevtQueryError, "Out of memory");
585
+ break;
586
+ }
587
+ }
588
+
589
+ if (EvtRender(NULL,
590
+ handle,
591
+ flags,
592
+ bufferSize,
593
+ buffer,
594
+ &bufferSizeNeeded,
595
+ &count) != FALSE) {
596
+ status = ERROR_SUCCESS;
597
+ } else {
598
+ status = GetLastError();
599
+ }
600
+ } while (status == ERROR_INSUFFICIENT_BUFFER);
601
+
602
+ if (status != ERROR_SUCCESS) {
603
+ FormatMessage(
604
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
605
+ FORMAT_MESSAGE_FROM_SYSTEM |
606
+ FORMAT_MESSAGE_IGNORE_INSERTS,
607
+ NULL, status,
608
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
609
+ &msgBuf, 0, NULL);
610
+ len = WideCharToMultiByte(CP_UTF8, 0, msgBuf, -1, NULL, 0, NULL, NULL);
611
+ if (!(result = malloc(len))) return "";
612
+ WideCharToMultiByte(CP_UTF8, 0, msgBuf, -1, result, len, NULL, NULL);
613
+
614
+ rb_raise(rb_eWinevtQueryError, "ErrorCode: %d\nError: %s\n", status, result);
615
+ }
616
+
617
+ len = WideCharToMultiByte(CP_UTF8, 0, buffer, -1, NULL, 0, NULL, NULL);
618
+ if (!(result = malloc(len))) return "";
619
+ WideCharToMultiByte(CP_UTF8, 0, buffer, -1, result, len, NULL, NULL);
620
+
621
+ return result;
622
+ }
623
+
624
+ static VALUE
625
+ rb_winevt_query_render(VALUE self)
626
+ {
627
+ char* result;
628
+ struct WinevtQuery *winevtQuery;
629
+
630
+ TypedData_Get_Struct(self, struct WinevtQuery, &rb_winevt_query_type, winevtQuery);
631
+ result = render_event(winevtQuery->event, EvtRenderEventXml);
632
+
633
+ return rb_str_new2(result);
634
+ }
635
+
636
+ static DWORD
637
+ get_evt_seek_flag_from_cstr(char* flag_str)
638
+ {
639
+ if (strcmp(flag_str, "first") == 0)
640
+ return EvtSeekRelativeToFirst;
641
+ else if (strcmp(flag_str, "last") == 0)
642
+ return EvtSeekRelativeToLast;
643
+ else if (strcmp(flag_str, "current") == 0)
644
+ return EvtSeekRelativeToCurrent;
645
+ else if (strcmp(flag_str, "bookmark") == 0)
646
+ return EvtSeekRelativeToBookmark;
647
+ else if (strcmp(flag_str, "originmask") == 0)
648
+ return EvtSeekOriginMask;
649
+ else if (strcmp(flag_str, "strict") == 0)
650
+ return EvtSeekStrict;
651
+ }
652
+
653
+ static VALUE
654
+ rb_winevt_query_seek(VALUE self, VALUE bookmark_or_flag)
655
+ {
656
+ struct WinevtQuery *winevtQuery;
657
+ struct WinevtBookmark *winevtBookmark = NULL;
658
+ DWORD status;
659
+ DWORD flag;
660
+
661
+ switch (TYPE(bookmark_or_flag)) {
662
+ case T_SYMBOL:
663
+ flag = get_evt_seek_flag_from_cstr(RSTRING_PTR(rb_sym2str(bookmark_or_flag)));
664
+ break;
665
+ case T_STRING:
666
+ flag = get_evt_seek_flag_from_cstr(StringValueCStr(bookmark_or_flag));
667
+ break;
668
+ default:
669
+ if (!rb_obj_is_kind_of(bookmark_or_flag, rb_cBookmark))
670
+ rb_raise(rb_eArgError, "Expected a String or a Symbol or a Bookmark instance");
671
+
672
+ winevtBookmark = EventBookMark(bookmark_or_flag);
673
+ }
674
+
675
+ if (winevtBookmark) {
676
+ TypedData_Get_Struct(self, struct WinevtQuery, &rb_winevt_query_type, winevtQuery);
677
+ if (EvtSeek(winevtQuery->query, winevtQuery->offset, winevtBookmark->bookmark, winevtQuery->timeout, EvtSeekRelativeToBookmark))
678
+ return Qtrue;
679
+ } else {
680
+ TypedData_Get_Struct(self, struct WinevtQuery, &rb_winevt_query_type, winevtQuery);
681
+ if (EvtSeek(winevtQuery->query, winevtQuery->offset, NULL, winevtQuery->timeout, flag))
682
+ return Qtrue;
683
+ }
684
+
685
+ return Qfalse;
686
+ }
687
+
688
+ static VALUE
689
+ rb_winevt_query_each(VALUE self)
690
+ {
691
+ struct WinevtQuery *winevtQuery;
692
+
693
+ RETURN_ENUMERATOR(self, 0, 0);
694
+
695
+ TypedData_Get_Struct(self, struct WinevtQuery, &rb_winevt_query_type, winevtQuery);
696
+
697
+ while (rb_winevt_query_next(self)) {
698
+ rb_yield(rb_winevt_query_render(self));
699
+ }
700
+
701
+ return Qnil;
702
+ }
703
+
704
+ void
705
+ Init_winevt(void)
706
+ {
707
+ rb_mWinevt = rb_define_module("Winevt");
708
+ rb_cEventLog = rb_define_class_under(rb_mWinevt, "EventLog", rb_cObject);
709
+ rb_cQuery = rb_define_class_under(rb_cEventLog, "Query", rb_cObject);
710
+ rb_cBookmark = rb_define_class_under(rb_cEventLog, "Bookmark", rb_cObject);
711
+ rb_cChannel = rb_define_class_under(rb_cEventLog, "Channel", rb_cObject);
712
+ rb_cSubscribe = rb_define_class_under(rb_cEventLog, "Subscribe", rb_cObject);
713
+ rb_eWinevtQueryError = rb_define_class_under(rb_cQuery, "Error", rb_eStandardError);
714
+
715
+ id_call = rb_intern("call");
716
+
717
+ rb_define_alloc_func(rb_cSubscribe, rb_winevt_subscribe_alloc);
718
+ rb_define_method(rb_cSubscribe, "initialize", rb_winevt_subscribe_initialize, 0);
719
+ rb_define_method(rb_cSubscribe, "subscribe", rb_winevt_subscribe_subscribe, -1);
720
+ rb_define_method(rb_cSubscribe, "next", rb_winevt_subscribe_next, 0);
721
+ rb_define_method(rb_cSubscribe, "render", rb_winevt_subscribe_render, 0);
722
+ rb_define_method(rb_cSubscribe, "each", rb_winevt_subscribe_each, 0);
723
+ rb_define_method(rb_cSubscribe, "bookmark", rb_winevt_subscribe_get_bookmark, 0);
724
+ rb_define_method(rb_cSubscribe, "tail?", rb_winevt_subscribe_tail_p, 0);
725
+ rb_define_method(rb_cSubscribe, "tail=", rb_winevt_subscribe_set_tail, 1);
726
+
727
+ rb_define_alloc_func(rb_cChannel, rb_winevt_channel_alloc);
728
+ rb_define_method(rb_cChannel, "initialize", rb_winevt_channel_initialize, 0);
729
+ rb_define_method(rb_cChannel, "each", rb_winevt_channel_each, 0);
730
+
731
+ rb_define_alloc_func(rb_cBookmark, rb_winevt_bookmark_alloc);
732
+ rb_define_method(rb_cBookmark, "initialize", rb_winevt_bookmark_initialize, -1);
733
+ rb_define_method(rb_cBookmark, "update", rb_winevt_bookmark_update, 1);
734
+ rb_define_method(rb_cBookmark, "render", rb_winevt_bookmark_render, 0);
735
+
736
+ rb_define_alloc_func(rb_cQuery, rb_winevt_query_alloc);
737
+ rb_define_method(rb_cQuery, "initialize", rb_winevt_query_initialize, 2);
738
+ rb_define_method(rb_cQuery, "next", rb_winevt_query_next, 0);
739
+ rb_define_method(rb_cQuery, "render", rb_winevt_query_render, 0);
740
+ rb_define_method(rb_cQuery, "seek", rb_winevt_query_seek, 1);
741
+ rb_define_method(rb_cQuery, "offset", rb_winevt_query_get_offset, 0);
742
+ rb_define_method(rb_cQuery, "offset=", rb_winevt_query_set_offset, 1);
743
+ rb_define_method(rb_cQuery, "timeout", rb_winevt_query_get_timeout, 0);
744
+ rb_define_method(rb_cQuery, "timeout=", rb_winevt_query_set_timeout, 1);
745
+ rb_define_method(rb_cQuery, "each", rb_winevt_query_each, 0);
746
+ }
Binary file
Binary file
Binary file
@@ -0,0 +1,6 @@
1
+ module Winevt
2
+ class EventLog
3
+ class Query
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module Winevt
2
+ VERSION = "0.1.0"
3
+ end
data/lib/winevt.rb ADDED
@@ -0,0 +1,11 @@
1
+ begin
2
+ require "winevt/#{RUBY_VERSION[/\d+.\d+/]}/winevt"
3
+ rescue LoadError
4
+ require "winevt/winevt"
5
+ end
6
+ require "winevt/query"
7
+ require "winevt/version"
8
+
9
+ module Winevt
10
+ # Your code goes here...
11
+ end
data/winevt_c.gemspec ADDED
@@ -0,0 +1,33 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "winevt/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "winevt_c"
8
+ spec.version = Winevt::VERSION
9
+ spec.authors = ["Hiroshi Hatake"]
10
+ spec.email = ["cosmo0920.wp@gmail.com"]
11
+
12
+ spec.summary = %q{Windows Event Log API bindings from winevt.h.}
13
+ spec.description = spec.summary
14
+ spec.homepage = "https://github.com/cosmo0920/winevt_c"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+ spec.extensions = ["ext/winevt/extconf.rb"]
25
+ spec.license = "Apache-2.0"
26
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4".freeze)
27
+
28
+ spec.add_development_dependency "bundler", [">= 1.16", "< 3"]
29
+ spec.add_development_dependency "rake", "~> 12.0"
30
+ spec.add_development_dependency "rake-compiler", "~> 1.0"
31
+ spec.add_development_dependency "rake-compiler-dock", "~> 0.7.2"
32
+ spec.add_development_dependency "test-unit", "~> 3.2"
33
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: winevt_c
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: x86-mingw32
6
+ authors:
7
+ - Hiroshi Hatake
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-06-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1.16'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3'
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '12.0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '12.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake-compiler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake-compiler-dock
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.7.2
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.7.2
75
+ - !ruby/object:Gem::Dependency
76
+ name: test-unit
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.2'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.2'
89
+ description: Windows Event Log API bindings from winevt.h.
90
+ email:
91
+ - cosmo0920.wp@gmail.com
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - ".gitignore"
97
+ - Gemfile
98
+ - LICENSE.txt
99
+ - README.md
100
+ - Rakefile
101
+ - appveyor.yml
102
+ - bin/console
103
+ - bin/setup
104
+ - example/bookmark.rb
105
+ - example/eventlog.rb
106
+ - example/tailing.rb
107
+ - ext/winevt/extconf.rb
108
+ - ext/winevt/winevt.c
109
+ - lib/winevt.rb
110
+ - lib/winevt/2.4/winevt.so
111
+ - lib/winevt/2.5/winevt.so
112
+ - lib/winevt/2.6/winevt.so
113
+ - lib/winevt/query.rb
114
+ - lib/winevt/version.rb
115
+ - winevt_c.gemspec
116
+ homepage: https://github.com/cosmo0920/winevt_c
117
+ licenses:
118
+ - Apache-2.0
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '2.4'
129
+ - - "<"
130
+ - !ruby/object:Gem::Version
131
+ version: 2.7.dev
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.7.9
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Windows Event Log API bindings from winevt.h.
143
+ test_files: []