├── LICENSE
├── README.md
├── dll
├── Driver.cpp
├── Driver.h
├── OlsApi.cpp
├── OlsApi.def
├── OlsApi.h
├── OlsApiInit.h
├── OlsApiInitDef.h
├── OlsApiInitExt.h
├── OlsDef.h
├── OlsDll.cpp
├── OlsDll.h
├── OlsDll.rc
├── OlsIoctl.h
├── resource.h
├── stdafx.cpp
├── stdafx.h
├── sys
│ ├── MAKEFILE
│ ├── OpenLibSys.c
│ ├── OpenLibSys.h
│ ├── OpenLibSys.rc
│ └── SOURCES
└── vxd
│ ├── Makefile
│ ├── OpenLS.c
│ ├── OpenLS.def
│ ├── OpenLS.h
│ ├── OpenLS.rc
│ └── ctrl.asm
└── drv
├── DriverApi.c
├── DriverApi.h
├── DriverIoCtl.h
└── DriverManage.c
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) {year} {name of author}
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | {project} Copyright (C) {year} {fullname}
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # WinRing0
2 | Windows Ring0 Access
3 |
4 | ###File Directory
5 |
6 | >dll
7 | * driver source
8 |
9 | >drv
10 | * driver normal interface
11 |
12 | ##Description
13 | Allow user application to access ring0 level resource
14 |
15 | * access cpu msr register
16 | * read/write memory directly
17 | * io pci device
18 | * etc...
19 |
--------------------------------------------------------------------------------
/dll/Driver.cpp:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------------
2 | // Author : hiyohiyo
3 | // Mail : hiyohiyo@crystalmark.info
4 | // Web : http://openlibsys.org/
5 | // License : The modified BSD license
6 | //
7 | // Copyright 2007 OpenLibSys.org. All rights reserved.
8 | //-----------------------------------------------------------------------------
9 |
10 | #include "stdafx.h"
11 | #include "Driver.h"
12 | #include
13 | #include "OlsDll.h"
14 |
15 | //-----------------------------------------------------------------------------
16 | //
17 | // Global
18 | //
19 | //-----------------------------------------------------------------------------
20 |
21 | extern HANDLE gHandle;
22 |
23 | //-----------------------------------------------------------------------------
24 | //
25 | // Prototypes
26 | //
27 | //-----------------------------------------------------------------------------
28 |
29 | static BOOL InstallDriver(SC_HANDLE hSCManager, LPCTSTR DriverId, LPCTSTR DriverPath);
30 | static BOOL RemoveDriver(SC_HANDLE hSCManager, LPCTSTR DriverId);
31 | static BOOL StartDriver(SC_HANDLE hSCManager, LPCTSTR DriverId);
32 | static BOOL StopDriver(SC_HANDLE hSCManager, LPCTSTR DriverId);
33 | static BOOL SystemInstallDriver(SC_HANDLE hSCManager, LPCTSTR DriverId, LPCTSTR DriverPath);
34 | static BOOL IsSystemInstallDriver(SC_HANDLE hSCManager, LPCTSTR DriverId, LPCTSTR DriverPath);
35 |
36 | //-----------------------------------------------------------------------------
37 | //
38 | // Manage Driver
39 | //
40 | //-----------------------------------------------------------------------------
41 |
42 | BOOL ManageDriver(LPCTSTR DriverId, LPCTSTR DriverPath, USHORT Function)
43 | {
44 | SC_HANDLE hSCManager = NULL;
45 | BOOL rCode = FALSE;
46 | DWORD error = NO_ERROR;
47 |
48 | if(DriverId == NULL || DriverPath == NULL)
49 | {
50 | return FALSE;
51 | }
52 | hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
53 |
54 | if(hSCManager == NULL)
55 | {
56 | return FALSE;
57 | }
58 |
59 | switch(Function)
60 | {
61 | case OLS_DRIVER_INSTALL:
62 | if(InstallDriver(hSCManager, DriverId, DriverPath))
63 | {
64 | rCode = StartDriver(hSCManager, DriverId);
65 | }
66 | break;
67 | case OLS_DRIVER_REMOVE:
68 | if(! IsSystemInstallDriver(hSCManager, DriverId, DriverPath))
69 | {
70 | StopDriver(hSCManager, DriverId);
71 | rCode = RemoveDriver(hSCManager, DriverId);
72 | }
73 | break;
74 | case OLS_DRIVER_SYSTEM_INSTALL:
75 | if(IsSystemInstallDriver(hSCManager, DriverId, DriverPath))
76 | {
77 | rCode = TRUE;
78 | }
79 | else
80 | {
81 | if(! OpenDriver())
82 | {
83 | StopDriver(hSCManager, DriverId);
84 | RemoveDriver(hSCManager, DriverId);
85 | if(InstallDriver(hSCManager, DriverId, DriverPath))
86 | {
87 | StartDriver(hSCManager, DriverId);
88 | }
89 | OpenDriver();
90 | }
91 | rCode = SystemInstallDriver(hSCManager, DriverId, DriverPath);
92 | }
93 | break;
94 | case OLS_DRIVER_SYSTEM_UNINSTALL:
95 | if(! IsSystemInstallDriver(hSCManager, DriverId, DriverPath))
96 | {
97 | rCode = TRUE;
98 | }
99 | else
100 | {
101 | if(gHandle != INVALID_HANDLE_VALUE)
102 | {
103 | CloseHandle(gHandle);
104 | gHandle = INVALID_HANDLE_VALUE;
105 | }
106 |
107 | if(StopDriver(hSCManager, DriverId))
108 | {
109 | rCode = RemoveDriver(hSCManager, DriverId);
110 | }
111 | }
112 | break;
113 | default:
114 | rCode = FALSE;
115 | break;
116 | }
117 |
118 | if(hSCManager != NULL)
119 | {
120 | CloseServiceHandle(hSCManager);
121 | }
122 |
123 | return rCode;
124 | }
125 |
126 | //-----------------------------------------------------------------------------
127 | //
128 | // Install Driver
129 | //
130 | //-----------------------------------------------------------------------------
131 |
132 | BOOL InstallDriver(SC_HANDLE hSCManager, LPCTSTR DriverId, LPCTSTR DriverPath)
133 | {
134 | SC_HANDLE hService = NULL;
135 | BOOL rCode = FALSE;
136 | DWORD error = NO_ERROR;
137 |
138 | hService = CreateService(hSCManager,
139 | DriverId,
140 | DriverId,
141 | SERVICE_ALL_ACCESS,
142 | SERVICE_KERNEL_DRIVER,
143 | SERVICE_DEMAND_START,
144 | SERVICE_ERROR_NORMAL,
145 | DriverPath,
146 | NULL,
147 | NULL,
148 | NULL,
149 | NULL,
150 | NULL
151 | );
152 |
153 | if(hService == NULL)
154 | {
155 | error = GetLastError();
156 | if(error == ERROR_SERVICE_EXISTS)
157 | {
158 | rCode = TRUE;
159 | }
160 | }
161 | else
162 | {
163 | rCode = TRUE;
164 | CloseServiceHandle(hService);
165 | }
166 |
167 | return rCode;
168 | }
169 |
170 | //-----------------------------------------------------------------------------
171 | //
172 | // System Install Driver
173 | //
174 | //-----------------------------------------------------------------------------
175 |
176 | BOOL SystemInstallDriver(SC_HANDLE hSCManager, LPCTSTR DriverId, LPCTSTR DriverPath)
177 | {
178 | SC_HANDLE hService = NULL;
179 | BOOL rCode = FALSE;
180 |
181 | hService = OpenService(hSCManager, DriverId, SERVICE_ALL_ACCESS);
182 |
183 | if(hService != NULL)
184 | {
185 | rCode = ChangeServiceConfig(hService,
186 | SERVICE_KERNEL_DRIVER,
187 | SERVICE_AUTO_START,
188 | SERVICE_ERROR_NORMAL,
189 | DriverPath,
190 | NULL,
191 | NULL,
192 | NULL,
193 | NULL,
194 | NULL,
195 | NULL
196 | );
197 | CloseServiceHandle(hService);
198 | }
199 |
200 | return rCode;
201 | }
202 |
203 | //-----------------------------------------------------------------------------
204 | //
205 | // Remove Driver
206 | //
207 | //-----------------------------------------------------------------------------
208 |
209 | BOOL RemoveDriver(SC_HANDLE hSCManager, LPCTSTR DriverId)
210 | {
211 | SC_HANDLE hService = NULL;
212 | BOOL rCode = FALSE;
213 |
214 | hService = OpenService(hSCManager, DriverId, SERVICE_ALL_ACCESS);
215 | if(hService == NULL)
216 | {
217 | rCode = TRUE;
218 | }
219 | else
220 | {
221 | rCode = DeleteService(hService);
222 | CloseServiceHandle(hService);
223 | }
224 |
225 | return rCode;
226 | }
227 |
228 | //-----------------------------------------------------------------------------
229 | //
230 | // Start Driver
231 | //
232 | //-----------------------------------------------------------------------------
233 |
234 | BOOL StartDriver(SC_HANDLE hSCManager, LPCTSTR DriverId)
235 | {
236 | SC_HANDLE hService = NULL;
237 | BOOL rCode = FALSE;
238 | DWORD error = NO_ERROR;
239 |
240 | hService = OpenService(hSCManager, DriverId, SERVICE_ALL_ACCESS);
241 |
242 | if(hService != NULL)
243 | {
244 | if(! StartService(hService, 0, NULL))
245 | {
246 | error = GetLastError();
247 | if(error == ERROR_SERVICE_ALREADY_RUNNING)
248 | {
249 | rCode = TRUE;
250 | }
251 | }
252 | else
253 | {
254 | rCode = TRUE;
255 | }
256 | CloseServiceHandle(hService);
257 | }
258 |
259 | return rCode;
260 | }
261 |
262 | //-----------------------------------------------------------------------------
263 | //
264 | // Stop Driver
265 | //
266 | //-----------------------------------------------------------------------------
267 |
268 | BOOL StopDriver(SC_HANDLE hSCManager, LPCTSTR DriverId)
269 | {
270 | SC_HANDLE hService = NULL;
271 | BOOL rCode = FALSE;
272 | SERVICE_STATUS serviceStatus;
273 | DWORD error = NO_ERROR;
274 |
275 | hService = OpenService(hSCManager, DriverId, SERVICE_ALL_ACCESS);
276 |
277 | if(hService != NULL)
278 | {
279 | rCode = ControlService(hService, SERVICE_CONTROL_STOP, &serviceStatus);
280 | error = GetLastError();
281 | CloseServiceHandle(hService);
282 | }
283 |
284 | return rCode;
285 | }
286 |
287 | //-----------------------------------------------------------------------------
288 | //
289 | // IsSystemInstallDriver
290 | //
291 | //-----------------------------------------------------------------------------
292 |
293 | BOOL IsSystemInstallDriver(SC_HANDLE hSCManager, LPCTSTR DriverId, LPCTSTR DriverPath)
294 | {
295 | SC_HANDLE hService = NULL;
296 | BOOL rCode = FALSE;
297 | DWORD dwSize;
298 | LPQUERY_SERVICE_CONFIG lpServiceConfig;
299 |
300 | hService = OpenService(hSCManager, DriverId, SERVICE_ALL_ACCESS);
301 |
302 | if(hService != NULL)
303 | {
304 | QueryServiceConfig(hService, NULL, 0, &dwSize);
305 | lpServiceConfig = (LPQUERY_SERVICE_CONFIG)HeapAlloc(GetProcessHeap(),
306 | HEAP_ZERO_MEMORY, dwSize);
307 | QueryServiceConfig(hService, lpServiceConfig, dwSize, &dwSize);
308 |
309 | if(lpServiceConfig->dwStartType == SERVICE_AUTO_START)
310 | {
311 | rCode = TRUE;
312 | }
313 |
314 | CloseServiceHandle(hService);
315 |
316 | HeapFree(GetProcessHeap(), HEAP_NO_SERIALIZE, lpServiceConfig);
317 | }
318 |
319 | return rCode;
320 | }
--------------------------------------------------------------------------------
/dll/Driver.h:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------------
2 | // Author : hiyohiyo
3 | // Mail : hiyohiyo@crystalmark.info
4 | // Web : http://openlibsys.org/
5 | // License : The modified BSD license
6 | //
7 | // Copyright 2007 OpenLibSys.org. All rights reserved.
8 | //-----------------------------------------------------------------------------
9 |
10 | #pragma once
11 |
12 | #define OLS_DRIVER_INSTALL 1
13 | #define OLS_DRIVER_REMOVE 2
14 | #define OLS_DRIVER_SYSTEM_INSTALL 3
15 | #define OLS_DRIVER_SYSTEM_UNINSTALL 4
16 |
17 | BOOL ManageDriver(LPCTSTR DriverId, LPCTSTR DriverPath, USHORT Function);
--------------------------------------------------------------------------------
/dll/OlsApi.def:
--------------------------------------------------------------------------------
1 | EXPORTS
2 |
3 | GetDllStatus @1
4 | GetDllVersion @2
5 | GetDriverVersion @3
6 | GetDriverType @4
7 |
8 | InitializeOls @7
9 | DeinitializeOls @8
10 |
11 | IsCpuid @11
12 | IsMsr @12
13 | IsTsc @13
14 |
15 | Hlt @20
16 | Rdmsr @21
17 | Wrmsr @22
18 | Rdpmc @23
19 | Cpuid @24
20 | Rdtsc @25
21 |
22 | HltTx @30
23 | RdmsrTx @31
24 | WrmsrTx @32
25 | RdpmcTx @33
26 | CpuidTx @34
27 | RdtscTx @35
28 |
29 | HltPx @40
30 | RdmsrPx @41
31 | WrmsrPx @42
32 | RdpmcPx @43
33 | CpuidPx @44
34 | RdtscPx @45
35 |
36 | ReadIoPortByte @51
37 | ReadIoPortWord @52
38 | ReadIoPortDword @53
39 | WriteIoPortByte @54
40 | WriteIoPortWord @55
41 | WriteIoPortDword @56
42 |
43 | ReadIoPortByteEx @61
44 | ReadIoPortWordEx @62
45 | ReadIoPortDwordEx @63
46 | WriteIoPortByteEx @64
47 | WriteIoPortWordEx @65
48 | WriteIoPortDwordEx @66
49 |
50 | SetPciMaxBusIndex @70
51 |
52 | ReadPciConfigByte @81
53 | ReadPciConfigWord @82
54 | ReadPciConfigDword @83
55 | WritePciConfigByte @84
56 | WritePciConfigWord @85
57 | WritePciConfigDword @86
58 | FindPciDeviceById @87
59 | FindPciDeviceByClass @88
60 |
61 | ReadPciConfigByteEx @91
62 | ReadPciConfigWordEx @92
63 | ReadPciConfigDwordEx @93
64 | WritePciConfigByteEx @94
65 | WritePciConfigWordEx @95
66 | WritePciConfigDwordEx @96
67 |
68 | ;ReadDmiMemory @100
69 | ;ReadPhysicalMemory @101
70 | ;WritePhysicalMemory @102
71 |
--------------------------------------------------------------------------------
/dll/OlsApi.h:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------------
2 | // Author : hiyohiyo
3 | // Mail : hiyohiyo@crystalmark.info
4 | // Web : http://openlibsys.org/
5 | // License : The modified BSD license
6 | //
7 | // Copyright 2007-2009 OpenLibSys.org. All rights reserved.
8 | //-----------------------------------------------------------------------------
9 | // for WinRing0 1.3.x
10 |
11 | #pragma once
12 |
13 | /******************************************************************************
14 | **
15 | ** DLL Information
16 | **
17 | ******************************************************************************/
18 |
19 | //-----------------------------------------------------------------------------
20 | // GetDllStatus
21 | //-----------------------------------------------------------------------------
22 | DWORD // DLL Status, defined OLS_DLL_****
23 | WINAPI GetDllStatus();
24 |
25 | //-----------------------------------------------------------------------------
26 | // GetDllVersion
27 | //-----------------------------------------------------------------------------
28 | DWORD // DLL Version, defined OLS_VERSION
29 | WINAPI GetDllVersion(
30 | PBYTE major, // major version
31 | PBYTE minor, // minor version
32 | PBYTE revision, // revision
33 | PBYTE release // release/build
34 | );
35 |
36 | //-----------------------------------------------------------------------------
37 | // GetDriverVersion
38 | //-----------------------------------------------------------------------------
39 | DWORD // Device Driver Version, defined OLS_DRIVER_VERSION
40 | WINAPI GetDriverVersion(
41 | PBYTE major, // major version
42 | PBYTE minor, // minor version
43 | PBYTE revision, // revision
44 | PBYTE release // release/build
45 | );
46 |
47 | //-----------------------------------------------------------------------------
48 | // GetDriverType
49 | //-----------------------------------------------------------------------------
50 | DWORD // Device Driver Type, defined OLS_DRIVER_TYPE_****
51 | WINAPI GetDriverType();
52 |
53 | //-----------------------------------------------------------------------------
54 | // InitializeOls
55 | //-----------------------------------------------------------------------------
56 | BOOL // TRUE: success, FALSE: failure
57 | WINAPI InitializeOls();
58 |
59 | //-----------------------------------------------------------------------------
60 | // DeinitializeOls
61 | //-----------------------------------------------------------------------------
62 | VOID WINAPI DeinitializeOls();
63 |
64 | /******************************************************************************
65 | **
66 | ** CPU
67 | **
68 | ******************************************************************************/
69 |
70 | //-----------------------------------------------------------------------------
71 | // IsCpuid
72 | //-----------------------------------------------------------------------------
73 | BOOL // TRUE: support CPUID instruction, FALSE: not support CPUID instruction
74 | WINAPI IsCpuid();
75 |
76 | //-----------------------------------------------------------------------------
77 | // IsMsr
78 | //-----------------------------------------------------------------------------
79 | BOOL // TRUE: support MSR(Model-Specific Register), FALSE: not support MSR
80 | WINAPI IsMsr();
81 |
82 | //-----------------------------------------------------------------------------
83 | // IsTsc
84 | //-----------------------------------------------------------------------------
85 | BOOL // TRUE: support TSC(Time Stamp Counter), FALSE: not support TSC
86 | WINAPI IsTsc();
87 |
88 | //-----------------------------------------------------------------------------
89 | // Rdmsr
90 | //-----------------------------------------------------------------------------
91 | BOOL // TRUE: success, FALSE: failure
92 | WINAPI Rdmsr(
93 | DWORD index, // MSR index
94 | PDWORD eax, // bit 0-31
95 | PDWORD edx // bit 32-63
96 | );
97 |
98 | //-----------------------------------------------------------------------------
99 | // RdmsrTx
100 | //-----------------------------------------------------------------------------
101 | BOOL // TRUE: success, FALSE: failure
102 | WINAPI RdmsrTx(
103 | DWORD index, // MSR index
104 | PDWORD eax, // bit 0-31
105 | PDWORD edx, // bit 32-63
106 | DWORD_PTR threadAffinityMask
107 | );
108 |
109 | //-----------------------------------------------------------------------------
110 | // RdmsrPx
111 | //-----------------------------------------------------------------------------
112 | BOOL // TRUE: success, FALSE: failure
113 | WINAPI RdmsrPx(
114 | DWORD index, // MSR index
115 | PDWORD eax, // bit 0-31
116 | PDWORD edx, // bit 32-63
117 | DWORD_PTR processAffinityMask
118 | );
119 |
120 | //-----------------------------------------------------------------------------
121 | // Wrmsr
122 | //-----------------------------------------------------------------------------
123 | BOOL // TRUE: success, FALSE: failure
124 | WINAPI Wrmsr(
125 | DWORD index, // MSR index
126 | DWORD eax, // bit 0-31
127 | DWORD edx // bit 32-63
128 | );
129 |
130 | //-----------------------------------------------------------------------------
131 | // WrmsrTx
132 | //-----------------------------------------------------------------------------
133 | BOOL // TRUE: success, FALSE: failure
134 | WINAPI WrmsrTx(
135 | DWORD index, // MSR index
136 | DWORD eax, // bit 0-31
137 | DWORD edx, // bit 32-63
138 | DWORD_PTR threadAffinityMask
139 | );
140 |
141 | //-----------------------------------------------------------------------------
142 | // WrmsrPx
143 | //-----------------------------------------------------------------------------
144 | BOOL // TRUE: success, FALSE: failure
145 | WINAPI WrmsrPx(
146 | DWORD index, // MSR index
147 | DWORD eax, // bit 0-31
148 | DWORD edx, // bit 32-63
149 | DWORD_PTR processAffinityMask
150 | );
151 |
152 | //-----------------------------------------------------------------------------
153 | // Rdpmc
154 | //-----------------------------------------------------------------------------
155 | BOOL // TRUE: success, FALSE: failure
156 | WINAPI Rdpmc(
157 | DWORD index, // PMC index
158 | PDWORD eax, // bit 0-31
159 | PDWORD edx // bit 32-63
160 | );
161 |
162 | //-----------------------------------------------------------------------------
163 | // RdmsrTx
164 | //-----------------------------------------------------------------------------
165 | BOOL // TRUE: success, FALSE: failure
166 | WINAPI RdpmcTx(
167 | DWORD index, // PMC index
168 | PDWORD eax, // bit 0-31
169 | PDWORD edx, // bit 32-63
170 | DWORD_PTR threadAffinityMask
171 | );
172 |
173 | //-----------------------------------------------------------------------------
174 | // RdmsrPx
175 | //-----------------------------------------------------------------------------
176 | BOOL // TRUE: success, FALSE: failure
177 | WINAPI RdpmcPx(
178 | DWORD index, // PMC index
179 | PDWORD eax, // bit 0-31
180 | PDWORD edx, // bit 32-63
181 | DWORD_PTR processAffinityMask
182 | );
183 |
184 | //-----------------------------------------------------------------------------
185 | // Cpuid
186 | //-----------------------------------------------------------------------------
187 | BOOL // TRUE: success, FALSE: failure
188 | WINAPI Cpuid(
189 | DWORD index, // CPUID index
190 | PDWORD eax,
191 | PDWORD ebx,
192 | PDWORD ecx,
193 | PDWORD edx
194 | );
195 |
196 | //-----------------------------------------------------------------------------
197 | // CpuidTx
198 | //-----------------------------------------------------------------------------
199 | BOOL // TRUE: success, FALSE: failure
200 | WINAPI CpuidTx(
201 | DWORD index, // CPUID index
202 | PDWORD eax,
203 | PDWORD ebx,
204 | PDWORD ecx,
205 | PDWORD edx,
206 | DWORD_PTR threadAffinityMask
207 | );
208 |
209 | //-----------------------------------------------------------------------------
210 | // CpuidPx
211 | //-----------------------------------------------------------------------------
212 | BOOL // TRUE: success, FALSE: failure
213 | WINAPI CpuidPx(
214 | DWORD index, // CPUID index
215 | PDWORD eax,
216 | PDWORD ebx,
217 | PDWORD ecx,
218 | PDWORD edx,
219 | DWORD_PTR processAffinityMask
220 | );
221 |
222 | //-----------------------------------------------------------------------------
223 | // Rdtsc
224 | //-----------------------------------------------------------------------------
225 | BOOL // TRUE: success, FALSE: failure
226 | WINAPI Rdtsc(
227 | PDWORD eax, // bit 0-31
228 | PDWORD edx // bit 32-63
229 | );
230 |
231 | //-----------------------------------------------------------------------------
232 | // RdmsrTx
233 | //-----------------------------------------------------------------------------
234 | BOOL // TRUE: success, FALSE: failure
235 | WINAPI RdtscTx(
236 | PDWORD eax, // bit 0-31
237 | PDWORD edx, // bit 32-63
238 | DWORD_PTR threadAffinityMask
239 | );
240 |
241 | //-----------------------------------------------------------------------------
242 | // RdmsrPx
243 | //-----------------------------------------------------------------------------
244 | BOOL // TRUE: success, FALSE: failure
245 | WINAPI RdtscPx(
246 | PDWORD eax, // bit 0-31
247 | PDWORD edx, // bit 32-63
248 | DWORD_PTR processAffinityMask
249 | );
250 |
251 | //-----------------------------------------------------------------------------
252 | // Hlt
253 | //-----------------------------------------------------------------------------
254 | BOOL // TRUE: success, FALSE: failure
255 | WINAPI Hlt();
256 |
257 | //-----------------------------------------------------------------------------
258 | // HltTx
259 | //-----------------------------------------------------------------------------
260 | BOOL // TRUE: success, FALSE: failure
261 | WINAPI HltTx(
262 | DWORD_PTR threadAffinityMask
263 | );
264 |
265 | //-----------------------------------------------------------------------------
266 | // HltPx
267 | //-----------------------------------------------------------------------------
268 | BOOL // TRUE: success, FALSE: failure
269 | WINAPI HltTx(
270 | DWORD_PTR processAffinityMask
271 | );
272 |
273 | /******************************************************************************
274 | **
275 | ** I/O
276 | **
277 | ******************************************************************************/
278 |
279 | //-----------------------------------------------------------------------------
280 | // ReadIoPortByte
281 | //-----------------------------------------------------------------------------
282 | BYTE // Read Value
283 | WINAPI ReadIoPortByte(
284 | WORD port // I/O port address
285 | );
286 |
287 | //-----------------------------------------------------------------------------
288 | // ReadIoPortWord
289 | //-----------------------------------------------------------------------------
290 | WORD // Read Value
291 | WINAPI ReadIoPortWord(
292 | WORD port // I/O port address
293 | );
294 |
295 | //-----------------------------------------------------------------------------
296 | // ReadIoPortDword
297 | //-----------------------------------------------------------------------------
298 | DWORD // Read Value
299 | WINAPI ReadIoPortDword(
300 | WORD port // I/O port address
301 | );
302 |
303 | //-----------------------------------------------------------------------------
304 | // ReadIoPortByteEx
305 | //-----------------------------------------------------------------------------
306 | BOOL // TRUE: success, FALSE: failure
307 | WINAPI ReadIoPortByteEx(
308 | WORD port, // I/O port address
309 | PBYTE value // Read Value
310 | );
311 | //-----------------------------------------------------------------------------
312 | // ReadIoPortWordEx
313 | //-----------------------------------------------------------------------------
314 | BOOL // TRUE: success, FALSE: failure
315 | WINAPI ReadIoPortWordEx(
316 | WORD port, // I/O port address
317 | PWORD value // Read Value
318 | );
319 | //-----------------------------------------------------------------------------
320 | // ReadIoPortDwordEx
321 | //-----------------------------------------------------------------------------
322 | BOOL // TRUE: success, FALSE: failure
323 | WINAPI ReadIoPortDwordEx(
324 | WORD port, // I/O port address
325 | PDWORD value // Read Value
326 | );
327 |
328 | //-----------------------------------------------------------------------------
329 | // WriteIoPortByte
330 | //-----------------------------------------------------------------------------
331 | VOID
332 | WINAPI WriteIoPortByte(
333 | WORD port, // I/O port address
334 | BYTE value // Write Value
335 | );
336 |
337 | //-----------------------------------------------------------------------------
338 | // WriteIoPortDword
339 | //-----------------------------------------------------------------------------
340 | VOID
341 | WINAPI WriteIoPortDword(
342 | WORD port, // I/O port address
343 | DWORD value // Write Value
344 | );
345 |
346 |
347 | //-----------------------------------------------------------------------------
348 | // WriteIoPortWord
349 | //-----------------------------------------------------------------------------
350 | VOID
351 | WINAPI WriteIoPortWord(
352 | WORD port, // I/O port address
353 | WORD value // Write Value
354 | );
355 |
356 | //-----------------------------------------------------------------------------
357 | // WriteIoPortByteEx
358 | //-----------------------------------------------------------------------------
359 | BOOL // TRUE: success, FALSE: failure
360 | WINAPI WriteIoPortByteEx(
361 | WORD port, // I/O port address
362 | BYTE value // Write Value
363 | );
364 |
365 | //-----------------------------------------------------------------------------
366 | // WriteIoPortWordEx
367 | //-----------------------------------------------------------------------------
368 | BOOL // TRUE: success, FALSE: failure
369 | WINAPI WriteIoPortWordEx(
370 | WORD port, // I/O port address
371 | WORD value // Write Value
372 | );
373 |
374 |
375 | //-----------------------------------------------------------------------------
376 | // WriteIoPortDwordEx
377 | //-----------------------------------------------------------------------------
378 | BOOL // TRUE: success, FALSE: failure
379 | WINAPI WriteIoPortDwordEx(
380 | WORD port, // I/O port address
381 | DWORD value // Write Value
382 | );
383 |
384 | /******************************************************************************
385 | **
386 | ** PCI
387 | **
388 | ******************************************************************************/
389 | // pciAddress
390 | // 0- 2: Function Number
391 | // 3- 7: Device Number
392 | // 8-15: PCI Bus Number
393 | // 16-31: Reserved
394 | // 0xFFFFFFFF : Error
395 |
396 | //-----------------------------------------------------------------------------
397 | // SetPciMaxBusNo
398 | //-----------------------------------------------------------------------------
399 | VOID
400 | WINAPI SetPciMaxBusIndex(
401 | BYTE max // Max PCI Bus to Scan
402 | );
403 |
404 | //-----------------------------------------------------------------------------
405 | // ReadPciConfigByte
406 | //-----------------------------------------------------------------------------
407 | BYTE // Read Value
408 | WINAPI ReadPciConfigByte(
409 | DWORD pciAddress, // PCI Device Address
410 | BYTE regAddress // Configuration Address 0-255
411 | );
412 |
413 | //-----------------------------------------------------------------------------
414 | // ReadPciConfigWord
415 | //-----------------------------------------------------------------------------
416 | WORD // Read Value
417 | WINAPI ReadPciConfigWord(
418 | DWORD pciAddress, // PCI Device Address
419 | BYTE regAddress // Configuration Address 0-255
420 | );
421 |
422 | //-----------------------------------------------------------------------------
423 | // ReadPciConfigDword
424 | //-----------------------------------------------------------------------------
425 | DWORD // Read Value
426 | WINAPI ReadPciConfigDword(
427 | DWORD pciAddress, // PCI Device Address
428 | BYTE regAddress // Configuration Address 0-255
429 | );
430 |
431 | //-----------------------------------------------------------------------------
432 | // ReadPciConfigByteEx
433 | //-----------------------------------------------------------------------------
434 | BOOL // TRUE: success, FALSE: failure
435 | WINAPI ReadPciConfigByteEx(
436 | DWORD pciAddress, // PCI Device Address
437 | DWORD regAddress, // Configuration Address 0-whatever
438 | PBYTE value // Read Value
439 | );
440 |
441 | //-----------------------------------------------------------------------------
442 | // ReadPciConfigWordEx
443 | //-----------------------------------------------------------------------------
444 | BOOL // TRUE: success, FALSE: failure
445 | WINAPI ReadPciConfigWordEx(
446 | DWORD pciAddress, // PCI Device Address
447 | DWORD regAddress, // Configuration Address 0-whatever
448 | PWORD value // Read Value
449 | );
450 |
451 | //-----------------------------------------------------------------------------
452 | // ReadPciConfigDwordEx
453 | //-----------------------------------------------------------------------------
454 | BOOL // TRUE: success, FALSE: failure
455 | WINAPI ReadPciConfigDwordEx(
456 | DWORD pciAddress, // PCI Device Address
457 | DWORD regAddress, // Configuration Address 0-whatever
458 | PDWORD value // Read Value
459 | );
460 |
461 | //-----------------------------------------------------------------------------
462 | // WritePciConfigByte
463 | //-----------------------------------------------------------------------------
464 | VOID
465 | WINAPI WritePciConfigByte(
466 | DWORD pciAddress, // PCI Device Address
467 | BYTE regAddress, // Configuration Address 0-255
468 | BYTE value // Write Value
469 | );
470 |
471 | //-----------------------------------------------------------------------------
472 | // WritePciConfigWord
473 | //-----------------------------------------------------------------------------
474 | VOID
475 | WINAPI WritePciConfigWord(
476 | DWORD pciAddress, // PCI Device Address
477 | BYTE regAddress, // Configuration Address 0-255
478 | WORD value // Write Value
479 | );
480 |
481 | //-----------------------------------------------------------------------------
482 | // WritePciConfigDword
483 | //-----------------------------------------------------------------------------
484 | VOID
485 | WINAPI WritePciConfigDword(
486 | DWORD pciAddress, // PCI Device Address
487 | BYTE regAddress, // Configuration Address 0-255
488 | DWORD value // Write Value
489 | );
490 |
491 | //-----------------------------------------------------------------------------
492 | // WritePciConfigByteEx
493 | //-----------------------------------------------------------------------------
494 | BOOL // TRUE: success, FALSE: failure
495 | WINAPI WritePciConfigByteEx(
496 | DWORD pciAddress, // PCI Device Address
497 | DWORD regAddress, // Configuration Address 0-whatever
498 | BYTE value // Write Value
499 | );
500 |
501 | //-----------------------------------------------------------------------------
502 | // WritePciConfigWordEx
503 | //-----------------------------------------------------------------------------
504 | BOOL // TRUE: success, FALSE: failure
505 | WINAPI WritePciConfigWordEx(
506 | DWORD pciAddress, // PCI Device Address
507 | DWORD regAddress, // Configuration Address 0-whatever
508 | WORD value // Write Value
509 | );
510 |
511 | //-----------------------------------------------------------------------------
512 | // WritePciConfigDwordEx
513 | //-----------------------------------------------------------------------------
514 | BOOL // TRUE: success, FALSE: failure
515 | WINAPI WritePciConfigDwordEx(
516 | DWORD pciAddress, // PCI Device Address
517 | DWORD regAddress, // Configuration Address 0-whatever
518 | DWORD value // Write Value
519 | );
520 |
521 | //-----------------------------------------------------------------------------
522 | // FindPciDeviceById
523 | //-----------------------------------------------------------------------------
524 | DWORD // pciAddress, 0xFFFFFFFF: failure
525 | WINAPI FindPciDeviceById(
526 | WORD vendorId, // Vendor ID
527 | WORD deviceId, // Device ID
528 | BYTE index // Index
529 | );
530 |
531 | //-----------------------------------------------------------------------------
532 | // FindPciDeviceByClass
533 | //-----------------------------------------------------------------------------
534 | DWORD // pciAddress, 0xFFFFFFFF: failure
535 | WINAPI FindPciDeviceByClass(
536 | BYTE baseClass, // Base Class
537 | BYTE subClass, // Sub Class
538 | BYTE programIf, // Program Interface
539 | BYTE index // Index
540 | );
541 |
542 | /******************************************************************************
543 | **
544 | ** Memory (Special API)
545 | **
546 | ******************************************************************************/
547 |
548 | #ifdef _PHYSICAL_MEMORY_SUPPORT
549 | //-----------------------------------------------------------------------------
550 | // ReadDmiMemory
551 | //-----------------------------------------------------------------------------
552 | DWORD // Read size(byte), 0: failure
553 | WINAPI ReadDmiMemory(
554 | PBYTE buffer, // Buffer
555 | DWORD count, // Count
556 | DWORD unitSize // Unit Size (BYTE, WORD, DWORD)
557 | );
558 |
559 | //-----------------------------------------------------------------------------
560 | // ReadPhysicalMemory
561 | //-----------------------------------------------------------------------------
562 | DWORD // Read size(byte), 0: failure
563 | WINAPI ReadPhysicalMemory(
564 | DWORD_PTR address, // Physical Memory Address
565 | PBYTE buffer, // Buffer
566 | DWORD count, // Count
567 | DWORD unitSize // Unit Size (BYTE, WORD, DWORD)
568 | );
569 |
570 | //-----------------------------------------------------------------------------
571 | // WritePhysicalMemory
572 | //-----------------------------------------------------------------------------
573 | DWORD // Write size(byte), 0: failure
574 | WINAPI WritePhysicalMemory(
575 | DWORD_PTR address, // Physical Memory Address
576 | PBYTE buffer, // Buffer
577 | DWORD count, // Count
578 | DWORD unitSize // Unit Size (BYTE, WORD, DWORD)
579 | );
580 | #endif
--------------------------------------------------------------------------------
/dll/OlsApiInit.h:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------------
2 | // Author : hiyohiyo
3 | // Mail : hiyohiyo@crystalmark.info
4 | // Web : http://openlibsys.org/
5 | // License : The modified BSD license
6 | //
7 | // Copyright 2007-2009 OpenLibSys.org. All rights reserved.
8 | //-----------------------------------------------------------------------------
9 | // for WinRing0 1.3.x
10 |
11 | #pragma once
12 |
13 | #include "OlsDef.h"
14 | #include "OlsApiInitDef.h"
15 |
16 | //-----------------------------------------------------------------------------
17 | //
18 | // Prototypes
19 | //
20 | //-----------------------------------------------------------------------------
21 |
22 | BOOL InitOpenLibSys(HMODULE *hModule);
23 | BOOL DeinitOpenLibSys(HMODULE *hModule);
24 |
25 | //-----------------------------------------------------------------------------
26 | //
27 | // Funtions
28 | //
29 | //-----------------------------------------------------------------------------
30 |
31 | // DLL
32 | _GetDllStatus GetDllStatus = NULL;
33 | _GetDllVersion GetDllVersion = NULL;
34 | _GetDriverVersion GetDriverVersion = NULL;
35 | _GetDriverType GetDriverType = NULL;
36 |
37 | _InitializeOls InitializeOls = NULL;
38 | _DeinitializeOls DeinitializeOls = NULL;
39 |
40 | // CPU
41 | _IsCpuid IsCpuid = NULL;
42 | _IsMsr IsMsr = NULL;
43 | _IsTsc IsTsc = NULL;
44 |
45 | _Hlt Hlt = NULL;
46 | _Rdmsr Rdmsr = NULL;
47 | _Wrmsr Wrmsr = NULL;
48 | _Rdpmc Rdpmc = NULL;
49 | _Cpuid Cpuid = NULL;
50 | _Rdtsc Rdtsc = NULL;
51 |
52 | _HltTx HltTx = NULL;
53 | _RdmsrTx RdmsrTx = NULL;
54 | _WrmsrTx WrmsrTx = NULL;
55 | _RdpmcTx RdpmcTx = NULL;
56 | _CpuidTx CpuidTx = NULL;
57 | _RdtscTx RdtscTx = NULL;
58 |
59 | _HltPx HltPx = NULL;
60 | _RdmsrPx RdmsrPx = NULL;
61 | _WrmsrPx WrmsrPx = NULL;
62 | _RdpmcPx RdpmcPx = NULL;
63 | _CpuidPx CpuidPx = NULL;
64 | _RdtscPx RdtscPx = NULL;
65 |
66 | // I/O
67 | _ReadIoPortByte ReadIoPortByte = NULL;
68 | _ReadIoPortWord ReadIoPortWord = NULL;
69 | _ReadIoPortDword ReadIoPortDword = NULL;
70 |
71 | _ReadIoPortByteEx ReadIoPortByteEx = NULL;
72 | _ReadIoPortWordEx ReadIoPortWordEx = NULL;
73 | _ReadIoPortDwordEx ReadIoPortDwordEx = NULL;
74 |
75 | _WriteIoPortByte WriteIoPortByte = NULL;
76 | _WriteIoPortWord WriteIoPortWord = NULL;
77 | _WriteIoPortDword WriteIoPortDword = NULL;
78 |
79 | _WriteIoPortByteEx WriteIoPortByteEx = NULL;
80 | _WriteIoPortWordEx WriteIoPortWordEx = NULL;
81 | _WriteIoPortDwordEx WriteIoPortDwordEx = NULL;
82 |
83 | // PCI
84 | _SetPciMaxBusIndex SetPciMaxBusIndex = NULL;
85 |
86 | _ReadPciConfigByte ReadPciConfigByte = NULL;
87 | _ReadPciConfigWord ReadPciConfigWord = NULL;
88 | _ReadPciConfigDword ReadPciConfigDword = NULL;
89 |
90 | _ReadPciConfigByteEx ReadPciConfigByteEx = NULL;
91 | _ReadPciConfigWordEx ReadPciConfigWordEx = NULL;
92 | _ReadPciConfigDwordEx ReadPciConfigDwordEx = NULL;
93 |
94 | _WritePciConfigByte WritePciConfigByte = NULL;
95 | _WritePciConfigWord WritePciConfigWord = NULL;
96 | _WritePciConfigDword WritePciConfigDword = NULL;
97 |
98 | _WritePciConfigByteEx WritePciConfigByteEx = NULL;
99 | _WritePciConfigWordEx WritePciConfigWordEx = NULL;
100 | _WritePciConfigDwordEx WritePciConfigDwordEx = NULL;
101 |
102 | _FindPciDeviceById FindPciDeviceById = NULL;
103 | _FindPciDeviceByClass FindPciDeviceByClass = NULL;
104 |
105 | // Memory
106 | #ifdef _PHYSICAL_MEMORY_SUPPORT
107 | _ReadDmiMemory ReadDmiMemory = NULL;
108 | _ReadPhysicalMemory ReadPhysicalMemory = NULL;
109 | _WritePhysicalMemory WritePhysicalMemory = NULL;
110 | #endif
111 |
112 | #ifdef _OPEN_LIB_SYS
113 | #ifdef _UNICODE
114 | #define GetOlsString GetOlsStringW
115 | #else
116 | #define GetOlsString GetOlsStringA
117 | #endif
118 |
119 | _InstallOpenLibSys InstallOpenLibSys = NULL;
120 | _UninstallOpenLibSys UninstallOpenLibSys = NULL;
121 | _GetDriverStatus GetDriverStatus = NULL;
122 |
123 | _GetOlsStringA GetOlsStringA = NULL;
124 | _GetOlsStringW GetOlsStringW = NULL;
125 | _GetOlsValue GetOlsValue = NULL;
126 | _SetOlsValue SetOlsValue = NULL;
127 | #endif
128 |
129 | //-----------------------------------------------------------------------------
130 | //
131 | // Initialize
132 | //
133 | //-----------------------------------------------------------------------------
134 |
135 | BOOL InitOpenLibSys(HMODULE *hModule)
136 | {
137 | #ifdef _M_X64
138 | *hModule = LoadLibrary(_T("WinRing0x64.dll"));
139 | #else
140 | *hModule = LoadLibrary(_T("WinRing0.dll"));
141 | #endif
142 |
143 | if(*hModule == NULL)
144 | {
145 | return FALSE;
146 | }
147 |
148 | //-----------------------------------------------------------------------------
149 | // GetProcAddress
150 | //-----------------------------------------------------------------------------
151 | // DLL
152 | GetDllStatus = (_GetDllStatus) GetProcAddress (*hModule, "GetDllStatus");
153 | GetDllVersion = (_GetDllVersion) GetProcAddress (*hModule, "GetDllVersion");
154 | GetDriverVersion = (_GetDriverVersion) GetProcAddress (*hModule, "GetDriverVersion");
155 | GetDriverType = (_GetDriverType) GetProcAddress (*hModule, "GetDriverType");
156 |
157 | InitializeOls = (_InitializeOls) GetProcAddress (*hModule, "InitializeOls");
158 | DeinitializeOls = (_DeinitializeOls) GetProcAddress (*hModule, "DeinitializeOls");
159 |
160 | // CPU
161 | IsCpuid = (_IsCpuid) GetProcAddress (*hModule, "IsCpuid");
162 | IsMsr = (_IsMsr) GetProcAddress (*hModule, "IsMsr");
163 | IsTsc = (_IsTsc) GetProcAddress (*hModule, "IsTsc");
164 | Hlt = (_Hlt) GetProcAddress (*hModule, "Hlt");
165 | Rdmsr = (_Rdmsr) GetProcAddress (*hModule, "Rdmsr");
166 | Wrmsr = (_Wrmsr) GetProcAddress (*hModule, "Wrmsr");
167 | Rdpmc = (_Rdpmc) GetProcAddress (*hModule, "Rdpmc");
168 | Cpuid = (_Cpuid) GetProcAddress (*hModule, "Cpuid");
169 | Rdtsc = (_Rdtsc) GetProcAddress (*hModule, "Rdtsc");
170 | HltTx = (_HltTx) GetProcAddress (*hModule, "HltTx");
171 | RdmsrTx = (_RdmsrTx) GetProcAddress (*hModule, "RdmsrTx");
172 | WrmsrTx = (_WrmsrTx) GetProcAddress (*hModule, "WrmsrTx");
173 | RdpmcTx = (_RdpmcTx) GetProcAddress (*hModule, "RdpmcTx");
174 | CpuidTx = (_CpuidTx) GetProcAddress (*hModule, "CpuidTx");
175 | RdtscTx = (_RdtscTx) GetProcAddress (*hModule, "RdtscTx");
176 | HltPx = (_HltPx) GetProcAddress (*hModule, "HltPx");
177 | RdmsrPx = (_RdmsrPx) GetProcAddress (*hModule, "RdmsrPx");
178 | WrmsrPx = (_WrmsrPx) GetProcAddress (*hModule, "WrmsrPx");
179 | RdpmcPx = (_RdpmcPx) GetProcAddress (*hModule, "RdpmcPx");
180 | CpuidPx = (_CpuidPx) GetProcAddress (*hModule, "CpuidPx");
181 | RdtscPx = (_RdtscPx) GetProcAddress (*hModule, "RdtscPx");
182 |
183 | // I/O
184 | ReadIoPortByte = (_ReadIoPortByte) GetProcAddress (*hModule, "ReadIoPortByte");
185 | ReadIoPortWord = (_ReadIoPortWord) GetProcAddress (*hModule, "ReadIoPortWord");
186 | ReadIoPortDword = (_ReadIoPortDword) GetProcAddress (*hModule, "ReadIoPortDword");
187 |
188 | ReadIoPortByteEx = (_ReadIoPortByteEx) GetProcAddress (*hModule, "ReadIoPortByteEx");
189 | ReadIoPortWordEx = (_ReadIoPortWordEx) GetProcAddress (*hModule, "ReadIoPortWordEx");
190 | ReadIoPortDwordEx = (_ReadIoPortDwordEx) GetProcAddress (*hModule, "ReadIoPortDwordEx");
191 |
192 | WriteIoPortByte = (_WriteIoPortByte) GetProcAddress (*hModule, "WriteIoPortByte");
193 | WriteIoPortWord = (_WriteIoPortWord) GetProcAddress (*hModule, "WriteIoPortWord");
194 | WriteIoPortDword = (_WriteIoPortDword) GetProcAddress (*hModule, "WriteIoPortDword");
195 |
196 | WriteIoPortByteEx = (_WriteIoPortByteEx) GetProcAddress (*hModule, "WriteIoPortByteEx");
197 | WriteIoPortWordEx = (_WriteIoPortWordEx) GetProcAddress (*hModule, "WriteIoPortWordEx");
198 | WriteIoPortDwordEx = (_WriteIoPortDwordEx) GetProcAddress (*hModule, "WriteIoPortDwordEx");
199 |
200 | // PCI
201 | SetPciMaxBusIndex = (_SetPciMaxBusIndex) GetProcAddress (*hModule, "SetPciMaxBusIndex");
202 |
203 | ReadPciConfigByte = (_ReadPciConfigByte) GetProcAddress (*hModule, "ReadPciConfigByte");
204 | ReadPciConfigWord = (_ReadPciConfigWord) GetProcAddress (*hModule, "ReadPciConfigWord");
205 | ReadPciConfigDword = (_ReadPciConfigDword) GetProcAddress (*hModule, "ReadPciConfigDword");
206 |
207 | ReadPciConfigByteEx = (_ReadPciConfigByteEx) GetProcAddress (*hModule, "ReadPciConfigByteEx");
208 | ReadPciConfigWordEx = (_ReadPciConfigWordEx) GetProcAddress (*hModule, "ReadPciConfigWordEx");
209 | ReadPciConfigDwordEx = (_ReadPciConfigDwordEx) GetProcAddress (*hModule, "ReadPciConfigDwordEx");
210 |
211 | WritePciConfigByte = (_WritePciConfigByte) GetProcAddress (*hModule, "WritePciConfigByte");
212 | WritePciConfigWord = (_WritePciConfigWord) GetProcAddress (*hModule, "WritePciConfigWord");
213 | WritePciConfigDword = (_WritePciConfigDword) GetProcAddress (*hModule, "WritePciConfigDword");
214 |
215 | WritePciConfigByteEx = (_WritePciConfigByteEx) GetProcAddress (*hModule, "WritePciConfigByteEx");
216 | WritePciConfigWordEx = (_WritePciConfigWordEx) GetProcAddress (*hModule, "WritePciConfigWordEx");
217 | WritePciConfigDwordEx = (_WritePciConfigDwordEx)GetProcAddress (*hModule, "WritePciConfigDwordEx");
218 |
219 | FindPciDeviceById = (_FindPciDeviceById) GetProcAddress (*hModule, "FindPciDeviceById");
220 | FindPciDeviceByClass = (_FindPciDeviceByClass) GetProcAddress (*hModule, "FindPciDeviceByClass");
221 |
222 | // Memory
223 | #ifdef _PHYSICAL_MEMORY_SUPPORT
224 | ReadDmiMemory = (_ReadDmiMemory) GetProcAddress (*hModule, "ReadDmiMemory");
225 | ReadPhysicalMemory = (_ReadPhysicalMemory) GetProcAddress (*hModule, "ReadPhysicalMemory");
226 | WritePhysicalMemory = (_WritePhysicalMemory) GetProcAddress (*hModule, "WritePhysicalMemory");
227 | #endif
228 |
229 | //-----------------------------------------------------------------------------
230 | // Check Functions
231 | //-----------------------------------------------------------------------------
232 | if(!(
233 | GetDllStatus
234 | && GetDllVersion
235 | && GetDriverVersion
236 | && GetDriverType
237 | && InitializeOls
238 | && DeinitializeOls
239 | && IsCpuid
240 | && IsMsr
241 | && IsTsc
242 | && Hlt
243 | && HltTx
244 | && HltPx
245 | && Rdmsr
246 | && RdmsrTx
247 | && RdmsrPx
248 | && Wrmsr
249 | && WrmsrTx
250 | && WrmsrPx
251 | && Rdpmc
252 | && RdpmcTx
253 | && RdpmcPx
254 | && Cpuid
255 | && CpuidTx
256 | && CpuidPx
257 | && Rdtsc
258 | && RdtscTx
259 | && RdtscPx
260 | && ReadIoPortByte
261 | && ReadIoPortWord
262 | && ReadIoPortDword
263 | && ReadIoPortByteEx
264 | && ReadIoPortWordEx
265 | && ReadIoPortDwordEx
266 | && WriteIoPortByte
267 | && WriteIoPortWord
268 | && WriteIoPortDword
269 | && WriteIoPortByteEx
270 | && WriteIoPortWordEx
271 | && WriteIoPortDwordEx
272 | && SetPciMaxBusIndex
273 | && ReadPciConfigByte
274 | && ReadPciConfigWord
275 | && ReadPciConfigDword
276 | && ReadPciConfigByteEx
277 | && ReadPciConfigWordEx
278 | && ReadPciConfigDwordEx
279 | && WritePciConfigByte
280 | && WritePciConfigWord
281 | && WritePciConfigDword
282 | && WritePciConfigByteEx
283 | && WritePciConfigWordEx
284 | && WritePciConfigDwordEx
285 | && FindPciDeviceById
286 | && FindPciDeviceByClass
287 | #ifdef _PHYSICAL_MEMORY_SUPPORT
288 | && ReadDmiMemory
289 | && ReadPhysicalMemory
290 | && WritePhysicalMemory
291 | #endif
292 | ))
293 | {
294 | return FALSE;
295 | }
296 |
297 | return InitializeOls();
298 | }
299 |
300 | //-----------------------------------------------------------------------------
301 | //
302 | // Deinitialize
303 | //
304 | //-----------------------------------------------------------------------------
305 |
306 | BOOL DeinitOpenLibSys(HMODULE *hModule)
307 | {
308 | BOOL result = FALSE;
309 |
310 | if(*hModule == NULL)
311 | {
312 | return TRUE;
313 | }
314 | else
315 | {
316 | DeinitializeOls();
317 | result = FreeLibrary(*hModule);
318 | *hModule = NULL;
319 |
320 | return result;
321 | }
322 | }
323 |
--------------------------------------------------------------------------------
/dll/OlsApiInitDef.h:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------------
2 | // Author : hiyohiyo
3 | // Mail : hiyohiyo@crystalmark.info
4 | // Web : http://openlibsys.org/
5 | // License : The modified BSD license
6 | //
7 | // Copyright 2007-2009 OpenLibSys.org. All rights reserved.
8 | //-----------------------------------------------------------------------------
9 | // for WinRing0 1.3.x
10 |
11 | #pragma once
12 |
13 | //-----------------------------------------------------------------------------
14 | //
15 | // Type Defines
16 | //
17 | //-----------------------------------------------------------------------------
18 |
19 | // DLL
20 | typedef DWORD (WINAPI *_GetDllStatus) ();
21 | typedef DWORD (WINAPI *_GetDllVersion) (PBYTE major, PBYTE minor, PBYTE revision, PBYTE release);
22 | typedef DWORD (WINAPI *_GetDriverVersion) (PBYTE major, PBYTE minor, PBYTE revision, PBYTE release);
23 | typedef DWORD (WINAPI *_GetDriverType) ();
24 |
25 | typedef BOOL (WINAPI *_InitializeOls) ();
26 | typedef VOID (WINAPI *_DeinitializeOls) ();
27 |
28 | // CPU
29 | typedef BOOL (WINAPI *_IsCpuid) ();
30 | typedef BOOL (WINAPI *_IsMsr) ();
31 | typedef BOOL (WINAPI *_IsTsc) ();
32 |
33 | typedef BOOL (WINAPI *_Hlt) ();
34 | typedef DWORD (WINAPI *_Rdmsr) (DWORD index, PDWORD eax, PDWORD edx);
35 | typedef DWORD (WINAPI *_Wrmsr) (DWORD index, DWORD eax, DWORD edx);
36 | typedef DWORD (WINAPI *_Rdpmc) (DWORD index, PDWORD eax, PDWORD edx);
37 | typedef DWORD (WINAPI *_Cpuid) (DWORD index, PDWORD eax, PDWORD ebx, PDWORD ecx, PDWORD edx);
38 | typedef DWORD (WINAPI *_Rdtsc) (PDWORD eax, PDWORD edx);
39 |
40 | typedef BOOL (WINAPI *_HltTx) (DWORD_PTR threadAffinityMask);
41 | typedef DWORD (WINAPI *_RdmsrTx) (DWORD index, PDWORD eax, PDWORD edx, DWORD_PTR threadAffinityMask);
42 | typedef DWORD (WINAPI *_WrmsrTx) (DWORD index, DWORD eax, DWORD edx, DWORD_PTR threadAffinityMask);
43 | typedef DWORD (WINAPI *_RdpmcTx) (DWORD index, PDWORD eax, PDWORD edx, DWORD_PTR threadAffinityMask);
44 | typedef DWORD (WINAPI *_CpuidTx) (DWORD index, PDWORD eax, PDWORD ebx, PDWORD ecx, PDWORD edx, DWORD_PTR threadAffinityMask);
45 | typedef DWORD (WINAPI *_RdtscTx) (PDWORD eax, PDWORD edx, DWORD_PTR threadAffinityMask);
46 |
47 | typedef BOOL (WINAPI *_HltPx) (DWORD_PTR processAffinityMask);
48 | typedef DWORD (WINAPI *_RdmsrPx) (DWORD index, PDWORD eax, PDWORD edx, DWORD_PTR processAffinityMask);
49 | typedef DWORD (WINAPI *_WrmsrPx) (DWORD index, DWORD eax, DWORD edx, DWORD_PTR processAffinityMask);
50 | typedef DWORD (WINAPI *_RdpmcPx) (DWORD index, PDWORD eax, PDWORD edx, DWORD_PTR processAffinityMask);
51 | typedef DWORD (WINAPI *_CpuidPx) (DWORD index, PDWORD eax, PDWORD ebx, PDWORD ecx, PDWORD edx, DWORD_PTR processAffinityMask);
52 | typedef DWORD (WINAPI *_RdtscPx) (PDWORD eax, PDWORD edx, DWORD_PTR processAffinityMask);
53 |
54 | // I/O
55 | typedef BYTE (WINAPI *_ReadIoPortByte) (WORD address);
56 | typedef WORD (WINAPI *_ReadIoPortWord) (WORD address);
57 | typedef DWORD (WINAPI *_ReadIoPortDword) (WORD address);
58 |
59 | typedef BOOL (WINAPI *_ReadIoPortByteEx) (WORD address, PBYTE value);
60 | typedef BOOL (WINAPI *_ReadIoPortWordEx) (WORD address, PWORD value);
61 | typedef BOOL (WINAPI *_ReadIoPortDwordEx) (WORD address, PDWORD value);
62 |
63 | typedef VOID (WINAPI *_WriteIoPortByte) (WORD address, BYTE value);
64 | typedef VOID (WINAPI *_WriteIoPortWord) (WORD address, WORD value);
65 | typedef VOID (WINAPI *_WriteIoPortDword) (WORD address, DWORD value);
66 |
67 | typedef BOOL (WINAPI *_WriteIoPortByteEx) (WORD address, BYTE value);
68 | typedef BOOL (WINAPI *_WriteIoPortWordEx) (WORD address, WORD value);
69 | typedef BOOL (WINAPI *_WriteIoPortDwordEx) (WORD address, DWORD value);
70 |
71 | // PCI
72 | typedef VOID (WINAPI *_SetPciMaxBusIndex) (BYTE max);
73 |
74 | typedef BYTE (WINAPI *_ReadPciConfigByte) (DWORD pciAddress, BYTE regAddress);
75 | typedef WORD (WINAPI *_ReadPciConfigWord) (DWORD pciAddress, BYTE regAddress);
76 | typedef DWORD (WINAPI *_ReadPciConfigDword) (DWORD pciAddress, BYTE regAddress);
77 |
78 | typedef BOOL (WINAPI *_ReadPciConfigByteEx) (DWORD pciAddress, DWORD regAddress, PBYTE value);
79 | typedef BOOL (WINAPI *_ReadPciConfigWordEx) (DWORD pciAddress, DWORD regAddress, PWORD value);
80 | typedef BOOL (WINAPI *_ReadPciConfigDwordEx) (DWORD pciAddress, DWORD regAddress, PDWORD value);
81 |
82 | typedef VOID (WINAPI *_WritePciConfigByte) (DWORD pciAddress, BYTE regAddress, BYTE value);
83 | typedef VOID (WINAPI *_WritePciConfigWord) (DWORD pciAddress, BYTE regAddress, WORD value);
84 | typedef VOID (WINAPI *_WritePciConfigDword) (DWORD pciAddress, BYTE regAddress, DWORD value);
85 |
86 | typedef BOOL (WINAPI *_WritePciConfigByteEx) (DWORD pciAddress, DWORD regAddress, BYTE value);
87 | typedef BOOL (WINAPI *_WritePciConfigWordEx) (DWORD pciAddress, DWORD regAddress, WORD value);
88 | typedef BOOL (WINAPI *_WritePciConfigDwordEx) (DWORD pciAddress, DWORD regAddress, DWORD value);
89 |
90 | typedef DWORD (WINAPI *_FindPciDeviceById) (WORD vendorId, WORD deviceId, BYTE index);
91 | typedef DWORD (WINAPI *_FindPciDeviceByClass) (BYTE baseClass, BYTE subClass, BYTE programIf, BYTE index);
92 |
93 | // Memory
94 | #ifdef _PHYSICAL_MEMORY_SUPPORT
95 | typedef DWORD (WINAPI *_ReadDmiMemory) (PBYTE buffer, DWORD count, DWORD unitSize);
96 | typedef DWORD (WINAPI *_ReadPhysicalMemory) (DWORD_PTR address, PBYTE buffer, DWORD count, DWORD unitSize);
97 | typedef DWORD (WINAPI *_WritePhysicalMemory) (DWORD_PTR address, PBYTE buffer, DWORD count, DWORD unitSize);
98 | #endif
99 |
--------------------------------------------------------------------------------
/dll/OlsApiInitExt.h:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------------
2 | // Author : hiyohiyo
3 | // Mail : hiyohiyo@crystalmark.info
4 | // Web : http://openlibsys.org/
5 | // License : The modified BSD license
6 | //
7 | // Copyright 2007-2009 OpenLibSys.org. All rights reserved.
8 | //-----------------------------------------------------------------------------
9 | // for WinRing0 1.3.x
10 |
11 | #pragma once
12 |
13 | #include "OlsApiInitDef.h"
14 |
15 | //-----------------------------------------------------------------------------
16 | //
17 | // Externs
18 | //
19 | //-----------------------------------------------------------------------------
20 |
21 | // DLL
22 | extern _GetDllStatus GetDllStatus;
23 | extern _GetDllVersion GetDllVersion;
24 | extern _GetDriverVersion GetDriverVersion;
25 | extern _GetDriverType GetDriverType;
26 |
27 | extern _InitializeOls InitializeOls;
28 | extern _DeinitializeOls DeinitializeOls;
29 |
30 | // CPU
31 | extern _IsCpuid IsCpuid;
32 | extern _IsMsr IsMsr;
33 | extern _IsTsc IsTsc;
34 |
35 | extern _Hlt Hlt;
36 | extern _Rdmsr Rdmsr;
37 | extern _Wrmsr Wrmsr;
38 | extern _Rdpmc Rdpmc;
39 | extern _Cpuid Cpuid;
40 | extern _Rdtsc Rdtsc;
41 |
42 | extern _HltTx HltTx;
43 | extern _RdmsrTx RdmsrTx;
44 | extern _WrmsrTx WrmsrTx;
45 | extern _RdpmcTx RdpmcTx;
46 | extern _CpuidTx CpuidTx;
47 | extern _RdtscTx RdtscTx;
48 |
49 | extern _HltPx HltPx;
50 | extern _RdmsrPx RdmsrPx;
51 | extern _WrmsrPx WrmsrPx;
52 | extern _RdpmcPx RdpmcPx;
53 | extern _CpuidPx CpuidPx;
54 | extern _RdtscPx RdtscPx;
55 |
56 | // I/O
57 | extern _ReadIoPortByte ReadIoPortByte;
58 | extern _ReadIoPortWord ReadIoPortWord;
59 | extern _ReadIoPortDword ReadIoPortDword;
60 |
61 | extern _ReadIoPortByteEx ReadIoPortByteEx;
62 | extern _ReadIoPortWordEx ReadIoPortWordEx;
63 | extern _ReadIoPortDwordEx ReadIoPortDwordEx;
64 |
65 | extern _WriteIoPortByte WriteIoPortByte;
66 | extern _WriteIoPortWord WriteIoPortWord;
67 | extern _WriteIoPortDword WriteIoPortDword;
68 |
69 | extern _WriteIoPortByteEx WriteIoPortByteEx;
70 | extern _WriteIoPortWordEx WriteIoPortWordEx;
71 | extern _WriteIoPortDwordEx WriteIoPortDwordEx;
72 |
73 | // PCI
74 | extern _SetPciMaxBusIndex SetPciMaxBusIndex;
75 |
76 | extern _ReadPciConfigByte ReadPciConfigByte;
77 | extern _ReadPciConfigWord ReadPciConfigWord;
78 | extern _ReadPciConfigDword ReadPciConfigDword;
79 |
80 | extern _ReadPciConfigByteEx ReadPciConfigByteEx;
81 | extern _ReadPciConfigWordEx ReadPciConfigWordEx;
82 | extern _ReadPciConfigDwordEx ReadPciConfigDwordEx;
83 |
84 | extern _WritePciConfigByte WritePciConfigByte;
85 | extern _WritePciConfigWord WritePciConfigWord;
86 | extern _WritePciConfigDword WritePciConfigDword;
87 |
88 | extern _WritePciConfigByteEx WritePciConfigByteEx;
89 | extern _WritePciConfigWordEx WritePciConfigWordEx;
90 | extern _WritePciConfigDwordEx WritePciConfigDwordEx;
91 |
92 | extern _FindPciDeviceById FindPciDeviceById;
93 | extern _FindPciDeviceByClass FindPciDeviceByClass;
94 |
95 | // Memory
96 | #ifdef _PHYSICAL_MEMORY_SUPPORT
97 | extern _ReadDmiMemory ReadDmiMemory;
98 | extern _ReadPhysicalMemory ReadPhysicalMemory;
99 | extern _WritePhysicalMemory WritePhysicalMemory;
100 | #endif
101 |
--------------------------------------------------------------------------------
/dll/OlsDef.h:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------------
2 | // Author : hiyohiyo
3 | // Mail : hiyohiyo@crystalmark.info
4 | // Web : http://openlibsys.org/
5 | // License : The modified BSD license
6 | //
7 | // Copyright 2007 OpenLibSys.org. All rights reserved.
8 | //-----------------------------------------------------------------------------
9 |
10 | #pragma once
11 |
12 | //-----------------------------------------------------------------------------
13 | //
14 | // DLL Status Code
15 | //
16 | //-----------------------------------------------------------------------------
17 |
18 | #define OLS_DLL_NO_ERROR 0
19 | #define OLS_DLL_UNSUPPORTED_PLATFORM 1
20 | #define OLS_DLL_DRIVER_NOT_LOADED 2
21 | #define OLS_DLL_DRIVER_NOT_FOUND 3
22 | #define OLS_DLL_DRIVER_UNLOADED 4
23 | #define OLS_DLL_DRIVER_NOT_LOADED_ON_NETWORK 5
24 | #define OLS_DLL_UNKNOWN_ERROR 9
25 |
26 | //-----------------------------------------------------------------------------
27 | //
28 | // Driver Type
29 | //
30 | //-----------------------------------------------------------------------------
31 |
32 | #define OLS_DRIVER_TYPE_UNKNOWN 0
33 | #define OLS_DRIVER_TYPE_WIN_9X 1
34 | #define OLS_DRIVER_TYPE_WIN_NT 2
35 | #define OLS_DRIVER_TYPE_WIN_NT4 3 // Obsolete
36 | #define OLS_DRIVER_TYPE_WIN_NT_X64 4
37 | #define OLS_DRIVER_TYPE_WIN_NT_IA64 5 // Reseved
38 |
39 | //-----------------------------------------------------------------------------
40 | //
41 | // PCI Error Code
42 | //
43 | //-----------------------------------------------------------------------------
44 |
45 | #define OLS_ERROR_PCI_BUS_NOT_EXIST (0xE0000001L)
46 | #define OLS_ERROR_PCI_NO_DEVICE (0xE0000002L)
47 | #define OLS_ERROR_PCI_WRITE_CONFIG (0xE0000003L)
48 | #define OLS_ERROR_PCI_READ_CONFIG (0xE0000004L)
49 |
50 | //-----------------------------------------------------------------------------
51 | //
52 | // Support Macros
53 | //
54 | //-----------------------------------------------------------------------------
55 |
56 | // Bus Number, Device Number and Function Number to PCI Device Address
57 | #define PciBusDevFunc(Bus, Dev, Func) ((Bus&0xFF)<<8) | ((Dev&0x1F)<<3) | (Func&7)
58 | // PCI Device Address to Bus Number
59 | #define PciGetBus(address) ((address>>8) & 0xFF)
60 | // PCI Device Address to Device Number
61 | #define PciGetDev(address) ((address>>3) & 0x1F)
62 | // PCI Device Address to Function Number
63 | #define PciGetFunc(address) (address&7)
64 |
--------------------------------------------------------------------------------
/dll/OlsDll.cpp:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------------
2 | // Author : hiyohiyo
3 | // Mail : hiyohiyo@crystalmark.info
4 | // Web : http://openlibsys.org/
5 | // License : The modified BSD license
6 | //
7 | // Copyright 2007 OpenLibSys.org. All rights reserved.
8 | //-----------------------------------------------------------------------------
9 |
10 | #include "stdafx.h"
11 | #include
12 | #include
13 | #include
14 |
15 | #include "OlsIoctl.h"
16 | #include "OlsDll.h"
17 | #include "OlsDef.h"
18 | #include "Driver.h"
19 |
20 | //-----------------------------------------------------------------------------
21 | //
22 | // Global
23 | //
24 | //-----------------------------------------------------------------------------
25 |
26 | HANDLE gHandle = INVALID_HANDLE_VALUE;
27 |
28 | BOOL gIsNT = FALSE;
29 | BOOL gIsCpuid = FALSE;
30 | BOOL gIsMsr = FALSE;
31 | BOOL gIsTsc = FALSE;
32 | BOOL gInitDll = FALSE;
33 |
34 | TCHAR gDriverFileName[MAX_PATH];
35 | TCHAR gDriverPath[MAX_PATH];
36 | DWORD gDllStatus = OLS_DLL_UNKNOWN_ERROR;
37 | DWORD gDriverType = OLS_DRIVER_TYPE_UNKNOWN;
38 |
39 | //-----------------------------------------------------------------------------
40 | //
41 | // Prototypes for Support Functions
42 | //
43 | //-----------------------------------------------------------------------------
44 |
45 | static BOOL IsNT();
46 | static BOOL IsCpuid();
47 | static BOOL IsMsr();
48 | static BOOL IsTsc();
49 | static BOOL IsWow64();
50 | static BOOL IsX64();
51 | static BOOL IsFileExist(LPCTSTR fileName);
52 | static BOOL IsOnNetworkDrive(LPCTSTR fileName);
53 |
54 | //-----------------------------------------------------------------------------
55 | //
56 | // Initialize/Deinitialize API
57 | //
58 | //-----------------------------------------------------------------------------
59 |
60 | BOOL WINAPI InitializeOls()
61 | {
62 | if(gInitDll == FALSE)
63 | {
64 | gIsNT = IsNT();
65 | gIsCpuid = IsCpuid();
66 | if(gIsCpuid)
67 | {
68 | gIsMsr = IsMsr();
69 | gIsTsc = IsTsc();
70 | }
71 | gDllStatus = InitDriverInfo();
72 |
73 | if(gDllStatus == OLS_DLL_NO_ERROR)
74 | {
75 | // Retry, Max 1000ms
76 | for(int i = 0; i < 4; i++)
77 | {
78 | gDllStatus = Initialize();
79 | if(gDllStatus == OLS_DLL_NO_ERROR)
80 | {
81 | break;
82 | }
83 | Sleep(100 * i);
84 | }
85 | }
86 | gInitDll = TRUE;
87 | }
88 | return (BOOL)(gDllStatus == OLS_DLL_NO_ERROR);
89 | }
90 |
91 | VOID WINAPI DeinitializeOls()
92 | {
93 | if(gInitDll == TRUE)
94 | {
95 | if(gIsNT && GetRefCount() == 1)
96 | {
97 | CloseHandle(gHandle);
98 | gHandle = INVALID_HANDLE_VALUE;
99 | ManageDriver(OLS_DRIVER_ID, gDriverPath, OLS_DRIVER_REMOVE);
100 | }
101 |
102 | if(gHandle != INVALID_HANDLE_VALUE)
103 | {
104 | CloseHandle(gHandle);
105 | gHandle = INVALID_HANDLE_VALUE;
106 | }
107 | gInitDll = FALSE;
108 | }
109 | }
110 |
111 | //-----------------------------------------------------------------------------
112 | //
113 | // DllMain
114 | //
115 | //-----------------------------------------------------------------------------
116 |
117 | BOOL APIENTRY DllMain( HMODULE hModule,
118 | DWORD ul_reason_for_call,
119 | LPVOID lpReserved
120 | )
121 | {
122 | switch (ul_reason_for_call)
123 | {
124 | case DLL_PROCESS_ATTACH:
125 | break;
126 | case DLL_THREAD_ATTACH:
127 | break;
128 | case DLL_THREAD_DETACH:
129 | break;
130 | case DLL_PROCESS_DETACH:
131 | DeinitializeOls();
132 | break;
133 | }
134 | return TRUE;
135 | }
136 |
137 | //-----------------------------------------------------------------------------
138 | //
139 | // Initialize/Deinitialize Functions
140 | //
141 | //-----------------------------------------------------------------------------
142 | DWORD Initialize()
143 | {
144 | TCHAR dir[MAX_PATH];
145 | TCHAR *ptr;
146 |
147 | GetModuleFileName(NULL, dir, MAX_PATH);
148 | if((ptr = _tcsrchr(dir, '\\')) != NULL)
149 | {
150 | *ptr = '\0';
151 | }
152 | wsprintf(gDriverPath, _T("%s\\%s"), dir, gDriverFileName);
153 |
154 | if(IsFileExist(gDriverPath) == FALSE)
155 | {
156 | return OLS_DLL_DRIVER_NOT_FOUND;
157 | }
158 |
159 | if(IsOnNetworkDrive(gDriverPath) == TRUE)
160 | {
161 | return OLS_DLL_DRIVER_NOT_LOADED_ON_NETWORK;
162 | }
163 |
164 | if(gIsNT)
165 | {
166 | if(OpenDriver())
167 | {
168 | return OLS_DLL_NO_ERROR;
169 | }
170 |
171 | ManageDriver(OLS_DRIVER_ID, gDriverPath, OLS_DRIVER_REMOVE);
172 | if(!ManageDriver(OLS_DRIVER_ID, gDriverPath, OLS_DRIVER_INSTALL))
173 | {
174 | ManageDriver(OLS_DRIVER_ID, gDriverPath, OLS_DRIVER_REMOVE);
175 | return OLS_DLL_DRIVER_NOT_LOADED;
176 | }
177 |
178 | if(OpenDriver())
179 | {
180 | return OLS_DLL_NO_ERROR;
181 | }
182 | return OLS_DLL_DRIVER_NOT_LOADED;
183 | }
184 | else
185 | {
186 | gHandle = CreateFile(
187 | _T("\\\\.\\") OLS_DRIVER_FILE_NAME_WIN_9X,
188 | 0, 0, NULL, 0,
189 | FILE_FLAG_DELETE_ON_CLOSE,
190 | NULL);
191 |
192 | if(gHandle == INVALID_HANDLE_VALUE)
193 | {
194 | return OLS_DLL_DRIVER_NOT_LOADED;
195 | }
196 | return OLS_DLL_NO_ERROR;
197 | }
198 | }
199 |
200 | BOOL OpenDriver()
201 | {
202 | gHandle = CreateFile(
203 | _T("\\\\.\\") OLS_DRIVER_ID,
204 | GENERIC_READ | GENERIC_WRITE,
205 | 0,
206 | NULL,
207 | OPEN_EXISTING,
208 | FILE_ATTRIBUTE_NORMAL,
209 | NULL
210 | );
211 |
212 | if(gHandle == INVALID_HANDLE_VALUE)
213 | {
214 | return FALSE;
215 | }
216 | return TRUE;
217 | }
218 |
219 | DWORD GetRefCount()
220 | {
221 | if(gHandle == INVALID_HANDLE_VALUE)
222 | {
223 | return 0;
224 | }
225 |
226 | DWORD refCount;
227 | DWORD length, result;
228 |
229 | refCount = 0;
230 |
231 | result = DeviceIoControl(
232 | gHandle,
233 | IOCTL_OLS_GET_REFCOUNT,
234 | NULL,
235 | 0,
236 | &refCount,
237 | sizeof(refCount),
238 | &length,
239 | NULL
240 | );
241 | if(! result)
242 | {
243 | refCount = 0;
244 | }
245 |
246 | return refCount;
247 | }
248 |
249 | DWORD InitDriverInfo()
250 | {
251 | OSVERSIONINFO osvi;
252 | osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
253 | GetVersionEx(&osvi);
254 |
255 | switch(osvi.dwPlatformId)
256 | {
257 | case VER_PLATFORM_WIN32s:
258 | gDriverType = OLS_DRIVER_TYPE_UNKNOWN;
259 | return OLS_DLL_UNSUPPORTED_PLATFORM;
260 | break;
261 | case VER_PLATFORM_WIN32_WINDOWS:
262 | _tcscpy_s(gDriverFileName, MAX_PATH, OLS_DRIVER_FILE_NAME_WIN_9X);
263 | gDriverType = OLS_DRIVER_TYPE_WIN_9X;
264 | return OLS_DLL_NO_ERROR;
265 | break;
266 | case VER_PLATFORM_WIN32_NT:
267 | #ifdef _WIN64
268 | #ifdef _M_X64
269 | _tcscpy_s(gDriverFileName, MAX_PATH, OLS_DRIVER_FILE_NAME_WIN_NT_X64);
270 | gDriverType = OLS_DRIVER_TYPE_WIN_NT_X64;
271 | #else // IA64
272 | _tcscpy_s(gDriverFileName, MAX_PATH, OLS_DRIVER_FILE_NAME_WIN_NT_IA64);
273 | gDriverType = OLS_DRIVER_TYPE_WIN_NT_IA64;
274 | return OLS_DLL_UNSUPPORTED_PLATFORM;
275 | #endif
276 | #else
277 | if(IsWow64())
278 | {
279 | if(IsX64())
280 | {
281 | _tcscpy_s(gDriverFileName, MAX_PATH, OLS_DRIVER_FILE_NAME_WIN_NT_X64);
282 | gDriverType = OLS_DRIVER_TYPE_WIN_NT_X64;
283 | }
284 | else
285 | {
286 | _tcscpy_s(gDriverFileName, MAX_PATH, OLS_DRIVER_FILE_NAME_WIN_NT_IA64);
287 | gDriverType = OLS_DRIVER_TYPE_WIN_NT_IA64;
288 | return OLS_DLL_UNSUPPORTED_PLATFORM;
289 | }
290 | }
291 | else
292 | {
293 | _tcscpy_s(gDriverFileName, MAX_PATH, OLS_DRIVER_FILE_NAME_WIN_NT);
294 | gDriverType = OLS_DRIVER_TYPE_WIN_NT;
295 | }
296 | #endif
297 | return OLS_DLL_NO_ERROR;
298 | break;
299 | default:
300 | gDriverType = OLS_DRIVER_TYPE_UNKNOWN;
301 | return OLS_DLL_UNKNOWN_ERROR;
302 | break;
303 | }
304 | }
305 |
306 | //-----------------------------------------------------------------------------
307 | //
308 | // Support Functions
309 | //
310 | //-----------------------------------------------------------------------------
311 |
312 | BOOL IsCpuid()
313 | {
314 | __try
315 | {
316 | int info[4];
317 | __cpuid(info, 0x0);
318 | }
319 | __except(EXCEPTION_EXECUTE_HANDLER)
320 | {
321 | return FALSE;
322 | }
323 |
324 | return TRUE;
325 | }
326 |
327 | BOOL IsMsr()
328 | {
329 | // MSR : Standard Feature Flag EDX, Bit 5
330 | int info[4];
331 | __cpuid(info, 0x1);
332 |
333 | return ((info[3] >> 5) & 1);
334 | }
335 |
336 | BOOL IsTsc()
337 | {
338 | // TSC : Standard Feature Flag EDX, Bit 4
339 | int info[4];
340 | __cpuid(info, 0x1);
341 |
342 | return ((info[3] >> 4) & 1);
343 | }
344 |
345 | BOOL IsNT()
346 | {
347 | OSVERSIONINFO osvi;
348 | osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
349 | GetVersionEx(&osvi);
350 |
351 | return (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT);
352 | }
353 |
354 | typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE hProcess, PBOOL Wow64Process);
355 |
356 | BOOL IsWow64()
357 | {
358 | BOOL isWow64 = FALSE;
359 | LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(
360 | GetModuleHandle(_T("kernel32")), "IsWow64Process");
361 |
362 | if(fnIsWow64Process != NULL)
363 | {
364 | if(! fnIsWow64Process(GetCurrentProcess(), &isWow64))
365 | {
366 | // handle error
367 | isWow64 = FALSE;
368 | }
369 | }
370 | return isWow64;
371 | }
372 |
373 | typedef void (WINAPI *LPFN_GETNATIVESYSTEMINFO) (LPSYSTEM_INFO lpSystemInfo);
374 |
375 | BOOL IsX64()
376 | {
377 | SYSTEM_INFO systemInfo;
378 | BOOL isX64 = FALSE;
379 | LPFN_GETNATIVESYSTEMINFO fnGetNativeSystemInfo = (LPFN_GETNATIVESYSTEMINFO)GetProcAddress(
380 | GetModuleHandle(_T("kernel32")), "GetNativeSystemInfo");
381 |
382 | if(fnGetNativeSystemInfo != NULL)
383 | {
384 | fnGetNativeSystemInfo(&systemInfo);
385 | isX64 = (systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64);
386 | }
387 | return isX64;
388 | }
389 |
390 | BOOL IsFileExist(LPCTSTR fileName)
391 | {
392 | WIN32_FIND_DATA findData;
393 |
394 | HANDLE hFile = FindFirstFile(fileName, &findData);
395 | if(hFile != INVALID_HANDLE_VALUE)
396 | {
397 | FindClose( hFile );
398 | return TRUE;
399 | }
400 | else
401 | {
402 | return FALSE;
403 | }
404 | }
405 |
406 | BOOL IsOnNetworkDrive(LPCTSTR fileName)
407 | {
408 | TCHAR root[4];
409 | root[0] = fileName[0];
410 | root[1] = ':';
411 | root[2] = '\\';
412 | root[3] = '\0';
413 |
414 | if(root[0] == '\\' || GetDriveType((LPCTSTR)root) == DRIVE_REMOTE)
415 | {
416 | return TRUE;
417 | }
418 |
419 | return FALSE;
420 | }
421 |
--------------------------------------------------------------------------------
/dll/OlsDll.h:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------------
2 | // Author : hiyohiyo
3 | // Mail : hiyohiyo@crystalmark.info
4 | // Web : http://openlibsys.org/
5 | // License : The modified BSD license
6 | //
7 | // Copyright 2007-2009 OpenLibSys.org. All rights reserved.
8 | //-----------------------------------------------------------------------------
9 |
10 | #pragma once
11 |
12 | //-----------------------------------------------------------------------------
13 | //
14 | // Version Information
15 | //
16 | //-----------------------------------------------------------------------------
17 |
18 | #define OLS_MAJOR_VERSION 1
19 | #define OLS_MINOR_VERSION 3
20 | #define OLS_REVISION 0
21 | #define OLS_RELESE 18
22 |
23 | #define OLS_VERSION ((OLS_MAJOR_VERSION << 24) | (OLS_MINOR_VERSION << 16) |\
24 | (OLS_REVISION << 8) | OLS_RELESE)
25 |
26 | //-----------------------------------------------------------------------------
27 | //
28 | // Defines
29 | //
30 | //-----------------------------------------------------------------------------
31 |
32 | #define OLS_DRIVER_FILE_NAME_WIN_9X _T("WinRing0.vxd")
33 | #define OLS_DRIVER_FILE_NAME_WIN_NT _T("WinRing0.sys")
34 | #define OLS_DRIVER_FILE_NAME_WIN_NT_X64 _T("WinRing0x64.sys")
35 | #define OLS_DRIVER_FILE_NAME_WIN_NT_IA64 _T("WinRing0ia64.sys") // Reserved
36 |
37 | //-----------------------------------------------------------------------------
38 | //
39 | // Prototypes
40 | //
41 | //-----------------------------------------------------------------------------
42 |
43 | DWORD Initialize();
44 | void Deinitialize();
45 | DWORD InitDriverInfo();
46 |
47 | BOOL OpenDriver();
48 | BOOL LoadDriver(TCHAR *DriverFileName, TCHAR *DriverId);
49 | BOOL UnloadDriver(TCHAR *DriverId);
50 | DWORD GetRefCount();
51 |
52 | BOOL IsNT();
53 | BOOL IsWow64();
--------------------------------------------------------------------------------
/dll/OlsDll.rc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QCute/WinRing0/53f73182f942c4f28b508d801db8934abc9663b5/dll/OlsDll.rc
--------------------------------------------------------------------------------
/dll/OlsIoctl.h:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------------
2 | // Author : hiyohiyo
3 | // Mail : hiyohiyo@crystalmark.info
4 | // Web : http://openlibsys.org/
5 | // License : The modified BSD license
6 | //
7 | // Copyright 2007-2008 OpenLibSys.org. All rights reserved.
8 | //-----------------------------------------------------------------------------
9 |
10 | #pragma once
11 |
12 | //-----------------------------------------------------------------------------
13 | //
14 | // The Device type codes form 32768 to 65535 are for customer use.
15 | //
16 | //-----------------------------------------------------------------------------
17 |
18 | #define OLS_TYPE 40000
19 |
20 | //-----------------------------------------------------------------------------
21 | //
22 | // Version Information
23 | //
24 | //-----------------------------------------------------------------------------
25 |
26 | #define OLS_DRIVER_ID _T("WinRing0_1_2_0")
27 |
28 | #define OLS_DRIVER_MAJOR_VERSION 1
29 | #define OLS_DRIVER_MINOR_VERSION 2
30 | #define OLS_DRIVER_REVISION 0
31 | #define OLS_DRIVER_RELESE 5
32 |
33 | #define OLS_DRIVER_VERSION \
34 | ((OLS_DRIVER_MAJOR_VERSION << 24) | (OLS_DRIVER_MINOR_VERSION << 16) \
35 | | (OLS_DRIVER_REVISION << 8) | OLS_DRIVER_RELESE)
36 |
37 | //-----------------------------------------------------------------------------
38 | //
39 | // The IOCTL function codes from 0x800 to 0xFFF are for customer use.
40 | //
41 | //-----------------------------------------------------------------------------
42 | #define IOCTL_OLS_GET_DRIVER_VERSION \
43 | CTL_CODE(OLS_TYPE, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS)
44 |
45 | #define IOCTL_OLS_GET_REFCOUNT \
46 | CTL_CODE(OLS_TYPE, 0x801, METHOD_BUFFERED, FILE_ANY_ACCESS)
47 |
48 | #define IOCTL_OLS_READ_MSR \
49 | CTL_CODE(OLS_TYPE, 0x821, METHOD_BUFFERED, FILE_ANY_ACCESS)
50 |
51 | #define IOCTL_OLS_WRITE_MSR \
52 | CTL_CODE(OLS_TYPE, 0x822, METHOD_BUFFERED, FILE_ANY_ACCESS)
53 |
54 | #define IOCTL_OLS_READ_PMC \
55 | CTL_CODE(OLS_TYPE, 0x823, METHOD_BUFFERED, FILE_ANY_ACCESS)
56 |
57 | #define IOCTL_OLS_HALT \
58 | CTL_CODE(OLS_TYPE, 0x824, METHOD_BUFFERED, FILE_ANY_ACCESS)
59 |
60 | #define IOCTL_OLS_READ_IO_PORT \
61 | CTL_CODE(OLS_TYPE, 0x831, METHOD_BUFFERED, FILE_READ_ACCESS)
62 |
63 | #define IOCTL_OLS_WRITE_IO_PORT \
64 | CTL_CODE(OLS_TYPE, 0x832, METHOD_BUFFERED, FILE_WRITE_ACCESS)
65 |
66 | #define IOCTL_OLS_READ_IO_PORT_BYTE \
67 | CTL_CODE(OLS_TYPE, 0x833, METHOD_BUFFERED, FILE_READ_ACCESS)
68 |
69 | #define IOCTL_OLS_READ_IO_PORT_WORD \
70 | CTL_CODE(OLS_TYPE, 0x834, METHOD_BUFFERED, FILE_READ_ACCESS)
71 |
72 | #define IOCTL_OLS_READ_IO_PORT_DWORD \
73 | CTL_CODE(OLS_TYPE, 0x835, METHOD_BUFFERED, FILE_READ_ACCESS)
74 |
75 | #define IOCTL_OLS_WRITE_IO_PORT_BYTE \
76 | CTL_CODE(OLS_TYPE, 0x836, METHOD_BUFFERED, FILE_WRITE_ACCESS)
77 |
78 | #define IOCTL_OLS_WRITE_IO_PORT_WORD \
79 | CTL_CODE(OLS_TYPE, 0x837, METHOD_BUFFERED, FILE_WRITE_ACCESS)
80 |
81 | #define IOCTL_OLS_WRITE_IO_PORT_DWORD \
82 | CTL_CODE(OLS_TYPE, 0x838, METHOD_BUFFERED, FILE_WRITE_ACCESS)
83 |
84 | #define IOCTL_OLS_READ_MEMORY \
85 | CTL_CODE(OLS_TYPE, 0x841, METHOD_BUFFERED, FILE_READ_ACCESS)
86 |
87 | #define IOCTL_OLS_WRITE_MEMORY \
88 | CTL_CODE(OLS_TYPE, 0x842, METHOD_BUFFERED, FILE_WRITE_ACCESS)
89 |
90 | #define IOCTL_OLS_READ_PCI_CONFIG \
91 | CTL_CODE(OLS_TYPE, 0x851, METHOD_BUFFERED, FILE_READ_ACCESS)
92 |
93 | #define IOCTL_OLS_WRITE_PCI_CONFIG \
94 | CTL_CODE(OLS_TYPE, 0x852, METHOD_BUFFERED, FILE_WRITE_ACCESS)
95 |
96 | //-----------------------------------------------------------------------------
97 | //
98 | // PCI Error Code
99 | //
100 | //-----------------------------------------------------------------------------
101 |
102 | #define OLS_ERROR_PCI_BUS_NOT_EXIST (0xE0000001L)
103 | #define OLS_ERROR_PCI_NO_DEVICE (0xE0000002L)
104 | #define OLS_ERROR_PCI_WRITE_CONFIG (0xE0000003L)
105 | #define OLS_ERROR_PCI_READ_CONFIG (0xE0000004L)
106 |
107 | //-----------------------------------------------------------------------------
108 | //
109 | // Support Macros
110 | //
111 | //-----------------------------------------------------------------------------
112 |
113 | // Bus Number, Device Number and Function Number to PCI Device Address
114 | #define PciBusDevFunc(Bus, Dev, Func) ((Bus&0xFF)<<8) | ((Dev&0x1F)<<3) | (Func&7)
115 | // PCI Device Address to Bus Number
116 | #define PciGetBus(address) ((address>>8) & 0xFF)
117 | // PCI Device Address to Device Number
118 | #define PciGetDev(address) ((address>>3) & 0x1F)
119 | // PCI Device Address to Function Number
120 | #define PciGetFunc(address) (address&7)
121 |
122 | //-----------------------------------------------------------------------------
123 | //
124 | // Typedef Struct
125 | //
126 | //-----------------------------------------------------------------------------
127 |
128 | #pragma pack(push,4)
129 |
130 | typedef struct _OLS_WRITE_MSR_INPUT {
131 | ULONG Register;
132 | ULARGE_INTEGER Value;
133 | } OLS_WRITE_MSR_INPUT;
134 |
135 | typedef struct _OLS_WRITE_IO_PORT_INPUT {
136 | ULONG PortNumber;
137 | union {
138 | ULONG LongData;
139 | USHORT ShortData;
140 | UCHAR CharData;
141 | };
142 | } OLS_WRITE_IO_PORT_INPUT;
143 |
144 | typedef struct _OLS_READ_PCI_CONFIG_INPUT {
145 | ULONG PciAddress;
146 | ULONG PciOffset;
147 | } OLS_READ_PCI_CONFIG_INPUT;
148 |
149 | typedef struct _OLS_WRITE_PCI_CONFIG_INPUT {
150 | ULONG PciAddress;
151 | ULONG PciOffset;
152 | UCHAR Data[1];
153 | } OLS_WRITE_PCI_CONFIG_INPUT;
154 |
155 | typedef LARGE_INTEGER PHYSICAL_ADDRESS;
156 |
157 | typedef struct _OLS_READ_MEMORY_INPUT {
158 | PHYSICAL_ADDRESS Address;
159 | ULONG UnitSize;
160 | ULONG Count;
161 | } OLS_READ_MEMORY_INPUT;
162 |
163 | typedef struct _OLS_WRITE_MEMORY_INPUT {
164 | PHYSICAL_ADDRESS Address;
165 | ULONG UnitSize;
166 | ULONG Count;
167 | UCHAR Data[1];
168 | } OLS_WRITE_MEMORY_INPUT;
169 |
170 | #pragma pack(pop)
171 |
--------------------------------------------------------------------------------
/dll/resource.h:
--------------------------------------------------------------------------------
1 | //{{NO_DEPENDENCIES}}
2 | // Microsoft Visual C++ generated include file.
3 | // Used by OlsDll.rc
4 | //
5 |
6 | // Next default values for new objects
7 | //
8 | #ifdef APSTUDIO_INVOKED
9 | #ifndef APSTUDIO_READONLY_SYMBOLS
10 | #define _APS_NEXT_RESOURCE_VALUE 101
11 | #define _APS_NEXT_COMMAND_VALUE 40001
12 | #define _APS_NEXT_CONTROL_VALUE 1001
13 | #define _APS_NEXT_SYMED_VALUE 101
14 | #endif
15 | #endif
16 |
--------------------------------------------------------------------------------
/dll/stdafx.cpp:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------------
2 | // Author : hiyohiyo
3 | // Mail : hiyohiyo@crystalmark.info
4 | // Web : http://openlibsys.org/
5 | // License : The modified BSD license
6 | //
7 | // Copyright 2007 OpenLibSys.org. All rights reserved.
8 | //-----------------------------------------------------------------------------
9 |
10 | #include "stdafx.h"
11 |
--------------------------------------------------------------------------------
/dll/stdafx.h:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------------
2 | // Author : hiyohiyo
3 | // Mail : hiyohiyo@crystalmark.info
4 | // Web : http://openlibsys.org/
5 | // License : The modified BSD license
6 | //
7 | // Copyright 2007-2008 OpenLibSys.org. All rights reserved.
8 | //-----------------------------------------------------------------------------
9 |
10 | #pragma once
11 |
12 | #ifndef WINVER
13 | #define WINVER 0x0400
14 | #endif
15 |
16 | #ifndef _WIN32_WINNT
17 | #define _WIN32_WINNT 0x0400
18 | #endif
19 |
20 | #ifndef _WIN32_WINDOWS
21 | #define _WIN32_WINDOWS 0x0410
22 | #endif
23 |
24 | #ifndef _WIN32_IE
25 | #define _WIN32_IE 0x0600
26 | #endif
27 |
28 | #define WIN32_LEAN_AND_MEAN
29 | #include
30 |
--------------------------------------------------------------------------------
/dll/sys/MAKEFILE:
--------------------------------------------------------------------------------
1 | #
2 | # DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source
3 | # file to this component. This file merely indirects to the real make file
4 | # that is shared by all the driver components of the Windows NT DDK
5 | #
6 |
7 | !INCLUDE $(NTMAKEENV)\makefile.def
8 |
--------------------------------------------------------------------------------
/dll/sys/OpenLibSys.c:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------------
2 | // Author : hiyohiyo
3 | // Mail : hiyohiyo@crystalmark.info
4 | // Web : http://openlibsys.org/
5 | // License : The modified BSD license
6 | //
7 | // Copyright 2007-2008 OpenLibSys.org. All rights reserved.
8 | //-----------------------------------------------------------------------------
9 |
10 | #include
11 | #include
12 | #include "OpenLibSys.h"
13 |
14 | //-----------------------------------------------------------------------------
15 | //
16 | // Global
17 | //
18 | //-----------------------------------------------------------------------------
19 |
20 | static ULONG refCount;
21 |
22 | //-----------------------------------------------------------------------------
23 | //
24 | // Classic NT driver
25 | // DriverEntry / OlsDispatch / Unload
26 | //
27 | //-----------------------------------------------------------------------------
28 |
29 | NTSTATUS
30 | DriverEntry(
31 | IN PDRIVER_OBJECT DriverObject,
32 | IN PUNICODE_STRING RegistryPath
33 | )
34 |
35 | /*
36 |
37 | Return Value:
38 |
39 | STATUS_SUCCESS if the driver initialized correctly, otherwise an erroror
40 | indicating the reason for failure.
41 | */
42 |
43 | {
44 | NTSTATUS status;
45 | UNICODE_STRING ntDeviceName;
46 | UNICODE_STRING win32DeviceName;
47 | PDEVICE_OBJECT deviceObject = NULL;
48 |
49 | RtlInitUnicodeString(&ntDeviceName, NT_DEVICE_NAME);
50 |
51 | status = IoCreateDevice(
52 | DriverObject, // Our Driver Object
53 | 0, // We don't use a device extension
54 | &ntDeviceName, // Device name
55 | OLS_TYPE, // Device type
56 | FILE_DEVICE_SECURE_OPEN, // Device characteristics
57 | FALSE, // Not an exclusive device
58 | &deviceObject ); // Returned ptr to Device Object
59 |
60 | if(!NT_SUCCESS(status))
61 | {
62 | refCount = (ULONG)-1;
63 | return status;
64 | }
65 | else
66 | {
67 | refCount = 0;
68 | }
69 |
70 | // Initialize the driver object with this driver's entry points.
71 | DriverObject->MajorFunction[IRP_MJ_CREATE] = OlsDispatch;
72 | DriverObject->MajorFunction[IRP_MJ_CLOSE] = OlsDispatch;
73 | DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = OlsDispatch;
74 | DriverObject->DriverUnload = Unload;
75 |
76 | // Initialize a Unicode String containing the Win32 name for our device.
77 | RtlInitUnicodeString(&win32DeviceName, DOS_DEVICE_NAME);
78 |
79 | // Create a symbolic link between our device name and the Win32 name
80 | status = IoCreateSymbolicLink(&win32DeviceName, &ntDeviceName);
81 |
82 | if (!NT_SUCCESS(status))
83 | {
84 | // Delete everything that this routine has allocated.
85 | IoDeleteDevice( deviceObject );
86 | }
87 |
88 | return status;
89 | }
90 |
91 | NTSTATUS
92 | OlsDispatch(
93 | IN PDEVICE_OBJECT pDO,
94 | IN PIRP pIrp
95 | )
96 |
97 | /*++
98 |
99 | Routine Description:
100 | This routine is the dispatch handler for the driver. It is responsible
101 | for processing the IRPs.
102 |
103 | Arguments:
104 |
105 | pDO - Pointer to device object.
106 |
107 | pIrp - Pointer to the current IRP.
108 |
109 | Return Value:
110 |
111 | STATUS_SUCCESS if the IRP was processed successfully, otherwise an erroror
112 | indicating the reason for failure.
113 |
114 | --*/
115 |
116 | {
117 | PIO_STACK_LOCATION pIrpStack;
118 | NTSTATUS status;
119 | int index;
120 |
121 | // Initialize the irp info field.
122 | // This is used to return the number of bytes transfered.
123 | pIrp->IoStatus.Information = 0;
124 | pIrpStack = IoGetCurrentIrpStackLocation(pIrp);
125 |
126 | // Set default return status
127 | status = STATUS_NOT_IMPLEMENTED;
128 |
129 | // Dispatch based on major fcn code.
130 | switch(pIrpStack->MajorFunction)
131 | {
132 | case IRP_MJ_CREATE:
133 | if(refCount != (ULONG)-1){refCount++;}
134 | status = STATUS_SUCCESS;
135 | break;
136 | case IRP_MJ_CLOSE:
137 | if(refCount != (ULONG)-1){refCount--;}
138 | status = STATUS_SUCCESS;
139 | break;
140 |
141 | case IRP_MJ_DEVICE_CONTROL:
142 | // Dispatch on IOCTL
143 | switch(pIrpStack->Parameters.DeviceIoControl.IoControlCode)
144 | {
145 | case IOCTL_OLS_GET_DRIVER_VERSION:
146 | *(PULONG)pIrp->AssociatedIrp.SystemBuffer = OLS_DRIVER_VERSION;
147 | pIrp->IoStatus.Information = 4;
148 | status = STATUS_SUCCESS;
149 | break;
150 |
151 | case IOCTL_OLS_GET_REFCOUNT:
152 | *(PULONG)pIrp->AssociatedIrp.SystemBuffer = refCount;
153 | pIrp->IoStatus.Information = sizeof(refCount);
154 | status = STATUS_SUCCESS;
155 | break;
156 |
157 | case IOCTL_OLS_READ_MSR:
158 | status = ReadMsr(
159 | pIrp->AssociatedIrp.SystemBuffer,
160 | pIrpStack->Parameters.DeviceIoControl.InputBufferLength,
161 | pIrp->AssociatedIrp.SystemBuffer,
162 | pIrpStack->Parameters.DeviceIoControl.OutputBufferLength,
163 | (ULONG*)&pIrp->IoStatus.Information
164 | );
165 | break;
166 | case IOCTL_OLS_WRITE_MSR:
167 | status = WriteMsr(
168 | pIrp->AssociatedIrp.SystemBuffer,
169 | pIrpStack->Parameters.DeviceIoControl.InputBufferLength,
170 | pIrp->AssociatedIrp.SystemBuffer,
171 | pIrpStack->Parameters.DeviceIoControl.OutputBufferLength,
172 | (ULONG*)&pIrp->IoStatus.Information
173 | );
174 | break;
175 | case IOCTL_OLS_READ_PMC:
176 | status = ReadPmc(
177 | pIrp->AssociatedIrp.SystemBuffer,
178 | pIrpStack->Parameters.DeviceIoControl.InputBufferLength,
179 | pIrp->AssociatedIrp.SystemBuffer,
180 | pIrpStack->Parameters.DeviceIoControl.OutputBufferLength,
181 | (ULONG*)&pIrp->IoStatus.Information
182 | );
183 | break;
184 | case IOCTL_OLS_HALT:
185 | __halt();
186 | status = STATUS_SUCCESS;
187 | break;
188 |
189 | case IOCTL_OLS_READ_IO_PORT:
190 | case IOCTL_OLS_READ_IO_PORT_BYTE:
191 | case IOCTL_OLS_READ_IO_PORT_WORD:
192 | case IOCTL_OLS_READ_IO_PORT_DWORD:
193 | status = ReadIoPort(
194 | pIrpStack->Parameters.DeviceIoControl.IoControlCode,
195 | pIrp->AssociatedIrp.SystemBuffer,
196 | pIrpStack->Parameters.DeviceIoControl.InputBufferLength,
197 | pIrp->AssociatedIrp.SystemBuffer,
198 | pIrpStack->Parameters.DeviceIoControl.OutputBufferLength,
199 | (ULONG*)&pIrp->IoStatus.Information
200 | );
201 | break;
202 | case IOCTL_OLS_WRITE_IO_PORT:
203 | case IOCTL_OLS_WRITE_IO_PORT_BYTE:
204 | case IOCTL_OLS_WRITE_IO_PORT_WORD:
205 | case IOCTL_OLS_WRITE_IO_PORT_DWORD:
206 | status = WriteIoPort(
207 | pIrpStack->Parameters.DeviceIoControl.IoControlCode,
208 | pIrp->AssociatedIrp.SystemBuffer,
209 | pIrpStack->Parameters.DeviceIoControl.InputBufferLength,
210 | pIrp->AssociatedIrp.SystemBuffer,
211 | pIrpStack->Parameters.DeviceIoControl.OutputBufferLength,
212 | (ULONG*)&pIrp->IoStatus.Information
213 | );
214 | break;
215 |
216 | case IOCTL_OLS_READ_PCI_CONFIG:
217 | status = ReadPciConfig(
218 | pIrp->AssociatedIrp.SystemBuffer,
219 | pIrpStack->Parameters.DeviceIoControl.InputBufferLength,
220 | pIrp->AssociatedIrp.SystemBuffer,
221 | pIrpStack->Parameters.DeviceIoControl.OutputBufferLength,
222 | (ULONG*)&pIrp->IoStatus.Information
223 | );
224 | break;
225 | case IOCTL_OLS_WRITE_PCI_CONFIG:
226 | status = WritePciConfig(
227 | pIrp->AssociatedIrp.SystemBuffer,
228 | pIrpStack->Parameters.DeviceIoControl.InputBufferLength,
229 | pIrp->AssociatedIrp.SystemBuffer,
230 | pIrpStack->Parameters.DeviceIoControl.OutputBufferLength,
231 | (ULONG*)&pIrp->IoStatus.Information
232 | );
233 | break;
234 |
235 | case IOCTL_OLS_READ_MEMORY:
236 | status = ReadMemory(
237 | pIrp->AssociatedIrp.SystemBuffer,
238 | pIrpStack->Parameters.DeviceIoControl.InputBufferLength,
239 | pIrp->AssociatedIrp.SystemBuffer,
240 | pIrpStack->Parameters.DeviceIoControl.OutputBufferLength,
241 | (ULONG*)&pIrp->IoStatus.Information
242 | );
243 | break;
244 | case IOCTL_OLS_WRITE_MEMORY:
245 | status = WriteMemory(
246 | pIrp->AssociatedIrp.SystemBuffer,
247 | pIrpStack->Parameters.DeviceIoControl.InputBufferLength,
248 | pIrp->AssociatedIrp.SystemBuffer,
249 | pIrpStack->Parameters.DeviceIoControl.OutputBufferLength,
250 | (ULONG*)&pIrp->IoStatus.Information
251 | );
252 | break;
253 |
254 |
255 | }
256 | break;
257 | }
258 |
259 | // We're done with I/O request. Record the status of the I/O action.
260 | pIrp->IoStatus.Status = status;
261 |
262 | // Don't boost priority when returning since this took little time.
263 | IoCompleteRequest(pIrp, IO_NO_INCREMENT);
264 |
265 | return status;
266 | }
267 |
268 | VOID
269 | Unload(
270 | PDRIVER_OBJECT DriverObject
271 | )
272 | /*++
273 |
274 | Routine Description:
275 |
276 | This routine is called by the I/O system to unload the driver.
277 |
278 | Any resources previously allocated must be freed.
279 |
280 | Arguments:
281 |
282 | DriverObject - a pointer to the object that represents our driver.
283 |
284 | Return Value:
285 |
286 | None
287 | --*/
288 |
289 | {
290 | PDEVICE_OBJECT deviceObject = DriverObject->DeviceObject;
291 | UNICODE_STRING win32NameString;
292 |
293 | PAGED_CODE();
294 |
295 | // Create counted string version of our Win32 device name.
296 | RtlInitUnicodeString(&win32NameString, DOS_DEVICE_NAME);
297 |
298 | // Delete the link from our device name to a name in the Win32 namespace.
299 | IoDeleteSymbolicLink(&win32NameString);
300 |
301 | if(deviceObject != NULL)
302 | {
303 | IoDeleteDevice(deviceObject);
304 | }
305 | }
306 |
307 | //-----------------------------------------------------------------------------
308 | //
309 | // CPU
310 | //
311 | //-----------------------------------------------------------------------------
312 |
313 | NTSTATUS
314 | ReadMsr( void *lpInBuffer,
315 | ULONG nInBufferSize,
316 | void *lpOutBuffer,
317 | ULONG nOutBufferSize,
318 | ULONG *lpBytesReturned)
319 | {
320 | __try
321 | {
322 | ULONGLONG data = __readmsr(*(ULONG*)lpInBuffer);
323 | memcpy((PULONG)lpOutBuffer, &data, 8);
324 | *lpBytesReturned = 8;
325 | return STATUS_SUCCESS;
326 | }
327 | __except(EXCEPTION_EXECUTE_HANDLER)
328 | {
329 | *lpBytesReturned = 0;
330 | return STATUS_UNSUCCESSFUL;
331 | }
332 | }
333 |
334 | NTSTATUS
335 | WriteMsr( void *lpInBuffer,
336 | ULONG nInBufferSize,
337 | void *lpOutBuffer,
338 | ULONG nOutBufferSize,
339 | ULONG *lpBytesReturned)
340 | {
341 | __try
342 | {
343 | OLS_WRITE_MSR_INPUT* param;
344 | param = (OLS_WRITE_MSR_INPUT*)lpInBuffer;
345 |
346 | __writemsr(param->Register, param->Value.QuadPart);
347 | *lpBytesReturned = 0;
348 | return STATUS_SUCCESS;
349 | }
350 | __except(EXCEPTION_EXECUTE_HANDLER)
351 | {
352 | *lpBytesReturned = 0;
353 | return STATUS_UNSUCCESSFUL;
354 | }
355 | }
356 |
357 | NTSTATUS
358 | ReadPmc( void *lpInBuffer,
359 | ULONG nInBufferSize,
360 | void *lpOutBuffer,
361 | ULONG nOutBufferSize,
362 | ULONG *lpBytesReturned)
363 | {
364 | __try
365 | {
366 | ULONGLONG data = __readpmc(*(ULONG*)lpInBuffer);
367 | memcpy((PULONG)lpOutBuffer, &data, 8);
368 | *lpBytesReturned = 8;
369 | return STATUS_SUCCESS;
370 | }
371 | __except(EXCEPTION_EXECUTE_HANDLER)
372 | {
373 | *lpBytesReturned = 0;
374 | return STATUS_UNSUCCESSFUL;
375 | }
376 | }
377 |
378 | //-----------------------------------------------------------------------------
379 | //
380 | // IO Port
381 | //
382 | //-----------------------------------------------------------------------------
383 |
384 | NTSTATUS
385 | ReadIoPort( ULONG ioControlCode,
386 | void *lpInBuffer,
387 | ULONG nInBufferSize,
388 | void *lpOutBuffer,
389 | ULONG nOutBufferSize,
390 | ULONG *lpBytesReturned)
391 | {
392 | ULONG nPort = *(ULONG*)lpInBuffer;
393 |
394 | switch(ioControlCode)
395 | {
396 | case IOCTL_OLS_READ_IO_PORT_BYTE:
397 | *(PUCHAR)lpOutBuffer = READ_PORT_UCHAR((PUCHAR)(ULONG_PTR)nPort);
398 | break;
399 | case IOCTL_OLS_READ_IO_PORT_WORD:
400 | *(PUSHORT)lpOutBuffer = READ_PORT_USHORT((PUSHORT)(ULONG_PTR)nPort);
401 | break;
402 | case IOCTL_OLS_READ_IO_PORT_DWORD:
403 | *(PULONG)lpOutBuffer = READ_PORT_ULONG((PULONG)(ULONG_PTR)nPort);
404 | break;
405 | default:
406 | *lpBytesReturned = 0;
407 | return STATUS_INVALID_PARAMETER;
408 | break;
409 | }
410 |
411 | *lpBytesReturned = nInBufferSize;
412 | return STATUS_SUCCESS;
413 | }
414 |
415 | NTSTATUS
416 | WriteIoPort(ULONG ioControlCode,
417 | void *lpInBuffer,
418 | ULONG nInBufferSize,
419 | void *lpOutBuffer,
420 | ULONG nOutBufferSize,
421 | ULONG *lpBytesReturned)
422 | {
423 | ULONG nPort;
424 | OLS_WRITE_IO_PORT_INPUT* param;
425 |
426 | param = (OLS_WRITE_IO_PORT_INPUT*)lpInBuffer;
427 | nPort = param->PortNumber;
428 |
429 | switch(ioControlCode)
430 | {
431 |
432 | case IOCTL_OLS_WRITE_IO_PORT_BYTE:
433 | WRITE_PORT_UCHAR((PUCHAR)(ULONG_PTR)nPort, param->CharData);
434 | break;
435 | case IOCTL_OLS_WRITE_IO_PORT_WORD:
436 | WRITE_PORT_USHORT((PUSHORT)(ULONG_PTR)nPort, param->ShortData);
437 | break;
438 | case IOCTL_OLS_WRITE_IO_PORT_DWORD:
439 | WRITE_PORT_ULONG((PULONG)(ULONG_PTR)nPort, param->LongData);
440 | break;
441 | default:
442 | return STATUS_INVALID_PARAMETER;
443 | break;
444 | }
445 |
446 | return STATUS_SUCCESS;
447 | }
448 |
449 | //-----------------------------------------------------------------------------
450 | //
451 | // PCI
452 | //
453 | //-----------------------------------------------------------------------------
454 |
455 | NTSTATUS
456 | ReadPciConfig( void *lpInBuffer,
457 | ULONG nInBufferSize,
458 | void *lpOutBuffer,
459 | ULONG nOutBufferSize,
460 | ULONG *lpBytesReturned)
461 | {
462 | OLS_READ_PCI_CONFIG_INPUT *param;
463 | NTSTATUS status;
464 |
465 | if(nInBufferSize != sizeof(OLS_READ_PCI_CONFIG_INPUT))
466 | {
467 | return STATUS_INVALID_PARAMETER;
468 | }
469 | param = (OLS_READ_PCI_CONFIG_INPUT *)lpInBuffer;
470 |
471 | status = pciConfigRead(param->PciAddress, param->PciOffset,
472 | lpOutBuffer, nOutBufferSize);
473 |
474 | if(status == STATUS_SUCCESS)
475 | {
476 | *lpBytesReturned = nOutBufferSize;
477 | }
478 | else
479 | {
480 | *lpBytesReturned = 0;
481 | }
482 |
483 | return status;
484 | }
485 |
486 | NTSTATUS
487 | WritePciConfig( void *lpInBuffer,
488 | ULONG nInBufferSize,
489 | void *lpOutBuffer,
490 | ULONG nOutBufferSize,
491 | ULONG *lpBytesReturned)
492 |
493 | {
494 | OLS_WRITE_PCI_CONFIG_INPUT *param;
495 | ULONG writeSize;
496 | NTSTATUS status;
497 |
498 | if(nInBufferSize < offsetof(OLS_WRITE_PCI_CONFIG_INPUT, Data))
499 | {
500 | return STATUS_INVALID_PARAMETER;
501 | }
502 |
503 | param = (OLS_WRITE_PCI_CONFIG_INPUT *)lpInBuffer;
504 | writeSize = nInBufferSize - offsetof(OLS_WRITE_PCI_CONFIG_INPUT, Data);
505 |
506 | *lpBytesReturned = 0;
507 |
508 | return pciConfigWrite(param->PciAddress, param->PciOffset,
509 | ¶m->Data, writeSize);
510 |
511 | }
512 |
513 | //-----------------------------------------------------------------------------
514 | //
515 | // Support Function
516 | //
517 | //-----------------------------------------------------------------------------
518 |
519 | NTSTATUS pciConfigRead(ULONG pciAddress, ULONG offset, void *data, int length)
520 | {
521 | PCI_SLOT_NUMBER slot;
522 | int error;
523 | ULONG busNumber;
524 |
525 | busNumber = PciGetBus(pciAddress);
526 | slot.u.AsULONG = 0;
527 | slot.u.bits.DeviceNumber = PciGetDev(pciAddress);
528 | slot.u.bits.FunctionNumber = PciGetFunc(pciAddress);
529 | error = HalGetBusDataByOffset(PCIConfiguration, busNumber, slot.u.AsULONG,
530 | data, offset, length);
531 |
532 | if(error == 0)
533 | {
534 | return OLS_ERROR_PCI_BUS_NOT_EXIST;
535 | }
536 | else if(length != 2 && error == 2)
537 | {
538 | return OLS_ERROR_PCI_NO_DEVICE;
539 | }
540 | else if(length != error)
541 | {
542 | return OLS_ERROR_PCI_READ_CONFIG;
543 | }
544 |
545 | return STATUS_SUCCESS;
546 | }
547 |
548 | NTSTATUS pciConfigWrite(ULONG pciAddress, ULONG offset, void *data, int length)
549 | {
550 | PCI_SLOT_NUMBER slot;
551 | int error;
552 | ULONG busNumber;
553 |
554 | busNumber = PciGetBus(pciAddress);
555 |
556 | slot.u.AsULONG = 0;
557 | slot.u.bits.DeviceNumber = PciGetDev(pciAddress);
558 | slot.u.bits.FunctionNumber = PciGetFunc(pciAddress);
559 | error = HalSetBusDataByOffset(PCIConfiguration, busNumber, slot.u.AsULONG,
560 | data, offset, length);
561 |
562 | if(error != length)
563 | {
564 | return OLS_ERROR_PCI_WRITE_CONFIG;
565 | }
566 |
567 | return STATUS_SUCCESS;
568 | }
569 |
570 |
571 | //-----------------------------------------------------------------------------
572 | //
573 | // Physical Memory
574 | //
575 | //-----------------------------------------------------------------------------
576 |
577 | NTSTATUS
578 | ReadMemory( void *lpInBuffer,
579 | ULONG nInBufferSize,
580 | void *lpOutBuffer,
581 | ULONG nOutBufferSize,
582 | ULONG *lpBytesReturned)
583 | {
584 | OLS_READ_MEMORY_INPUT *param;
585 | ULONG size;
586 | PHYSICAL_ADDRESS address;
587 | PVOID maped;
588 | BOOLEAN error;
589 |
590 | if(nInBufferSize != sizeof(OLS_READ_MEMORY_INPUT))
591 | {
592 | return STATUS_INVALID_PARAMETER;
593 | }
594 |
595 | param = (OLS_READ_MEMORY_INPUT *)lpInBuffer;
596 | size = param->UnitSize * param->Count;
597 |
598 | if(nOutBufferSize < size)
599 | {
600 | return STATUS_INVALID_PARAMETER;
601 | }
602 |
603 | address.QuadPart = param->Address.QuadPart;
604 |
605 | #ifndef _PHYSICAL_MEMORY_SUPPORT
606 |
607 | if(0x000C0000 > address.QuadPart
608 | || (address.QuadPart + size - 1) > 0x000FFFFF)
609 | {
610 | return STATUS_INVALID_PARAMETER;
611 | }
612 |
613 | #endif
614 |
615 | maped = MmMapIoSpace(address, size, FALSE);
616 |
617 | error = FALSE;
618 | switch(param->UnitSize){
619 | case 1:
620 | READ_REGISTER_BUFFER_UCHAR(maped, lpOutBuffer, param->Count);
621 | break;
622 | case 2:
623 | READ_REGISTER_BUFFER_USHORT(maped, lpOutBuffer, param->Count);
624 | break;
625 | case 4:
626 | READ_REGISTER_BUFFER_ULONG(maped, lpOutBuffer, param->Count);
627 | break;
628 | default:
629 | error = TRUE;
630 | break;
631 | }
632 |
633 | MmUnmapIoSpace(maped, size);
634 |
635 | if(error)
636 | {
637 | return STATUS_INVALID_PARAMETER;
638 | }
639 |
640 | *lpBytesReturned = nOutBufferSize;
641 |
642 | return STATUS_SUCCESS;
643 | }
644 |
645 | NTSTATUS
646 | WriteMemory(void *lpInBuffer,
647 | ULONG nInBufferSize,
648 | void *lpOutBuffer,
649 | ULONG nOutBufferSize,
650 | ULONG *lpBytesReturned)
651 | {
652 | #ifdef _PHYSICAL_MEMORY_SUPPORT
653 |
654 | OLS_WRITE_MEMORY_INPUT *param;
655 | ULONG size;
656 | PHYSICAL_ADDRESS address;
657 | PVOID maped;
658 | BOOLEAN error;
659 |
660 | if(nInBufferSize < offsetof(OLS_WRITE_MEMORY_INPUT, Data))
661 | {
662 | return STATUS_INVALID_PARAMETER;
663 | }
664 |
665 | param = (OLS_WRITE_MEMORY_INPUT *)lpInBuffer;
666 |
667 | size = param->UnitSize * param->Count;
668 | if (nInBufferSize < size + offsetof(OLS_WRITE_MEMORY_INPUT, Data))
669 | {
670 | return STATUS_INVALID_PARAMETER;
671 | }
672 |
673 | address.QuadPart = param->Address.QuadPart;
674 |
675 | maped = MmMapIoSpace(address, size, FALSE);
676 |
677 | error = FALSE;
678 | switch(param->UnitSize){
679 | case 1:
680 | WRITE_REGISTER_BUFFER_UCHAR(maped,
681 | (UCHAR*)¶m->Data, param->Count);
682 | break;
683 | case 2:
684 | WRITE_REGISTER_BUFFER_USHORT(maped,
685 | (USHORT*)¶m->Data, param->Count);
686 | break;
687 | case 4:
688 | WRITE_REGISTER_BUFFER_ULONG(maped,
689 | (ULONG*)¶m->Data, param->Count);
690 | break;
691 | default:
692 | error = TRUE;
693 | break;
694 | }
695 |
696 | MmUnmapIoSpace(maped, size);
697 |
698 | if(error)
699 | {
700 | return STATUS_INVALID_PARAMETER;
701 | }
702 |
703 | *lpBytesReturned = 0;
704 |
705 | return STATUS_SUCCESS;
706 |
707 | #else
708 |
709 | *lpBytesReturned = 0;
710 |
711 | return STATUS_INVALID_PARAMETER;
712 |
713 | #endif
714 | }
715 |
--------------------------------------------------------------------------------
/dll/sys/OpenLibSys.h:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------------
2 | // Author : hiyohiyo
3 | // Mail : hiyohiyo@crystalmark.info
4 | // Web : http://openlibsys.org/
5 | // License : The modified BSD license
6 | //
7 | // Copyright 2007-2008 OpenLibSys.org. All rights reserved.
8 | //-----------------------------------------------------------------------------
9 |
10 | #include
11 | #include
12 | #include "../OlsIoctl.h"
13 |
14 | //-----------------------------------------------------------------------------
15 | //
16 | // Device Name
17 | //
18 | //-----------------------------------------------------------------------------
19 |
20 | #define NT_DEVICE_NAME L"\\Device\\WinRing0_1_2_0"
21 | #define DOS_DEVICE_NAME L"\\DosDevices\\WinRing0_1_2_0"
22 |
23 | //-----------------------------------------------------------------------------
24 | //
25 | // Function Prototypes
26 | //
27 | //-----------------------------------------------------------------------------
28 |
29 | NTSTATUS DriverEntry(
30 | IN PDRIVER_OBJECT DriverObject,
31 | IN PUNICODE_STRING RegistryPath
32 | );
33 |
34 | NTSTATUS OlsDispatch(
35 | IN PDEVICE_OBJECT pDO,
36 | IN PIRP pIrp
37 | );
38 |
39 | VOID Unload(
40 | IN PDRIVER_OBJECT DriverObject
41 | );
42 |
43 | //-----------------------------------------------------------------------------
44 | //
45 | // Function Prototypes for Control Code
46 | //
47 | //-----------------------------------------------------------------------------
48 |
49 | NTSTATUS ReadMsr(
50 | void *lpInBuffer,
51 | ULONG nInBufferSize,
52 | void *lpOutBuffer,
53 | ULONG nOutBufferSize,
54 | ULONG *lpBytesReturned
55 | );
56 |
57 | NTSTATUS WriteMsr(
58 | void *lpInBuffer,
59 | ULONG nInBufferSize,
60 | void *lpOutBuffer,
61 | ULONG nOutBufferSize,
62 | ULONG *lpBytesReturned
63 | );
64 |
65 | NTSTATUS ReadPmc(
66 | void *lpInBuffer,
67 | ULONG nInBufferSize,
68 | void *lpOutBuffer,
69 | ULONG nOutBufferSize,
70 | ULONG *lpBytesReturned
71 | );
72 |
73 | NTSTATUS ReadIoPort(
74 | ULONG ioControlCode,
75 | void *lpInBuffer,
76 | ULONG nInBufferSize,
77 | void *lpOutBuffer,
78 | ULONG nOutBufferSize,
79 | ULONG *lpBytesReturned
80 | );
81 |
82 | NTSTATUS WriteIoPort(
83 | ULONG ioControlCode,
84 | void *lpInBuffer,
85 | ULONG nInBufferSize,
86 | void *lpOutBuffer,
87 | ULONG nOutBufferSize,
88 | ULONG *lpBytesReturned
89 | );
90 |
91 | NTSTATUS ReadPciConfig(
92 | void *lpInBuffer,
93 | ULONG nInBufferSize,
94 | void *lpOutBuffer,
95 | ULONG nOutBufferSize,
96 | ULONG *lpBytesReturned
97 | );
98 |
99 | NTSTATUS WritePciConfig(
100 | void *lpInBuffer,
101 | ULONG nInBufferSize,
102 | void *lpOutBuffer,
103 | ULONG nOutBufferSize,
104 | ULONG *lpBytesReturned
105 | );
106 |
107 | NTSTATUS ReadMemory(
108 | void *lpInBuffer,
109 | ULONG nInBufferSize,
110 | void *lpOutBuffer,
111 | ULONG nOutBufferSize,
112 | ULONG *lpBytesReturned
113 | );
114 |
115 | NTSTATUS WriteMemory(
116 | void *lpInBuffer,
117 | ULONG nInBufferSize,
118 | void *lpOutBuffer,
119 | ULONG nOutBufferSize,
120 | ULONG *lpBytesReturned
121 | );
122 |
123 |
124 | //-----------------------------------------------------------------------------
125 | //
126 | // Support Function Prototypes
127 | //
128 | //-----------------------------------------------------------------------------
129 |
130 | NTSTATUS pciConfigRead(ULONG pciAddress, ULONG offset, void *data, int length);
131 | NTSTATUS pciConfigWrite(ULONG pciAddress, ULONG offset, void *data, int length);
132 |
--------------------------------------------------------------------------------
/dll/sys/OpenLibSys.rc:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #define VER_FILETYPE VFT_DRV
5 | #define VER_FILESUBTYPE VFT2_DRV_SYSTEM
6 |
7 | #define VER_FILEDESCRIPTION_STR "WinRing0"
8 | #define VER_INTERNALNAME_STR "WinRing0.sys"
9 |
10 | /////////////////////////////////////////////////////////////////////////////
11 | //
12 | // Version
13 | //
14 |
15 | VS_VERSION_INFO VERSIONINFO
16 | FILEVERSION 1, 2, 0, 5
17 | PRODUCTVERSION 1, 2, 0, 5
18 | FILEFLAGSMASK 0x3fL
19 | FILEFLAGS 0x0L
20 | FILEOS 0x40004L
21 | FILETYPE 0x2L
22 | FILESUBTYPE 0x0L
23 | BEGIN
24 | BLOCK "StringFileInfo"
25 | BEGIN
26 | BLOCK "041104b0"
27 | BEGIN
28 | VALUE "Comments", "The modified BSD license\0"
29 | VALUE "CompanyName", "OpenLibSys.org\0"
30 | VALUE "FileDescription", "WinRing0\0"
31 | VALUE "FileVersion", "1.2.0.5\0"
32 | VALUE "InternalName", "WinRing0.sys\0"
33 | VALUE "LegalCopyright", "Copyright (C) 2007-2008 OpenLibSys.org. All rights reserved.\0"
34 | VALUE "OriginalFilename", "WinRing0.sys\0"
35 | VALUE "ProductName", "WinRing0\0"
36 | VALUE "ProductVersion", "1.2.0.5\0"
37 | END
38 | END
39 | BLOCK "VarFileInfo"
40 | BEGIN
41 | VALUE "Translation", 0x411, 1200
42 | END
43 | END
44 |
--------------------------------------------------------------------------------
/dll/sys/SOURCES:
--------------------------------------------------------------------------------
1 | TARGETNAME=WinRing0
2 | TARGETPATH=lib
3 | TARGETTYPE=DRIVER
4 |
5 | INCLUDES=..\
6 |
7 | SOURCES=OpenLibSys.c OpenLibSys.rc
8 |
--------------------------------------------------------------------------------
/dll/vxd/Makefile:
--------------------------------------------------------------------------------
1 | #-----------------------------------------------------------------------------
2 | # Author : hiyohiyo
3 | # Mail : hiyohiyo@crystalmark.info
4 | # Web : http://openlibsys.org/
5 | # License : The modified BSD license
6 | #
7 | # Copyright 2007 hiyohiyo, All rights reserved.
8 | #-----------------------------------------------------------------------------
9 | #
10 | # How to build on Windows XP SP1 DDK (Win Me Free Build Environment)
11 | #
12 | # 0. Get Windows XP SP1 DDK from MSDN
13 | # 1. Install Windows XP SP1 DDK with Win Me support
14 | # 2. Open "Win Me Free Build Environment"
15 | # 3. cd (WinRing0)\source\dll\vxd
16 | # 4. nmake
17 | #
18 | # Compile Options
19 | #_OPEN_LIB_SYS=
20 |
21 | !ifdef _OPEN_LIB_SYS
22 | VXDFILE = OpenLibSys.vxd
23 | !else
24 | VXDFILE = WinRing0.vxd
25 | !endif
26 |
27 | OBJDIR = bin
28 | VXDWRAPSDIR = $(DDKROOT)\lib\win_me\
29 |
30 | RC16 = $(DDKROOT)\bin\win_me\bin16\rc
31 | ML = $(DDKROOT)\bin\win_me\bin\ml
32 | CL = $(DDKROOT)\bin\x86\cl
33 | LINK = $(DDKROOT)\bin\x86\link
34 |
35 | !ifdef DEBUG
36 | DDEBUG =-DDEBLEVEL=1 -DDEBUG
37 | !else
38 | DDEBUG =-DDEBLEVEL=0
39 | !endif
40 |
41 | CFLAGS = -Zdp -Gs -c -DIS_32 $(DDEBUG)
42 | LFLAGS = -machine:i386 -debug:none kernel32.lib
43 | AFLAGS = -coff -DBLD_COFF -DIS_32 -W2 -Zd -c -Cx -DMASM6
44 |
45 | all: direxist $(OBJDIR)\OpenLS.vxd
46 |
47 | direxist:
48 | if not exist $(OBJDIR)\nul md $(OBJDIR)
49 |
50 | $(OBJDIR)\OpenLS.res: OpenLS.rc
51 | $(RC16) -Fo$@ -r OpenLS.rc
52 |
53 | $(OBJDIR)\OpenLS.obj: OpenLS.c
54 | $(CL) $(CFLAGS) -Fo$@ %s
55 |
56 | $(OBJDIR)\ctrl.obj: ctrl.asm
57 | $(ML) $(AFLAGS) -Fo$@ %s
58 |
59 | $(OBJDIR)\OpenLS.vxd: $(OBJDIR)\OpenLS.obj $(OBJDIR)\ctrl.obj\
60 | $(OBJDIR)\OpenLS.res OpenLS.def
61 | echo >NUL @<
14 | #include
15 |
16 | #pragma VxD_LOCKED_CODE_SEG
17 | #pragma VxD_LOCKED_DATA_SEG
18 |
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 |
25 | #include "OpenLS.h"
26 | #include "../OlsIoctl.h"
27 |
28 | //-----------------------------------------------------------------------------
29 | //
30 | // W32_DeviceIOControl
31 | //
32 | //-----------------------------------------------------------------------------
33 |
34 | DWORD _stdcall W32_DeviceIOControl(DWORD dwService,
35 | DWORD dwDDB,
36 | DWORD hDevice,
37 | LPDIOC lpDIOCParms)
38 | {
39 | DWORD dwRetVal = 0;
40 | int count;
41 | int index;
42 |
43 | switch(dwService)
44 | {
45 | case DIOC_OPEN:
46 | dwRetVal = NO_ERROR;
47 | break;
48 | case DIOC_CLOSEHANDLE:
49 | dwRetVal = CleanUp();
50 | break;
51 | case IOCTL_OLS_GET_DRIVER_VERSION:
52 | *(PULONG)lpDIOCParms->lpvOutBuffer = OLS_DRIVER_VERSION;
53 | *(PULONG)lpDIOCParms->lpcbBytesReturned = 4;
54 | dwRetVal = NO_ERROR;
55 | break;
56 |
57 | case IOCTL_OLS_READ_MSR:
58 | dwRetVal = ReadMsr(
59 | (void *)lpDIOCParms->lpvInBuffer,
60 | lpDIOCParms->cbInBuffer,
61 | (void *)lpDIOCParms->lpvOutBuffer,
62 | lpDIOCParms->cbOutBuffer,
63 | (void *)lpDIOCParms->lpcbBytesReturned
64 | );
65 | break;
66 | case IOCTL_OLS_WRITE_MSR:
67 | dwRetVal = WriteMsr(
68 | (void *)lpDIOCParms->lpvInBuffer,
69 | lpDIOCParms->cbInBuffer,
70 | (void *)lpDIOCParms->lpvOutBuffer,
71 | lpDIOCParms->cbOutBuffer,
72 | (void *)lpDIOCParms->lpcbBytesReturned
73 | );
74 | break;
75 | case IOCTL_OLS_READ_PMC:
76 | dwRetVal = ReadPmc(
77 | (void *)lpDIOCParms->lpvInBuffer,
78 | lpDIOCParms->cbInBuffer,
79 | (void *)lpDIOCParms->lpvOutBuffer,
80 | lpDIOCParms->cbOutBuffer,
81 | (void *)lpDIOCParms->lpcbBytesReturned
82 | );
83 | break;
84 | case IOCTL_OLS_HALT:
85 | __asm hlt;
86 | dwRetVal = NO_ERROR;
87 | break;
88 |
89 | case IOCTL_OLS_READ_IO_PORT:
90 | case IOCTL_OLS_READ_IO_PORT_BYTE:
91 | case IOCTL_OLS_READ_IO_PORT_WORD:
92 | case IOCTL_OLS_READ_IO_PORT_DWORD:
93 | dwRetVal = ReadIoPort(
94 | dwService,
95 | (void *)lpDIOCParms->lpvInBuffer,
96 | lpDIOCParms->cbInBuffer,
97 | (void *)lpDIOCParms->lpvOutBuffer,
98 | lpDIOCParms->cbOutBuffer,
99 | (void *)lpDIOCParms->lpcbBytesReturned
100 | );
101 | break;
102 | case IOCTL_OLS_WRITE_IO_PORT:
103 | case IOCTL_OLS_WRITE_IO_PORT_BYTE:
104 | case IOCTL_OLS_WRITE_IO_PORT_WORD:
105 | case IOCTL_OLS_WRITE_IO_PORT_DWORD:
106 | dwRetVal = WriteIoPort(
107 | dwService,
108 | (void *)lpDIOCParms->lpvInBuffer,
109 | lpDIOCParms->cbInBuffer,
110 | (void *)lpDIOCParms->lpvOutBuffer,
111 | lpDIOCParms->cbOutBuffer,
112 | (void *)lpDIOCParms->lpcbBytesReturned
113 | );
114 | break;
115 |
116 | case IOCTL_OLS_READ_PCI_CONFIG:
117 | dwRetVal = ReadPciConfig(
118 | (void *)lpDIOCParms->lpvInBuffer,
119 | lpDIOCParms->cbInBuffer,
120 | (void *)lpDIOCParms->lpvOutBuffer,
121 | lpDIOCParms->cbOutBuffer,
122 | (void *)lpDIOCParms->lpcbBytesReturned
123 | );
124 | break;
125 | case IOCTL_OLS_WRITE_PCI_CONFIG:
126 | dwRetVal = WritePciConfig(
127 | (void *)lpDIOCParms->lpvInBuffer,
128 | lpDIOCParms->cbInBuffer,
129 | (void *)lpDIOCParms->lpvOutBuffer,
130 | lpDIOCParms->cbOutBuffer,
131 | (void *)lpDIOCParms->lpcbBytesReturned
132 | );
133 | break;
134 |
135 | case IOCTL_OLS_READ_MEMORY:
136 | dwRetVal = ReadMemory(
137 | (void *)lpDIOCParms->lpvInBuffer,
138 | lpDIOCParms->cbInBuffer,
139 | (void *)lpDIOCParms->lpvOutBuffer,
140 | lpDIOCParms->cbOutBuffer,
141 | (void *)lpDIOCParms->lpcbBytesReturned
142 | );
143 | break;
144 | case IOCTL_OLS_WRITE_MEMORY:
145 | dwRetVal = WriteMemory(
146 | (void *)lpDIOCParms->lpvInBuffer,
147 | lpDIOCParms->cbInBuffer,
148 | (void *)lpDIOCParms->lpvOutBuffer,
149 | lpDIOCParms->cbOutBuffer,
150 | (void *)lpDIOCParms->lpcbBytesReturned
151 | );
152 | break;
153 |
154 | default:
155 | dwRetVal = ERROR_NOT_SUPPORTED;
156 | }
157 | return dwRetVal;
158 | }
159 |
160 | //-----------------------------------------------------------------------------
161 | //
162 | // CPU
163 | //
164 | //-----------------------------------------------------------------------------
165 |
166 | NTSTATUS
167 | ReadMsr(void *lpInBuffer,
168 | ULONG nInBufferSize,
169 | void *lpOutBuffer,
170 | ULONG nOutBufferSize,
171 | ULONG *lpBytesReturned)
172 | {
173 | ULONG ulECX = *(ULONG*)lpInBuffer;
174 | ULONG ulEAX = 0;
175 | ULONG ulEDX = 0;
176 |
177 | _asm
178 | {
179 | mov ecx, ulECX
180 | rdmsr
181 | mov ulEAX, eax
182 | mov ulEDX, edx
183 | }
184 | memcpy((PULONG)lpOutBuffer, &ulEAX, 4);
185 | memcpy((PULONG)lpOutBuffer+1, &ulEDX, 4);
186 |
187 | *lpBytesReturned = 8;
188 | return STATUS_SUCCESS;
189 | }
190 |
191 |
192 | NTSTATUS
193 | WriteMsr( void *lpInBuffer,
194 | ULONG nInBufferSize,
195 | void *lpOutBuffer,
196 | ULONG nOutBufferSize,
197 | ULONG *lpBytesReturned)
198 | {
199 | OLS_WRITE_MSR_INPUT* param = (OLS_WRITE_MSR_INPUT*)lpInBuffer;
200 |
201 | ULONG ulECX = param->Register;
202 | ULONG ulEAX = param->Value.LowPart;
203 | ULONG ulEDX = param->Value.HighPart;
204 |
205 | _asm
206 | {
207 | mov eax, ulEAX
208 | mov edx, ulEDX
209 | mov ecx, ulECX
210 | wrmsr
211 | }
212 | *lpBytesReturned = 0;
213 | return STATUS_SUCCESS;
214 | }
215 |
216 | NTSTATUS
217 | ReadPmc(void *lpInBuffer,
218 | ULONG nInBufferSize,
219 | void *lpOutBuffer,
220 | ULONG nOutBufferSize,
221 | ULONG *lpBytesReturned)
222 | {
223 | ULONG ulECX = *(ULONG*)lpInBuffer;
224 | ULONG ulEAX = 0;
225 | ULONG ulEDX = 0;
226 |
227 | _asm
228 | {
229 | mov ecx, ulECX
230 | rdpmc
231 | mov ulEAX, eax
232 | mov ulEDX, edx
233 | }
234 | memcpy((PULONG)lpOutBuffer, &ulEAX, 4);
235 | memcpy((PULONG)lpOutBuffer+1, &ulEDX, 4);
236 |
237 | *lpBytesReturned = 8;
238 |
239 | return STATUS_SUCCESS;
240 | }
241 |
242 | //-----------------------------------------------------------------------------
243 | //
244 | // I/O Port
245 | //
246 | //-----------------------------------------------------------------------------
247 |
248 | NTSTATUS
249 | ReadIoPort( ULONG ioControlCode,
250 | void *lpInBuffer,
251 | ULONG nInBufferSize,
252 | void *lpOutBuffer,
253 | ULONG nOutBufferSize,
254 | ULONG *lpBytesReturned)
255 | {
256 | ULONG nPort = *(ULONG*)lpInBuffer;
257 |
258 | switch(ioControlCode)
259 | {
260 | case IOCTL_OLS_READ_IO_PORT_BYTE:
261 | *(PUCHAR)lpOutBuffer = _inp((USHORT)nPort);
262 | break;
263 | case IOCTL_OLS_READ_IO_PORT_WORD:
264 | *(PUSHORT)lpOutBuffer = _inpw((USHORT)nPort);
265 | break;
266 | case IOCTL_OLS_READ_IO_PORT_DWORD:
267 | *(PULONG)lpOutBuffer = _inpd((USHORT)nPort);
268 | break;
269 | default:
270 | *lpBytesReturned = 0;
271 | return STATUS_INVALID_PARAMETER;
272 | break;
273 | }
274 |
275 | *lpBytesReturned = nInBufferSize;
276 | return STATUS_SUCCESS;
277 | }
278 |
279 | NTSTATUS
280 | WriteIoPort(ULONG ioControlCode,
281 | void *lpInBuffer,
282 | ULONG nInBufferSize,
283 | void *lpOutBuffer,
284 | ULONG nOutBufferSize,
285 | ULONG *lpBytesReturned)
286 | {
287 | ULONG nPort;
288 | OLS_WRITE_IO_PORT_INPUT* param;
289 |
290 | param = (OLS_WRITE_IO_PORT_INPUT*)lpInBuffer;
291 | nPort = param->PortNumber;
292 |
293 | switch(ioControlCode)
294 | {
295 | case IOCTL_OLS_WRITE_IO_PORT_BYTE:
296 | _outp((USHORT)nPort, param->CharData);
297 | break;
298 | case IOCTL_OLS_WRITE_IO_PORT_WORD:
299 | _outpw((USHORT)nPort, param->ShortData);
300 | break;
301 | case IOCTL_OLS_WRITE_IO_PORT_DWORD:
302 | _outpd((USHORT)nPort, param->LongData);
303 | break;
304 | default:
305 | return STATUS_INVALID_PARAMETER;
306 | break;
307 | }
308 |
309 | return STATUS_SUCCESS;
310 | }
311 |
312 | //-----------------------------------------------------------------------------
313 | //
314 | // PCI
315 | //
316 | //-----------------------------------------------------------------------------
317 |
318 | DWORD
319 | ReadPciConfig( void *lpInBuffer,
320 | ULONG nInBufferSize,
321 | void *lpOutBuffer,
322 | ULONG nOutBufferSize,
323 | ULONG *lpBytesReturned)
324 | {
325 | OLS_READ_PCI_CONFIG_INPUT *param;
326 | DWORD status;
327 |
328 | if(nInBufferSize != sizeof(OLS_READ_PCI_CONFIG_INPUT))
329 | {
330 | return STATUS_INVALID_PARAMETER;
331 | }
332 | param = (OLS_READ_PCI_CONFIG_INPUT *) lpInBuffer;
333 |
334 | status = pciConfigRead(param->PciAddress, param->PciOffset,
335 | lpOutBuffer, nOutBufferSize);
336 |
337 | if(status == STATUS_SUCCESS) {
338 | *lpBytesReturned = nOutBufferSize;
339 | } else {
340 | *lpBytesReturned = 0;
341 | }
342 |
343 | return status;
344 | }
345 |
346 | NTSTATUS
347 | WritePciConfig( void *lpInBuffer,
348 | ULONG nInBufferSize,
349 | void *lpOutBuffer,
350 | ULONG nOutBufferSize,
351 | ULONG *lpBytesReturned)
352 |
353 | {
354 | OLS_WRITE_PCI_CONFIG_INPUT *param;
355 | ULONG writeSize;
356 | NTSTATUS status;
357 |
358 | if(nInBufferSize < offsetof(OLS_WRITE_PCI_CONFIG_INPUT, Data))
359 | {
360 | return STATUS_INVALID_PARAMETER;
361 | }
362 |
363 | param = (OLS_WRITE_PCI_CONFIG_INPUT *)lpInBuffer;
364 | writeSize = nInBufferSize - offsetof(OLS_WRITE_PCI_CONFIG_INPUT, Data);
365 |
366 | *lpBytesReturned = 0;
367 |
368 | return pciConfigWrite(param->PciAddress, param->PciOffset,
369 | ¶m->Data, writeSize);
370 | }
371 |
372 | //-----------------------------------------------------------------------------
373 | //
374 | // Support Function
375 | //
376 | //-----------------------------------------------------------------------------
377 |
378 | NTSTATUS
379 | pciConfigRead(ULONG pciAddress, ULONG loffsetadd, char *data, int len)
380 | {
381 | BYTE status, maxbusnumber;
382 | WORD offsetadd = loffsetadd;
383 |
384 | while(len > 0)
385 | {
386 | if(len >=4 && (offsetadd & 3) == 0)
387 | {
388 | DWORD d;
389 | __asm mov ax, word ptr 0xb10a;
390 | __asm mov bx, word ptr pciAddress;
391 | __asm mov di, offsetadd
392 | CallPciBios();
393 | __asm mov d, ecx;
394 | __asm mov status, ah;
395 | *(DWORD*)data = d;
396 | data += 4;
397 | len -= 4;
398 | offsetadd += 4;
399 | }
400 | else if(len >=2 && (offsetadd & 1) == 0)
401 | {
402 | WORD d;
403 | __asm mov ax, word ptr 0xb109;
404 | __asm mov bx, word ptr pciAddress;
405 | __asm mov di, offsetadd;
406 | CallPciBios();
407 | __asm mov d, cx;
408 | __asm mov status, ah;
409 | *(WORD*)data = d;
410 | data += 2;
411 | len -= 2;
412 | offsetadd += 2;
413 | }
414 | else
415 | {
416 | BYTE d;
417 | __asm mov ax, word ptr 0xb108;
418 | __asm mov bx, word ptr pciAddress;
419 | __asm mov di, offsetadd;
420 | CallPciBios();
421 | __asm mov d, cl;
422 | __asm mov status, ah;
423 | *(WORD*)data = d;
424 | data += 1;
425 | len -= 1;
426 | offsetadd += 1;
427 | }
428 |
429 | if(status != 0)
430 | {
431 | return STATUS_UNSUCCESSFUL;
432 | }
433 | }
434 | return STATUS_SUCCESS;
435 | }
436 |
437 | NTSTATUS
438 | pciConfigWrite(ULONG pciAddress, ULONG loffsetadd, char *data, int len)
439 | {
440 | BYTE status, maxbusnumber;
441 | WORD offsetadd = loffsetadd;
442 |
443 | while(len >0)
444 | {
445 | if(len >=4 && (offsetadd & 3) ==0)
446 | {
447 | DWORD d = *(DWORD*)data;
448 | __asm mov ax, word ptr 0xb10d;
449 | __asm mov bx, word ptr pciAddress;
450 | __asm mov di, offsetadd;
451 | __asm mov ecx, d;
452 | CallPciBios();
453 | __asm mov status, ah
454 | data += 4;
455 | len -= 4;
456 | offsetadd += 4;
457 | }
458 | else if(len >=2 && (offsetadd & 1) == 0)
459 | {
460 | WORD d = *(DWORD*)data;
461 | __asm mov ax, word ptr 0xb10c;
462 | __asm mov bx, word ptr pciAddress;
463 | __asm mov di, offsetadd;
464 | __asm mov cx, d;
465 | CallPciBios();
466 | __asm mov status, ah
467 | data += 2;
468 | len -= 2;
469 | offsetadd += 2;
470 | }
471 | else
472 | {
473 | BYTE d = *(DWORD*)data;
474 | __asm mov ax, word ptr 0xb10b;
475 | __asm mov bx, word ptr pciAddress;
476 | __asm mov di, offsetadd;
477 | __asm mov cl, d ;
478 | CallPciBios();
479 | __asm mov status, ah
480 | data += 1;
481 | len -= 1;
482 | offsetadd += 1;
483 | }
484 |
485 | if(status != 0)
486 | {
487 | return STATUS_UNSUCCESSFUL;
488 | }
489 | }
490 | return STATUS_SUCCESS;
491 | }
492 |
493 | //-----------------------------------------------------------------------------
494 | //
495 | // Physical Memory
496 | //
497 | //-----------------------------------------------------------------------------
498 |
499 | NTSTATUS
500 | ReadMemory( void *lpInBuffer,
501 | ULONG nInBufferSize,
502 | void *lpOutBuffer,
503 | ULONG nOutBufferSize,
504 | ULONG *lpBytesReturned)
505 | {
506 | int i;
507 | ULONG size;
508 | PVOID maped;
509 | OLS_READ_MEMORY_INPUT *param;
510 |
511 | param = (OLS_READ_MEMORY_INPUT *)lpInBuffer;
512 |
513 | if(nInBufferSize != sizeof(OLS_READ_MEMORY_INPUT))
514 | {
515 | return STATUS_INVALID_PARAMETER;
516 | }
517 |
518 | size = param->UnitSize * param->Count;
519 |
520 | if(nOutBufferSize < size)
521 | {
522 | return STATUS_INVALID_PARAMETER;
523 | }
524 |
525 | #ifndef _PHYSICAL_MEMORY_SUPPORT
526 |
527 | if(0x000C0000 > param->Address.LowPart
528 | || (param->Address.LowPart + size - 1) > 0x000FFFFF)
529 | {
530 | return STATUS_INVALID_PARAMETER;
531 | }
532 |
533 | #endif
534 |
535 | maped = _MapPhysToLinear(param->Address.LowPart, size, 0);
536 |
537 | switch(param->UnitSize)
538 | {
539 | case 1:
540 | for(i = 0; i< param->Count; i++){
541 | ((UCHAR*)lpOutBuffer)[i] = ((UCHAR*)maped)[i];
542 | }
543 | break;
544 | case 2:
545 | for(i = 0; i< param->Count; i++){
546 | ((USHORT*)lpOutBuffer)[i] = ((USHORT*)maped)[i];
547 | }
548 | break;
549 | case 4:
550 | for(i = 0; i< param->Count; i++){
551 | ((ULONG*)lpOutBuffer)[i] = ((ULONG*)maped)[i];
552 | }
553 | break;
554 | default:
555 | return STATUS_INVALID_PARAMETER;
556 | break;
557 | }
558 |
559 | *lpBytesReturned = nOutBufferSize;
560 | return STATUS_SUCCESS;
561 | }
562 |
563 | NTSTATUS
564 | WriteMemory(void *lpInBuffer,
565 | ULONG nInBufferSize,
566 | void *lpOutBuffer,
567 | ULONG nOutBufferSize,
568 | ULONG *lpBytesReturned)
569 | {
570 | #ifdef _PHYSICAL_MEMORY_SUPPORT
571 |
572 | OLS_WRITE_MEMORY_INPUT *param;
573 | ULONG size;
574 | PVOID maped;
575 | int i;
576 |
577 | if(nInBufferSize < offsetof(OLS_WRITE_MEMORY_INPUT, Data))
578 | {
579 | return STATUS_INVALID_PARAMETER;
580 | }
581 |
582 | param = (OLS_WRITE_MEMORY_INPUT *)lpInBuffer;
583 |
584 | size = param->UnitSize * param->Count;
585 | if(nInBufferSize < size + offsetof(OLS_WRITE_MEMORY_INPUT, Data))
586 | {
587 | return STATUS_INVALID_PARAMETER;
588 | }
589 |
590 | maped = _MapPhysToLinear(param->Address.LowPart, size, 0);
591 |
592 | switch(param->UnitSize)
593 | {
594 | case 1:
595 | for(i = 0; i< param->Count; i++){
596 | ((UCHAR*)maped)[i] = ((UCHAR*)param->Data)[i];
597 | }
598 | break;
599 | case 2:
600 | for(i = 0; i< param->Count; i++){
601 | ((USHORT*)maped)[i] = ((USHORT*)param->Data)[i];
602 | }
603 | break;
604 | case 4:
605 | for(i = 0; i< param->Count; i++){
606 | ((ULONG*)maped)[i] = ((ULONG*)param->Data)[i];
607 | }
608 | break;
609 | default:
610 | return STATUS_INVALID_PARAMETER;
611 | break;
612 | }
613 |
614 | *lpBytesReturned = 0;
615 |
616 | return STATUS_SUCCESS;
617 |
618 | #else
619 |
620 | *lpBytesReturned = 0;
621 |
622 | return STATUS_INVALID_PARAMETER;
623 |
624 | #endif
625 |
626 | }
627 |
--------------------------------------------------------------------------------
/dll/vxd/OpenLS.def:
--------------------------------------------------------------------------------
1 | VXD OPENLS DYNAMIC
2 |
3 | DESCRIPTION 'OPENLS VXD'
4 |
5 | SEGMENTS
6 | _LTEXT CLASS 'LCODE' PRELOAD NONDISCARDABLE
7 | _LDATA CLASS 'LCODE' PRELOAD NONDISCARDABLE
8 | EXPORTS
9 | OPENLS_DDB @1
10 |
--------------------------------------------------------------------------------
/dll/vxd/OpenLS.h:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------------
2 | // Author : hiyohiyo
3 | // Mail : hiyohiyo@crystalmark.info
4 | // Web : http://openlibsys.org/
5 | // License : The modified BSD license
6 | //
7 | // Copyright 2007-2008 OpenLibSys.org. All rights reserved.
8 | //-----------------------------------------------------------------------------
9 |
10 | #include
11 |
12 | //-----------------------------------------------------------------------------
13 | //
14 | // typedef/define
15 | //
16 | //-----------------------------------------------------------------------------
17 |
18 | typedef DWORD NTSTATUS;
19 | typedef BYTE BOOLEAN;
20 | typedef DIOCPARAMETERS *LPDIOC;
21 |
22 | #define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
23 | #define STATUS_UNSUCCESSFUL ((NTSTATUS)0xC0000001L)
24 | #define STATUS_INVALID_PARAMETER ((NTSTATUS)0xC000000DL)
25 |
26 | //-----------------------------------------------------------------------------
27 | //
28 | // Function Prototypes
29 | //
30 | //-----------------------------------------------------------------------------
31 |
32 | DWORD _stdcall W32_DeviceIOControl(DWORD, DWORD, DWORD, LPDIOC);
33 |
34 | DWORD _stdcall Dynamic_Init(void)
35 | {
36 | return (VXD_SUCCESS);
37 | }
38 |
39 | DWORD _stdcall Dynamic_Exit(void)
40 | {
41 | return (VXD_SUCCESS);
42 | }
43 |
44 | DWORD _stdcall CleanUp(void)
45 | {
46 | return (VXD_SUCCESS);
47 | }
48 |
49 | extern void Exec_VxD_Int_rap(void);
50 | #define CallPciBios() Exec_VxD_Int_rap()
51 |
52 | //-----------------------------------------------------------------------------
53 | //
54 | // Function Prototypes for Control Code
55 | //
56 | //-----------------------------------------------------------------------------
57 |
58 | NTSTATUS ReadMsr(
59 | void *lpInBuffer,
60 | ULONG nInBufferSize,
61 | void *lpOutBuffer,
62 | ULONG nOutBufferSize,
63 | ULONG *lpBytesReturned
64 | );
65 |
66 | NTSTATUS WriteMsr(
67 | void *lpInBuffer,
68 | ULONG nInBufferSize,
69 | void *lpOutBuffer,
70 | ULONG nOutBufferSize,
71 | ULONG *lpBytesReturned
72 | );
73 |
74 | NTSTATUS ReadPmc(
75 | void *lpInBuffer,
76 | ULONG nInBufferSize,
77 | void *lpOutBuffer,
78 | ULONG nOutBufferSize,
79 | ULONG *lpBytesReturned
80 | );
81 |
82 | NTSTATUS ReadIoPort(
83 | ULONG ioControlCode,
84 | void *lpInBuffer,
85 | ULONG nInBufferSize,
86 | void *lpOutBuffer,
87 | ULONG nOutBufferSize,
88 | ULONG *lpBytesReturned
89 | );
90 |
91 | NTSTATUS WriteIoPort(
92 | ULONG ioControlCode,
93 | void *lpInBuffer,
94 | ULONG nInBufferSize,
95 | void *lpOutBuffer,
96 | ULONG nOutBufferSize,
97 | ULONG *lpBytesReturned
98 | );
99 |
100 | NTSTATUS ReadPciConfig(
101 | void *lpInBuffer,
102 | ULONG nInBufferSize,
103 | void *lpOutBuffer,
104 | ULONG nOutBufferSize,
105 | ULONG *lpBytesReturned
106 | );
107 |
108 | NTSTATUS WritePciConfig(
109 | void *lpInBuffer,
110 | ULONG nInBufferSize,
111 | void *lpOutBuffer,
112 | ULONG nOutBufferSize,
113 | ULONG *lpBytesReturned
114 | );
115 |
116 | NTSTATUS ReadMemory(
117 | void *lpInBuffer,
118 | ULONG nInBufferSize,
119 | void *lpOutBuffer,
120 | ULONG nOutBufferSize,
121 | ULONG *lpBytesReturned
122 | );
123 |
124 | NTSTATUS WriteMemory(
125 | void *lpInBuffer,
126 | ULONG nInBufferSize,
127 | void *lpOutBuffer,
128 | ULONG nOutBufferSize,
129 | ULONG *lpBytesReturned
130 | );
131 |
132 |
133 | //-----------------------------------------------------------------------------
134 | //
135 | // Support Function Prototypes
136 | //
137 | //-----------------------------------------------------------------------------
138 |
139 | NTSTATUS pciConfigRead(ULONG pciAddress, ULONG offset, void *data, int length);
140 | NTSTATUS pciConfigWrite(ULONG pciAddress, ULONG offset, void *data, int length);
141 |
--------------------------------------------------------------------------------
/dll/vxd/OpenLS.rc:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////
2 | //
3 | // Version
4 | //
5 | VS_VERSION_INFO VERSIONINFO
6 | FILEVERSION 1,2,0,5
7 | PRODUCTVERSION 1,2,0,5
8 | FILEFLAGSMASK 0x3fL
9 | FILEFLAGS 0x0L
10 | FILEOS 0x40004L
11 | FILETYPE 0x2L
12 | FILESUBTYPE 0x0L
13 | BEGIN
14 | BLOCK "StringFileInfo"
15 | BEGIN
16 | BLOCK "041104b0"
17 | BEGIN
18 | VALUE "Comments", "The modified BSD license\0"
19 | VALUE "CompanyName", "OpenLibSys.org\0"
20 | VALUE "FileDescription", "WinRing0.vxd\0"
21 | VALUE "FileVersion", "1.2.0.5\0"
22 | VALUE "InternalName", "WinRing0.vxd\0"
23 | VALUE "LegalCopyright", "Copyright (C) 2007-2008 OpenLibSys.org. All rights reserved.\0"
24 | VALUE "OriginalFilename", "WinRing0.vxd\0"
25 | VALUE "ProductName", "WinRing0\0"
26 | VALUE "ProductVersion", "1.2.0.5\0"
27 | END
28 | END
29 | BLOCK "VarFileInfo"
30 | BEGIN
31 | VALUE "Translation", 0x411, 1200
32 | END
33 | END
34 |
--------------------------------------------------------------------------------
/dll/vxd/ctrl.asm:
--------------------------------------------------------------------------------
1 | ;-----------------------------------------------------------------------------
2 | ; Author : hiyohiyo
3 | ; Mail : hiyohiyo@crystalmark.info
4 | ; Web : http://openlibsys.org/
5 | ; License : The modified BSD license
6 | ;
7 | ; Copyright 2007 hiyohiyo, All rights reserved.
8 | ;-----------------------------------------------------------------------------
9 |
10 | WIN40COMPAT EQU 1
11 | PAGE 58,132
12 |
13 | .386p
14 | .xlist
15 | include vmm.inc
16 | .list
17 |
18 | ;============================================================================
19 | ; V I R T U A L D E V I C E D E C L A R A T I O N
20 | ;============================================================================
21 |
22 | DECLARE_VIRTUAL_DEVICE OPENLS, 1, 0, OPENLS_Control, Undefined_Device_ID, \
23 | UNDEFINED_INIT_ORDER, 0 ,0
24 |
25 | ;============================================================================
26 | ; OPENLS_Control
27 | ;============================================================================
28 |
29 | VxD_LOCKED_CODE_SEG
30 |
31 | BeginProc OPENLS_Control
32 | Control_Dispatch SYS_DYNAMIC_DEVICE_INIT, Dynamic_Init, sCall
33 | Control_Dispatch SYS_DYNAMIC_DEVICE_EXIT, Dynamic_Exit, sCall
34 | Control_Dispatch W32_DEVICEIOCONTROL, W32_DeviceIOControl,\
35 | sCall,
36 | clc
37 | ret
38 | EndProc OPENLS_Control
39 |
40 | public C Exec_VxD_Int_rap
41 | Exec_VxD_Int_rap proc
42 | push dword ptr 1ah
43 | VmmCall Exec_VxD_Int
44 | ret
45 | Exec_VxD_Int_rap endp
46 |
47 | VxD_LOCKED_CODE_ENDS
48 |
49 | end
50 |
--------------------------------------------------------------------------------
/drv/DriverApi.h:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------------
2 | // Author : hiyohiyo
3 | // Mail : hiyohiyo@crystalmark.info
4 | // Web : http://openlibsys.org/
5 | // License : The modified BSD license
6 | //
7 | // Copyright 2007 OpenLibSys.org. All rights reserved.
8 | //-----------------------------------------------------------------------------
9 | // for WinRing0 1.3.x
10 |
11 | #pragma once
12 |
13 | //-----------------------------------------------------------------------------
14 | // Use Driver Must Be Initialize
15 | //-----------------------------------------------------------------------------
16 | BOOL Initialize(LPCTSTR DriverPath);
17 |
18 | //-----------------------------------------------------------------------------
19 | // Must Remove Before Application leave
20 | //-----------------------------------------------------------------------------
21 | BOOL Deinitialize();
22 |
23 | //-----------------------------------------------------------------------------
24 | // GetDriverVersion
25 | //-----------------------------------------------------------------------------
26 | DWORD // Device Driver Version, defined OLS_DRIVER_VERSION
27 | WINAPI GetDriverVersion(
28 | PBYTE major, // major version
29 | PBYTE minor, // minor version
30 | PBYTE revision, // revision
31 | PBYTE release // release/build
32 | );
33 |
34 | //-----------------------------------------------------------------------------
35 | // GetDriverType
36 | //-----------------------------------------------------------------------------
37 | DWORD // Device Driver Type, defined OLS_DRIVER_TYPE_****
38 | WINAPI GetDriverType();
39 |
40 | //-----------------------------------------------------------------------------
41 | // InitializeOls
42 | //-----------------------------------------------------------------------------
43 | BOOL // TRUE: success, FALSE: failure
44 | WINAPI InitializeOls();
45 |
46 | //-----------------------------------------------------------------------------
47 | // DeinitializeOls
48 | //-----------------------------------------------------------------------------
49 | VOID WINAPI DeinitializeOls();
50 |
51 | /******************************************************************************
52 | **
53 | ** CPU
54 | **
55 | ******************************************************************************/
56 |
57 | //-----------------------------------------------------------------------------
58 | // IsCpuid
59 | //-----------------------------------------------------------------------------
60 | BOOL // TRUE: support CPUID instruction, FALSE: not support CPUID instruction
61 | WINAPI IsCpuid();
62 |
63 | //-----------------------------------------------------------------------------
64 | // IsMsr
65 | //-----------------------------------------------------------------------------
66 | BOOL // TRUE: support MSR(Model-Specific Register), FALSE: not support MSR
67 | WINAPI IsMsr();
68 |
69 | //-----------------------------------------------------------------------------
70 | // IsTsc
71 | //-----------------------------------------------------------------------------
72 | BOOL // TRUE: support TSC(Time Stamp Counter), FALSE: not support TSC
73 | WINAPI IsTsc();
74 |
75 | //-----------------------------------------------------------------------------
76 | // Rdmsr
77 | //-----------------------------------------------------------------------------
78 | BOOL // TRUE: success, FALSE: failure
79 | WINAPI Rdmsr(
80 | DWORD index, // MSR index
81 | PDWORD eax, // bit 0-31
82 | PDWORD edx // bit 32-63
83 | );
84 |
85 | //-----------------------------------------------------------------------------
86 | // RdmsrTx
87 | //-----------------------------------------------------------------------------
88 | BOOL // TRUE: success, FALSE: failure
89 | WINAPI RdmsrTx(
90 | DWORD index, // MSR index
91 | PDWORD eax, // bit 0-31
92 | PDWORD edx, // bit 32-63
93 | DWORD_PTR threadAffinityMask
94 | );
95 |
96 | //-----------------------------------------------------------------------------
97 | // RdmsrPx
98 | //-----------------------------------------------------------------------------
99 | BOOL // TRUE: success, FALSE: failure
100 | WINAPI RdmsrPx(
101 | DWORD index, // MSR index
102 | PDWORD eax, // bit 0-31
103 | PDWORD edx, // bit 32-63
104 | DWORD_PTR processAffinityMask
105 | );
106 |
107 | //-----------------------------------------------------------------------------
108 | // Wrmsr
109 | //-----------------------------------------------------------------------------
110 | BOOL // TRUE: success, FALSE: failure
111 | WINAPI Wrmsr(
112 | DWORD index, // MSR index
113 | DWORD eax, // bit 0-31
114 | DWORD edx // bit 32-63
115 | );
116 |
117 | //-----------------------------------------------------------------------------
118 | // WrmsrTx
119 | //-----------------------------------------------------------------------------
120 | BOOL // TRUE: success, FALSE: failure
121 | WINAPI WrmsrTx(
122 | DWORD index, // MSR index
123 | DWORD eax, // bit 0-31
124 | DWORD edx, // bit 32-63
125 | DWORD_PTR threadAffinityMask
126 | );
127 |
128 | //-----------------------------------------------------------------------------
129 | // WrmsrPx
130 | //-----------------------------------------------------------------------------
131 | BOOL // TRUE: success, FALSE: failure
132 | WINAPI WrmsrPx(
133 | DWORD index, // MSR index
134 | DWORD eax, // bit 0-31
135 | DWORD edx, // bit 32-63
136 | DWORD_PTR processAffinityMask
137 | );
138 |
139 | //-----------------------------------------------------------------------------
140 | // Rdpmc
141 | //-----------------------------------------------------------------------------
142 | BOOL // TRUE: success, FALSE: failure
143 | WINAPI Rdpmc(
144 | DWORD index, // PMC index
145 | PDWORD eax, // bit 0-31
146 | PDWORD edx // bit 32-63
147 | );
148 |
149 | //-----------------------------------------------------------------------------
150 | // RdmsrTx
151 | //-----------------------------------------------------------------------------
152 | BOOL // TRUE: success, FALSE: failure
153 | WINAPI RdpmcTx(
154 | DWORD index, // PMC index
155 | PDWORD eax, // bit 0-31
156 | PDWORD edx, // bit 32-63
157 | DWORD_PTR threadAffinityMask
158 | );
159 |
160 | //-----------------------------------------------------------------------------
161 | // RdmsrPx
162 | //-----------------------------------------------------------------------------
163 | BOOL // TRUE: success, FALSE: failure
164 | WINAPI RdpmcPx(
165 | DWORD index, // PMC index
166 | PDWORD eax, // bit 0-31
167 | PDWORD edx, // bit 32-63
168 | DWORD_PTR processAffinityMask
169 | );
170 |
171 | //-----------------------------------------------------------------------------
172 | // Cpuid
173 | //-----------------------------------------------------------------------------
174 | BOOL // TRUE: success, FALSE: failure
175 | WINAPI Cpuid(
176 | DWORD index, // CPUID index
177 | PDWORD eax,
178 | PDWORD ebx,
179 | PDWORD ecx,
180 | PDWORD edx
181 | );
182 |
183 | //-----------------------------------------------------------------------------
184 | // CpuidTx
185 | //-----------------------------------------------------------------------------
186 | BOOL // TRUE: success, FALSE: failure
187 | WINAPI CpuidTx(
188 | DWORD index, // CPUID index
189 | PDWORD eax,
190 | PDWORD ebx,
191 | PDWORD ecx,
192 | PDWORD edx,
193 | DWORD_PTR threadAffinityMask
194 | );
195 |
196 | //-----------------------------------------------------------------------------
197 | // CpuidPx
198 | //-----------------------------------------------------------------------------
199 | BOOL // TRUE: success, FALSE: failure
200 | WINAPI CpuidPx(
201 | DWORD index, // CPUID index
202 | PDWORD eax,
203 | PDWORD ebx,
204 | PDWORD ecx,
205 | PDWORD edx,
206 | DWORD_PTR processAffinityMask
207 | );
208 |
209 | //-----------------------------------------------------------------------------
210 | // Rdtsc
211 | //-----------------------------------------------------------------------------
212 | BOOL // TRUE: success, FALSE: failure
213 | WINAPI Rdtsc(
214 | PDWORD eax, // bit 0-31
215 | PDWORD edx // bit 32-63
216 | );
217 |
218 | //-----------------------------------------------------------------------------
219 | // RdmsrTx
220 | //-----------------------------------------------------------------------------
221 | BOOL // TRUE: success, FALSE: failure
222 | WINAPI RdtscTx(
223 | PDWORD eax, // bit 0-31
224 | PDWORD edx, // bit 32-63
225 | DWORD_PTR threadAffinityMask
226 | );
227 |
228 | //-----------------------------------------------------------------------------
229 | // RdmsrPx
230 | //-----------------------------------------------------------------------------
231 | BOOL // TRUE: success, FALSE: failure
232 | WINAPI RdtscPx(
233 | PDWORD eax, // bit 0-31
234 | PDWORD edx, // bit 32-63
235 | DWORD_PTR processAffinityMask
236 | );
237 |
238 | //-----------------------------------------------------------------------------
239 | // Hlt
240 | //-----------------------------------------------------------------------------
241 | BOOL // TRUE: success, FALSE: failure
242 | WINAPI Hlt();
243 |
244 | //-----------------------------------------------------------------------------
245 | // HltTx
246 | //-----------------------------------------------------------------------------
247 | BOOL // TRUE: success, FALSE: failure
248 | WINAPI HltTx(
249 | DWORD_PTR threadAffinityMask
250 | );
251 |
252 | //-----------------------------------------------------------------------------
253 | // HltPx
254 | //-----------------------------------------------------------------------------
255 | BOOL // TRUE: success, FALSE: failure
256 | WINAPI HltTx(
257 | DWORD_PTR processAffinityMask
258 | );
259 |
260 | /******************************************************************************
261 | **
262 | ** I/O
263 | **
264 | ******************************************************************************/
265 |
266 | //-----------------------------------------------------------------------------
267 | // ReadIoPortByte
268 | //-----------------------------------------------------------------------------
269 | BYTE // Read Value
270 | WINAPI ReadIoPortByte(
271 | WORD port // I/O port address
272 | );
273 |
274 | //-----------------------------------------------------------------------------
275 | // ReadIoPortWord
276 | //-----------------------------------------------------------------------------
277 | WORD // Read Value
278 | WINAPI ReadIoPortWord(
279 | WORD port // I/O port address
280 | );
281 |
282 | //-----------------------------------------------------------------------------
283 | // ReadIoPortDword
284 | //-----------------------------------------------------------------------------
285 | DWORD // Read Value
286 | WINAPI ReadIoPortDword(
287 | WORD port // I/O port address
288 | );
289 |
290 | //-----------------------------------------------------------------------------
291 | // ReadIoPortByteEx
292 | //-----------------------------------------------------------------------------
293 | BOOL // TRUE: success, FALSE: failure
294 | WINAPI ReadIoPortByteEx(
295 | WORD port, // I/O port address
296 | PBYTE value // Read Value
297 | );
298 | //-----------------------------------------------------------------------------
299 | // ReadIoPortWordEx
300 | //-----------------------------------------------------------------------------
301 | BOOL // TRUE: success, FALSE: failure
302 | WINAPI ReadIoPortWordEx(
303 | WORD port, // I/O port address
304 | PWORD value // Read Value
305 | );
306 | //-----------------------------------------------------------------------------
307 | // ReadIoPortDwordEx
308 | //-----------------------------------------------------------------------------
309 | BOOL // TRUE: success, FALSE: failure
310 | WINAPI ReadIoPortDwordEx(
311 | WORD port, // I/O port address
312 | PDWORD value // Read Value
313 | );
314 |
315 | //-----------------------------------------------------------------------------
316 | // WriteIoPortByte
317 | //-----------------------------------------------------------------------------
318 | VOID
319 | WINAPI WriteIoPortByte(
320 | WORD port, // I/O port address
321 | BYTE value // Write Value
322 | );
323 |
324 | //-----------------------------------------------------------------------------
325 | // WriteIoPortDword
326 | //-----------------------------------------------------------------------------
327 | VOID
328 | WINAPI WriteIoPortDword(
329 | WORD port, // I/O port address
330 | DWORD value // Write Value
331 | );
332 |
333 |
334 | //-----------------------------------------------------------------------------
335 | // WriteIoPortWord
336 | //-----------------------------------------------------------------------------
337 | VOID
338 | WINAPI WriteIoPortWord(
339 | WORD port, // I/O port address
340 | WORD value // Write Value
341 | );
342 |
343 | //-----------------------------------------------------------------------------
344 | // WriteIoPortByteEx
345 | //-----------------------------------------------------------------------------
346 | BOOL // TRUE: success, FALSE: failure
347 | WINAPI WriteIoPortByteEx(
348 | WORD port, // I/O port address
349 | BYTE value // Write Value
350 | );
351 |
352 | //-----------------------------------------------------------------------------
353 | // WriteIoPortWordEx
354 | //-----------------------------------------------------------------------------
355 | BOOL // TRUE: success, FALSE: failure
356 | WINAPI WriteIoPortWordEx(
357 | WORD port, // I/O port address
358 | WORD value // Write Value
359 | );
360 |
361 |
362 | //-----------------------------------------------------------------------------
363 | // WriteIoPortDwordEx
364 | //-----------------------------------------------------------------------------
365 | BOOL // TRUE: success, FALSE: failure
366 | WINAPI WriteIoPortDwordEx(
367 | WORD port, // I/O port address
368 | DWORD value // Write Value
369 | );
370 |
371 | /******************************************************************************
372 | **
373 | ** PCI
374 | **
375 | ******************************************************************************/
376 | // pciAddress
377 | // 0- 2: Function Number
378 | // 3- 7: Device Number
379 | // 8-15: PCI Bus Number
380 | // 16-31: Reserved
381 | // 0xFFFFFFFF : Error
382 |
383 | //-----------------------------------------------------------------------------
384 | // SetPciMaxBusNo
385 | //-----------------------------------------------------------------------------
386 | VOID
387 | WINAPI SetPciMaxBusIndex(
388 | BYTE max // Max PCI Bus to Scan
389 | );
390 |
391 | //-----------------------------------------------------------------------------
392 | // ReadPciConfigByte
393 | //-----------------------------------------------------------------------------
394 | BYTE // Read Value
395 | WINAPI ReadPciConfigByte(
396 | DWORD pciAddress, // PCI Device Address
397 | BYTE regAddress // Configuration Address 0-255
398 | );
399 |
400 | //-----------------------------------------------------------------------------
401 | // ReadPciConfigWord
402 | //-----------------------------------------------------------------------------
403 | WORD // Read Value
404 | WINAPI ReadPciConfigWord(
405 | DWORD pciAddress, // PCI Device Address
406 | BYTE regAddress // Configuration Address 0-255
407 | );
408 |
409 | //-----------------------------------------------------------------------------
410 | // ReadPciConfigDword
411 | //-----------------------------------------------------------------------------
412 | DWORD // Read Value
413 | WINAPI ReadPciConfigDword(
414 | DWORD pciAddress, // PCI Device Address
415 | BYTE regAddress // Configuration Address 0-255
416 | );
417 |
418 | //-----------------------------------------------------------------------------
419 | // ReadPciConfigByteEx
420 | //-----------------------------------------------------------------------------
421 | BOOL // TRUE: success, FALSE: failure
422 | WINAPI ReadPciConfigByteEx(
423 | DWORD pciAddress, // PCI Device Address
424 | DWORD regAddress, // Configuration Address 0-whatever
425 | PBYTE value // Read Value
426 | );
427 |
428 | //-----------------------------------------------------------------------------
429 | // ReadPciConfigWordEx
430 | //-----------------------------------------------------------------------------
431 | BOOL // TRUE: success, FALSE: failure
432 | WINAPI ReadPciConfigWordEx(
433 | DWORD pciAddress, // PCI Device Address
434 | DWORD regAddress, // Configuration Address 0-whatever
435 | PWORD value // Read Value
436 | );
437 |
438 | //-----------------------------------------------------------------------------
439 | // ReadPciConfigDwordEx
440 | //-----------------------------------------------------------------------------
441 | BOOL // TRUE: success, FALSE: failure
442 | WINAPI ReadPciConfigDwordEx(
443 | DWORD pciAddress, // PCI Device Address
444 | DWORD regAddress, // Configuration Address 0-whatever
445 | PDWORD value // Read Value
446 | );
447 |
448 | //-----------------------------------------------------------------------------
449 | // WritePciConfigByte
450 | //-----------------------------------------------------------------------------
451 | VOID
452 | WINAPI WritePciConfigByte(
453 | DWORD pciAddress, // PCI Device Address
454 | BYTE regAddress, // Configuration Address 0-255
455 | BYTE value // Write Value
456 | );
457 |
458 | //-----------------------------------------------------------------------------
459 | // WritePciConfigWord
460 | //-----------------------------------------------------------------------------
461 | VOID
462 | WINAPI WritePciConfigWord(
463 | DWORD pciAddress, // PCI Device Address
464 | BYTE regAddress, // Configuration Address 0-255
465 | WORD value // Write Value
466 | );
467 |
468 | //-----------------------------------------------------------------------------
469 | // WritePciConfigDword
470 | //-----------------------------------------------------------------------------
471 | VOID
472 | WINAPI WritePciConfigDword(
473 | DWORD pciAddress, // PCI Device Address
474 | BYTE regAddress, // Configuration Address 0-255
475 | DWORD value // Write Value
476 | );
477 |
478 | //-----------------------------------------------------------------------------
479 | // WritePciConfigByteEx
480 | //-----------------------------------------------------------------------------
481 | BOOL // TRUE: success, FALSE: failure
482 | WINAPI WritePciConfigByteEx(
483 | DWORD pciAddress, // PCI Device Address
484 | DWORD regAddress, // Configuration Address 0-whatever
485 | BYTE value // Write Value
486 | );
487 |
488 | //-----------------------------------------------------------------------------
489 | // WritePciConfigWordEx
490 | //-----------------------------------------------------------------------------
491 | BOOL // TRUE: success, FALSE: failure
492 | WINAPI WritePciConfigWordEx(
493 | DWORD pciAddress, // PCI Device Address
494 | DWORD regAddress, // Configuration Address 0-whatever
495 | WORD value // Write Value
496 | );
497 |
498 | //-----------------------------------------------------------------------------
499 | // WritePciConfigDwordEx
500 | //-----------------------------------------------------------------------------
501 | BOOL // TRUE: success, FALSE: failure
502 | WINAPI WritePciConfigDwordEx(
503 | DWORD pciAddress, // PCI Device Address
504 | DWORD regAddress, // Configuration Address 0-whatever
505 | DWORD value // Write Value
506 | );
507 |
508 | //-----------------------------------------------------------------------------
509 | // FindPciDeviceById
510 | //-----------------------------------------------------------------------------
511 | DWORD // pciAddress, 0xFFFFFFFF: failure
512 | WINAPI FindPciDeviceById(
513 | WORD vendorId, // Vendor ID
514 | WORD deviceId, // Device ID
515 | BYTE index // Index
516 | );
517 |
518 | //-----------------------------------------------------------------------------
519 | // FindPciDeviceByClass
520 | //-----------------------------------------------------------------------------
521 | DWORD // pciAddress, 0xFFFFFFFF: failure
522 | WINAPI FindPciDeviceByClass(
523 | BYTE baseClass, // Base Class
524 | BYTE subClass, // Sub Class
525 | BYTE programIf, // Program Interface
526 | BYTE index // Index
527 | );
528 |
529 | /******************************************************************************
530 | **
531 | ** Memory (Special API)
532 | **
533 | ******************************************************************************/
534 |
535 | #ifdef _PHYSICAL_MEMORY_SUPPORT
536 | //-----------------------------------------------------------------------------
537 | // ReadDmiMemory
538 | //-----------------------------------------------------------------------------
539 | DWORD // Read size(byte), 0: failure
540 | WINAPI ReadDmiMemory(
541 | PBYTE buffer, // Buffer
542 | DWORD count, // Count
543 | DWORD unitSize // Unit Size (BYTE, WORD, DWORD)
544 | );
545 |
546 | //-----------------------------------------------------------------------------
547 | // ReadPhysicalMemory
548 | //-----------------------------------------------------------------------------
549 | DWORD // Read size(byte), 0: failure
550 | WINAPI ReadPhysicalMemory(
551 | DWORD_PTR address, // Physical Memory Address
552 | PBYTE buffer, // Buffer
553 | DWORD count, // Count
554 | DWORD unitSize // Unit Size (BYTE, WORD, DWORD)
555 | );
556 |
557 | //-----------------------------------------------------------------------------
558 | // WritePhysicalMemory
559 | //-----------------------------------------------------------------------------
560 | DWORD // Write size(byte), 0: failure
561 | WINAPI WritePhysicalMemory(
562 | DWORD_PTR address, // Physical Memory Address
563 | PBYTE buffer, // Buffer
564 | DWORD count, // Count
565 | DWORD unitSize // Unit Size (BYTE, WORD, DWORD)
566 | );
567 | #endif
568 |
--------------------------------------------------------------------------------
/drv/DriverIoCtl.h:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------------
2 | // Author : hiyohiyo
3 | // Mail : hiyohiyo@crystalmark.info
4 | // Web : http://openlibsys.org/
5 | // License : The modified BSD license
6 | //
7 | // Copyright 2007 OpenLibSys.org. All rights reserved.
8 | //-----------------------------------------------------------------------------
9 |
10 | #pragma once
11 |
12 | //-----------------------------------------------------------------------------
13 | //
14 | // The Device type codes form 32768 to 65535 are for customer use.
15 | //
16 | //-----------------------------------------------------------------------------
17 |
18 | #define OLS_TYPE 40000
19 |
20 | //-----------------------------------------------------------------------------
21 | //
22 | // Version Information
23 | //
24 | //-----------------------------------------------------------------------------
25 |
26 | #define OLS_DRIVER_ID _T("WinRing0_1_2_0")
27 |
28 | #define OLS_DRIVER_MAJOR_VERSION 1
29 | #define OLS_DRIVER_MINOR_VERSION 2
30 | #define OLS_DRIVER_REVISION 0
31 | #define OLS_DRIVER_RELESE 5
32 |
33 | #define OLS_DRIVER_VERSION \
34 | ((OLS_DRIVER_MAJOR_VERSION << 24) | (OLS_DRIVER_MINOR_VERSION << 16) \
35 | | (OLS_DRIVER_REVISION << 8) | OLS_DRIVER_RELESE)
36 |
37 | //-----------------------------------------------------------------------------
38 | //
39 | // The IOCTL function codes from 0x800 to 0xFFF are for customer use.
40 | //
41 | //-----------------------------------------------------------------------------
42 | #define IOCTL_OLS_GET_DRIVER_VERSION \
43 | CTL_CODE(OLS_TYPE, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS)
44 |
45 | #define IOCTL_OLS_GET_REFCOUNT \
46 | CTL_CODE(OLS_TYPE, 0x801, METHOD_BUFFERED, FILE_ANY_ACCESS)
47 |
48 | #define IOCTL_OLS_READ_MSR \
49 | CTL_CODE(OLS_TYPE, 0x821, METHOD_BUFFERED, FILE_ANY_ACCESS)
50 |
51 | #define IOCTL_OLS_WRITE_MSR \
52 | CTL_CODE(OLS_TYPE, 0x822, METHOD_BUFFERED, FILE_ANY_ACCESS)
53 |
54 | #define IOCTL_OLS_READ_PMC \
55 | CTL_CODE(OLS_TYPE, 0x823, METHOD_BUFFERED, FILE_ANY_ACCESS)
56 |
57 | #define IOCTL_OLS_HALT \
58 | CTL_CODE(OLS_TYPE, 0x824, METHOD_BUFFERED, FILE_ANY_ACCESS)
59 |
60 | #define IOCTL_OLS_READ_IO_PORT \
61 | CTL_CODE(OLS_TYPE, 0x831, METHOD_BUFFERED, FILE_READ_ACCESS)
62 |
63 | #define IOCTL_OLS_WRITE_IO_PORT \
64 | CTL_CODE(OLS_TYPE, 0x832, METHOD_BUFFERED, FILE_WRITE_ACCESS)
65 |
66 | #define IOCTL_OLS_READ_IO_PORT_BYTE \
67 | CTL_CODE(OLS_TYPE, 0x833, METHOD_BUFFERED, FILE_READ_ACCESS)
68 |
69 | #define IOCTL_OLS_READ_IO_PORT_WORD \
70 | CTL_CODE(OLS_TYPE, 0x834, METHOD_BUFFERED, FILE_READ_ACCESS)
71 |
72 | #define IOCTL_OLS_READ_IO_PORT_DWORD \
73 | CTL_CODE(OLS_TYPE, 0x835, METHOD_BUFFERED, FILE_READ_ACCESS)
74 |
75 | #define IOCTL_OLS_WRITE_IO_PORT_BYTE \
76 | CTL_CODE(OLS_TYPE, 0x836, METHOD_BUFFERED, FILE_WRITE_ACCESS)
77 |
78 | #define IOCTL_OLS_WRITE_IO_PORT_WORD \
79 | CTL_CODE(OLS_TYPE, 0x837, METHOD_BUFFERED, FILE_WRITE_ACCESS)
80 |
81 | #define IOCTL_OLS_WRITE_IO_PORT_DWORD \
82 | CTL_CODE(OLS_TYPE, 0x838, METHOD_BUFFERED, FILE_WRITE_ACCESS)
83 |
84 | #define IOCTL_OLS_READ_MEMORY \
85 | CTL_CODE(OLS_TYPE, 0x841, METHOD_BUFFERED, FILE_READ_ACCESS)
86 |
87 | #define IOCTL_OLS_WRITE_MEMORY \
88 | CTL_CODE(OLS_TYPE, 0x842, METHOD_BUFFERED, FILE_WRITE_ACCESS)
89 |
90 | #define IOCTL_OLS_READ_PCI_CONFIG \
91 | CTL_CODE(OLS_TYPE, 0x851, METHOD_BUFFERED, FILE_READ_ACCESS)
92 |
93 | #define IOCTL_OLS_WRITE_PCI_CONFIG \
94 | CTL_CODE(OLS_TYPE, 0x852, METHOD_BUFFERED, FILE_WRITE_ACCESS)
95 |
96 | //-----------------------------------------------------------------------------
97 | //
98 | // PCI Error Code
99 | //
100 | //-----------------------------------------------------------------------------
101 |
102 | #define OLS_ERROR_PCI_BUS_NOT_EXIST (0xE0000001L)
103 | #define OLS_ERROR_PCI_NO_DEVICE (0xE0000002L)
104 | #define OLS_ERROR_PCI_WRITE_CONFIG (0xE0000003L)
105 | #define OLS_ERROR_PCI_READ_CONFIG (0xE0000004L)
106 |
107 | //-----------------------------------------------------------------------------
108 | //
109 | // Support Macros
110 | //
111 | //-----------------------------------------------------------------------------
112 |
113 | // Bus Number, Device Number and Function Number to PCI Device Address
114 | #define PciBusDevFunc(Bus, Dev, Func) ((Bus&0xFF)<<8) | ((Dev&0x1F)<<3) | (Func&7)
115 | // PCI Device Address to Bus Number
116 | #define PciGetBus(address) ((address>>8) & 0xFF)
117 | // PCI Device Address to Device Number
118 | #define PciGetDev(address) ((address>>3) & 0x1F)
119 | // PCI Device Address to Function Number
120 | #define PciGetFunc(address) (address&7)
121 |
122 | //-----------------------------------------------------------------------------
123 | //
124 | // Typedef Struct
125 | //
126 | //-----------------------------------------------------------------------------
127 |
128 | typedef unsigned char UCHAR;
129 | typedef unsigned short USHORT;
130 | typedef unsigned long ULONG;
131 |
132 | #include
133 |
134 | #pragma pack(push,4)
135 |
136 | typedef struct _OLS_WRITE_MSR_INPUT {
137 | ULONG Register;
138 | ULARGE_INTEGER Value;
139 | } OLS_WRITE_MSR_INPUT;
140 |
141 | typedef struct _OLS_WRITE_IO_PORT_INPUT {
142 | ULONG PortNumber;
143 | union {
144 | ULONG LongData;
145 | USHORT ShortData;
146 | UCHAR CharData;
147 | };
148 | } OLS_WRITE_IO_PORT_INPUT;
149 |
150 | typedef struct _OLS_READ_PCI_CONFIG_INPUT {
151 | ULONG PciAddress;
152 | ULONG PciOffset;
153 | } OLS_READ_PCI_CONFIG_INPUT;
154 |
155 | typedef struct _OLS_WRITE_PCI_CONFIG_INPUT {
156 | ULONG PciAddress;
157 | ULONG PciOffset;
158 | UCHAR Data[1];
159 | } OLS_WRITE_PCI_CONFIG_INPUT;
160 |
161 | typedef LARGE_INTEGER PHYSICAL_ADDRESS;
162 |
163 | typedef struct _OLS_READ_MEMORY_INPUT {
164 | PHYSICAL_ADDRESS Address;
165 | ULONG UnitSize;
166 | ULONG Count;
167 | } OLS_READ_MEMORY_INPUT;
168 |
169 | typedef struct _OLS_WRITE_MEMORY_INPUT {
170 | PHYSICAL_ADDRESS Address;
171 | ULONG UnitSize;
172 | ULONG Count;
173 | UCHAR Data[1];
174 | } OLS_WRITE_MEMORY_INPUT;
175 |
176 | #pragma pack(pop)
177 |
--------------------------------------------------------------------------------
/drv/DriverManage.c:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------------
2 | // Author : hiyohiyo
3 | // Mail : hiyohiyo@crystalmark.info
4 | // Web : http://openlibsys.org/
5 | // License : The modified BSD license
6 | //
7 | // Copyright 2007 OpenLibSys.org. All rights reserved.
8 | //-----------------------------------------------------------------------------
9 |
10 | #include
11 | #include
12 | #include "DriverApi.h"
13 |
14 | //Driver Id
15 | #define OLS_DRIVER_ID _T("WinRing0_1_2_0")
16 | //Diever Show Name
17 | #define DRIVER_ID _T("WinRing0")
18 | //The main Handle
19 | extern HANDLE gHandle;
20 | //-----------------------------------------------------------------------------
21 | //
22 | // Initialize
23 | //
24 | //-----------------------------------------------------------------------------
25 |
26 | //please use absolute file path
27 | BOOL Initialize(LPCTSTR DriverPath)
28 | {
29 | //32 bit system use 32 bit dirver
30 | //64 bit system use 64 bit dirver
31 | //BOOL bIsWow64 = FALSE;
32 | //IsWow64Process(GetCurrentProcess(), &bIsWow64);
33 | //if (bIsWow64)InstallDriver(DRIVER_ID, DRIVER_x64);
34 | //else InstallDriver(DRIVER_ID, DRIVER_x86);
35 | if (InstallDriver(DRIVER_ID, DriverPath))
36 | if (StartDriver(DRIVER_ID))
37 | if(OpenDriver())return TRUE;
38 | return FALSE;
39 | }
40 |
41 | //-----------------------------------------------------------------------------
42 | //
43 | // Deinitialize
44 | //
45 | //-----------------------------------------------------------------------------
46 |
47 | BOOL Deinitialize()
48 | {
49 | StopDriver(DRIVER_ID);
50 | RemoveDriver(DRIVER_ID);
51 | return TRUE;
52 | }
53 |
54 |
55 | //-----------------------------------------------------------------------------
56 | //
57 | // Open Driver
58 | //
59 | //-----------------------------------------------------------------------------
60 |
61 | BOOL OpenDriver()
62 | {
63 | gHandle = CreateFile(
64 | _T("\\\\.\\") OLS_DRIVER_ID,
65 | GENERIC_READ | GENERIC_WRITE,
66 | 0,
67 | NULL,
68 | OPEN_EXISTING,
69 | FILE_ATTRIBUTE_NORMAL,
70 | NULL
71 | );
72 | int error = GetLastError();
73 |
74 | if (gHandle == INVALID_HANDLE_VALUE)
75 | {
76 | return FALSE;
77 | }
78 | return TRUE;
79 | }
80 |
81 |
82 | //-----------------------------------------------------------------------------
83 | //
84 | // Install Driver
85 | //
86 | //-----------------------------------------------------------------------------
87 |
88 | BOOL InstallDriver(LPCTSTR DriverId, LPCTSTR DriverPath)
89 | {
90 | SC_HANDLE hSCManager = NULL;
91 | SC_HANDLE hService = NULL;
92 | BOOL rCode = FALSE;
93 | DWORD error = NO_ERROR;
94 |
95 | hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
96 | if (hSCManager == NULL)
97 | {
98 | return FALSE;
99 | }
100 |
101 | hService = CreateService(hSCManager,
102 | DriverId,
103 | DriverId,
104 | SERVICE_ALL_ACCESS,
105 | SERVICE_KERNEL_DRIVER,
106 | SERVICE_DEMAND_START,
107 | SERVICE_ERROR_NORMAL,
108 | DriverPath,
109 | NULL,
110 | NULL,
111 | NULL,
112 | NULL,
113 | NULL
114 | );
115 |
116 | if (hService == NULL)
117 | {
118 | error = GetLastError();
119 | if (error == ERROR_SERVICE_EXISTS)
120 | {
121 | rCode = TRUE;
122 | }
123 | }
124 | else
125 | {
126 | rCode = TRUE;
127 | CloseServiceHandle(hService);
128 | }
129 | CloseServiceHandle(hSCManager);
130 | return rCode;
131 | }
132 |
133 |
134 | //-----------------------------------------------------------------------------
135 | //
136 | // Remove Driver
137 | //
138 | //-----------------------------------------------------------------------------
139 |
140 | BOOL RemoveDriver(LPCTSTR DriverId)
141 | {
142 | SC_HANDLE hSCManager = NULL;
143 | SC_HANDLE hService = NULL;
144 | BOOL rCode = FALSE;
145 |
146 | hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
147 | if (hSCManager == NULL)
148 | {
149 | return FALSE;
150 | }
151 |
152 | hService = OpenService(hSCManager, DriverId, SERVICE_ALL_ACCESS);
153 | if (hService == NULL)
154 | {
155 | rCode = TRUE;
156 | }
157 | else
158 | {
159 | rCode = DeleteService(hService);
160 | CloseServiceHandle(hService);
161 | }
162 | CloseServiceHandle(hSCManager);
163 | return rCode;
164 | }
165 |
166 |
167 | //-----------------------------------------------------------------------------
168 | //
169 | // Start Driver
170 | //
171 | //-----------------------------------------------------------------------------
172 |
173 | BOOL StartDriver(LPCTSTR DriverId)
174 | {
175 | SC_HANDLE hSCManager = NULL;
176 | SC_HANDLE hService = NULL;
177 | BOOL rCode = FALSE;
178 | DWORD error = NO_ERROR;
179 |
180 | hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
181 | if (hSCManager == NULL)
182 | {
183 | return FALSE;
184 | }
185 |
186 | hService = OpenService(hSCManager, DriverId, SERVICE_ALL_ACCESS);
187 |
188 | if (hService != NULL)
189 | {
190 | if (!StartService(hService, 0, NULL))
191 | {
192 | if (GetLastError() == ERROR_SERVICE_ALREADY_RUNNING)
193 | {
194 | rCode = TRUE;
195 | }
196 | }
197 | else
198 | {
199 | rCode = TRUE;
200 | }
201 | CloseServiceHandle(hService);
202 | }
203 | CloseServiceHandle(hSCManager);
204 | return rCode;
205 | }
206 |
207 |
208 | //-----------------------------------------------------------------------------
209 | //
210 | // Stop Driver
211 | //
212 | //-----------------------------------------------------------------------------
213 |
214 | BOOL StopDriver(LPCTSTR DriverId)
215 | {
216 | SC_HANDLE hSCManager = NULL;
217 | SC_HANDLE hService = NULL;
218 | BOOL rCode = FALSE;
219 | SERVICE_STATUS serviceStatus;
220 | DWORD error = NO_ERROR;
221 |
222 | hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
223 | if (hSCManager == NULL)
224 | {
225 | return FALSE;
226 | }
227 |
228 | hService = OpenService(hSCManager, DriverId, SERVICE_ALL_ACCESS);
229 |
230 | if (hService != NULL)
231 | {
232 | rCode = ControlService(hService, SERVICE_CONTROL_STOP, &serviceStatus);
233 | CloseServiceHandle(hService);
234 | }
235 | CloseServiceHandle(hSCManager);
236 | return rCode;
237 | }
238 |
--------------------------------------------------------------------------------