update
This commit is contained in:
parent
0e3352c444
commit
c898b202f3
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
674
LICENSE.txt
Normal file
674
LICENSE.txt
Normal file
@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
62
hook_lib.sln
62
hook_lib.sln
@ -1,31 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.33130.400
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hook_lib", "hook_lib\hook_lib.vcxproj", "{D84DCA02-7BEE-40E4-81D5-75EB0AA0A9D3}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{D84DCA02-7BEE-40E4-81D5-75EB0AA0A9D3}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{D84DCA02-7BEE-40E4-81D5-75EB0AA0A9D3}.Debug|x64.Build.0 = Debug|x64
|
||||
{D84DCA02-7BEE-40E4-81D5-75EB0AA0A9D3}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{D84DCA02-7BEE-40E4-81D5-75EB0AA0A9D3}.Debug|x86.Build.0 = Debug|Win32
|
||||
{D84DCA02-7BEE-40E4-81D5-75EB0AA0A9D3}.Release|x64.ActiveCfg = Release|x64
|
||||
{D84DCA02-7BEE-40E4-81D5-75EB0AA0A9D3}.Release|x64.Build.0 = Release|x64
|
||||
{D84DCA02-7BEE-40E4-81D5-75EB0AA0A9D3}.Release|x86.ActiveCfg = Release|Win32
|
||||
{D84DCA02-7BEE-40E4-81D5-75EB0AA0A9D3}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {58937352-3EDA-4AEE-A7FD-C21D6955F38B}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.33130.400
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hook_lib", "hook_lib\hook_lib.vcxproj", "{D84DCA02-7BEE-40E4-81D5-75EB0AA0A9D3}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{D84DCA02-7BEE-40E4-81D5-75EB0AA0A9D3}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{D84DCA02-7BEE-40E4-81D5-75EB0AA0A9D3}.Debug|x64.Build.0 = Debug|x64
|
||||
{D84DCA02-7BEE-40E4-81D5-75EB0AA0A9D3}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{D84DCA02-7BEE-40E4-81D5-75EB0AA0A9D3}.Debug|x86.Build.0 = Debug|Win32
|
||||
{D84DCA02-7BEE-40E4-81D5-75EB0AA0A9D3}.Release|x64.ActiveCfg = Release|x64
|
||||
{D84DCA02-7BEE-40E4-81D5-75EB0AA0A9D3}.Release|x64.Build.0 = Release|x64
|
||||
{D84DCA02-7BEE-40E4-81D5-75EB0AA0A9D3}.Release|x86.ActiveCfg = Release|Win32
|
||||
{D84DCA02-7BEE-40E4-81D5-75EB0AA0A9D3}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {58937352-3EDA-4AEE-A7FD-C21D6955F38B}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
3000
hook_lib/Main.cpp
3000
hook_lib/Main.cpp
File diff suppressed because it is too large
Load Diff
@ -1,117 +1,117 @@
|
||||
#pragma once
|
||||
#include <Windows.h>
|
||||
#include <winternl.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#include <dxgi1_5.h>
|
||||
#include <d3d12.h>
|
||||
#include <intrin.h>
|
||||
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
#pragma comment(lib, "user32.lib")
|
||||
|
||||
#include "common/utils/hook.hpp"
|
||||
#include "common/utils/hardware_breakpoint.hpp"
|
||||
#include "functions.hpp"
|
||||
#include "structs.h"
|
||||
#include "assets.h"
|
||||
|
||||
#include "ini.h"
|
||||
#include "json.hpp"
|
||||
#include "splashscreen.hpp"
|
||||
|
||||
extern void* exception_handler;
|
||||
|
||||
#define base g_Addrs.ModuleBase
|
||||
|
||||
#pragma warning(disable:4996)
|
||||
#pragma comment(lib, "Gdi32.lib")
|
||||
|
||||
|
||||
|
||||
|
||||
#define INRANGE(x, a, b) (x >= a && x <= b)
|
||||
#define GET_BITS( x ) (INRANGE((x&(~0x20)),'A','F') ? ((x&(~0x20)) - 'A' + 0xa) : (INRANGE(x,'0','9') ? x - '0' : 0))
|
||||
#define GET_BYTE( x ) (GET_BITS(x[0]) << 4 | GET_BITS(x[1]))
|
||||
|
||||
struct menu_variables {
|
||||
bool bInitiateMenu;
|
||||
bool bMenuOpen;
|
||||
|
||||
};
|
||||
extern menu_variables vars;
|
||||
|
||||
void nlog(const char* str, ...);
|
||||
uintptr_t find_pattern(const char* module_name, const char* pattern);
|
||||
uintptr_t find_pattern(uintptr_t start, const char* module_name, const char* pattern);
|
||||
|
||||
size_t operator"" _b(size_t val);
|
||||
size_t reverse_b(size_t val);
|
||||
size_t reverse_b(const void* val);
|
||||
|
||||
size_t operator"" _g(size_t val);
|
||||
size_t reverse_g(size_t val);
|
||||
size_t reverse_g(const void* val);
|
||||
|
||||
void log(const char* str);
|
||||
void log(const char* file, const char* str);
|
||||
|
||||
struct DvarPair
|
||||
{
|
||||
const char* m_key;
|
||||
const char* m_value;
|
||||
};
|
||||
inline bool IsBadPointer(uintptr_t* ptr)
|
||||
{
|
||||
__try
|
||||
{
|
||||
volatile auto result = *ptr;
|
||||
}
|
||||
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
struct DvarMap
|
||||
{
|
||||
DvarPair m_pairs[10000];
|
||||
};
|
||||
extern int g_dvarmapcount;
|
||||
extern DvarPair g_dvarmap[6821];
|
||||
|
||||
struct shaderOverride_t
|
||||
{
|
||||
float scrollRateX;
|
||||
float scrollRateY;
|
||||
float scrollRateR;
|
||||
float tilingX;
|
||||
float tilingY;
|
||||
float rotation;
|
||||
float alpha;
|
||||
float emissive;
|
||||
float atlasTime;
|
||||
};
|
||||
|
||||
struct GfxSceneHudOutlineInfo
|
||||
{
|
||||
unsigned int color;
|
||||
float scopeStencil;
|
||||
bool drawOccludedPixels;
|
||||
bool drawNonOccludedPixels;
|
||||
bool fill;
|
||||
bool useAlternateColor;
|
||||
bool forSpectator;
|
||||
bool specialActive;
|
||||
unsigned __int8 renderMode;
|
||||
unsigned __int8 lineWidth;
|
||||
unsigned __int8 temperatureSet;
|
||||
unsigned int mapEntLookup;
|
||||
float temperatureBase;
|
||||
float temperatureScale;
|
||||
float characterEVOffset;
|
||||
};
|
||||
|
||||
#pragma once
|
||||
#include <Windows.h>
|
||||
#include <winternl.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#include <dxgi1_5.h>
|
||||
#include <d3d12.h>
|
||||
#include <intrin.h>
|
||||
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
#pragma comment(lib, "user32.lib")
|
||||
|
||||
#include "common/utils/hook.hpp"
|
||||
#include "common/utils/hardware_breakpoint.hpp"
|
||||
#include "functions.hpp"
|
||||
#include "structs.h"
|
||||
#include "assets.h"
|
||||
|
||||
#include "ini.h"
|
||||
#include "json.hpp"
|
||||
#include "splashscreen.hpp"
|
||||
|
||||
extern void* exception_handler;
|
||||
|
||||
#define base g_Addrs.ModuleBase
|
||||
|
||||
#pragma warning(disable:4996)
|
||||
#pragma comment(lib, "Gdi32.lib")
|
||||
|
||||
|
||||
|
||||
|
||||
#define INRANGE(x, a, b) (x >= a && x <= b)
|
||||
#define GET_BITS( x ) (INRANGE((x&(~0x20)),'A','F') ? ((x&(~0x20)) - 'A' + 0xa) : (INRANGE(x,'0','9') ? x - '0' : 0))
|
||||
#define GET_BYTE( x ) (GET_BITS(x[0]) << 4 | GET_BITS(x[1]))
|
||||
|
||||
struct menu_variables {
|
||||
bool bInitiateMenu;
|
||||
bool bMenuOpen;
|
||||
|
||||
};
|
||||
extern menu_variables vars;
|
||||
|
||||
void nlog(const char* str, ...);
|
||||
uintptr_t find_pattern(const char* module_name, const char* pattern);
|
||||
uintptr_t find_pattern(uintptr_t start, const char* module_name, const char* pattern);
|
||||
|
||||
size_t operator"" _b(size_t val);
|
||||
size_t reverse_b(size_t val);
|
||||
size_t reverse_b(const void* val);
|
||||
|
||||
size_t operator"" _g(size_t val);
|
||||
size_t reverse_g(size_t val);
|
||||
size_t reverse_g(const void* val);
|
||||
|
||||
void log(const char* str);
|
||||
void log(const char* file, const char* str);
|
||||
|
||||
struct DvarPair
|
||||
{
|
||||
const char* m_key;
|
||||
const char* m_value;
|
||||
};
|
||||
inline bool IsBadPointer(uintptr_t* ptr)
|
||||
{
|
||||
__try
|
||||
{
|
||||
volatile auto result = *ptr;
|
||||
}
|
||||
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
struct DvarMap
|
||||
{
|
||||
DvarPair m_pairs[10000];
|
||||
};
|
||||
extern int g_dvarmapcount;
|
||||
extern DvarPair g_dvarmap[6821];
|
||||
|
||||
struct shaderOverride_t
|
||||
{
|
||||
float scrollRateX;
|
||||
float scrollRateY;
|
||||
float scrollRateR;
|
||||
float tilingX;
|
||||
float tilingY;
|
||||
float rotation;
|
||||
float alpha;
|
||||
float emissive;
|
||||
float atlasTime;
|
||||
};
|
||||
|
||||
struct GfxSceneHudOutlineInfo
|
||||
{
|
||||
unsigned int color;
|
||||
float scopeStencil;
|
||||
bool drawOccludedPixels;
|
||||
bool drawNonOccludedPixels;
|
||||
bool fill;
|
||||
bool useAlternateColor;
|
||||
bool forSpectator;
|
||||
bool specialActive;
|
||||
unsigned __int8 renderMode;
|
||||
unsigned __int8 lineWidth;
|
||||
unsigned __int8 temperatureSet;
|
||||
unsigned int mapEntLookup;
|
||||
float temperatureBase;
|
||||
float temperatureScale;
|
||||
float characterEVOffset;
|
||||
};
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "assets.h"
|
||||
|
||||
|
||||
void test() {
|
||||
sizeof(VehicleDef);
|
||||
#include "assets.h"
|
||||
|
||||
|
||||
void test() {
|
||||
sizeof(VehicleDef);
|
||||
}
|
8766
hook_lib/assets.h
8766
hook_lib/assets.h
File diff suppressed because it is too large
Load Diff
@ -1,85 +1,85 @@
|
||||
#include "minidump.hpp"
|
||||
|
||||
#include <DbgHelp.h>
|
||||
#pragma comment(lib, "dbghelp.lib")
|
||||
|
||||
namespace exception
|
||||
{
|
||||
namespace
|
||||
{
|
||||
constexpr MINIDUMP_TYPE get_minidump_type()
|
||||
{
|
||||
constexpr auto type = MiniDumpIgnoreInaccessibleMemory //
|
||||
| MiniDumpWithHandleData //
|
||||
| MiniDumpScanMemory //
|
||||
| MiniDumpWithProcessThreadData //
|
||||
| MiniDumpWithFullMemoryInfo //
|
||||
| MiniDumpWithThreadInfo //
|
||||
| MiniDumpWithUnloadedModules;
|
||||
|
||||
return static_cast<MINIDUMP_TYPE>(type);
|
||||
}
|
||||
|
||||
std::string get_temp_filename()
|
||||
{
|
||||
char filename[MAX_PATH] = {0};
|
||||
char pathname[MAX_PATH] = {0};
|
||||
|
||||
GetTempPathA(sizeof(pathname), pathname);
|
||||
GetTempFileNameA(pathname, "boiii-", 0, filename);
|
||||
return filename;
|
||||
}
|
||||
|
||||
HANDLE write_dump_to_temp_file(const LPEXCEPTION_POINTERS exceptioninfo)
|
||||
{
|
||||
MINIDUMP_EXCEPTION_INFORMATION minidump_exception_info = {GetCurrentThreadId(), exceptioninfo, FALSE};
|
||||
|
||||
auto* const file_handle = CreateFileA(get_temp_filename().data(), GENERIC_WRITE | GENERIC_READ,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_ALWAYS,
|
||||
FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE,
|
||||
nullptr);
|
||||
|
||||
if (!MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), file_handle, get_minidump_type(),
|
||||
&minidump_exception_info,
|
||||
nullptr,
|
||||
nullptr))
|
||||
{
|
||||
MessageBoxA(nullptr, "There was an error creating the minidump! Hit OK to close the program.",
|
||||
"Minidump Error", MB_OK | MB_ICONERROR);
|
||||
TerminateProcess(GetCurrentProcess(), 123);
|
||||
}
|
||||
|
||||
return file_handle;
|
||||
}
|
||||
|
||||
std::string read_file(const HANDLE file_handle)
|
||||
{
|
||||
FlushFileBuffers(file_handle);
|
||||
SetFilePointer(file_handle, 0, nullptr, FILE_BEGIN);
|
||||
|
||||
std::string buffer{};
|
||||
|
||||
DWORD bytes_read = 0;
|
||||
char temp_bytes[0x2000];
|
||||
|
||||
do
|
||||
{
|
||||
if (!ReadFile(file_handle, temp_bytes, sizeof(temp_bytes), &bytes_read, nullptr))
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
buffer.append(temp_bytes, bytes_read);
|
||||
}
|
||||
while (bytes_read == sizeof(temp_bytes));
|
||||
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
||||
std::string create_minidump(const LPEXCEPTION_POINTERS exceptioninfo)
|
||||
{
|
||||
const utils::nt::handle file_handle = write_dump_to_temp_file(exceptioninfo);
|
||||
return read_file(file_handle);
|
||||
}
|
||||
}
|
||||
#include "minidump.hpp"
|
||||
|
||||
#include <DbgHelp.h>
|
||||
#pragma comment(lib, "dbghelp.lib")
|
||||
|
||||
namespace exception
|
||||
{
|
||||
namespace
|
||||
{
|
||||
constexpr MINIDUMP_TYPE get_minidump_type()
|
||||
{
|
||||
constexpr auto type = MiniDumpIgnoreInaccessibleMemory //
|
||||
| MiniDumpWithHandleData //
|
||||
| MiniDumpScanMemory //
|
||||
| MiniDumpWithProcessThreadData //
|
||||
| MiniDumpWithFullMemoryInfo //
|
||||
| MiniDumpWithThreadInfo //
|
||||
| MiniDumpWithUnloadedModules;
|
||||
|
||||
return static_cast<MINIDUMP_TYPE>(type);
|
||||
}
|
||||
|
||||
std::string get_temp_filename()
|
||||
{
|
||||
char filename[MAX_PATH] = {0};
|
||||
char pathname[MAX_PATH] = {0};
|
||||
|
||||
GetTempPathA(sizeof(pathname), pathname);
|
||||
GetTempFileNameA(pathname, "boiii-", 0, filename);
|
||||
return filename;
|
||||
}
|
||||
|
||||
HANDLE write_dump_to_temp_file(const LPEXCEPTION_POINTERS exceptioninfo)
|
||||
{
|
||||
MINIDUMP_EXCEPTION_INFORMATION minidump_exception_info = {GetCurrentThreadId(), exceptioninfo, FALSE};
|
||||
|
||||
auto* const file_handle = CreateFileA(get_temp_filename().data(), GENERIC_WRITE | GENERIC_READ,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_ALWAYS,
|
||||
FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE,
|
||||
nullptr);
|
||||
|
||||
if (!MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), file_handle, get_minidump_type(),
|
||||
&minidump_exception_info,
|
||||
nullptr,
|
||||
nullptr))
|
||||
{
|
||||
MessageBoxA(nullptr, "There was an error creating the minidump! Hit OK to close the program.",
|
||||
"Minidump Error", MB_OK | MB_ICONERROR);
|
||||
TerminateProcess(GetCurrentProcess(), 123);
|
||||
}
|
||||
|
||||
return file_handle;
|
||||
}
|
||||
|
||||
std::string read_file(const HANDLE file_handle)
|
||||
{
|
||||
FlushFileBuffers(file_handle);
|
||||
SetFilePointer(file_handle, 0, nullptr, FILE_BEGIN);
|
||||
|
||||
std::string buffer{};
|
||||
|
||||
DWORD bytes_read = 0;
|
||||
char temp_bytes[0x2000];
|
||||
|
||||
do
|
||||
{
|
||||
if (!ReadFile(file_handle, temp_bytes, sizeof(temp_bytes), &bytes_read, nullptr))
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
buffer.append(temp_bytes, bytes_read);
|
||||
}
|
||||
while (bytes_read == sizeof(temp_bytes));
|
||||
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
||||
std::string create_minidump(const LPEXCEPTION_POINTERS exceptioninfo)
|
||||
{
|
||||
const utils::nt::handle file_handle = write_dump_to_temp_file(exceptioninfo);
|
||||
return read_file(file_handle);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "../utils/nt.hpp"
|
||||
|
||||
namespace exception
|
||||
{
|
||||
std::string create_minidump(LPEXCEPTION_POINTERS exceptioninfo);
|
||||
}
|
||||
#pragma once
|
||||
|
||||
#include "../utils/nt.hpp"
|
||||
|
||||
namespace exception
|
||||
{
|
||||
std::string create_minidump(LPEXCEPTION_POINTERS exceptioninfo);
|
||||
}
|
||||
|
@ -1,185 +1,185 @@
|
||||
/*
|
||||
* MinHook - The Minimalistic API Hooking Library for x64/x86
|
||||
* Copyright (C) 2009-2017 Tsuda Kageyu.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !(defined _M_IX86) && !(defined _M_X64) && !(defined __i386__) && !(defined __x86_64__)
|
||||
#error MinHook supports only x86 and x64 systems.
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
// MinHook Error Codes.
|
||||
typedef enum MH_STATUS
|
||||
{
|
||||
// Unknown error. Should not be returned.
|
||||
MH_UNKNOWN = -1,
|
||||
|
||||
// Successful.
|
||||
MH_OK = 0,
|
||||
|
||||
// MinHook is already initialized.
|
||||
MH_ERROR_ALREADY_INITIALIZED,
|
||||
|
||||
// MinHook is not initialized yet, or already uninitialized.
|
||||
MH_ERROR_NOT_INITIALIZED,
|
||||
|
||||
// The hook for the specified target function is already created.
|
||||
MH_ERROR_ALREADY_CREATED,
|
||||
|
||||
// The hook for the specified target function is not created yet.
|
||||
MH_ERROR_NOT_CREATED,
|
||||
|
||||
// The hook for the specified target function is already enabled.
|
||||
MH_ERROR_ENABLED,
|
||||
|
||||
// The hook for the specified target function is not enabled yet, or already
|
||||
// disabled.
|
||||
MH_ERROR_DISABLED,
|
||||
|
||||
// The specified pointer is invalid. It points the address of non-allocated
|
||||
// and/or non-executable region.
|
||||
MH_ERROR_NOT_EXECUTABLE,
|
||||
|
||||
// The specified target function cannot be hooked.
|
||||
MH_ERROR_UNSUPPORTED_FUNCTION,
|
||||
|
||||
// Failed to allocate memory.
|
||||
MH_ERROR_MEMORY_ALLOC,
|
||||
|
||||
// Failed to change the memory protection.
|
||||
MH_ERROR_MEMORY_PROTECT,
|
||||
|
||||
// The specified module is not loaded.
|
||||
MH_ERROR_MODULE_NOT_FOUND,
|
||||
|
||||
// The specified function is not found.
|
||||
MH_ERROR_FUNCTION_NOT_FOUND
|
||||
}
|
||||
MH_STATUS;
|
||||
|
||||
// Can be passed as a parameter to MH_EnableHook, MH_DisableHook,
|
||||
// MH_QueueEnableHook or MH_QueueDisableHook.
|
||||
#define MH_ALL_HOOKS NULL
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Initialize the MinHook library. You must call this function EXACTLY ONCE
|
||||
// at the beginning of your program.
|
||||
MH_STATUS WINAPI MH_Initialize(VOID);
|
||||
|
||||
// Uninitialize the MinHook library. You must call this function EXACTLY
|
||||
// ONCE at the end of your program.
|
||||
MH_STATUS WINAPI MH_Uninitialize(VOID);
|
||||
|
||||
// Creates a hook for the specified target function, in disabled state.
|
||||
// Parameters:
|
||||
// pTarget [in] A pointer to the target function, which will be
|
||||
// overridden by the detour function.
|
||||
// pDetour [in] A pointer to the detour function, which will override
|
||||
// the target function.
|
||||
// ppOriginal [out] A pointer to the trampoline function, which will be
|
||||
// used to call the original target function.
|
||||
// This parameter can be NULL.
|
||||
MH_STATUS WINAPI MH_CreateHook(LPVOID pTarget, LPVOID pDetour, LPVOID *ppOriginal);
|
||||
|
||||
// Creates a hook for the specified API function, in disabled state.
|
||||
// Parameters:
|
||||
// pszModule [in] A pointer to the loaded module name which contains the
|
||||
// target function.
|
||||
// pszProcName [in] A pointer to the target function name, which will be
|
||||
// overridden by the detour function.
|
||||
// pDetour [in] A pointer to the detour function, which will override
|
||||
// the target function.
|
||||
// ppOriginal [out] A pointer to the trampoline function, which will be
|
||||
// used to call the original target function.
|
||||
// This parameter can be NULL.
|
||||
MH_STATUS WINAPI MH_CreateHookApi(
|
||||
LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, LPVOID *ppOriginal);
|
||||
|
||||
// Creates a hook for the specified API function, in disabled state.
|
||||
// Parameters:
|
||||
// pszModule [in] A pointer to the loaded module name which contains the
|
||||
// target function.
|
||||
// pszProcName [in] A pointer to the target function name, which will be
|
||||
// overridden by the detour function.
|
||||
// pDetour [in] A pointer to the detour function, which will override
|
||||
// the target function.
|
||||
// ppOriginal [out] A pointer to the trampoline function, which will be
|
||||
// used to call the original target function.
|
||||
// This parameter can be NULL.
|
||||
// ppTarget [out] A pointer to the target function, which will be used
|
||||
// with other functions.
|
||||
// This parameter can be NULL.
|
||||
MH_STATUS WINAPI MH_CreateHookApiEx(
|
||||
LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, LPVOID *ppOriginal, LPVOID *ppTarget);
|
||||
|
||||
// Removes an already created hook.
|
||||
// Parameters:
|
||||
// pTarget [in] A pointer to the target function.
|
||||
MH_STATUS WINAPI MH_RemoveHook(LPVOID pTarget);
|
||||
|
||||
// Enables an already created hook.
|
||||
// Parameters:
|
||||
// pTarget [in] A pointer to the target function.
|
||||
// If this parameter is MH_ALL_HOOKS, all created hooks are
|
||||
// enabled in one go.
|
||||
MH_STATUS WINAPI MH_EnableHook(LPVOID pTarget);
|
||||
|
||||
// Disables an already created hook.
|
||||
// Parameters:
|
||||
// pTarget [in] A pointer to the target function.
|
||||
// If this parameter is MH_ALL_HOOKS, all created hooks are
|
||||
// disabled in one go.
|
||||
MH_STATUS WINAPI MH_DisableHook(LPVOID pTarget);
|
||||
|
||||
// Queues to enable an already created hook.
|
||||
// Parameters:
|
||||
// pTarget [in] A pointer to the target function.
|
||||
// If this parameter is MH_ALL_HOOKS, all created hooks are
|
||||
// queued to be enabled.
|
||||
MH_STATUS WINAPI MH_QueueEnableHook(LPVOID pTarget);
|
||||
|
||||
// Queues to disable an already created hook.
|
||||
// Parameters:
|
||||
// pTarget [in] A pointer to the target function.
|
||||
// If this parameter is MH_ALL_HOOKS, all created hooks are
|
||||
// queued to be disabled.
|
||||
MH_STATUS WINAPI MH_QueueDisableHook(LPVOID pTarget);
|
||||
|
||||
// Applies all queued changes in one go.
|
||||
MH_STATUS WINAPI MH_ApplyQueued(VOID);
|
||||
|
||||
// Translates the MH_STATUS to its name as a string.
|
||||
const char * WINAPI MH_StatusToString(MH_STATUS status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* MinHook - The Minimalistic API Hooking Library for x64/x86
|
||||
* Copyright (C) 2009-2017 Tsuda Kageyu.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !(defined _M_IX86) && !(defined _M_X64) && !(defined __i386__) && !(defined __x86_64__)
|
||||
#error MinHook supports only x86 and x64 systems.
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
// MinHook Error Codes.
|
||||
typedef enum MH_STATUS
|
||||
{
|
||||
// Unknown error. Should not be returned.
|
||||
MH_UNKNOWN = -1,
|
||||
|
||||
// Successful.
|
||||
MH_OK = 0,
|
||||
|
||||
// MinHook is already initialized.
|
||||
MH_ERROR_ALREADY_INITIALIZED,
|
||||
|
||||
// MinHook is not initialized yet, or already uninitialized.
|
||||
MH_ERROR_NOT_INITIALIZED,
|
||||
|
||||
// The hook for the specified target function is already created.
|
||||
MH_ERROR_ALREADY_CREATED,
|
||||
|
||||
// The hook for the specified target function is not created yet.
|
||||
MH_ERROR_NOT_CREATED,
|
||||
|
||||
// The hook for the specified target function is already enabled.
|
||||
MH_ERROR_ENABLED,
|
||||
|
||||
// The hook for the specified target function is not enabled yet, or already
|
||||
// disabled.
|
||||
MH_ERROR_DISABLED,
|
||||
|
||||
// The specified pointer is invalid. It points the address of non-allocated
|
||||
// and/or non-executable region.
|
||||
MH_ERROR_NOT_EXECUTABLE,
|
||||
|
||||
// The specified target function cannot be hooked.
|
||||
MH_ERROR_UNSUPPORTED_FUNCTION,
|
||||
|
||||
// Failed to allocate memory.
|
||||
MH_ERROR_MEMORY_ALLOC,
|
||||
|
||||
// Failed to change the memory protection.
|
||||
MH_ERROR_MEMORY_PROTECT,
|
||||
|
||||
// The specified module is not loaded.
|
||||
MH_ERROR_MODULE_NOT_FOUND,
|
||||
|
||||
// The specified function is not found.
|
||||
MH_ERROR_FUNCTION_NOT_FOUND
|
||||
}
|
||||
MH_STATUS;
|
||||
|
||||
// Can be passed as a parameter to MH_EnableHook, MH_DisableHook,
|
||||
// MH_QueueEnableHook or MH_QueueDisableHook.
|
||||
#define MH_ALL_HOOKS NULL
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Initialize the MinHook library. You must call this function EXACTLY ONCE
|
||||
// at the beginning of your program.
|
||||
MH_STATUS WINAPI MH_Initialize(VOID);
|
||||
|
||||
// Uninitialize the MinHook library. You must call this function EXACTLY
|
||||
// ONCE at the end of your program.
|
||||
MH_STATUS WINAPI MH_Uninitialize(VOID);
|
||||
|
||||
// Creates a hook for the specified target function, in disabled state.
|
||||
// Parameters:
|
||||
// pTarget [in] A pointer to the target function, which will be
|
||||
// overridden by the detour function.
|
||||
// pDetour [in] A pointer to the detour function, which will override
|
||||
// the target function.
|
||||
// ppOriginal [out] A pointer to the trampoline function, which will be
|
||||
// used to call the original target function.
|
||||
// This parameter can be NULL.
|
||||
MH_STATUS WINAPI MH_CreateHook(LPVOID pTarget, LPVOID pDetour, LPVOID *ppOriginal);
|
||||
|
||||
// Creates a hook for the specified API function, in disabled state.
|
||||
// Parameters:
|
||||
// pszModule [in] A pointer to the loaded module name which contains the
|
||||
// target function.
|
||||
// pszProcName [in] A pointer to the target function name, which will be
|
||||
// overridden by the detour function.
|
||||
// pDetour [in] A pointer to the detour function, which will override
|
||||
// the target function.
|
||||
// ppOriginal [out] A pointer to the trampoline function, which will be
|
||||
// used to call the original target function.
|
||||
// This parameter can be NULL.
|
||||
MH_STATUS WINAPI MH_CreateHookApi(
|
||||
LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, LPVOID *ppOriginal);
|
||||
|
||||
// Creates a hook for the specified API function, in disabled state.
|
||||
// Parameters:
|
||||
// pszModule [in] A pointer to the loaded module name which contains the
|
||||
// target function.
|
||||
// pszProcName [in] A pointer to the target function name, which will be
|
||||
// overridden by the detour function.
|
||||
// pDetour [in] A pointer to the detour function, which will override
|
||||
// the target function.
|
||||
// ppOriginal [out] A pointer to the trampoline function, which will be
|
||||
// used to call the original target function.
|
||||
// This parameter can be NULL.
|
||||
// ppTarget [out] A pointer to the target function, which will be used
|
||||
// with other functions.
|
||||
// This parameter can be NULL.
|
||||
MH_STATUS WINAPI MH_CreateHookApiEx(
|
||||
LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, LPVOID *ppOriginal, LPVOID *ppTarget);
|
||||
|
||||
// Removes an already created hook.
|
||||
// Parameters:
|
||||
// pTarget [in] A pointer to the target function.
|
||||
MH_STATUS WINAPI MH_RemoveHook(LPVOID pTarget);
|
||||
|
||||
// Enables an already created hook.
|
||||
// Parameters:
|
||||
// pTarget [in] A pointer to the target function.
|
||||
// If this parameter is MH_ALL_HOOKS, all created hooks are
|
||||
// enabled in one go.
|
||||
MH_STATUS WINAPI MH_EnableHook(LPVOID pTarget);
|
||||
|
||||
// Disables an already created hook.
|
||||
// Parameters:
|
||||
// pTarget [in] A pointer to the target function.
|
||||
// If this parameter is MH_ALL_HOOKS, all created hooks are
|
||||
// disabled in one go.
|
||||
MH_STATUS WINAPI MH_DisableHook(LPVOID pTarget);
|
||||
|
||||
// Queues to enable an already created hook.
|
||||
// Parameters:
|
||||
// pTarget [in] A pointer to the target function.
|
||||
// If this parameter is MH_ALL_HOOKS, all created hooks are
|
||||
// queued to be enabled.
|
||||
MH_STATUS WINAPI MH_QueueEnableHook(LPVOID pTarget);
|
||||
|
||||
// Queues to disable an already created hook.
|
||||
// Parameters:
|
||||
// pTarget [in] A pointer to the target function.
|
||||
// If this parameter is MH_ALL_HOOKS, all created hooks are
|
||||
// queued to be disabled.
|
||||
MH_STATUS WINAPI MH_QueueDisableHook(LPVOID pTarget);
|
||||
|
||||
// Applies all queued changes in one go.
|
||||
MH_STATUS WINAPI MH_ApplyQueued(VOID);
|
||||
|
||||
// Translates the MH_STATUS to its name as a string.
|
||||
const char * WINAPI MH_StatusToString(MH_STATUS status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,75 +1,75 @@
|
||||
#include "binary_resource.hpp"
|
||||
|
||||
#include <utility>
|
||||
#include "nt.hpp"
|
||||
#include "io.hpp"
|
||||
|
||||
namespace utils
|
||||
{
|
||||
namespace
|
||||
{
|
||||
std::string get_temp_folder()
|
||||
{
|
||||
char path[MAX_PATH] = {0};
|
||||
if (!GetTempPathA(sizeof(path), path))
|
||||
{
|
||||
throw std::runtime_error("Unable to get temp path");
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
std::string write_existing_temp_file(const std::string& file, const std::string& data,
|
||||
const bool fatal_if_overwrite_fails)
|
||||
{
|
||||
const auto temp = get_temp_folder();
|
||||
auto file_path = temp + file;
|
||||
|
||||
std::string current_data;
|
||||
if (!io::read_file(file_path, ¤t_data))
|
||||
{
|
||||
if (!io::write_file(file_path, data))
|
||||
{
|
||||
throw std::runtime_error("Failed to write file: " + file_path);
|
||||
}
|
||||
|
||||
return file_path;
|
||||
}
|
||||
|
||||
if (current_data == data || io::write_file(file_path, data) || !fatal_if_overwrite_fails)
|
||||
{
|
||||
return file_path;
|
||||
}
|
||||
|
||||
throw std::runtime_error(
|
||||
"Temporary file was already written, but differs. It can't be overwritten as it's still in use: " +
|
||||
file_path);
|
||||
}
|
||||
}
|
||||
|
||||
binary_resource::binary_resource(const int id, std::string file)
|
||||
: filename_(std::move(file))
|
||||
{
|
||||
this->resource_ = nt::load_resource(id);
|
||||
|
||||
if (this->resource_.empty())
|
||||
{
|
||||
throw std::runtime_error("Unable to load resource: " + std::to_string(id));
|
||||
}
|
||||
}
|
||||
|
||||
std::string binary_resource::get_extracted_file(const bool fatal_if_overwrite_fails)
|
||||
{
|
||||
if (this->path_.empty())
|
||||
{
|
||||
this->path_ = write_existing_temp_file(this->filename_, this->resource_, fatal_if_overwrite_fails);
|
||||
}
|
||||
|
||||
return this->path_;
|
||||
}
|
||||
|
||||
const std::string& binary_resource::get_data() const
|
||||
{
|
||||
return this->resource_;
|
||||
}
|
||||
}
|
||||
#include "binary_resource.hpp"
|
||||
|
||||
#include <utility>
|
||||
#include "nt.hpp"
|
||||
#include "io.hpp"
|
||||
|
||||
namespace utils
|
||||
{
|
||||
namespace
|
||||
{
|
||||
std::string get_temp_folder()
|
||||
{
|
||||
char path[MAX_PATH] = {0};
|
||||
if (!GetTempPathA(sizeof(path), path))
|
||||
{
|
||||
throw std::runtime_error("Unable to get temp path");
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
std::string write_existing_temp_file(const std::string& file, const std::string& data,
|
||||
const bool fatal_if_overwrite_fails)
|
||||
{
|
||||
const auto temp = get_temp_folder();
|
||||
auto file_path = temp + file;
|
||||
|
||||
std::string current_data;
|
||||
if (!io::read_file(file_path, ¤t_data))
|
||||
{
|
||||
if (!io::write_file(file_path, data))
|
||||
{
|
||||
throw std::runtime_error("Failed to write file: " + file_path);
|
||||
}
|
||||
|
||||
return file_path;
|
||||
}
|
||||
|
||||
if (current_data == data || io::write_file(file_path, data) || !fatal_if_overwrite_fails)
|
||||
{
|
||||
return file_path;
|
||||
}
|
||||
|
||||
throw std::runtime_error(
|
||||
"Temporary file was already written, but differs. It can't be overwritten as it's still in use: " +
|
||||
file_path);
|
||||
}
|
||||
}
|
||||
|
||||
binary_resource::binary_resource(const int id, std::string file)
|
||||
: filename_(std::move(file))
|
||||
{
|
||||
this->resource_ = nt::load_resource(id);
|
||||
|
||||
if (this->resource_.empty())
|
||||
{
|
||||
throw std::runtime_error("Unable to load resource: " + std::to_string(id));
|
||||
}
|
||||
}
|
||||
|
||||
std::string binary_resource::get_extracted_file(const bool fatal_if_overwrite_fails)
|
||||
{
|
||||
if (this->path_.empty())
|
||||
{
|
||||
this->path_ = write_existing_temp_file(this->filename_, this->resource_, fatal_if_overwrite_fails);
|
||||
}
|
||||
|
||||
return this->path_;
|
||||
}
|
||||
|
||||
const std::string& binary_resource::get_data() const
|
||||
{
|
||||
return this->resource_;
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace utils
|
||||
{
|
||||
class binary_resource
|
||||
{
|
||||
public:
|
||||
binary_resource(int id, std::string file);
|
||||
|
||||
std::string get_extracted_file(bool fatal_if_overwrite_fails = false);
|
||||
const std::string& get_data() const;
|
||||
|
||||
private:
|
||||
std::string resource_;
|
||||
std::string filename_;
|
||||
std::string path_;
|
||||
};
|
||||
}
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace utils
|
||||
{
|
||||
class binary_resource
|
||||
{
|
||||
public:
|
||||
binary_resource(int id, std::string file);
|
||||
|
||||
std::string get_extracted_file(bool fatal_if_overwrite_fails = false);
|
||||
const std::string& get_data() const;
|
||||
|
||||
private:
|
||||
std::string resource_;
|
||||
std::string filename_;
|
||||
std::string path_;
|
||||
};
|
||||
}
|
||||
|
@ -1,46 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
|
||||
namespace utils::concurrency
|
||||
{
|
||||
template <typename T, typename MutexType = std::mutex>
|
||||
class container
|
||||
{
|
||||
public:
|
||||
template <typename R = void, typename F>
|
||||
R access(F&& accessor) const
|
||||
{
|
||||
std::lock_guard<MutexType> _{mutex_};
|
||||
return accessor(object_);
|
||||
}
|
||||
|
||||
template <typename R = void, typename F>
|
||||
R access(F&& accessor)
|
||||
{
|
||||
std::lock_guard<MutexType> _{mutex_};
|
||||
return accessor(object_);
|
||||
}
|
||||
|
||||
template <typename R = void, typename F>
|
||||
R access_with_lock(F&& accessor) const
|
||||
{
|
||||
std::unique_lock<MutexType> lock{mutex_};
|
||||
return accessor(object_, lock);
|
||||
}
|
||||
|
||||
template <typename R = void, typename F>
|
||||
R access_with_lock(F&& accessor)
|
||||
{
|
||||
std::unique_lock<MutexType> lock{mutex_};
|
||||
return accessor(object_, lock);
|
||||
}
|
||||
|
||||
T& get_raw() { return object_; }
|
||||
const T& get_raw() const { return object_; }
|
||||
|
||||
private:
|
||||
mutable MutexType mutex_{};
|
||||
T object_{};
|
||||
};
|
||||
}
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
|
||||
namespace utils::concurrency
|
||||
{
|
||||
template <typename T, typename MutexType = std::mutex>
|
||||
class container
|
||||
{
|
||||
public:
|
||||
template <typename R = void, typename F>
|
||||
R access(F&& accessor) const
|
||||
{
|
||||
std::lock_guard<MutexType> _{mutex_};
|
||||
return accessor(object_);
|
||||
}
|
||||
|
||||
template <typename R = void, typename F>
|
||||
R access(F&& accessor)
|
||||
{
|
||||
std::lock_guard<MutexType> _{mutex_};
|
||||
return accessor(object_);
|
||||
}
|
||||
|
||||
template <typename R = void, typename F>
|
||||
R access_with_lock(F&& accessor) const
|
||||
{
|
||||
std::unique_lock<MutexType> lock{mutex_};
|
||||
return accessor(object_, lock);
|
||||
}
|
||||
|
||||
template <typename R = void, typename F>
|
||||
R access_with_lock(F&& accessor)
|
||||
{
|
||||
std::unique_lock<MutexType> lock{mutex_};
|
||||
return accessor(object_, lock);
|
||||
}
|
||||
|
||||
T& get_raw() { return object_; }
|
||||
const T& get_raw() const { return object_; }
|
||||
|
||||
private:
|
||||
mutable MutexType mutex_{};
|
||||
T object_{};
|
||||
};
|
||||
}
|
||||
|
@ -1,54 +1,54 @@
|
||||
#pragma once
|
||||
#include <type_traits>
|
||||
|
||||
namespace utils
|
||||
{
|
||||
/*
|
||||
* Copied from here: https://github.com/microsoft/GSL/blob/e0880931ae5885eb988d1a8a57acf8bc2b8dacda/include/gsl/util#L57
|
||||
*/
|
||||
|
||||
template <class F>
|
||||
class final_action
|
||||
{
|
||||
public:
|
||||
static_assert(!std::is_reference<F>::value && !std::is_const<F>::value &&
|
||||
!std::is_volatile<F>::value,
|
||||
"Final_action should store its callable by value");
|
||||
|
||||
explicit final_action(F f) noexcept : f_(std::move(f))
|
||||
{
|
||||
}
|
||||
|
||||
final_action(final_action&& other) noexcept
|
||||
: f_(std::move(other.f_)), invoke_(std::exchange(other.invoke_, false))
|
||||
{
|
||||
}
|
||||
|
||||
final_action(const final_action&) = delete;
|
||||
final_action& operator=(const final_action&) = delete;
|
||||
final_action& operator=(final_action&&) = delete;
|
||||
|
||||
~final_action() noexcept
|
||||
{
|
||||
if (invoke_) f_();
|
||||
}
|
||||
|
||||
// Added by momo5502
|
||||
void cancel()
|
||||
{
|
||||
invoke_ = false;
|
||||
}
|
||||
|
||||
private:
|
||||
F f_;
|
||||
bool invoke_{true};
|
||||
};
|
||||
|
||||
template <class F>
|
||||
final_action<typename std::remove_cv<typename std::remove_reference<F>::type>::type>
|
||||
finally(F&& f) noexcept
|
||||
{
|
||||
return final_action<typename std::remove_cv<typename std::remove_reference<F>::type>::type>(
|
||||
std::forward<F>(f));
|
||||
}
|
||||
#pragma once
|
||||
#include <type_traits>
|
||||
|
||||
namespace utils
|
||||
{
|
||||
/*
|
||||
* Copied from here: https://github.com/microsoft/GSL/blob/e0880931ae5885eb988d1a8a57acf8bc2b8dacda/include/gsl/util#L57
|
||||
*/
|
||||
|
||||
template <class F>
|
||||
class final_action
|
||||
{
|
||||
public:
|
||||
static_assert(!std::is_reference<F>::value && !std::is_const<F>::value &&
|
||||
!std::is_volatile<F>::value,
|
||||
"Final_action should store its callable by value");
|
||||
|
||||
explicit final_action(F f) noexcept : f_(std::move(f))
|
||||
{
|
||||
}
|
||||
|
||||
final_action(final_action&& other) noexcept
|
||||
: f_(std::move(other.f_)), invoke_(std::exchange(other.invoke_, false))
|
||||
{
|
||||
}
|
||||
|
||||
final_action(const final_action&) = delete;
|
||||
final_action& operator=(const final_action&) = delete;
|
||||
final_action& operator=(final_action&&) = delete;
|
||||
|
||||
~final_action() noexcept
|
||||
{
|
||||
if (invoke_) f_();
|
||||
}
|
||||
|
||||
// Added by momo5502
|
||||
void cancel()
|
||||
{
|
||||
invoke_ = false;
|
||||
}
|
||||
|
||||
private:
|
||||
F f_;
|
||||
bool invoke_{true};
|
||||
};
|
||||
|
||||
template <class F>
|
||||
final_action<typename std::remove_cv<typename std::remove_reference<F>::type>::type>
|
||||
finally(F&& f) noexcept
|
||||
{
|
||||
return final_action<typename std::remove_cv<typename std::remove_reference<F>::type>::type>(
|
||||
std::forward<F>(f));
|
||||
}
|
||||
}
|
@ -1,173 +1,173 @@
|
||||
#include "hardware_breakpoint.hpp"
|
||||
#include "thread.hpp"
|
||||
|
||||
|
||||
namespace utils::hardware_breakpoint
|
||||
{
|
||||
namespace
|
||||
{
|
||||
void set_bits(uintptr_t& value, const uint32_t bit_index, const uint32_t bits, const uintptr_t new_value)
|
||||
{
|
||||
const uintptr_t range_mask = (1ull << bits) - 1ull;
|
||||
const uintptr_t full_mask = ~(range_mask << bit_index);
|
||||
value = (value & full_mask) | (new_value << bit_index);
|
||||
}
|
||||
|
||||
void validate_index(const uint32_t index)
|
||||
{
|
||||
if (index >= 4)
|
||||
{
|
||||
throw std::runtime_error("Invalid index");
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t translate_length(const uint32_t length)
|
||||
{
|
||||
if (length != 1 && length != 2 && length != 4)
|
||||
{
|
||||
throw std::runtime_error("Invalid length");
|
||||
}
|
||||
|
||||
return length - 1;
|
||||
}
|
||||
|
||||
class debug_context
|
||||
{
|
||||
public:
|
||||
debug_context(uint32_t thread_id)
|
||||
: handle_(thread_id, THREAD_SET_CONTEXT | THREAD_GET_CONTEXT)
|
||||
{
|
||||
if (!this->handle_)
|
||||
{
|
||||
throw std::runtime_error("Unable to access thread");
|
||||
}
|
||||
|
||||
this->context_.ContextFlags = CONTEXT_DEBUG_REGISTERS;
|
||||
|
||||
if (!GetThreadContext(this->handle_, &this->context_))
|
||||
{
|
||||
throw std::runtime_error("Unable to get thread context");
|
||||
}
|
||||
}
|
||||
|
||||
~debug_context()
|
||||
{
|
||||
SetThreadContext(this->handle_, &this->context_);
|
||||
}
|
||||
|
||||
debug_context(const debug_context&) = delete;
|
||||
debug_context& operator=(const debug_context&) = delete;
|
||||
|
||||
debug_context(debug_context&& obj) noexcept = delete;
|
||||
debug_context& operator=(debug_context&& obj) noexcept = delete;
|
||||
|
||||
CONTEXT* operator->()
|
||||
{
|
||||
return &this->context_;
|
||||
}
|
||||
|
||||
operator CONTEXT&()
|
||||
{
|
||||
return this->context_;
|
||||
}
|
||||
|
||||
private:
|
||||
thread::handle handle_;
|
||||
CONTEXT context_{};
|
||||
};
|
||||
|
||||
uint32_t find_free_index(const CONTEXT& context)
|
||||
{
|
||||
for (uint32_t i = 0; i < 4; ++i)
|
||||
{
|
||||
if ((context.Dr7 & (1ull << (i << 1ull))) == 0)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
throw std::runtime_error("No free index");
|
||||
}
|
||||
}
|
||||
|
||||
void set_branch_tracing(const bool enabled, CONTEXT& context)
|
||||
{
|
||||
set_bits(context.Dr7, 8, 1, enabled ? 1 : 0);
|
||||
}
|
||||
|
||||
void set_branch_tracing(const bool enabled, const uint32_t thread_id)
|
||||
{
|
||||
debug_context context(thread_id);
|
||||
set_branch_tracing(enabled, context);
|
||||
}
|
||||
|
||||
uint32_t activate(const uintptr_t address, uint32_t length, const condition cond, CONTEXT& context)
|
||||
{
|
||||
const auto index = find_free_index(context);
|
||||
length = translate_length(length);
|
||||
|
||||
(&context.Dr0)[index] = address;
|
||||
set_bits(context.Dr7, 16 + (index << 2ull), 2, cond);
|
||||
set_bits(context.Dr7, 18 + (index << 2ull), 2, length);
|
||||
set_bits(context.Dr7, index << 1ull, 1, 1);
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
uint32_t activate(void* address, const uint32_t length, const condition cond, const uint32_t thread_id)
|
||||
{
|
||||
return activate(reinterpret_cast<uint64_t>(address), length, cond, thread_id);
|
||||
}
|
||||
|
||||
uint32_t activate(const uint64_t address, const uint32_t length, const condition cond, const uint32_t thread_id)
|
||||
{
|
||||
debug_context context(thread_id);
|
||||
return activate(address, length, cond, context);
|
||||
}
|
||||
|
||||
void deactivate_address(const uint64_t address, CONTEXT& context)
|
||||
{
|
||||
for (auto i = 0; i < 4; ++i)
|
||||
{
|
||||
if ((&context.Dr0)[i] == address)
|
||||
{
|
||||
deactivate(i, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void deactivate_address(void* address, const uint32_t thread_id)
|
||||
{
|
||||
return deactivate_address(reinterpret_cast<uint64_t>(address), thread_id);
|
||||
}
|
||||
|
||||
void deactivate_address(const uint64_t address, const uint32_t thread_id)
|
||||
{
|
||||
debug_context context(thread_id);
|
||||
deactivate_address(address, context);
|
||||
}
|
||||
|
||||
void deactivate(const uint32_t index, CONTEXT& context)
|
||||
{
|
||||
validate_index(index);
|
||||
set_bits(context.Dr7, index << 1ull, 1, 0);
|
||||
}
|
||||
|
||||
void deactivate(const uint32_t index, const uint32_t thread_id)
|
||||
{
|
||||
debug_context context(thread_id);
|
||||
deactivate(index, context);
|
||||
}
|
||||
|
||||
void deactivate_all(CONTEXT& context)
|
||||
{
|
||||
context.Dr7 = 0;
|
||||
}
|
||||
|
||||
void deactivate_all(const uint32_t thread_id)
|
||||
{
|
||||
debug_context context(thread_id);
|
||||
deactivate_all(context);
|
||||
}
|
||||
}
|
||||
|
||||
#include "hardware_breakpoint.hpp"
|
||||
#include "thread.hpp"
|
||||
|
||||
|
||||
namespace utils::hardware_breakpoint
|
||||
{
|
||||
namespace
|
||||
{
|
||||
void set_bits(uintptr_t& value, const uint32_t bit_index, const uint32_t bits, const uintptr_t new_value)
|
||||
{
|
||||
const uintptr_t range_mask = (1ull << bits) - 1ull;
|
||||
const uintptr_t full_mask = ~(range_mask << bit_index);
|
||||
value = (value & full_mask) | (new_value << bit_index);
|
||||
}
|
||||
|
||||
void validate_index(const uint32_t index)
|
||||
{
|
||||
if (index >= 4)
|
||||
{
|
||||
throw std::runtime_error("Invalid index");
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t translate_length(const uint32_t length)
|
||||
{
|
||||
if (length != 1 && length != 2 && length != 4)
|
||||
{
|
||||
throw std::runtime_error("Invalid length");
|
||||
}
|
||||
|
||||
return length - 1;
|
||||
}
|
||||
|
||||
class debug_context
|
||||
{
|
||||
public:
|
||||
debug_context(uint32_t thread_id)
|
||||
: handle_(thread_id, THREAD_SET_CONTEXT | THREAD_GET_CONTEXT)
|
||||
{
|
||||
if (!this->handle_)
|
||||
{
|
||||
throw std::runtime_error("Unable to access thread");
|
||||
}
|
||||
|
||||
this->context_.ContextFlags = CONTEXT_DEBUG_REGISTERS;
|
||||
|
||||
if (!GetThreadContext(this->handle_, &this->context_))
|
||||
{
|
||||
throw std::runtime_error("Unable to get thread context");
|
||||
}
|
||||
}
|
||||
|
||||
~debug_context()
|
||||
{
|
||||
SetThreadContext(this->handle_, &this->context_);
|
||||
}
|
||||
|
||||
debug_context(const debug_context&) = delete;
|
||||
debug_context& operator=(const debug_context&) = delete;
|
||||
|
||||
debug_context(debug_context&& obj) noexcept = delete;
|
||||
debug_context& operator=(debug_context&& obj) noexcept = delete;
|
||||
|
||||
CONTEXT* operator->()
|
||||
{
|
||||
return &this->context_;
|
||||
}
|
||||
|
||||
operator CONTEXT&()
|
||||
{
|
||||
return this->context_;
|
||||
}
|
||||
|
||||
private:
|
||||
thread::handle handle_;
|
||||
CONTEXT context_{};
|
||||
};
|
||||
|
||||
uint32_t find_free_index(const CONTEXT& context)
|
||||
{
|
||||
for (uint32_t i = 0; i < 4; ++i)
|
||||
{
|
||||
if ((context.Dr7 & (1ull << (i << 1ull))) == 0)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
throw std::runtime_error("No free index");
|
||||
}
|
||||
}
|
||||
|
||||
void set_branch_tracing(const bool enabled, CONTEXT& context)
|
||||
{
|
||||
set_bits(context.Dr7, 8, 1, enabled ? 1 : 0);
|
||||
}
|
||||
|
||||
void set_branch_tracing(const bool enabled, const uint32_t thread_id)
|
||||
{
|
||||
debug_context context(thread_id);
|
||||
set_branch_tracing(enabled, context);
|
||||
}
|
||||
|
||||
uint32_t activate(const uintptr_t address, uint32_t length, const condition cond, CONTEXT& context)
|
||||
{
|
||||
const auto index = find_free_index(context);
|
||||
length = translate_length(length);
|
||||
|
||||
(&context.Dr0)[index] = address;
|
||||
set_bits(context.Dr7, 16 + (index << 2ull), 2, cond);
|
||||
set_bits(context.Dr7, 18 + (index << 2ull), 2, length);
|
||||
set_bits(context.Dr7, index << 1ull, 1, 1);
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
uint32_t activate(void* address, const uint32_t length, const condition cond, const uint32_t thread_id)
|
||||
{
|
||||
return activate(reinterpret_cast<uint64_t>(address), length, cond, thread_id);
|
||||
}
|
||||
|
||||
uint32_t activate(const uint64_t address, const uint32_t length, const condition cond, const uint32_t thread_id)
|
||||
{
|
||||
debug_context context(thread_id);
|
||||
return activate(address, length, cond, context);
|
||||
}
|
||||
|
||||
void deactivate_address(const uint64_t address, CONTEXT& context)
|
||||
{
|
||||
for (auto i = 0; i < 4; ++i)
|
||||
{
|
||||
if ((&context.Dr0)[i] == address)
|
||||
{
|
||||
deactivate(i, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void deactivate_address(void* address, const uint32_t thread_id)
|
||||
{
|
||||
return deactivate_address(reinterpret_cast<uint64_t>(address), thread_id);
|
||||
}
|
||||
|
||||
void deactivate_address(const uint64_t address, const uint32_t thread_id)
|
||||
{
|
||||
debug_context context(thread_id);
|
||||
deactivate_address(address, context);
|
||||
}
|
||||
|
||||
void deactivate(const uint32_t index, CONTEXT& context)
|
||||
{
|
||||
validate_index(index);
|
||||
set_bits(context.Dr7, index << 1ull, 1, 0);
|
||||
}
|
||||
|
||||
void deactivate(const uint32_t index, const uint32_t thread_id)
|
||||
{
|
||||
debug_context context(thread_id);
|
||||
deactivate(index, context);
|
||||
}
|
||||
|
||||
void deactivate_all(CONTEXT& context)
|
||||
{
|
||||
context.Dr7 = 0;
|
||||
}
|
||||
|
||||
void deactivate_all(const uint32_t thread_id)
|
||||
{
|
||||
debug_context context(thread_id);
|
||||
deactivate_all(context);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,32 +1,32 @@
|
||||
#pragma once
|
||||
#include <thread>
|
||||
#include "nt.hpp"
|
||||
|
||||
|
||||
namespace utils::hardware_breakpoint
|
||||
{
|
||||
enum condition
|
||||
{
|
||||
execute = 0,
|
||||
write = 1,
|
||||
read_write = 3
|
||||
};
|
||||
|
||||
|
||||
void set_branch_tracing(bool enabled, CONTEXT& context);
|
||||
void set_branch_tracing(bool enabled, uint32_t thread_id = GetCurrentThreadId());
|
||||
|
||||
uint32_t activate(uint64_t address, uint32_t length, condition cond, CONTEXT& context);
|
||||
uint32_t activate(void* address, uint32_t length, condition cond, uint32_t thread_id = GetCurrentThreadId());
|
||||
uint32_t activate(uint64_t address, uint32_t length, condition cond, uint32_t thread_id = GetCurrentThreadId());
|
||||
|
||||
void deactivate_address(uint64_t address, CONTEXT& context);
|
||||
void deactivate_address(void* address, uint32_t thread_id = GetCurrentThreadId());
|
||||
void deactivate_address(uint64_t address, uint32_t thread_id = GetCurrentThreadId());
|
||||
|
||||
void deactivate(uint32_t index, CONTEXT& context);
|
||||
void deactivate(uint32_t index, uint32_t thread_id = GetCurrentThreadId());
|
||||
|
||||
void deactivate_all(CONTEXT& context);
|
||||
void deactivate_all(uint32_t thread_id = GetCurrentThreadId());
|
||||
}
|
||||
#pragma once
|
||||
#include <thread>
|
||||
#include "nt.hpp"
|
||||
|
||||
|
||||
namespace utils::hardware_breakpoint
|
||||
{
|
||||
enum condition
|
||||
{
|
||||
execute = 0,
|
||||
write = 1,
|
||||
read_write = 3
|
||||
};
|
||||
|
||||
|
||||
void set_branch_tracing(bool enabled, CONTEXT& context);
|
||||
void set_branch_tracing(bool enabled, uint32_t thread_id = GetCurrentThreadId());
|
||||
|
||||
uint32_t activate(uint64_t address, uint32_t length, condition cond, CONTEXT& context);
|
||||
uint32_t activate(void* address, uint32_t length, condition cond, uint32_t thread_id = GetCurrentThreadId());
|
||||
uint32_t activate(uint64_t address, uint32_t length, condition cond, uint32_t thread_id = GetCurrentThreadId());
|
||||
|
||||
void deactivate_address(uint64_t address, CONTEXT& context);
|
||||
void deactivate_address(void* address, uint32_t thread_id = GetCurrentThreadId());
|
||||
void deactivate_address(uint64_t address, uint32_t thread_id = GetCurrentThreadId());
|
||||
|
||||
void deactivate(uint32_t index, CONTEXT& context);
|
||||
void deactivate(uint32_t index, uint32_t thread_id = GetCurrentThreadId());
|
||||
|
||||
void deactivate_all(CONTEXT& context);
|
||||
void deactivate_all(uint32_t thread_id = GetCurrentThreadId());
|
||||
}
|
||||
|
@ -1,484 +1,484 @@
|
||||
#include "hook.hpp"
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "MinHook.hpp"
|
||||
|
||||
#include "concurrency.hpp"
|
||||
#include "string.hpp"
|
||||
#include "nt.hpp"
|
||||
|
||||
#ifdef max
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
#ifdef min
|
||||
#undef min
|
||||
#endif
|
||||
|
||||
namespace utils::hook
|
||||
{
|
||||
namespace
|
||||
{
|
||||
uint8_t* allocate_somewhere_near(const void* base_address, const size_t size)
|
||||
{
|
||||
size_t offset = 0;
|
||||
while (true)
|
||||
{
|
||||
offset += size;
|
||||
auto* target_address = static_cast<const uint8_t*>(base_address) - offset;
|
||||
if (is_relatively_far(base_address, target_address))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const auto res = VirtualAlloc(const_cast<uint8_t*>(target_address), size, MEM_RESERVE | MEM_COMMIT,
|
||||
PAGE_EXECUTE_READWRITE);
|
||||
if (res)
|
||||
{
|
||||
if (is_relatively_far(base_address, target_address))
|
||||
{
|
||||
VirtualFree(res, 0, MEM_RELEASE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return static_cast<uint8_t*>(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class memory
|
||||
{
|
||||
public:
|
||||
memory() = default;
|
||||
|
||||
memory(const void* ptr)
|
||||
: memory()
|
||||
{
|
||||
this->length_ = 0x1000;
|
||||
this->buffer_ = allocate_somewhere_near(ptr, this->length_);
|
||||
if (!this->buffer_)
|
||||
{
|
||||
throw std::runtime_error("Failed to allocate");
|
||||
}
|
||||
}
|
||||
|
||||
~memory()
|
||||
{
|
||||
if (this->buffer_)
|
||||
{
|
||||
VirtualFree(this->buffer_, 0, MEM_RELEASE);
|
||||
}
|
||||
}
|
||||
|
||||
memory(memory&& obj) noexcept
|
||||
: memory()
|
||||
{
|
||||
this->operator=(std::move(obj));
|
||||
}
|
||||
|
||||
memory& operator=(memory&& obj) noexcept
|
||||
{
|
||||
if (this != &obj)
|
||||
{
|
||||
this->~memory();
|
||||
this->buffer_ = obj.buffer_;
|
||||
this->length_ = obj.length_;
|
||||
this->offset_ = obj.offset_;
|
||||
|
||||
obj.buffer_ = nullptr;
|
||||
obj.length_ = 0;
|
||||
obj.offset_ = 0;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void* allocate(const size_t length)
|
||||
{
|
||||
if (!this->buffer_)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (this->offset_ + length > this->length_)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const auto ptr = this->get_ptr();
|
||||
this->offset_ += length;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void* get_ptr() const
|
||||
{
|
||||
return this->buffer_ + this->offset_;
|
||||
}
|
||||
|
||||
private:
|
||||
uint8_t* buffer_{};
|
||||
size_t length_{};
|
||||
size_t offset_{};
|
||||
};
|
||||
|
||||
void* get_memory_near(const void* address, const size_t size)
|
||||
{
|
||||
static concurrency::container<std::vector<memory>> memory_container{};
|
||||
|
||||
return memory_container.access<void*>([&](std::vector<memory>& memories)
|
||||
{
|
||||
for (auto& memory : memories)
|
||||
{
|
||||
if (!is_relatively_far(address, memory.get_ptr()))
|
||||
{
|
||||
const auto buffer = memory.allocate(size);
|
||||
if (buffer)
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
memories.emplace_back(address);
|
||||
return memories.back().allocate(size);
|
||||
});
|
||||
}
|
||||
|
||||
void* initialize_min_hook()
|
||||
{
|
||||
static class min_hook_init
|
||||
{
|
||||
public:
|
||||
min_hook_init()
|
||||
{
|
||||
if (MH_Initialize() != MH_OK)
|
||||
{
|
||||
throw std::runtime_error("Failed to initialize MinHook");
|
||||
}
|
||||
}
|
||||
|
||||
~min_hook_init()
|
||||
{
|
||||
MH_Uninitialize();
|
||||
}
|
||||
} min_hook_init;
|
||||
return &min_hook_init;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
detour::detour()
|
||||
{
|
||||
(void)initialize_min_hook();
|
||||
}
|
||||
|
||||
detour::detour(const size_t place, void* target)
|
||||
: detour(reinterpret_cast<void*>(place), target)
|
||||
{
|
||||
}
|
||||
|
||||
detour::detour(void* place, void* target)
|
||||
: detour()
|
||||
{
|
||||
this->create(place, target);
|
||||
}
|
||||
|
||||
detour::~detour()
|
||||
{
|
||||
this->clear();
|
||||
}
|
||||
|
||||
void detour::enable()
|
||||
{
|
||||
MH_EnableHook(this->place_);
|
||||
if (!this->moved_data_.empty())
|
||||
{
|
||||
this->move();
|
||||
}
|
||||
}
|
||||
|
||||
void detour::disable()
|
||||
{
|
||||
this->un_move();
|
||||
MH_DisableHook(this->place_);
|
||||
}
|
||||
|
||||
void detour::create(void* place, void* target)
|
||||
{
|
||||
this->clear();
|
||||
this->place_ = place;
|
||||
|
||||
if (MH_CreateHook(this->place_, target, &this->original_) != MH_OK)
|
||||
{
|
||||
//throw std::runtime_error(string::va("Unable to create hook at location: %p", this->place_));
|
||||
}
|
||||
|
||||
this->enable();
|
||||
}
|
||||
|
||||
void detour::create(const size_t place, void* target)
|
||||
{
|
||||
MH_Initialize();
|
||||
this->create(reinterpret_cast<void*>(place), target);
|
||||
}
|
||||
|
||||
void detour::clear()
|
||||
{
|
||||
if (this->place_)
|
||||
{
|
||||
this->un_move();
|
||||
MH_RemoveHook(this->place_);
|
||||
}
|
||||
|
||||
this->place_ = nullptr;
|
||||
this->original_ = nullptr;
|
||||
this->moved_data_ = {};
|
||||
}
|
||||
|
||||
void detour::move()
|
||||
{
|
||||
this->moved_data_ = move_hook(this->place_);
|
||||
}
|
||||
|
||||
void* detour::get_place() const
|
||||
{
|
||||
return this->place_;
|
||||
}
|
||||
|
||||
void* detour::get_original() const
|
||||
{
|
||||
return this->original_;
|
||||
}
|
||||
|
||||
void detour::un_move()
|
||||
{
|
||||
if (!this->moved_data_.empty())
|
||||
{
|
||||
copy(this->place_, this->moved_data_.data(), this->moved_data_.size());
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<std::pair<void*, void*>> iat(const nt::library& library, const std::string& target_library, const std::string& process, void* stub)
|
||||
{
|
||||
if (!library.is_valid()) return {};
|
||||
|
||||
auto* const ptr = library.get_iat_entry(target_library, process);
|
||||
if (!ptr) return {};
|
||||
|
||||
DWORD protect;
|
||||
VirtualProtect(ptr, sizeof(*ptr), PAGE_EXECUTE_READWRITE, &protect);
|
||||
|
||||
std::swap(*ptr, stub);
|
||||
|
||||
VirtualProtect(ptr, sizeof(*ptr), protect, &protect);
|
||||
return {{ptr, stub}};
|
||||
}
|
||||
|
||||
void nop(void* place, const size_t length)
|
||||
{
|
||||
DWORD old_protect{};
|
||||
VirtualProtect(place, length, PAGE_EXECUTE_READWRITE, &old_protect);
|
||||
|
||||
std::memset(place, 0x90, length);
|
||||
|
||||
VirtualProtect(place, length, old_protect, &old_protect);
|
||||
FlushInstructionCache(GetCurrentProcess(), place, length);
|
||||
}
|
||||
|
||||
void nop(const size_t place, const size_t length)
|
||||
{
|
||||
nop(reinterpret_cast<void*>(place), length);
|
||||
}
|
||||
|
||||
void copy(void* place, const void* data, const size_t length)
|
||||
{
|
||||
DWORD old_protect{};
|
||||
VirtualProtect(place, length, PAGE_EXECUTE_READWRITE, &old_protect);
|
||||
|
||||
std::memmove(place, data, length);
|
||||
|
||||
VirtualProtect(place, length, old_protect, &old_protect);
|
||||
FlushInstructionCache(GetCurrentProcess(), place, length);
|
||||
}
|
||||
|
||||
void copy(const size_t place, const void* data, const size_t length)
|
||||
{
|
||||
copy(reinterpret_cast<void*>(place), data, length);
|
||||
}
|
||||
|
||||
void copy_string(void* place, const char* str)
|
||||
{
|
||||
copy(reinterpret_cast<void*>(place), str, strlen(str) + 1);
|
||||
}
|
||||
|
||||
void copy_string(const size_t place, const char* str)
|
||||
{
|
||||
copy_string(reinterpret_cast<void*>(place), str);
|
||||
}
|
||||
|
||||
bool is_relatively_far(const void* pointer, const void* data, const int offset)
|
||||
{
|
||||
const int64_t diff = size_t(data) - (size_t(pointer) + offset);
|
||||
const auto small_diff = int32_t(diff);
|
||||
return diff != int64_t(small_diff);
|
||||
}
|
||||
|
||||
void call(void* pointer, void* data)
|
||||
{
|
||||
if (is_relatively_far(pointer, data))
|
||||
{
|
||||
auto* trampoline = get_memory_near(pointer, 14);
|
||||
if (!trampoline)
|
||||
{
|
||||
throw std::runtime_error("Too far away to create 32bit relative branch");
|
||||
}
|
||||
|
||||
call(pointer, trampoline);
|
||||
jump(trampoline, data, true, true);
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t copy_data[5];
|
||||
copy_data[0] = 0xE8;
|
||||
*reinterpret_cast<int32_t*>(©_data[1]) = int32_t(size_t(data) - (size_t(pointer) + 5));
|
||||
|
||||
auto* patch_pointer = PBYTE(pointer);
|
||||
copy(patch_pointer, copy_data, sizeof(copy_data));
|
||||
}
|
||||
|
||||
void call(const size_t pointer, void* data)
|
||||
{
|
||||
return call(reinterpret_cast<void*>(pointer), data);
|
||||
}
|
||||
|
||||
void call(const size_t pointer, const size_t data)
|
||||
{
|
||||
return call(pointer, reinterpret_cast<void*>(data));
|
||||
}
|
||||
|
||||
void jump(void* pointer, void* data, const bool use_far, const bool use_safe)
|
||||
{
|
||||
static const unsigned char jump_data[] = {
|
||||
0x48, 0xb8, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0xff, 0xe0
|
||||
};
|
||||
|
||||
static const unsigned char jump_data_safe[] = {
|
||||
0xFF, 0x25, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
if (!use_far && is_relatively_far(pointer, data))
|
||||
{
|
||||
auto* trampoline = get_memory_near(pointer, 14);
|
||||
if (!trampoline)
|
||||
{
|
||||
throw std::runtime_error("Too far away to create 32bit relative branch");
|
||||
}
|
||||
jump(pointer, trampoline, false, false);
|
||||
jump(trampoline, data, true, true);
|
||||
return;
|
||||
}
|
||||
|
||||
auto* patch_pointer = PBYTE(pointer);
|
||||
|
||||
if (use_far)
|
||||
{
|
||||
if (use_safe)
|
||||
{
|
||||
uint8_t copy_data[sizeof(jump_data_safe) + sizeof(data)];
|
||||
memcpy(copy_data, jump_data_safe, sizeof(jump_data_safe));
|
||||
memcpy(copy_data + sizeof(jump_data_safe), &data, sizeof(data));
|
||||
|
||||
copy(patch_pointer, copy_data, sizeof(copy_data));
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t copy_data[sizeof(jump_data)];
|
||||
memcpy(copy_data, jump_data, sizeof(jump_data));
|
||||
memcpy(copy_data + 2, &data, sizeof(data));
|
||||
|
||||
copy(patch_pointer, copy_data, sizeof(copy_data));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t copy_data[5];
|
||||
copy_data[0] = 0xE9;
|
||||
*reinterpret_cast<int32_t*>(©_data[1]) = int32_t(size_t(data) - (size_t(pointer) + 5));
|
||||
|
||||
copy(patch_pointer, copy_data, sizeof(copy_data));
|
||||
}
|
||||
}
|
||||
|
||||
void jump(const size_t pointer, void* data, const bool use_far, const bool use_safe)
|
||||
{
|
||||
return jump(reinterpret_cast<void*>(pointer), data, use_far, use_safe);
|
||||
}
|
||||
|
||||
void jump(const size_t pointer, const size_t data, const bool use_far, const bool use_safe)
|
||||
{
|
||||
return jump(pointer, reinterpret_cast<void*>(data), use_far, use_safe);
|
||||
}
|
||||
|
||||
|
||||
void inject(void* pointer, const void* data)
|
||||
{
|
||||
if (is_relatively_far(pointer, data, 4))
|
||||
{
|
||||
throw std::runtime_error("Too far away to create 32bit relative branch");
|
||||
}
|
||||
|
||||
set<int32_t>(pointer, int32_t(size_t(data) - (size_t(pointer) + 4)));
|
||||
}
|
||||
|
||||
void inject(const size_t pointer, const void* data)
|
||||
{
|
||||
return inject(reinterpret_cast<void*>(pointer), data);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> move_hook(void* pointer)
|
||||
{
|
||||
std::vector<uint8_t> original_data{};
|
||||
|
||||
auto* data_ptr = static_cast<uint8_t*>(pointer);
|
||||
if (data_ptr[0] == 0xE9)
|
||||
{
|
||||
original_data.resize(6);
|
||||
memmove(original_data.data(), pointer, original_data.size());
|
||||
|
||||
auto* target = follow_branch(data_ptr);
|
||||
nop(data_ptr, 1);
|
||||
jump(data_ptr + 1, target);
|
||||
}
|
||||
else if (data_ptr[0] == 0xFF && data_ptr[1] == 0x25)
|
||||
{
|
||||
original_data.resize(15);
|
||||
memmove(original_data.data(), pointer, original_data.size());
|
||||
|
||||
copy(data_ptr + 1, data_ptr, 14);
|
||||
nop(data_ptr, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("No branch instruction found");
|
||||
}
|
||||
|
||||
return original_data;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> move_hook(const size_t pointer)
|
||||
{
|
||||
return move_hook(reinterpret_cast<void*>(pointer));
|
||||
}
|
||||
|
||||
void* follow_branch(void* address)
|
||||
{
|
||||
auto* const data = static_cast<uint8_t*>(address);
|
||||
if (*data != 0xE8 && *data != 0xE9)
|
||||
{
|
||||
throw std::runtime_error("No branch instruction found");
|
||||
}
|
||||
|
||||
return extract<void*>(data + 1);
|
||||
}
|
||||
}
|
||||
#include "hook.hpp"
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "MinHook.hpp"
|
||||
|
||||
#include "concurrency.hpp"
|
||||
#include "string.hpp"
|
||||
#include "nt.hpp"
|
||||
|
||||
#ifdef max
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
#ifdef min
|
||||
#undef min
|
||||
#endif
|
||||
|
||||
namespace utils::hook
|
||||
{
|
||||
namespace
|
||||
{
|
||||
uint8_t* allocate_somewhere_near(const void* base_address, const size_t size)
|
||||
{
|
||||
size_t offset = 0;
|
||||
while (true)
|
||||
{
|
||||
offset += size;
|
||||
auto* target_address = static_cast<const uint8_t*>(base_address) - offset;
|
||||
if (is_relatively_far(base_address, target_address))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const auto res = VirtualAlloc(const_cast<uint8_t*>(target_address), size, MEM_RESERVE | MEM_COMMIT,
|
||||
PAGE_EXECUTE_READWRITE);
|
||||
if (res)
|
||||
{
|
||||
if (is_relatively_far(base_address, target_address))
|
||||
{
|
||||
VirtualFree(res, 0, MEM_RELEASE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return static_cast<uint8_t*>(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class memory
|
||||
{
|
||||
public:
|
||||
memory() = default;
|
||||
|
||||
memory(const void* ptr)
|
||||
: memory()
|
||||
{
|
||||
this->length_ = 0x1000;
|
||||
this->buffer_ = allocate_somewhere_near(ptr, this->length_);
|
||||
if (!this->buffer_)
|
||||
{
|
||||
throw std::runtime_error("Failed to allocate");
|
||||
}
|
||||
}
|
||||
|
||||
~memory()
|
||||
{
|
||||
if (this->buffer_)
|
||||
{
|
||||
VirtualFree(this->buffer_, 0, MEM_RELEASE);
|
||||
}
|
||||
}
|
||||
|
||||
memory(memory&& obj) noexcept
|
||||
: memory()
|
||||
{
|
||||
this->operator=(std::move(obj));
|
||||
}
|
||||
|
||||
memory& operator=(memory&& obj) noexcept
|
||||
{
|
||||
if (this != &obj)
|
||||
{
|
||||
this->~memory();
|
||||
this->buffer_ = obj.buffer_;
|
||||
this->length_ = obj.length_;
|
||||
this->offset_ = obj.offset_;
|
||||
|
||||
obj.buffer_ = nullptr;
|
||||
obj.length_ = 0;
|
||||
obj.offset_ = 0;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void* allocate(const size_t length)
|
||||
{
|
||||
if (!this->buffer_)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (this->offset_ + length > this->length_)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const auto ptr = this->get_ptr();
|
||||
this->offset_ += length;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void* get_ptr() const
|
||||
{
|
||||
return this->buffer_ + this->offset_;
|
||||
}
|
||||
|
||||
private:
|
||||
uint8_t* buffer_{};
|
||||
size_t length_{};
|
||||
size_t offset_{};
|
||||
};
|
||||
|
||||
void* get_memory_near(const void* address, const size_t size)
|
||||
{
|
||||
static concurrency::container<std::vector<memory>> memory_container{};
|
||||
|
||||
return memory_container.access<void*>([&](std::vector<memory>& memories)
|
||||
{
|
||||
for (auto& memory : memories)
|
||||
{
|
||||
if (!is_relatively_far(address, memory.get_ptr()))
|
||||
{
|
||||
const auto buffer = memory.allocate(size);
|
||||
if (buffer)
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
memories.emplace_back(address);
|
||||
return memories.back().allocate(size);
|
||||
});
|
||||
}
|
||||
|
||||
void* initialize_min_hook()
|
||||
{
|
||||
static class min_hook_init
|
||||
{
|
||||
public:
|
||||
min_hook_init()
|
||||
{
|
||||
if (MH_Initialize() != MH_OK)
|
||||
{
|
||||
throw std::runtime_error("Failed to initialize MinHook");
|
||||
}
|
||||
}
|
||||
|
||||
~min_hook_init()
|
||||
{
|
||||
MH_Uninitialize();
|
||||
}
|
||||
} min_hook_init;
|
||||
return &min_hook_init;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
detour::detour()
|
||||
{
|
||||
(void)initialize_min_hook();
|
||||
}
|
||||
|
||||
detour::detour(const size_t place, void* target)
|
||||
: detour(reinterpret_cast<void*>(place), target)
|
||||
{
|
||||
}
|
||||
|
||||
detour::detour(void* place, void* target)
|
||||
: detour()
|
||||
{
|
||||
this->create(place, target);
|
||||
}
|
||||
|
||||
detour::~detour()
|
||||
{
|
||||
this->clear();
|
||||
}
|
||||
|
||||
void detour::enable()
|
||||
{
|
||||
MH_EnableHook(this->place_);
|
||||
if (!this->moved_data_.empty())
|
||||
{
|
||||
this->move();
|
||||
}
|
||||
}
|
||||
|
||||
void detour::disable()
|
||||
{
|
||||
this->un_move();
|
||||
MH_DisableHook(this->place_);
|
||||
}
|
||||
|
||||
void detour::create(void* place, void* target)
|
||||
{
|
||||
this->clear();
|
||||
this->place_ = place;
|
||||
|
||||
if (MH_CreateHook(this->place_, target, &this->original_) != MH_OK)
|
||||
{
|
||||
//throw std::runtime_error(string::va("Unable to create hook at location: %p", this->place_));
|
||||
}
|
||||
|
||||
this->enable();
|
||||
}
|
||||
|
||||
void detour::create(const size_t place, void* target)
|
||||
{
|
||||
MH_Initialize();
|
||||
this->create(reinterpret_cast<void*>(place), target);
|
||||
}
|
||||
|
||||
void detour::clear()
|
||||
{
|
||||
if (this->place_)
|
||||
{
|
||||
this->un_move();
|
||||
MH_RemoveHook(this->place_);
|
||||
}
|
||||
|
||||
this->place_ = nullptr;
|
||||
this->original_ = nullptr;
|
||||
this->moved_data_ = {};
|
||||
}
|
||||
|
||||
void detour::move()
|
||||
{
|
||||
this->moved_data_ = move_hook(this->place_);
|
||||
}
|
||||
|
||||
void* detour::get_place() const
|
||||
{
|
||||
return this->place_;
|
||||
}
|
||||
|
||||
void* detour::get_original() const
|
||||
{
|
||||
return this->original_;
|
||||
}
|
||||
|
||||
void detour::un_move()
|
||||
{
|
||||
if (!this->moved_data_.empty())
|
||||
{
|
||||
copy(this->place_, this->moved_data_.data(), this->moved_data_.size());
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<std::pair<void*, void*>> iat(const nt::library& library, const std::string& target_library, const std::string& process, void* stub)
|
||||
{
|
||||
if (!library.is_valid()) return {};
|
||||
|
||||
auto* const ptr = library.get_iat_entry(target_library, process);
|
||||
if (!ptr) return {};
|
||||
|
||||
DWORD protect;
|
||||
VirtualProtect(ptr, sizeof(*ptr), PAGE_EXECUTE_READWRITE, &protect);
|
||||
|
||||
std::swap(*ptr, stub);
|
||||
|
||||
VirtualProtect(ptr, sizeof(*ptr), protect, &protect);
|
||||
return {{ptr, stub}};
|
||||
}
|
||||
|
||||
void nop(void* place, const size_t length)
|
||||
{
|
||||
DWORD old_protect{};
|
||||
VirtualProtect(place, length, PAGE_EXECUTE_READWRITE, &old_protect);
|
||||
|
||||
std::memset(place, 0x90, length);
|
||||
|
||||
VirtualProtect(place, length, old_protect, &old_protect);
|
||||
FlushInstructionCache(GetCurrentProcess(), place, length);
|
||||
}
|
||||
|
||||
void nop(const size_t place, const size_t length)
|
||||
{
|
||||
nop(reinterpret_cast<void*>(place), length);
|
||||
}
|
||||
|
||||
void copy(void* place, const void* data, const size_t length)
|
||||
{
|
||||
DWORD old_protect{};
|
||||
VirtualProtect(place, length, PAGE_EXECUTE_READWRITE, &old_protect);
|
||||
|
||||
std::memmove(place, data, length);
|
||||
|
||||
VirtualProtect(place, length, old_protect, &old_protect);
|
||||
FlushInstructionCache(GetCurrentProcess(), place, length);
|
||||
}
|
||||
|
||||
void copy(const size_t place, const void* data, const size_t length)
|
||||
{
|
||||
copy(reinterpret_cast<void*>(place), data, length);
|
||||
}
|
||||
|
||||
void copy_string(void* place, const char* str)
|
||||
{
|
||||
copy(reinterpret_cast<void*>(place), str, strlen(str) + 1);
|
||||
}
|
||||
|
||||
void copy_string(const size_t place, const char* str)
|
||||
{
|
||||
copy_string(reinterpret_cast<void*>(place), str);
|
||||
}
|
||||
|
||||
bool is_relatively_far(const void* pointer, const void* data, const int offset)
|
||||
{
|
||||
const int64_t diff = size_t(data) - (size_t(pointer) + offset);
|
||||
const auto small_diff = int32_t(diff);
|
||||
return diff != int64_t(small_diff);
|
||||
}
|
||||
|
||||
void call(void* pointer, void* data)
|
||||
{
|
||||
if (is_relatively_far(pointer, data))
|
||||
{
|
||||
auto* trampoline = get_memory_near(pointer, 14);
|
||||
if (!trampoline)
|
||||
{
|
||||
throw std::runtime_error("Too far away to create 32bit relative branch");
|
||||
}
|
||||
|
||||
call(pointer, trampoline);
|
||||
jump(trampoline, data, true, true);
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t copy_data[5];
|
||||
copy_data[0] = 0xE8;
|
||||
*reinterpret_cast<int32_t*>(©_data[1]) = int32_t(size_t(data) - (size_t(pointer) + 5));
|
||||
|
||||
auto* patch_pointer = PBYTE(pointer);
|
||||
copy(patch_pointer, copy_data, sizeof(copy_data));
|
||||
}
|
||||
|
||||
void call(const size_t pointer, void* data)
|
||||
{
|
||||
return call(reinterpret_cast<void*>(pointer), data);
|
||||
}
|
||||
|
||||
void call(const size_t pointer, const size_t data)
|
||||
{
|
||||
return call(pointer, reinterpret_cast<void*>(data));
|
||||
}
|
||||
|
||||
void jump(void* pointer, void* data, const bool use_far, const bool use_safe)
|
||||
{
|
||||
static const unsigned char jump_data[] = {
|
||||
0x48, 0xb8, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0xff, 0xe0
|
||||
};
|
||||
|
||||
static const unsigned char jump_data_safe[] = {
|
||||
0xFF, 0x25, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
if (!use_far && is_relatively_far(pointer, data))
|
||||
{
|
||||
auto* trampoline = get_memory_near(pointer, 14);
|
||||
if (!trampoline)
|
||||
{
|
||||
throw std::runtime_error("Too far away to create 32bit relative branch");
|
||||
}
|
||||
jump(pointer, trampoline, false, false);
|
||||
jump(trampoline, data, true, true);
|
||||
return;
|
||||
}
|
||||
|
||||
auto* patch_pointer = PBYTE(pointer);
|
||||
|
||||
if (use_far)
|
||||
{
|
||||
if (use_safe)
|
||||
{
|
||||
uint8_t copy_data[sizeof(jump_data_safe) + sizeof(data)];
|
||||
memcpy(copy_data, jump_data_safe, sizeof(jump_data_safe));
|
||||
memcpy(copy_data + sizeof(jump_data_safe), &data, sizeof(data));
|
||||
|
||||
copy(patch_pointer, copy_data, sizeof(copy_data));
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t copy_data[sizeof(jump_data)];
|
||||
memcpy(copy_data, jump_data, sizeof(jump_data));
|
||||
memcpy(copy_data + 2, &data, sizeof(data));
|
||||
|
||||
copy(patch_pointer, copy_data, sizeof(copy_data));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t copy_data[5];
|
||||
copy_data[0] = 0xE9;
|
||||
*reinterpret_cast<int32_t*>(©_data[1]) = int32_t(size_t(data) - (size_t(pointer) + 5));
|
||||
|
||||
copy(patch_pointer, copy_data, sizeof(copy_data));
|
||||
}
|
||||
}
|
||||
|
||||
void jump(const size_t pointer, void* data, const bool use_far, const bool use_safe)
|
||||
{
|
||||
return jump(reinterpret_cast<void*>(pointer), data, use_far, use_safe);
|
||||
}
|
||||
|
||||
void jump(const size_t pointer, const size_t data, const bool use_far, const bool use_safe)
|
||||
{
|
||||
return jump(pointer, reinterpret_cast<void*>(data), use_far, use_safe);
|
||||
}
|
||||
|
||||
|
||||
void inject(void* pointer, const void* data)
|
||||
{
|
||||
if (is_relatively_far(pointer, data, 4))
|
||||
{
|
||||
throw std::runtime_error("Too far away to create 32bit relative branch");
|
||||
}
|
||||
|
||||
set<int32_t>(pointer, int32_t(size_t(data) - (size_t(pointer) + 4)));
|
||||
}
|
||||
|
||||
void inject(const size_t pointer, const void* data)
|
||||
{
|
||||
return inject(reinterpret_cast<void*>(pointer), data);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> move_hook(void* pointer)
|
||||
{
|
||||
std::vector<uint8_t> original_data{};
|
||||
|
||||
auto* data_ptr = static_cast<uint8_t*>(pointer);
|
||||
if (data_ptr[0] == 0xE9)
|
||||
{
|
||||
original_data.resize(6);
|
||||
memmove(original_data.data(), pointer, original_data.size());
|
||||
|
||||
auto* target = follow_branch(data_ptr);
|
||||
nop(data_ptr, 1);
|
||||
jump(data_ptr + 1, target);
|
||||
}
|
||||
else if (data_ptr[0] == 0xFF && data_ptr[1] == 0x25)
|
||||
{
|
||||
original_data.resize(15);
|
||||
memmove(original_data.data(), pointer, original_data.size());
|
||||
|
||||
copy(data_ptr + 1, data_ptr, 14);
|
||||
nop(data_ptr, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("No branch instruction found");
|
||||
}
|
||||
|
||||
return original_data;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> move_hook(const size_t pointer)
|
||||
{
|
||||
return move_hook(reinterpret_cast<void*>(pointer));
|
||||
}
|
||||
|
||||
void* follow_branch(void* address)
|
||||
{
|
||||
auto* const data = static_cast<uint8_t*>(address);
|
||||
if (*data != 0xE8 && *data != 0xE9)
|
||||
{
|
||||
throw std::runtime_error("No branch instruction found");
|
||||
}
|
||||
|
||||
return extract<void*>(data + 1);
|
||||
}
|
||||
}
|
||||
|
@ -1,186 +1,186 @@
|
||||
#pragma once
|
||||
#include "signature.hpp"
|
||||
|
||||
#pragma comment(lib, "minhook.lib")
|
||||
|
||||
namespace utils::hook
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template <size_t Entries>
|
||||
std::vector<size_t(*)()> get_iota_functions()
|
||||
{
|
||||
if constexpr (Entries == 0)
|
||||
{
|
||||
std::vector<size_t(*)()> functions;
|
||||
return functions;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto functions = get_iota_functions<Entries - 1>();
|
||||
functions.emplace_back([]()
|
||||
{
|
||||
return Entries - 1;
|
||||
});
|
||||
return functions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Gets the pointer to the entry in the v-table.
|
||||
// It seems otherwise impossible to get this.
|
||||
// This is ugly as fuck and only safely works on x64
|
||||
// Example:
|
||||
// ID3D11Device* device = ...
|
||||
// auto entry = get_vtable_entry(device, &ID3D11Device::CreateTexture2D);
|
||||
template <size_t Entries = 100, typename Class, typename T, typename... Args>
|
||||
void** get_vtable_entry(Class* obj, T (Class::* entry)(Args ...))
|
||||
{
|
||||
union
|
||||
{
|
||||
decltype(entry) func;
|
||||
void* pointer;
|
||||
};
|
||||
|
||||
func = entry;
|
||||
|
||||
auto iota_functions = detail::get_iota_functions<Entries>();
|
||||
auto* object = iota_functions.data();
|
||||
|
||||
using fake_func = size_t(__thiscall*)(void* self);
|
||||
auto index = static_cast<fake_func>(pointer)(&object);
|
||||
|
||||
void** obj_v_table = *reinterpret_cast<void***>(obj);
|
||||
return &obj_v_table[index];
|
||||
}
|
||||
|
||||
|
||||
class detour
|
||||
{
|
||||
public:
|
||||
detour();
|
||||
detour(void* place, void* target);
|
||||
detour(size_t place, void* target);
|
||||
~detour();
|
||||
|
||||
detour(detour&& other) noexcept
|
||||
{
|
||||
this->operator=(std::move(other));
|
||||
}
|
||||
|
||||
detour& operator=(detour&& other) noexcept
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
this->clear();
|
||||
|
||||
this->place_ = other.place_;
|
||||
this->original_ = other.original_;
|
||||
this->moved_data_ = other.moved_data_;
|
||||
|
||||
other.place_ = nullptr;
|
||||
other.original_ = nullptr;
|
||||
other.moved_data_ = {};
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
detour(const detour&) = delete;
|
||||
detour& operator=(const detour&) = delete;
|
||||
|
||||
void enable();
|
||||
void disable();
|
||||
|
||||
void create(void* place, void* target);
|
||||
void create(size_t place, void* target);
|
||||
void clear();
|
||||
|
||||
void move();
|
||||
|
||||
void* get_place() const;
|
||||
|
||||
template <typename T>
|
||||
T* get() const
|
||||
{
|
||||
return static_cast<T*>(this->get_original());
|
||||
}
|
||||
|
||||
template <typename T = void, typename... Args>
|
||||
T stub(Args ... args)
|
||||
{
|
||||
return static_cast<T(*)(Args ...)>(this->get_original())(args...);
|
||||
}
|
||||
|
||||
[[nodiscard]] void* get_original() const;
|
||||
|
||||
private:
|
||||
std::vector<uint8_t> moved_data_{};
|
||||
void* place_{};
|
||||
void* original_{};
|
||||
|
||||
void un_move();
|
||||
};
|
||||
|
||||
std::optional<std::pair<void*, void*>> iat(const nt::library& library, const std::string& target_library,
|
||||
const std::string& process, void* stub);
|
||||
|
||||
void nop(void* place, size_t length);
|
||||
void nop(size_t place, size_t length);
|
||||
|
||||
void copy(void* place, const void* data, size_t length);
|
||||
void copy(size_t place, const void* data, size_t length);
|
||||
|
||||
void copy_string(void* place, const char* str);
|
||||
void copy_string(size_t place, const char* str);
|
||||
|
||||
bool is_relatively_far(const void* pointer, const void* data, int offset = 5);
|
||||
|
||||
void call(void* pointer, void* data);
|
||||
void call(size_t pointer, void* data);
|
||||
void call(size_t pointer, size_t data);
|
||||
|
||||
void jump(void* pointer, void* data, bool use_far = false, bool use_safe = false);
|
||||
void jump(size_t pointer, void* data, bool use_far = false, bool use_safe = false);
|
||||
void jump(size_t pointer, size_t data, bool use_far = false, bool use_safe = false);
|
||||
|
||||
void inject(void* pointer, const void* data);
|
||||
void inject(size_t pointer, const void* data);
|
||||
|
||||
std::vector<uint8_t> move_hook(void* pointer);
|
||||
std::vector<uint8_t> move_hook(size_t pointer);
|
||||
|
||||
template <typename T>
|
||||
T extract(void* address)
|
||||
{
|
||||
auto* const data = static_cast<uint8_t*>(address);
|
||||
const auto offset = *reinterpret_cast<int32_t*>(data);
|
||||
return reinterpret_cast<T>(data + offset + 4);
|
||||
}
|
||||
|
||||
void* follow_branch(void* address);
|
||||
|
||||
template <typename T>
|
||||
static void set(void* place, T value = false)
|
||||
{
|
||||
copy(place, &value, sizeof(value));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void set(const size_t place, T value = false)
|
||||
{
|
||||
return set<T>(reinterpret_cast<void*>(place), value);
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
static T invoke(size_t func, Args ... args)
|
||||
{
|
||||
return reinterpret_cast<T(*)(Args ...)>(func)(args...);
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
static T invoke(void* func, Args ... args)
|
||||
{
|
||||
return static_cast<T(*)(Args ...)>(func)(args...);
|
||||
}
|
||||
}
|
||||
#pragma once
|
||||
#include "signature.hpp"
|
||||
|
||||
#pragma comment(lib, "minhook.lib")
|
||||
|
||||
namespace utils::hook
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template <size_t Entries>
|
||||
std::vector<size_t(*)()> get_iota_functions()
|
||||
{
|
||||
if constexpr (Entries == 0)
|
||||
{
|
||||
std::vector<size_t(*)()> functions;
|
||||
return functions;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto functions = get_iota_functions<Entries - 1>();
|
||||
functions.emplace_back([]()
|
||||
{
|
||||
return Entries - 1;
|
||||
});
|
||||
return functions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Gets the pointer to the entry in the v-table.
|
||||
// It seems otherwise impossible to get this.
|
||||
// This is ugly as fuck and only safely works on x64
|
||||
// Example:
|
||||
// ID3D11Device* device = ...
|
||||
// auto entry = get_vtable_entry(device, &ID3D11Device::CreateTexture2D);
|
||||
template <size_t Entries = 100, typename Class, typename T, typename... Args>
|
||||
void** get_vtable_entry(Class* obj, T (Class::* entry)(Args ...))
|
||||
{
|
||||
union
|
||||
{
|
||||
decltype(entry) func;
|
||||
void* pointer;
|
||||
};
|
||||
|
||||
func = entry;
|
||||
|
||||
auto iota_functions = detail::get_iota_functions<Entries>();
|
||||
auto* object = iota_functions.data();
|
||||
|
||||
using fake_func = size_t(__thiscall*)(void* self);
|
||||
auto index = static_cast<fake_func>(pointer)(&object);
|
||||
|
||||
void** obj_v_table = *reinterpret_cast<void***>(obj);
|
||||
return &obj_v_table[index];
|
||||
}
|
||||
|
||||
|
||||
class detour
|
||||
{
|
||||
public:
|
||||
detour();
|
||||
detour(void* place, void* target);
|
||||
detour(size_t place, void* target);
|
||||
~detour();
|
||||
|
||||
detour(detour&& other) noexcept
|
||||
{
|
||||
this->operator=(std::move(other));
|
||||
}
|
||||
|
||||
detour& operator=(detour&& other) noexcept
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
this->clear();
|
||||
|
||||
this->place_ = other.place_;
|
||||
this->original_ = other.original_;
|
||||
this->moved_data_ = other.moved_data_;
|
||||
|
||||
other.place_ = nullptr;
|
||||
other.original_ = nullptr;
|
||||
other.moved_data_ = {};
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
detour(const detour&) = delete;
|
||||
detour& operator=(const detour&) = delete;
|
||||
|
||||
void enable();
|
||||
void disable();
|
||||
|
||||
void create(void* place, void* target);
|
||||
void create(size_t place, void* target);
|
||||
void clear();
|
||||
|
||||
void move();
|
||||
|
||||
void* get_place() const;
|
||||
|
||||
template <typename T>
|
||||
T* get() const
|
||||
{
|
||||
return static_cast<T*>(this->get_original());
|
||||
}
|
||||
|
||||
template <typename T = void, typename... Args>
|
||||
T stub(Args ... args)
|
||||
{
|
||||
return static_cast<T(*)(Args ...)>(this->get_original())(args...);
|
||||
}
|
||||
|
||||
[[nodiscard]] void* get_original() const;
|
||||
|
||||
private:
|
||||
std::vector<uint8_t> moved_data_{};
|
||||
void* place_{};
|
||||
void* original_{};
|
||||
|
||||
void un_move();
|
||||
};
|
||||
|
||||
std::optional<std::pair<void*, void*>> iat(const nt::library& library, const std::string& target_library,
|
||||
const std::string& process, void* stub);
|
||||
|
||||
void nop(void* place, size_t length);
|
||||
void nop(size_t place, size_t length);
|
||||
|
||||
void copy(void* place, const void* data, size_t length);
|
||||
void copy(size_t place, const void* data, size_t length);
|
||||
|
||||
void copy_string(void* place, const char* str);
|
||||
void copy_string(size_t place, const char* str);
|
||||
|
||||
bool is_relatively_far(const void* pointer, const void* data, int offset = 5);
|
||||
|
||||
void call(void* pointer, void* data);
|
||||
void call(size_t pointer, void* data);
|
||||
void call(size_t pointer, size_t data);
|
||||
|
||||
void jump(void* pointer, void* data, bool use_far = false, bool use_safe = false);
|
||||
void jump(size_t pointer, void* data, bool use_far = false, bool use_safe = false);
|
||||
void jump(size_t pointer, size_t data, bool use_far = false, bool use_safe = false);
|
||||
|
||||
void inject(void* pointer, const void* data);
|
||||
void inject(size_t pointer, const void* data);
|
||||
|
||||
std::vector<uint8_t> move_hook(void* pointer);
|
||||
std::vector<uint8_t> move_hook(size_t pointer);
|
||||
|
||||
template <typename T>
|
||||
T extract(void* address)
|
||||
{
|
||||
auto* const data = static_cast<uint8_t*>(address);
|
||||
const auto offset = *reinterpret_cast<int32_t*>(data);
|
||||
return reinterpret_cast<T>(data + offset + 4);
|
||||
}
|
||||
|
||||
void* follow_branch(void* address);
|
||||
|
||||
template <typename T>
|
||||
static void set(void* place, T value = false)
|
||||
{
|
||||
copy(place, &value, sizeof(value));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void set(const size_t place, T value = false)
|
||||
{
|
||||
return set<T>(reinterpret_cast<void*>(place), value);
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
static T invoke(size_t func, Args ... args)
|
||||
{
|
||||
return reinterpret_cast<T(*)(Args ...)>(func)(args...);
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
static T invoke(void* func, Args ... args)
|
||||
{
|
||||
return static_cast<T(*)(Args ...)>(func)(args...);
|
||||
}
|
||||
}
|
||||
|
@ -1,48 +1,48 @@
|
||||
#include "http.hpp"
|
||||
#include "nt.hpp"
|
||||
#include <atlcomcli.h>
|
||||
|
||||
namespace utils::http
|
||||
{
|
||||
std::optional<std::string> get_data(const std::string& url)
|
||||
{
|
||||
CComPtr<IStream> stream;
|
||||
|
||||
if (FAILED(URLOpenBlockingStreamA(nullptr, url.data(), &stream, 0, nullptr)))
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
char buffer[0x1000];
|
||||
std::string result;
|
||||
|
||||
HRESULT status{};
|
||||
|
||||
do
|
||||
{
|
||||
DWORD bytes_read = 0;
|
||||
status = stream->Read(buffer, sizeof(buffer), &bytes_read);
|
||||
|
||||
if (bytes_read > 0)
|
||||
{
|
||||
result.append(buffer, bytes_read);
|
||||
}
|
||||
}
|
||||
while (SUCCEEDED(status) && status != S_FALSE);
|
||||
|
||||
if (FAILED(status))
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
return {result};
|
||||
}
|
||||
|
||||
std::future<std::optional<std::string>> get_data_async(const std::string& url)
|
||||
{
|
||||
return std::async(std::launch::async, [url]()
|
||||
{
|
||||
return get_data(url);
|
||||
});
|
||||
}
|
||||
}
|
||||
#include "http.hpp"
|
||||
#include "nt.hpp"
|
||||
#include <atlcomcli.h>
|
||||
|
||||
namespace utils::http
|
||||
{
|
||||
std::optional<std::string> get_data(const std::string& url)
|
||||
{
|
||||
CComPtr<IStream> stream;
|
||||
|
||||
if (FAILED(URLOpenBlockingStreamA(nullptr, url.data(), &stream, 0, nullptr)))
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
char buffer[0x1000];
|
||||
std::string result;
|
||||
|
||||
HRESULT status{};
|
||||
|
||||
do
|
||||
{
|
||||
DWORD bytes_read = 0;
|
||||
status = stream->Read(buffer, sizeof(buffer), &bytes_read);
|
||||
|
||||
if (bytes_read > 0)
|
||||
{
|
||||
result.append(buffer, bytes_read);
|
||||
}
|
||||
}
|
||||
while (SUCCEEDED(status) && status != S_FALSE);
|
||||
|
||||
if (FAILED(status))
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
return {result};
|
||||
}
|
||||
|
||||
std::future<std::optional<std::string>> get_data_async(const std::string& url)
|
||||
{
|
||||
return std::async(std::launch::async, [url]()
|
||||
{
|
||||
return get_data(url);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <optional>
|
||||
#include <future>
|
||||
|
||||
#pragma comment(lib, "Urlmon.lib")
|
||||
|
||||
namespace utils::http
|
||||
{
|
||||
std::optional<std::string> get_data(const std::string& url);
|
||||
std::future<std::optional<std::string>> get_data_async(const std::string& url);
|
||||
}
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <optional>
|
||||
#include <future>
|
||||
|
||||
#pragma comment(lib, "Urlmon.lib")
|
||||
|
||||
namespace utils::http
|
||||
{
|
||||
std::optional<std::string> get_data(const std::string& url);
|
||||
std::future<std::optional<std::string>> get_data_async(const std::string& url);
|
||||
}
|
||||
|
@ -1,130 +1,130 @@
|
||||
#include "io.hpp"
|
||||
#include "nt.hpp"
|
||||
#include <fstream>
|
||||
|
||||
namespace utils::io
|
||||
{
|
||||
bool remove_file(const std::filesystem::path& file)
|
||||
{
|
||||
if(DeleteFileW(file.wstring().data()) != FALSE)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return GetLastError() == ERROR_FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
bool move_file(const std::filesystem::path& src, const std::filesystem::path& target)
|
||||
{
|
||||
return MoveFileW(src.wstring().data(), target.wstring().data()) == TRUE;
|
||||
}
|
||||
|
||||
bool file_exists(const std::string& file)
|
||||
{
|
||||
return std::ifstream(file).good();
|
||||
}
|
||||
|
||||
bool write_file(const std::string& file, const std::string& data, const bool append)
|
||||
{
|
||||
const auto pos = file.find_last_of("/\\");
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
create_directory(file.substr(0, pos));
|
||||
}
|
||||
|
||||
std::ofstream stream(
|
||||
file, std::ios::binary | std::ofstream::out | (append ? std::ofstream::app : 0));
|
||||
|
||||
if (stream.is_open())
|
||||
{
|
||||
stream.write(data.data(), static_cast<std::streamsize>(data.size()));
|
||||
stream.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string read_file(const std::string& file)
|
||||
{
|
||||
std::string data;
|
||||
read_file(file, &data);
|
||||
return data;
|
||||
}
|
||||
|
||||
bool read_file(const std::string& file, std::string* data)
|
||||
{
|
||||
if (!data) return false;
|
||||
data->clear();
|
||||
|
||||
if (file_exists(file))
|
||||
{
|
||||
std::ifstream stream(file, std::ios::binary);
|
||||
if (!stream.is_open()) return false;
|
||||
|
||||
stream.seekg(0, std::ios::end);
|
||||
const std::streamsize size = stream.tellg();
|
||||
stream.seekg(0, std::ios::beg);
|
||||
|
||||
if (size > -1)
|
||||
{
|
||||
data->resize(static_cast<std::uint32_t>(size));
|
||||
stream.read(data->data(), size);
|
||||
stream.close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::size_t file_size(const std::string& file)
|
||||
{
|
||||
if (file_exists(file))
|
||||
{
|
||||
std::ifstream stream(file, std::ios::binary);
|
||||
|
||||
if (stream.good())
|
||||
{
|
||||
stream.seekg(0, std::ios::end);
|
||||
return static_cast<std::size_t>(stream.tellg());
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool create_directory(const std::filesystem::path& directory)
|
||||
{
|
||||
return std::filesystem::create_directories(directory);
|
||||
}
|
||||
|
||||
bool directory_exists(const std::filesystem::path& directory)
|
||||
{
|
||||
return std::filesystem::is_directory(directory);
|
||||
}
|
||||
|
||||
bool directory_is_empty(const std::filesystem::path& directory)
|
||||
{
|
||||
return std::filesystem::is_empty(directory);
|
||||
}
|
||||
|
||||
std::vector<std::string> list_files(const std::filesystem::path& directory)
|
||||
{
|
||||
std::vector<std::string> files;
|
||||
|
||||
for (auto& file : std::filesystem::directory_iterator(directory))
|
||||
{
|
||||
files.push_back(file.path().generic_string());
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
void copy_folder(const std::filesystem::path& src, const std::filesystem::path& target)
|
||||
{
|
||||
std::filesystem::copy(src, target,
|
||||
std::filesystem::copy_options::overwrite_existing |
|
||||
std::filesystem::copy_options::recursive);
|
||||
}
|
||||
}
|
||||
#include "io.hpp"
|
||||
#include "nt.hpp"
|
||||
#include <fstream>
|
||||
|
||||
namespace utils::io
|
||||
{
|
||||
bool remove_file(const std::filesystem::path& file)
|
||||
{
|
||||
if(DeleteFileW(file.wstring().data()) != FALSE)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return GetLastError() == ERROR_FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
bool move_file(const std::filesystem::path& src, const std::filesystem::path& target)
|
||||
{
|
||||
return MoveFileW(src.wstring().data(), target.wstring().data()) == TRUE;
|
||||
}
|
||||
|
||||
bool file_exists(const std::string& file)
|
||||
{
|
||||
return std::ifstream(file).good();
|
||||
}
|
||||
|
||||
bool write_file(const std::string& file, const std::string& data, const bool append)
|
||||
{
|
||||
const auto pos = file.find_last_of("/\\");
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
create_directory(file.substr(0, pos));
|
||||
}
|
||||
|
||||
std::ofstream stream(
|
||||
file, std::ios::binary | std::ofstream::out | (append ? std::ofstream::app : 0));
|
||||
|
||||
if (stream.is_open())
|
||||
{
|
||||
stream.write(data.data(), static_cast<std::streamsize>(data.size()));
|
||||
stream.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string read_file(const std::string& file)
|
||||
{
|
||||
std::string data;
|
||||
read_file(file, &data);
|
||||
return data;
|
||||
}
|
||||
|
||||
bool read_file(const std::string& file, std::string* data)
|
||||
{
|
||||
if (!data) return false;
|
||||
data->clear();
|
||||
|
||||
if (file_exists(file))
|
||||
{
|
||||
std::ifstream stream(file, std::ios::binary);
|
||||
if (!stream.is_open()) return false;
|
||||
|
||||
stream.seekg(0, std::ios::end);
|
||||
const std::streamsize size = stream.tellg();
|
||||
stream.seekg(0, std::ios::beg);
|
||||
|
||||
if (size > -1)
|
||||
{
|
||||
data->resize(static_cast<std::uint32_t>(size));
|
||||
stream.read(data->data(), size);
|
||||
stream.close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::size_t file_size(const std::string& file)
|
||||
{
|
||||
if (file_exists(file))
|
||||
{
|
||||
std::ifstream stream(file, std::ios::binary);
|
||||
|
||||
if (stream.good())
|
||||
{
|
||||
stream.seekg(0, std::ios::end);
|
||||
return static_cast<std::size_t>(stream.tellg());
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool create_directory(const std::filesystem::path& directory)
|
||||
{
|
||||
return std::filesystem::create_directories(directory);
|
||||
}
|
||||
|
||||
bool directory_exists(const std::filesystem::path& directory)
|
||||
{
|
||||
return std::filesystem::is_directory(directory);
|
||||
}
|
||||
|
||||
bool directory_is_empty(const std::filesystem::path& directory)
|
||||
{
|
||||
return std::filesystem::is_empty(directory);
|
||||
}
|
||||
|
||||
std::vector<std::string> list_files(const std::filesystem::path& directory)
|
||||
{
|
||||
std::vector<std::string> files;
|
||||
|
||||
for (auto& file : std::filesystem::directory_iterator(directory))
|
||||
{
|
||||
files.push_back(file.path().generic_string());
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
void copy_folder(const std::filesystem::path& src, const std::filesystem::path& target)
|
||||
{
|
||||
std::filesystem::copy(src, target,
|
||||
std::filesystem::copy_options::overwrite_existing |
|
||||
std::filesystem::copy_options::recursive);
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <filesystem>
|
||||
|
||||
namespace utils::io
|
||||
{
|
||||
bool remove_file(const std::filesystem::path& file);
|
||||
bool move_file(const std::filesystem::path& src, const std::filesystem::path& target);
|
||||
bool file_exists(const std::string& file);
|
||||
bool write_file(const std::string& file, const std::string& data, bool append = false);
|
||||
bool read_file(const std::string& file, std::string* data);
|
||||
std::string read_file(const std::string& file);
|
||||
size_t file_size(const std::string& file);
|
||||
bool create_directory(const std::filesystem::path& directory);
|
||||
bool directory_exists(const std::filesystem::path& directory);
|
||||
bool directory_is_empty(const std::filesystem::path& directory);
|
||||
std::vector<std::string> list_files(const std::filesystem::path& directory);
|
||||
void copy_folder(const std::filesystem::path& src, const std::filesystem::path& target);
|
||||
}
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <filesystem>
|
||||
|
||||
namespace utils::io
|
||||
{
|
||||
bool remove_file(const std::filesystem::path& file);
|
||||
bool move_file(const std::filesystem::path& src, const std::filesystem::path& target);
|
||||
bool file_exists(const std::string& file);
|
||||
bool write_file(const std::string& file, const std::string& data, bool append = false);
|
||||
bool read_file(const std::string& file, std::string* data);
|
||||
std::string read_file(const std::string& file);
|
||||
size_t file_size(const std::string& file);
|
||||
bool create_directory(const std::filesystem::path& directory);
|
||||
bool directory_exists(const std::filesystem::path& directory);
|
||||
bool directory_is_empty(const std::filesystem::path& directory);
|
||||
std::vector<std::string> list_files(const std::filesystem::path& directory);
|
||||
void copy_folder(const std::filesystem::path& src, const std::filesystem::path& target);
|
||||
}
|
||||
|
@ -1,170 +1,170 @@
|
||||
#include "memory.hpp"
|
||||
#include "nt.hpp"
|
||||
|
||||
namespace utils
|
||||
{
|
||||
memory::allocator memory::mem_allocator_;
|
||||
|
||||
memory::allocator::~allocator()
|
||||
{
|
||||
this->clear();
|
||||
}
|
||||
|
||||
void memory::allocator::clear()
|
||||
{
|
||||
std::lock_guard _(this->mutex_);
|
||||
|
||||
for (auto& data : this->pool_)
|
||||
{
|
||||
memory::free(data);
|
||||
}
|
||||
|
||||
this->pool_.clear();
|
||||
}
|
||||
|
||||
void memory::allocator::free(void* data)
|
||||
{
|
||||
std::lock_guard _(this->mutex_);
|
||||
|
||||
const auto j = std::find(this->pool_.begin(), this->pool_.end(), data);
|
||||
if (j != this->pool_.end())
|
||||
{
|
||||
memory::free(data);
|
||||
this->pool_.erase(j);
|
||||
}
|
||||
}
|
||||
|
||||
void memory::allocator::free(const void* data)
|
||||
{
|
||||
this->free(const_cast<void*>(data));
|
||||
}
|
||||
|
||||
void* memory::allocator::allocate(const size_t length)
|
||||
{
|
||||
std::lock_guard _(this->mutex_);
|
||||
|
||||
const auto data = memory::allocate(length);
|
||||
this->pool_.push_back(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
bool memory::allocator::empty() const
|
||||
{
|
||||
return this->pool_.empty();
|
||||
}
|
||||
|
||||
char* memory::allocator::duplicate_string(const std::string& string)
|
||||
{
|
||||
std::lock_guard _(this->mutex_);
|
||||
|
||||
const auto data = memory::duplicate_string(string);
|
||||
this->pool_.push_back(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
bool memory::allocator::find(const void* data)
|
||||
{
|
||||
std::lock_guard _(this->mutex_);
|
||||
|
||||
const auto j = std::find(this->pool_.begin(), this->pool_.end(), data);
|
||||
return j != this->pool_.end();
|
||||
}
|
||||
|
||||
void* memory::allocate(const size_t length)
|
||||
{
|
||||
return std::calloc(length, 1);
|
||||
}
|
||||
|
||||
char* memory::duplicate_string(const std::string& string)
|
||||
{
|
||||
const auto new_string = allocate_array<char>(string.size() + 1);
|
||||
std::memcpy(new_string, string.data(), string.size());
|
||||
return new_string;
|
||||
}
|
||||
|
||||
void memory::free(void* data)
|
||||
{
|
||||
std::free(data);
|
||||
}
|
||||
|
||||
void memory::free(const void* data)
|
||||
{
|
||||
free(const_cast<void*>(data));
|
||||
}
|
||||
|
||||
bool memory::is_set(const void* mem, const char chr, const size_t length)
|
||||
{
|
||||
const auto mem_arr = static_cast<const char*>(mem);
|
||||
|
||||
for (size_t i = 0; i < length; ++i)
|
||||
{
|
||||
if (mem_arr[i] != chr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool memory::is_bad_read_ptr(const void* ptr)
|
||||
{
|
||||
MEMORY_BASIC_INFORMATION mbi = {};
|
||||
if (VirtualQuery(ptr, &mbi, sizeof(mbi)))
|
||||
{
|
||||
const DWORD mask = (PAGE_READONLY | PAGE_READWRITE | PAGE_WRITECOPY | PAGE_EXECUTE_READ |
|
||||
PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY);
|
||||
auto b = !(mbi.Protect & mask);
|
||||
// check the page is not a guard page
|
||||
if (mbi.Protect & (PAGE_GUARD | PAGE_NOACCESS)) b = true;
|
||||
|
||||
return b;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool memory::is_bad_code_ptr(const void* ptr)
|
||||
{
|
||||
MEMORY_BASIC_INFORMATION mbi = {};
|
||||
if (VirtualQuery(ptr, &mbi, sizeof(mbi)))
|
||||
{
|
||||
const DWORD mask = (PAGE_EXECUTE_READ | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY);
|
||||
auto b = !(mbi.Protect & mask);
|
||||
// check the page is not a guard page
|
||||
if (mbi.Protect & (PAGE_GUARD | PAGE_NOACCESS)) b = true;
|
||||
|
||||
return b;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool memory::is_rdata_ptr(void* pointer)
|
||||
{
|
||||
const std::string rdata = ".rdata";
|
||||
const auto pointer_lib = utils::nt::library::get_by_address(pointer);
|
||||
|
||||
for (const auto& section : pointer_lib.get_section_headers())
|
||||
{
|
||||
const auto size = sizeof(section->Name);
|
||||
char name[size + 1];
|
||||
name[size] = 0;
|
||||
std::memcpy(name, section->Name, size);
|
||||
|
||||
if (name == rdata)
|
||||
{
|
||||
const auto target = size_t(pointer);
|
||||
const size_t source_start = size_t(pointer_lib.get_ptr()) + section->PointerToRawData;
|
||||
const size_t source_end = source_start + section->SizeOfRawData;
|
||||
|
||||
return target >= source_start && target <= source_end;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
memory::allocator* memory::get_allocator()
|
||||
{
|
||||
return &memory::mem_allocator_;
|
||||
}
|
||||
}
|
||||
#include "memory.hpp"
|
||||
#include "nt.hpp"
|
||||
|
||||
namespace utils
|
||||
{
|
||||
memory::allocator memory::mem_allocator_;
|
||||
|
||||
memory::allocator::~allocator()
|
||||
{
|
||||
this->clear();
|
||||
}
|
||||
|
||||
void memory::allocator::clear()
|
||||
{
|
||||
std::lock_guard _(this->mutex_);
|
||||
|
||||
for (auto& data : this->pool_)
|
||||
{
|
||||
memory::free(data);
|
||||
}
|
||||
|
||||
this->pool_.clear();
|
||||
}
|
||||
|
||||
void memory::allocator::free(void* data)
|
||||
{
|
||||
std::lock_guard _(this->mutex_);
|
||||
|
||||
const auto j = std::find(this->pool_.begin(), this->pool_.end(), data);
|
||||
if (j != this->pool_.end())
|
||||
{
|
||||
memory::free(data);
|
||||
this->pool_.erase(j);
|
||||
}
|
||||
}
|
||||
|
||||
void memory::allocator::free(const void* data)
|
||||
{
|
||||
this->free(const_cast<void*>(data));
|
||||
}
|
||||
|
||||
void* memory::allocator::allocate(const size_t length)
|
||||
{
|
||||
std::lock_guard _(this->mutex_);
|
||||
|
||||
const auto data = memory::allocate(length);
|
||||
this->pool_.push_back(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
bool memory::allocator::empty() const
|
||||
{
|
||||
return this->pool_.empty();
|
||||
}
|
||||
|
||||
char* memory::allocator::duplicate_string(const std::string& string)
|
||||
{
|
||||
std::lock_guard _(this->mutex_);
|
||||
|
||||
const auto data = memory::duplicate_string(string);
|
||||
this->pool_.push_back(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
bool memory::allocator::find(const void* data)
|
||||
{
|
||||
std::lock_guard _(this->mutex_);
|
||||
|
||||
const auto j = std::find(this->pool_.begin(), this->pool_.end(), data);
|
||||
return j != this->pool_.end();
|
||||
}
|
||||
|
||||
void* memory::allocate(const size_t length)
|
||||
{
|
||||
return std::calloc(length, 1);
|
||||
}
|
||||
|
||||
char* memory::duplicate_string(const std::string& string)
|
||||
{
|
||||
const auto new_string = allocate_array<char>(string.size() + 1);
|
||||
std::memcpy(new_string, string.data(), string.size());
|
||||
return new_string;
|
||||
}
|
||||
|
||||
void memory::free(void* data)
|
||||
{
|
||||
std::free(data);
|
||||
}
|
||||
|
||||
void memory::free(const void* data)
|
||||
{
|
||||
free(const_cast<void*>(data));
|
||||
}
|
||||
|
||||
bool memory::is_set(const void* mem, const char chr, const size_t length)
|
||||
{
|
||||
const auto mem_arr = static_cast<const char*>(mem);
|
||||
|
||||
for (size_t i = 0; i < length; ++i)
|
||||
{
|
||||
if (mem_arr[i] != chr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool memory::is_bad_read_ptr(const void* ptr)
|
||||
{
|
||||
MEMORY_BASIC_INFORMATION mbi = {};
|
||||
if (VirtualQuery(ptr, &mbi, sizeof(mbi)))
|
||||
{
|
||||
const DWORD mask = (PAGE_READONLY | PAGE_READWRITE | PAGE_WRITECOPY | PAGE_EXECUTE_READ |
|
||||
PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY);
|
||||
auto b = !(mbi.Protect & mask);
|
||||
// check the page is not a guard page
|
||||
if (mbi.Protect & (PAGE_GUARD | PAGE_NOACCESS)) b = true;
|
||||
|
||||
return b;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool memory::is_bad_code_ptr(const void* ptr)
|
||||
{
|
||||
MEMORY_BASIC_INFORMATION mbi = {};
|
||||
if (VirtualQuery(ptr, &mbi, sizeof(mbi)))
|
||||
{
|
||||
const DWORD mask = (PAGE_EXECUTE_READ | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY);
|
||||
auto b = !(mbi.Protect & mask);
|
||||
// check the page is not a guard page
|
||||
if (mbi.Protect & (PAGE_GUARD | PAGE_NOACCESS)) b = true;
|
||||
|
||||
return b;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool memory::is_rdata_ptr(void* pointer)
|
||||
{
|
||||
const std::string rdata = ".rdata";
|
||||
const auto pointer_lib = utils::nt::library::get_by_address(pointer);
|
||||
|
||||
for (const auto& section : pointer_lib.get_section_headers())
|
||||
{
|
||||
const auto size = sizeof(section->Name);
|
||||
char name[size + 1];
|
||||
name[size] = 0;
|
||||
std::memcpy(name, section->Name, size);
|
||||
|
||||
if (name == rdata)
|
||||
{
|
||||
const auto target = size_t(pointer);
|
||||
const size_t source_start = size_t(pointer_lib.get_ptr()) + section->PointerToRawData;
|
||||
const size_t source_end = source_start + section->SizeOfRawData;
|
||||
|
||||
return target >= source_start && target <= source_end;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
memory::allocator* memory::get_allocator()
|
||||
{
|
||||
return &memory::mem_allocator_;
|
||||
}
|
||||
}
|
||||
|
@ -1,77 +1,77 @@
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
namespace utils
|
||||
{
|
||||
class memory final
|
||||
{
|
||||
public:
|
||||
class allocator final
|
||||
{
|
||||
public:
|
||||
~allocator();
|
||||
|
||||
void clear();
|
||||
|
||||
void free(void* data);
|
||||
|
||||
void free(const void* data);
|
||||
|
||||
void* allocate(size_t length);
|
||||
|
||||
template <typename T>
|
||||
T* allocate()
|
||||
{
|
||||
return this->allocate_array<T>(1);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* allocate_array(const size_t count = 1)
|
||||
{
|
||||
return static_cast<T*>(this->allocate(count * sizeof(T)));
|
||||
}
|
||||
|
||||
bool empty() const;
|
||||
|
||||
char* duplicate_string(const std::string& string);
|
||||
|
||||
bool find(const void* data);
|
||||
|
||||
private:
|
||||
std::mutex mutex_;
|
||||
std::vector<void*> pool_;
|
||||
};
|
||||
|
||||
static void* allocate(size_t length);
|
||||
|
||||
template <typename T>
|
||||
static T* allocate()
|
||||
{
|
||||
return allocate_array<T>(1);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static T* allocate_array(const size_t count = 1)
|
||||
{
|
||||
return static_cast<T*>(allocate(count * sizeof(T)));
|
||||
}
|
||||
|
||||
static char* duplicate_string(const std::string& string);
|
||||
|
||||
static void free(void* data);
|
||||
static void free(const void* data);
|
||||
|
||||
static bool is_set(const void* mem, char chr, size_t length);
|
||||
|
||||
static bool is_bad_read_ptr(const void* ptr);
|
||||
static bool is_bad_code_ptr(const void* ptr);
|
||||
static bool is_rdata_ptr(void* ptr);
|
||||
|
||||
static allocator* get_allocator();
|
||||
|
||||
private:
|
||||
static allocator mem_allocator_;
|
||||
};
|
||||
}
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
namespace utils
|
||||
{
|
||||
class memory final
|
||||
{
|
||||
public:
|
||||
class allocator final
|
||||
{
|
||||
public:
|
||||
~allocator();
|
||||
|
||||
void clear();
|
||||
|
||||
void free(void* data);
|
||||
|
||||
void free(const void* data);
|
||||
|
||||
void* allocate(size_t length);
|
||||
|
||||
template <typename T>
|
||||
T* allocate()
|
||||
{
|
||||
return this->allocate_array<T>(1);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* allocate_array(const size_t count = 1)
|
||||
{
|
||||
return static_cast<T*>(this->allocate(count * sizeof(T)));
|
||||
}
|
||||
|
||||
bool empty() const;
|
||||
|
||||
char* duplicate_string(const std::string& string);
|
||||
|
||||
bool find(const void* data);
|
||||
|
||||
private:
|
||||
std::mutex mutex_;
|
||||
std::vector<void*> pool_;
|
||||
};
|
||||
|
||||
static void* allocate(size_t length);
|
||||
|
||||
template <typename T>
|
||||
static T* allocate()
|
||||
{
|
||||
return allocate_array<T>(1);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static T* allocate_array(const size_t count = 1)
|
||||
{
|
||||
return static_cast<T*>(allocate(count * sizeof(T)));
|
||||
}
|
||||
|
||||
static char* duplicate_string(const std::string& string);
|
||||
|
||||
static void free(void* data);
|
||||
static void free(const void* data);
|
||||
|
||||
static bool is_set(const void* mem, char chr, size_t length);
|
||||
|
||||
static bool is_bad_read_ptr(const void* ptr);
|
||||
static bool is_bad_code_ptr(const void* ptr);
|
||||
static bool is_rdata_ptr(void* ptr);
|
||||
|
||||
static allocator* get_allocator();
|
||||
|
||||
private:
|
||||
static allocator mem_allocator_;
|
||||
};
|
||||
}
|
||||
|
@ -1,291 +1,291 @@
|
||||
#include "nt.hpp"
|
||||
|
||||
namespace utils::nt
|
||||
{
|
||||
library library::load(const char* name)
|
||||
{
|
||||
return library(LoadLibraryA(name));
|
||||
}
|
||||
|
||||
library library::load(const std::string& name)
|
||||
{
|
||||
return library::load(name.data());
|
||||
}
|
||||
|
||||
library library::load(const std::filesystem::path& path)
|
||||
{
|
||||
return library::load(path.generic_string());
|
||||
}
|
||||
|
||||
library library::get_by_address(const void* address)
|
||||
{
|
||||
HMODULE handle = nullptr;
|
||||
GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
||||
static_cast<LPCSTR>(address), &handle);
|
||||
return library(handle);
|
||||
}
|
||||
|
||||
library::library()
|
||||
: module_(GetModuleHandleA(nullptr))
|
||||
{
|
||||
}
|
||||
|
||||
library::library(const std::string& name)
|
||||
: module_(GetModuleHandleA(name.data()))
|
||||
{
|
||||
}
|
||||
|
||||
library::library(const HMODULE handle)
|
||||
: module_(handle)
|
||||
{
|
||||
}
|
||||
|
||||
bool library::operator==(const library& obj) const
|
||||
{
|
||||
return this->module_ == obj.module_;
|
||||
}
|
||||
|
||||
library::operator bool() const
|
||||
{
|
||||
return this->is_valid();
|
||||
}
|
||||
|
||||
library::operator HMODULE() const
|
||||
{
|
||||
return this->get_handle();
|
||||
}
|
||||
|
||||
PIMAGE_NT_HEADERS library::get_nt_headers() const
|
||||
{
|
||||
if (!this->is_valid()) return nullptr;
|
||||
return reinterpret_cast<PIMAGE_NT_HEADERS>(this->get_ptr() + this->get_dos_header()->e_lfanew);
|
||||
}
|
||||
|
||||
PIMAGE_DOS_HEADER library::get_dos_header() const
|
||||
{
|
||||
return reinterpret_cast<PIMAGE_DOS_HEADER>(this->get_ptr());
|
||||
}
|
||||
|
||||
PIMAGE_OPTIONAL_HEADER library::get_optional_header() const
|
||||
{
|
||||
if (!this->is_valid()) return nullptr;
|
||||
return &this->get_nt_headers()->OptionalHeader;
|
||||
}
|
||||
|
||||
std::vector<PIMAGE_SECTION_HEADER> library::get_section_headers() const
|
||||
{
|
||||
std::vector<PIMAGE_SECTION_HEADER> headers;
|
||||
|
||||
auto nt_headers = this->get_nt_headers();
|
||||
auto section = IMAGE_FIRST_SECTION(nt_headers);
|
||||
|
||||
for (uint16_t i = 0; i < nt_headers->FileHeader.NumberOfSections; ++i, ++section)
|
||||
{
|
||||
if (section) headers.push_back(section);
|
||||
else OutputDebugStringA("There was an invalid section :O");
|
||||
}
|
||||
|
||||
return headers;
|
||||
}
|
||||
|
||||
std::uint8_t* library::get_ptr() const
|
||||
{
|
||||
return reinterpret_cast<std::uint8_t*>(this->module_);
|
||||
}
|
||||
|
||||
void library::unprotect() const
|
||||
{
|
||||
if (!this->is_valid()) return;
|
||||
|
||||
DWORD protection;
|
||||
VirtualProtect(this->get_ptr(), this->get_optional_header()->SizeOfImage, PAGE_EXECUTE_READWRITE,
|
||||
&protection);
|
||||
}
|
||||
|
||||
size_t library::get_relative_entry_point() const
|
||||
{
|
||||
if (!this->is_valid()) return 0;
|
||||
return this->get_nt_headers()->OptionalHeader.AddressOfEntryPoint;
|
||||
}
|
||||
|
||||
void* library::get_entry_point() const
|
||||
{
|
||||
if (!this->is_valid()) return nullptr;
|
||||
return this->get_ptr() + this->get_relative_entry_point();
|
||||
}
|
||||
|
||||
bool library::is_valid() const
|
||||
{
|
||||
return this->module_ != nullptr && this->get_dos_header()->e_magic == IMAGE_DOS_SIGNATURE;
|
||||
}
|
||||
|
||||
std::string library::get_name() const
|
||||
{
|
||||
if (!this->is_valid()) return {};
|
||||
|
||||
const auto path = this->get_path();
|
||||
const auto pos = path.generic_string().find_last_of("/\\");
|
||||
if (pos == std::string::npos) return path.generic_string();
|
||||
|
||||
return path.generic_string().substr(pos + 1);
|
||||
}
|
||||
|
||||
std::filesystem::path library::get_path() const
|
||||
{
|
||||
if (!this->is_valid()) return {};
|
||||
|
||||
wchar_t name[MAX_PATH] = {0};
|
||||
GetModuleFileNameW(this->module_, name, MAX_PATH);
|
||||
|
||||
return {name};
|
||||
}
|
||||
|
||||
std::filesystem::path library::get_folder() const
|
||||
{
|
||||
if (!this->is_valid()) return {};
|
||||
|
||||
const auto path = std::filesystem::path(this->get_path());
|
||||
return path.parent_path().generic_string();
|
||||
}
|
||||
|
||||
void library::free()
|
||||
{
|
||||
if (this->is_valid())
|
||||
{
|
||||
FreeLibrary(this->module_);
|
||||
this->module_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
HMODULE library::get_handle() const
|
||||
{
|
||||
return this->module_;
|
||||
}
|
||||
|
||||
void** library::get_iat_entry(const std::string& module_name, const std::string& proc_name) const
|
||||
{
|
||||
if (!this->is_valid()) return nullptr;
|
||||
|
||||
const library other_module(module_name);
|
||||
if (!other_module.is_valid()) return nullptr;
|
||||
|
||||
auto* const target_function = other_module.get_proc<void*>(proc_name);
|
||||
if (!target_function) return nullptr;
|
||||
|
||||
auto* header = this->get_optional_header();
|
||||
if (!header) return nullptr;
|
||||
|
||||
auto* import_descriptor = reinterpret_cast<PIMAGE_IMPORT_DESCRIPTOR>(this->get_ptr() + header->DataDirectory
|
||||
[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress);
|
||||
|
||||
while (import_descriptor->Name)
|
||||
{
|
||||
if (!_stricmp(reinterpret_cast<char*>(this->get_ptr() + import_descriptor->Name), module_name.data()))
|
||||
{
|
||||
auto* original_thunk_data = reinterpret_cast<PIMAGE_THUNK_DATA>(import_descriptor->
|
||||
OriginalFirstThunk + this->get_ptr());
|
||||
auto* thunk_data = reinterpret_cast<PIMAGE_THUNK_DATA>(import_descriptor->FirstThunk + this->
|
||||
get_ptr());
|
||||
|
||||
while (original_thunk_data->u1.AddressOfData)
|
||||
{
|
||||
if (thunk_data->u1.Function == reinterpret_cast<uint64_t>(target_function))
|
||||
{
|
||||
return reinterpret_cast<void**>(&thunk_data->u1.Function);
|
||||
}
|
||||
|
||||
const size_t ordinal_number = original_thunk_data->u1.AddressOfData & 0xFFFFFFF;
|
||||
|
||||
if (ordinal_number <= 0xFFFF)
|
||||
{
|
||||
auto* proc = GetProcAddress(other_module.module_, reinterpret_cast<char*>(ordinal_number));
|
||||
if (reinterpret_cast<void*>(proc) == target_function)
|
||||
{
|
||||
return reinterpret_cast<void**>(&thunk_data->u1.Function);
|
||||
}
|
||||
}
|
||||
|
||||
++original_thunk_data;
|
||||
++thunk_data;
|
||||
}
|
||||
|
||||
//break;
|
||||
}
|
||||
|
||||
++import_descriptor;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool is_wine()
|
||||
{
|
||||
static const auto has_wine_export = []() -> bool
|
||||
{
|
||||
const library ntdll("ntdll.dll");
|
||||
return ntdll.get_proc<void*>("wine_get_version");
|
||||
}();
|
||||
|
||||
return has_wine_export;
|
||||
}
|
||||
|
||||
bool is_shutdown_in_progress()
|
||||
{
|
||||
static auto* shutdown_in_progress = []
|
||||
{
|
||||
const library ntdll("ntdll.dll");
|
||||
return ntdll.get_proc<BOOLEAN(*)()>("RtlDllShutdownInProgress");
|
||||
}();
|
||||
|
||||
return shutdown_in_progress();
|
||||
}
|
||||
|
||||
void raise_hard_exception()
|
||||
{
|
||||
int data = false;
|
||||
const library ntdll("ntdll.dll");
|
||||
ntdll.invoke_pascal<void>("RtlAdjustPrivilege", 19, true, false, &data);
|
||||
ntdll.invoke_pascal<void>("NtRaiseHardError", 0xC000007B, 0, nullptr, nullptr, 6, &data);
|
||||
_Exit(0);
|
||||
}
|
||||
|
||||
std::string load_resource(const int id)
|
||||
{
|
||||
const auto lib = library::get_by_address(load_resource);
|
||||
auto* const res = FindResource(lib, MAKEINTRESOURCE(id), RT_RCDATA);
|
||||
if (!res) return {};
|
||||
|
||||
auto* const handle = LoadResource(lib, res);
|
||||
if (!handle) return {};
|
||||
|
||||
return std::string(LPSTR(LockResource(handle)), SizeofResource(lib, res));
|
||||
}
|
||||
|
||||
void relaunch_self()
|
||||
{
|
||||
const auto self = utils::nt::library::get_by_address(relaunch_self);
|
||||
|
||||
STARTUPINFOA startup_info;
|
||||
PROCESS_INFORMATION process_info;
|
||||
|
||||
ZeroMemory(&startup_info, sizeof(startup_info));
|
||||
ZeroMemory(&process_info, sizeof(process_info));
|
||||
startup_info.cb = sizeof(startup_info);
|
||||
|
||||
char current_dir[MAX_PATH];
|
||||
GetCurrentDirectoryA(sizeof(current_dir), current_dir);
|
||||
auto* const command_line = GetCommandLineA();
|
||||
|
||||
CreateProcessA(self.get_path().generic_string().data(), command_line, nullptr, nullptr, false, NULL, nullptr, current_dir,
|
||||
&startup_info, &process_info);
|
||||
|
||||
if (process_info.hThread && process_info.hThread != INVALID_HANDLE_VALUE) CloseHandle(process_info.hThread);
|
||||
if (process_info.hProcess && process_info.hProcess != INVALID_HANDLE_VALUE) CloseHandle(process_info.hProcess);
|
||||
}
|
||||
|
||||
void terminate(const uint32_t code)
|
||||
{
|
||||
TerminateProcess(GetCurrentProcess(), code);
|
||||
_Exit(code);
|
||||
}
|
||||
}
|
||||
#include "nt.hpp"
|
||||
|
||||
namespace utils::nt
|
||||
{
|
||||
library library::load(const char* name)
|
||||
{
|
||||
return library(LoadLibraryA(name));
|
||||
}
|
||||
|
||||
library library::load(const std::string& name)
|
||||
{
|
||||
return library::load(name.data());
|
||||
}
|
||||
|
||||
library library::load(const std::filesystem::path& path)
|
||||
{
|
||||
return library::load(path.generic_string());
|
||||
}
|
||||
|
||||
library library::get_by_address(const void* address)
|
||||
{
|
||||
HMODULE handle = nullptr;
|
||||
GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
||||
static_cast<LPCSTR>(address), &handle);
|
||||
return library(handle);
|
||||
}
|
||||
|
||||
library::library()
|
||||
: module_(GetModuleHandleA(nullptr))
|
||||
{
|
||||
}
|
||||
|
||||
library::library(const std::string& name)
|
||||
: module_(GetModuleHandleA(name.data()))
|
||||
{
|
||||
}
|
||||
|
||||
library::library(const HMODULE handle)
|
||||
: module_(handle)
|
||||
{
|
||||
}
|
||||
|
||||
bool library::operator==(const library& obj) const
|
||||
{
|
||||
return this->module_ == obj.module_;
|
||||
}
|
||||
|
||||
library::operator bool() const
|
||||
{
|
||||
return this->is_valid();
|
||||
}
|
||||
|
||||
library::operator HMODULE() const
|
||||
{
|
||||
return this->get_handle();
|
||||
}
|
||||
|
||||
PIMAGE_NT_HEADERS library::get_nt_headers() const
|
||||
{
|
||||
if (!this->is_valid()) return nullptr;
|
||||
return reinterpret_cast<PIMAGE_NT_HEADERS>(this->get_ptr() + this->get_dos_header()->e_lfanew);
|
||||
}
|
||||
|
||||
PIMAGE_DOS_HEADER library::get_dos_header() const
|
||||
{
|
||||
return reinterpret_cast<PIMAGE_DOS_HEADER>(this->get_ptr());
|
||||
}
|
||||
|
||||
PIMAGE_OPTIONAL_HEADER library::get_optional_header() const
|
||||
{
|
||||
if (!this->is_valid()) return nullptr;
|
||||
return &this->get_nt_headers()->OptionalHeader;
|
||||
}
|
||||
|
||||
std::vector<PIMAGE_SECTION_HEADER> library::get_section_headers() const
|
||||
{
|
||||
std::vector<PIMAGE_SECTION_HEADER> headers;
|
||||
|
||||
auto nt_headers = this->get_nt_headers();
|
||||
auto section = IMAGE_FIRST_SECTION(nt_headers);
|
||||
|
||||
for (uint16_t i = 0; i < nt_headers->FileHeader.NumberOfSections; ++i, ++section)
|
||||
{
|
||||
if (section) headers.push_back(section);
|
||||
else OutputDebugStringA("There was an invalid section :O");
|
||||
}
|
||||
|
||||
return headers;
|
||||
}
|
||||
|
||||
std::uint8_t* library::get_ptr() const
|
||||
{
|
||||
return reinterpret_cast<std::uint8_t*>(this->module_);
|
||||
}
|
||||
|
||||
void library::unprotect() const
|
||||
{
|
||||
if (!this->is_valid()) return;
|
||||
|
||||
DWORD protection;
|
||||
VirtualProtect(this->get_ptr(), this->get_optional_header()->SizeOfImage, PAGE_EXECUTE_READWRITE,
|
||||
&protection);
|
||||
}
|
||||
|
||||
size_t library::get_relative_entry_point() const
|
||||
{
|
||||
if (!this->is_valid()) return 0;
|
||||
return this->get_nt_headers()->OptionalHeader.AddressOfEntryPoint;
|
||||
}
|
||||
|
||||
void* library::get_entry_point() const
|
||||
{
|
||||
if (!this->is_valid()) return nullptr;
|
||||
return this->get_ptr() + this->get_relative_entry_point();
|
||||
}
|
||||
|
||||
bool library::is_valid() const
|
||||
{
|
||||
return this->module_ != nullptr && this->get_dos_header()->e_magic == IMAGE_DOS_SIGNATURE;
|
||||
}
|
||||
|
||||
std::string library::get_name() const
|
||||
{
|
||||
if (!this->is_valid()) return {};
|
||||
|
||||
const auto path = this->get_path();
|
||||
const auto pos = path.generic_string().find_last_of("/\\");
|
||||
if (pos == std::string::npos) return path.generic_string();
|
||||
|
||||
return path.generic_string().substr(pos + 1);
|
||||
}
|
||||
|
||||
std::filesystem::path library::get_path() const
|
||||
{
|
||||
if (!this->is_valid()) return {};
|
||||
|
||||
wchar_t name[MAX_PATH] = {0};
|
||||
GetModuleFileNameW(this->module_, name, MAX_PATH);
|
||||
|
||||
return {name};
|
||||
}
|
||||
|
||||
std::filesystem::path library::get_folder() const
|
||||
{
|
||||
if (!this->is_valid()) return {};
|
||||
|
||||
const auto path = std::filesystem::path(this->get_path());
|
||||
return path.parent_path().generic_string();
|
||||
}
|
||||
|
||||
void library::free()
|
||||
{
|
||||
if (this->is_valid())
|
||||
{
|
||||
FreeLibrary(this->module_);
|
||||
this->module_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
HMODULE library::get_handle() const
|
||||
{
|
||||
return this->module_;
|
||||
}
|
||||
|
||||
void** library::get_iat_entry(const std::string& module_name, const std::string& proc_name) const
|
||||
{
|
||||
if (!this->is_valid()) return nullptr;
|
||||
|
||||
const library other_module(module_name);
|
||||
if (!other_module.is_valid()) return nullptr;
|
||||
|
||||
auto* const target_function = other_module.get_proc<void*>(proc_name);
|
||||
if (!target_function) return nullptr;
|
||||
|
||||
auto* header = this->get_optional_header();
|
||||
if (!header) return nullptr;
|
||||
|
||||
auto* import_descriptor = reinterpret_cast<PIMAGE_IMPORT_DESCRIPTOR>(this->get_ptr() + header->DataDirectory
|
||||
[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress);
|
||||
|
||||
while (import_descriptor->Name)
|
||||
{
|
||||
if (!_stricmp(reinterpret_cast<char*>(this->get_ptr() + import_descriptor->Name), module_name.data()))
|
||||
{
|
||||
auto* original_thunk_data = reinterpret_cast<PIMAGE_THUNK_DATA>(import_descriptor->
|
||||
OriginalFirstThunk + this->get_ptr());
|
||||
auto* thunk_data = reinterpret_cast<PIMAGE_THUNK_DATA>(import_descriptor->FirstThunk + this->
|
||||
get_ptr());
|
||||
|
||||
while (original_thunk_data->u1.AddressOfData)
|
||||
{
|
||||
if (thunk_data->u1.Function == reinterpret_cast<uint64_t>(target_function))
|
||||
{
|
||||
return reinterpret_cast<void**>(&thunk_data->u1.Function);
|
||||
}
|
||||
|
||||
const size_t ordinal_number = original_thunk_data->u1.AddressOfData & 0xFFFFFFF;
|
||||
|
||||
if (ordinal_number <= 0xFFFF)
|
||||
{
|
||||
auto* proc = GetProcAddress(other_module.module_, reinterpret_cast<char*>(ordinal_number));
|
||||
if (reinterpret_cast<void*>(proc) == target_function)
|
||||
{
|
||||
return reinterpret_cast<void**>(&thunk_data->u1.Function);
|
||||
}
|
||||
}
|
||||
|
||||
++original_thunk_data;
|
||||
++thunk_data;
|
||||
}
|
||||
|
||||
//break;
|
||||
}
|
||||
|
||||
++import_descriptor;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool is_wine()
|
||||
{
|
||||
static const auto has_wine_export = []() -> bool
|
||||
{
|
||||
const library ntdll("ntdll.dll");
|
||||
return ntdll.get_proc<void*>("wine_get_version");
|
||||
}();
|
||||
|
||||
return has_wine_export;
|
||||
}
|
||||
|
||||
bool is_shutdown_in_progress()
|
||||
{
|
||||
static auto* shutdown_in_progress = []
|
||||
{
|
||||
const library ntdll("ntdll.dll");
|
||||
return ntdll.get_proc<BOOLEAN(*)()>("RtlDllShutdownInProgress");
|
||||
}();
|
||||
|
||||
return shutdown_in_progress();
|
||||
}
|
||||
|
||||
void raise_hard_exception()
|
||||
{
|
||||
int data = false;
|
||||
const library ntdll("ntdll.dll");
|
||||
ntdll.invoke_pascal<void>("RtlAdjustPrivilege", 19, true, false, &data);
|
||||
ntdll.invoke_pascal<void>("NtRaiseHardError", 0xC000007B, 0, nullptr, nullptr, 6, &data);
|
||||
_Exit(0);
|
||||
}
|
||||
|
||||
std::string load_resource(const int id)
|
||||
{
|
||||
const auto lib = library::get_by_address(load_resource);
|
||||
auto* const res = FindResource(lib, MAKEINTRESOURCE(id), RT_RCDATA);
|
||||
if (!res) return {};
|
||||
|
||||
auto* const handle = LoadResource(lib, res);
|
||||
if (!handle) return {};
|
||||
|
||||
return std::string(LPSTR(LockResource(handle)), SizeofResource(lib, res));
|
||||
}
|
||||
|
||||
void relaunch_self()
|
||||
{
|
||||
const auto self = utils::nt::library::get_by_address(relaunch_self);
|
||||
|
||||
STARTUPINFOA startup_info;
|
||||
PROCESS_INFORMATION process_info;
|
||||
|
||||
ZeroMemory(&startup_info, sizeof(startup_info));
|
||||
ZeroMemory(&process_info, sizeof(process_info));
|
||||
startup_info.cb = sizeof(startup_info);
|
||||
|
||||
char current_dir[MAX_PATH];
|
||||
GetCurrentDirectoryA(sizeof(current_dir), current_dir);
|
||||
auto* const command_line = GetCommandLineA();
|
||||
|
||||
CreateProcessA(self.get_path().generic_string().data(), command_line, nullptr, nullptr, false, NULL, nullptr, current_dir,
|
||||
&startup_info, &process_info);
|
||||
|
||||
if (process_info.hThread && process_info.hThread != INVALID_HANDLE_VALUE) CloseHandle(process_info.hThread);
|
||||
if (process_info.hProcess && process_info.hProcess != INVALID_HANDLE_VALUE) CloseHandle(process_info.hProcess);
|
||||
}
|
||||
|
||||
void terminate(const uint32_t code)
|
||||
{
|
||||
TerminateProcess(GetCurrentProcess(), code);
|
||||
_Exit(code);
|
||||
}
|
||||
}
|
||||
|
@ -1,177 +1,177 @@
|
||||
#pragma once
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
|
||||
// min and max is required by gdi, therefore NOMINMAX won't work
|
||||
#ifdef max
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
#ifdef min
|
||||
#undef min
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <filesystem>
|
||||
|
||||
namespace utils::nt
|
||||
{
|
||||
class library final
|
||||
{
|
||||
public:
|
||||
static library load(const char* name);
|
||||
static library load(const std::string& name);
|
||||
static library load(const std::filesystem::path& path);
|
||||
static library get_by_address(const void* address);
|
||||
|
||||
library();
|
||||
explicit library(const std::string& name);
|
||||
explicit library(HMODULE handle);
|
||||
|
||||
library(const library& a) : module_(a.module_)
|
||||
{
|
||||
}
|
||||
|
||||
bool operator!=(const library& obj) const { return !(*this == obj); };
|
||||
bool operator==(const library& obj) const;
|
||||
|
||||
operator bool() const;
|
||||
operator HMODULE() const;
|
||||
|
||||
void unprotect() const;
|
||||
[[nodiscard]] void* get_entry_point() const;
|
||||
[[nodiscard]] size_t get_relative_entry_point() const;
|
||||
|
||||
[[nodiscard]] bool is_valid() const;
|
||||
[[nodiscard]] std::string get_name() const;
|
||||
[[nodiscard]] std::filesystem::path get_path() const;
|
||||
[[nodiscard]] std::filesystem::path get_folder() const;
|
||||
[[nodiscard]] std::uint8_t* get_ptr() const;
|
||||
void free();
|
||||
|
||||
[[nodiscard]] HMODULE get_handle() const;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] T get_proc(const std::string& process) const
|
||||
{
|
||||
if (!this->is_valid()) T{};
|
||||
return reinterpret_cast<T>(GetProcAddress(this->module_, process.data()));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] std::function<T> get(const std::string& process) const
|
||||
{
|
||||
if (!this->is_valid()) return std::function<T>();
|
||||
return static_cast<T*>(this->get_proc<void*>(process));
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
T invoke(const std::string& process, Args ... args) const
|
||||
{
|
||||
auto method = this->get<T(__cdecl)(Args ...)>(process);
|
||||
if (method) return method(args...);
|
||||
return T();
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
T invoke_pascal(const std::string& process, Args ... args) const
|
||||
{
|
||||
auto method = this->get<T(__stdcall)(Args ...)>(process);
|
||||
if (method) return method(args...);
|
||||
return T();
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
T invoke_this(const std::string& process, void* this_ptr, Args ... args) const
|
||||
{
|
||||
auto method = this->get<T(__thiscall)(void*, Args ...)>(this_ptr, process);
|
||||
if (method) return method(args...);
|
||||
return T();
|
||||
}
|
||||
|
||||
[[nodiscard]] std::vector<PIMAGE_SECTION_HEADER> get_section_headers() const;
|
||||
|
||||
[[nodiscard]] PIMAGE_NT_HEADERS get_nt_headers() const;
|
||||
[[nodiscard]] PIMAGE_DOS_HEADER get_dos_header() const;
|
||||
[[nodiscard]] PIMAGE_OPTIONAL_HEADER get_optional_header() const;
|
||||
|
||||
[[nodiscard]] void** get_iat_entry(const std::string& module_name, const std::string& proc_name) const;
|
||||
|
||||
private:
|
||||
HMODULE module_;
|
||||
};
|
||||
|
||||
template <HANDLE InvalidHandle = nullptr>
|
||||
class handle
|
||||
{
|
||||
public:
|
||||
handle() = default;
|
||||
|
||||
handle(const HANDLE h)
|
||||
: handle_(h)
|
||||
{
|
||||
}
|
||||
|
||||
~handle()
|
||||
{
|
||||
if (*this)
|
||||
{
|
||||
CloseHandle(this->handle_);
|
||||
this->handle_ = InvalidHandle;
|
||||
}
|
||||
}
|
||||
|
||||
handle(const handle&) = delete;
|
||||
handle& operator=(const handle&) = delete;
|
||||
|
||||
handle(handle&& obj) noexcept
|
||||
: handle()
|
||||
{
|
||||
this->operator=(std::move(obj));
|
||||
}
|
||||
|
||||
handle& operator=(handle&& obj) noexcept
|
||||
{
|
||||
if (this != &obj)
|
||||
{
|
||||
this->~handle();
|
||||
this->handle_ = obj.handle_;
|
||||
obj.handle_ = InvalidHandle;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
handle& operator=(HANDLE h) noexcept
|
||||
{
|
||||
this->~handle();
|
||||
this->handle_ = h;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator bool() const
|
||||
{
|
||||
return this->handle_ != InvalidHandle;
|
||||
}
|
||||
|
||||
operator HANDLE() const
|
||||
{
|
||||
return this->handle_;
|
||||
}
|
||||
|
||||
private:
|
||||
HANDLE handle_{InvalidHandle};
|
||||
};
|
||||
|
||||
bool is_wine();
|
||||
bool is_shutdown_in_progress();
|
||||
|
||||
__declspec(noreturn) void raise_hard_exception();
|
||||
std::string load_resource(int id);
|
||||
|
||||
void relaunch_self();
|
||||
__declspec(noreturn) void terminate(uint32_t code = 0);
|
||||
}
|
||||
#pragma once
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
|
||||
// min and max is required by gdi, therefore NOMINMAX won't work
|
||||
#ifdef max
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
#ifdef min
|
||||
#undef min
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <filesystem>
|
||||
|
||||
namespace utils::nt
|
||||
{
|
||||
class library final
|
||||
{
|
||||
public:
|
||||
static library load(const char* name);
|
||||
static library load(const std::string& name);
|
||||
static library load(const std::filesystem::path& path);
|
||||
static library get_by_address(const void* address);
|
||||
|
||||
library();
|
||||
explicit library(const std::string& name);
|
||||
explicit library(HMODULE handle);
|
||||
|
||||
library(const library& a) : module_(a.module_)
|
||||
{
|
||||
}
|
||||
|
||||
bool operator!=(const library& obj) const { return !(*this == obj); };
|
||||
bool operator==(const library& obj) const;
|
||||
|
||||
operator bool() const;
|
||||
operator HMODULE() const;
|
||||
|
||||
void unprotect() const;
|
||||
[[nodiscard]] void* get_entry_point() const;
|
||||
[[nodiscard]] size_t get_relative_entry_point() const;
|
||||
|
||||
[[nodiscard]] bool is_valid() const;
|
||||
[[nodiscard]] std::string get_name() const;
|
||||
[[nodiscard]] std::filesystem::path get_path() const;
|
||||
[[nodiscard]] std::filesystem::path get_folder() const;
|
||||
[[nodiscard]] std::uint8_t* get_ptr() const;
|
||||
void free();
|
||||
|
||||
[[nodiscard]] HMODULE get_handle() const;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] T get_proc(const std::string& process) const
|
||||
{
|
||||
if (!this->is_valid()) T{};
|
||||
return reinterpret_cast<T>(GetProcAddress(this->module_, process.data()));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] std::function<T> get(const std::string& process) const
|
||||
{
|
||||
if (!this->is_valid()) return std::function<T>();
|
||||
return static_cast<T*>(this->get_proc<void*>(process));
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
T invoke(const std::string& process, Args ... args) const
|
||||
{
|
||||
auto method = this->get<T(__cdecl)(Args ...)>(process);
|
||||
if (method) return method(args...);
|
||||
return T();
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
T invoke_pascal(const std::string& process, Args ... args) const
|
||||
{
|
||||
auto method = this->get<T(__stdcall)(Args ...)>(process);
|
||||
if (method) return method(args...);
|
||||
return T();
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
T invoke_this(const std::string& process, void* this_ptr, Args ... args) const
|
||||
{
|
||||
auto method = this->get<T(__thiscall)(void*, Args ...)>(this_ptr, process);
|
||||
if (method) return method(args...);
|
||||
return T();
|
||||
}
|
||||
|
||||
[[nodiscard]] std::vector<PIMAGE_SECTION_HEADER> get_section_headers() const;
|
||||
|
||||
[[nodiscard]] PIMAGE_NT_HEADERS get_nt_headers() const;
|
||||
[[nodiscard]] PIMAGE_DOS_HEADER get_dos_header() const;
|
||||
[[nodiscard]] PIMAGE_OPTIONAL_HEADER get_optional_header() const;
|
||||
|
||||
[[nodiscard]] void** get_iat_entry(const std::string& module_name, const std::string& proc_name) const;
|
||||
|
||||
private:
|
||||
HMODULE module_;
|
||||
};
|
||||
|
||||
template <HANDLE InvalidHandle = nullptr>
|
||||
class handle
|
||||
{
|
||||
public:
|
||||
handle() = default;
|
||||
|
||||
handle(const HANDLE h)
|
||||
: handle_(h)
|
||||
{
|
||||
}
|
||||
|
||||
~handle()
|
||||
{
|
||||
if (*this)
|
||||
{
|
||||
CloseHandle(this->handle_);
|
||||
this->handle_ = InvalidHandle;
|
||||
}
|
||||
}
|
||||
|
||||
handle(const handle&) = delete;
|
||||
handle& operator=(const handle&) = delete;
|
||||
|
||||
handle(handle&& obj) noexcept
|
||||
: handle()
|
||||
{
|
||||
this->operator=(std::move(obj));
|
||||
}
|
||||
|
||||
handle& operator=(handle&& obj) noexcept
|
||||
{
|
||||
if (this != &obj)
|
||||
{
|
||||
this->~handle();
|
||||
this->handle_ = obj.handle_;
|
||||
obj.handle_ = InvalidHandle;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
handle& operator=(HANDLE h) noexcept
|
||||
{
|
||||
this->~handle();
|
||||
this->handle_ = h;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator bool() const
|
||||
{
|
||||
return this->handle_ != InvalidHandle;
|
||||
}
|
||||
|
||||
operator HANDLE() const
|
||||
{
|
||||
return this->handle_;
|
||||
}
|
||||
|
||||
private:
|
||||
HANDLE handle_{InvalidHandle};
|
||||
};
|
||||
|
||||
bool is_wine();
|
||||
bool is_shutdown_in_progress();
|
||||
|
||||
__declspec(noreturn) void raise_hard_exception();
|
||||
std::string load_resource(int id);
|
||||
|
||||
void relaunch_self();
|
||||
__declspec(noreturn) void terminate(uint32_t code = 0);
|
||||
}
|
||||
|
@ -1,220 +1,220 @@
|
||||
#include "signature.hpp"
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
|
||||
#include <intrin.h>
|
||||
|
||||
#ifdef max
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
#ifdef min
|
||||
#undef min
|
||||
#endif
|
||||
|
||||
namespace utils::hook
|
||||
{
|
||||
void signature::load_pattern(const std::string& pattern)
|
||||
{
|
||||
this->mask_.clear();
|
||||
this->pattern_.clear();
|
||||
|
||||
uint8_t nibble = 0;
|
||||
auto has_nibble = false;
|
||||
|
||||
for (auto val : pattern)
|
||||
{
|
||||
if (val == ' ') continue;
|
||||
if (val == '?')
|
||||
{
|
||||
this->mask_.push_back(val);
|
||||
this->pattern_.push_back(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((val < '0' || val > '9') && (val < 'A' || val > 'F') && (val < 'a' || val > 'f'))
|
||||
{
|
||||
throw std::runtime_error("Invalid pattern");
|
||||
}
|
||||
|
||||
char str[] = {val, 0};
|
||||
const auto current_nibble = static_cast<uint8_t>(strtol(str, nullptr, 16));
|
||||
|
||||
if (!has_nibble)
|
||||
{
|
||||
has_nibble = true;
|
||||
nibble = current_nibble;
|
||||
}
|
||||
else
|
||||
{
|
||||
has_nibble = false;
|
||||
const uint8_t byte = current_nibble | (nibble << 4);
|
||||
|
||||
this->mask_.push_back('x');
|
||||
this->pattern_.push_back(byte);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (!this->mask_.empty() && this->mask_.back() == '?')
|
||||
{
|
||||
this->mask_.pop_back();
|
||||
this->pattern_.pop_back();
|
||||
}
|
||||
|
||||
if (this->has_sse_support())
|
||||
{
|
||||
while (this->pattern_.size() < 16)
|
||||
{
|
||||
this->pattern_.push_back(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (has_nibble)
|
||||
{
|
||||
throw std::runtime_error("Invalid pattern");
|
||||
}
|
||||
}
|
||||
|
||||
signature::signature_result signature::process_range(uint8_t* start, const size_t length) const
|
||||
{
|
||||
if (this->has_sse_support()) return this->process_range_vectorized(start, length);
|
||||
return this->process_range_linear(start, length);
|
||||
}
|
||||
|
||||
signature::signature_result signature::process_range_linear(uint8_t* start, const size_t length) const
|
||||
{
|
||||
std::vector<uint8_t*> result;
|
||||
|
||||
for (size_t i = 0; i < length; ++i)
|
||||
{
|
||||
const auto address = start + i;
|
||||
|
||||
size_t j = 0;
|
||||
for (; j < this->mask_.size(); ++j)
|
||||
{
|
||||
if (this->mask_[j] != '?' && this->pattern_[j] != address[j])
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (j == this->mask_.size())
|
||||
{
|
||||
result.push_back(address);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
signature::signature_result signature::process_range_vectorized(uint8_t* start, const size_t length) const
|
||||
{
|
||||
std::vector<uint8_t*> result;
|
||||
__declspec(align(16)) char desired_mask[16] = {0};
|
||||
|
||||
for (size_t i = 0; i < this->mask_.size(); i++)
|
||||
{
|
||||
desired_mask[i / 8] |= (this->mask_[i] == '?' ? 0 : 1) << i % 8;
|
||||
}
|
||||
|
||||
const auto mask = _mm_load_si128(reinterpret_cast<const __m128i*>(desired_mask));
|
||||
const auto comparand = _mm_loadu_si128(reinterpret_cast<const __m128i*>(this->pattern_.data()));
|
||||
|
||||
for (size_t i = 0; i < length; ++i)
|
||||
{
|
||||
const auto address = start + i;
|
||||
const auto value = _mm_loadu_si128(reinterpret_cast<const __m128i*>(address));
|
||||
const auto comparison = _mm_cmpestrm(value, 16, comparand, static_cast<int>(this->mask_.size()),
|
||||
_SIDD_CMP_EQUAL_EACH);
|
||||
|
||||
const auto matches = _mm_and_si128(mask, comparison);
|
||||
const auto equivalence = _mm_xor_si128(mask, matches);
|
||||
|
||||
if (_mm_test_all_zeros(equivalence, equivalence))
|
||||
{
|
||||
result.push_back(address);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
signature::signature_result signature::process() const
|
||||
{
|
||||
const auto range = this->length_ - this->mask_.size();
|
||||
const auto cores = std::max(1u, std::thread::hardware_concurrency());
|
||||
|
||||
if (range <= cores * 10ull) return this->process_serial();
|
||||
return this->process_parallel();
|
||||
}
|
||||
|
||||
signature::signature_result signature::process_serial() const
|
||||
{
|
||||
const auto sub = this->has_sse_support() ? 16 : this->mask_.size();
|
||||
return {this->process_range(this->start_, this->length_ - sub)};
|
||||
}
|
||||
|
||||
signature::signature_result signature::process_parallel() const
|
||||
{
|
||||
const auto sub = this->has_sse_support() ? 16 : this->mask_.size();
|
||||
const auto range = this->length_ - sub;
|
||||
const auto cores = std::max(1u, std::thread::hardware_concurrency() / 2);
|
||||
// Only use half of the available cores
|
||||
const auto grid = range / cores;
|
||||
|
||||
std::mutex mutex;
|
||||
std::vector<uint8_t*> result;
|
||||
std::vector<std::thread> threads;
|
||||
|
||||
for (auto i = 0u; i < cores; ++i)
|
||||
{
|
||||
const auto start = this->start_ + (grid * i);
|
||||
const auto length = (i + 1 == cores) ? (this->start_ + this->length_ - sub) - start : grid;
|
||||
threads.emplace_back([&, start, length]()
|
||||
{
|
||||
const auto local_result = this->process_range(start, length);
|
||||
if (local_result.empty()) return;
|
||||
|
||||
std::lock_guard _(mutex);
|
||||
for (const auto& address : local_result)
|
||||
{
|
||||
result.push_back(address);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for (auto& t : threads)
|
||||
{
|
||||
if (t.joinable())
|
||||
{
|
||||
t.join();
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(result.begin(), result.end());
|
||||
return {std::move(result)};
|
||||
}
|
||||
|
||||
bool signature::has_sse_support() const
|
||||
{
|
||||
if (this->mask_.size() <= 16)
|
||||
{
|
||||
int cpu_id[4];
|
||||
__cpuid(cpu_id, 0);
|
||||
|
||||
if (cpu_id[0] >= 1)
|
||||
{
|
||||
__cpuidex(cpu_id, 1, 0);
|
||||
return (cpu_id[2] & (1 << 20)) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
utils::hook::signature::signature_result operator"" _sig(const char* str, const size_t len)
|
||||
{
|
||||
return utils::hook::signature(std::string(str, len)).process();
|
||||
}
|
||||
#include "signature.hpp"
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
|
||||
#include <intrin.h>
|
||||
|
||||
#ifdef max
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
#ifdef min
|
||||
#undef min
|
||||
#endif
|
||||
|
||||
namespace utils::hook
|
||||
{
|
||||
void signature::load_pattern(const std::string& pattern)
|
||||
{
|
||||
this->mask_.clear();
|
||||
this->pattern_.clear();
|
||||
|
||||
uint8_t nibble = 0;
|
||||
auto has_nibble = false;
|
||||
|
||||
for (auto val : pattern)
|
||||
{
|
||||
if (val == ' ') continue;
|
||||
if (val == '?')
|
||||
{
|
||||
this->mask_.push_back(val);
|
||||
this->pattern_.push_back(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((val < '0' || val > '9') && (val < 'A' || val > 'F') && (val < 'a' || val > 'f'))
|
||||
{
|
||||
throw std::runtime_error("Invalid pattern");
|
||||
}
|
||||
|
||||
char str[] = {val, 0};
|
||||
const auto current_nibble = static_cast<uint8_t>(strtol(str, nullptr, 16));
|
||||
|
||||
if (!has_nibble)
|
||||
{
|
||||
has_nibble = true;
|
||||
nibble = current_nibble;
|
||||
}
|
||||
else
|
||||
{
|
||||
has_nibble = false;
|
||||
const uint8_t byte = current_nibble | (nibble << 4);
|
||||
|
||||
this->mask_.push_back('x');
|
||||
this->pattern_.push_back(byte);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (!this->mask_.empty() && this->mask_.back() == '?')
|
||||
{
|
||||
this->mask_.pop_back();
|
||||
this->pattern_.pop_back();
|
||||
}
|
||||
|
||||
if (this->has_sse_support())
|
||||
{
|
||||
while (this->pattern_.size() < 16)
|
||||
{
|
||||
this->pattern_.push_back(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (has_nibble)
|
||||
{
|
||||
throw std::runtime_error("Invalid pattern");
|
||||
}
|
||||
}
|
||||
|
||||
signature::signature_result signature::process_range(uint8_t* start, const size_t length) const
|
||||
{
|
||||
if (this->has_sse_support()) return this->process_range_vectorized(start, length);
|
||||
return this->process_range_linear(start, length);
|
||||
}
|
||||
|
||||
signature::signature_result signature::process_range_linear(uint8_t* start, const size_t length) const
|
||||
{
|
||||
std::vector<uint8_t*> result;
|
||||
|
||||
for (size_t i = 0; i < length; ++i)
|
||||
{
|
||||
const auto address = start + i;
|
||||
|
||||
size_t j = 0;
|
||||
for (; j < this->mask_.size(); ++j)
|
||||
{
|
||||
if (this->mask_[j] != '?' && this->pattern_[j] != address[j])
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (j == this->mask_.size())
|
||||
{
|
||||
result.push_back(address);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
signature::signature_result signature::process_range_vectorized(uint8_t* start, const size_t length) const
|
||||
{
|
||||
std::vector<uint8_t*> result;
|
||||
__declspec(align(16)) char desired_mask[16] = {0};
|
||||
|
||||
for (size_t i = 0; i < this->mask_.size(); i++)
|
||||
{
|
||||
desired_mask[i / 8] |= (this->mask_[i] == '?' ? 0 : 1) << i % 8;
|
||||
}
|
||||
|
||||
const auto mask = _mm_load_si128(reinterpret_cast<const __m128i*>(desired_mask));
|
||||
const auto comparand = _mm_loadu_si128(reinterpret_cast<const __m128i*>(this->pattern_.data()));
|
||||
|
||||
for (size_t i = 0; i < length; ++i)
|
||||
{
|
||||
const auto address = start + i;
|
||||
const auto value = _mm_loadu_si128(reinterpret_cast<const __m128i*>(address));
|
||||
const auto comparison = _mm_cmpestrm(value, 16, comparand, static_cast<int>(this->mask_.size()),
|
||||
_SIDD_CMP_EQUAL_EACH);
|
||||
|
||||
const auto matches = _mm_and_si128(mask, comparison);
|
||||
const auto equivalence = _mm_xor_si128(mask, matches);
|
||||
|
||||
if (_mm_test_all_zeros(equivalence, equivalence))
|
||||
{
|
||||
result.push_back(address);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
signature::signature_result signature::process() const
|
||||
{
|
||||
const auto range = this->length_ - this->mask_.size();
|
||||
const auto cores = std::max(1u, std::thread::hardware_concurrency());
|
||||
|
||||
if (range <= cores * 10ull) return this->process_serial();
|
||||
return this->process_parallel();
|
||||
}
|
||||
|
||||
signature::signature_result signature::process_serial() const
|
||||
{
|
||||
const auto sub = this->has_sse_support() ? 16 : this->mask_.size();
|
||||
return {this->process_range(this->start_, this->length_ - sub)};
|
||||
}
|
||||
|
||||
signature::signature_result signature::process_parallel() const
|
||||
{
|
||||
const auto sub = this->has_sse_support() ? 16 : this->mask_.size();
|
||||
const auto range = this->length_ - sub;
|
||||
const auto cores = std::max(1u, std::thread::hardware_concurrency() / 2);
|
||||
// Only use half of the available cores
|
||||
const auto grid = range / cores;
|
||||
|
||||
std::mutex mutex;
|
||||
std::vector<uint8_t*> result;
|
||||
std::vector<std::thread> threads;
|
||||
|
||||
for (auto i = 0u; i < cores; ++i)
|
||||
{
|
||||
const auto start = this->start_ + (grid * i);
|
||||
const auto length = (i + 1 == cores) ? (this->start_ + this->length_ - sub) - start : grid;
|
||||
threads.emplace_back([&, start, length]()
|
||||
{
|
||||
const auto local_result = this->process_range(start, length);
|
||||
if (local_result.empty()) return;
|
||||
|
||||
std::lock_guard _(mutex);
|
||||
for (const auto& address : local_result)
|
||||
{
|
||||
result.push_back(address);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for (auto& t : threads)
|
||||
{
|
||||
if (t.joinable())
|
||||
{
|
||||
t.join();
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(result.begin(), result.end());
|
||||
return {std::move(result)};
|
||||
}
|
||||
|
||||
bool signature::has_sse_support() const
|
||||
{
|
||||
if (this->mask_.size() <= 16)
|
||||
{
|
||||
int cpu_id[4];
|
||||
__cpuid(cpu_id, 0);
|
||||
|
||||
if (cpu_id[0] >= 1)
|
||||
{
|
||||
__cpuidex(cpu_id, 1, 0);
|
||||
return (cpu_id[2] & (1 << 20)) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
utils::hook::signature::signature_result operator"" _sig(const char* str, const size_t len)
|
||||
{
|
||||
return utils::hook::signature(std::string(str, len)).process();
|
||||
}
|
||||
|
@ -1,49 +1,49 @@
|
||||
#pragma once
|
||||
#include "nt.hpp"
|
||||
#include <cstdint>
|
||||
|
||||
namespace utils::hook
|
||||
{
|
||||
class signature final
|
||||
{
|
||||
public:
|
||||
using signature_result = std::vector<uint8_t*>;
|
||||
|
||||
explicit signature(const std::string& pattern, const nt::library& library = {})
|
||||
: signature(pattern, library.get_ptr(), library.get_optional_header()->SizeOfImage)
|
||||
{
|
||||
}
|
||||
|
||||
signature(const std::string& pattern, void* start, void* end)
|
||||
: signature(pattern, start, size_t(end) - size_t(start))
|
||||
{
|
||||
}
|
||||
|
||||
signature(const std::string& pattern, void* start, const size_t length)
|
||||
: start_(static_cast<uint8_t*>(start)), length_(length)
|
||||
{
|
||||
this->load_pattern(pattern);
|
||||
}
|
||||
|
||||
signature_result process() const;
|
||||
|
||||
private:
|
||||
std::string mask_;
|
||||
std::basic_string<uint8_t> pattern_;
|
||||
|
||||
uint8_t* start_;
|
||||
size_t length_;
|
||||
|
||||
void load_pattern(const std::string& pattern);
|
||||
|
||||
signature_result process_parallel() const;
|
||||
signature_result process_serial() const;
|
||||
signature_result process_range(uint8_t* start, size_t length) const;
|
||||
signature_result process_range_linear(uint8_t* start, size_t length) const;
|
||||
signature_result process_range_vectorized(uint8_t* start, size_t length) const;
|
||||
|
||||
bool has_sse_support() const;
|
||||
};
|
||||
}
|
||||
|
||||
utils::hook::signature::signature_result operator"" _sig(const char* str, size_t len);
|
||||
#pragma once
|
||||
#include "nt.hpp"
|
||||
#include <cstdint>
|
||||
|
||||
namespace utils::hook
|
||||
{
|
||||
class signature final
|
||||
{
|
||||
public:
|
||||
using signature_result = std::vector<uint8_t*>;
|
||||
|
||||
explicit signature(const std::string& pattern, const nt::library& library = {})
|
||||
: signature(pattern, library.get_ptr(), library.get_optional_header()->SizeOfImage)
|
||||
{
|
||||
}
|
||||
|
||||
signature(const std::string& pattern, void* start, void* end)
|
||||
: signature(pattern, start, size_t(end) - size_t(start))
|
||||
{
|
||||
}
|
||||
|
||||
signature(const std::string& pattern, void* start, const size_t length)
|
||||
: start_(static_cast<uint8_t*>(start)), length_(length)
|
||||
{
|
||||
this->load_pattern(pattern);
|
||||
}
|
||||
|
||||
signature_result process() const;
|
||||
|
||||
private:
|
||||
std::string mask_;
|
||||
std::basic_string<uint8_t> pattern_;
|
||||
|
||||
uint8_t* start_;
|
||||
size_t length_;
|
||||
|
||||
void load_pattern(const std::string& pattern);
|
||||
|
||||
signature_result process_parallel() const;
|
||||
signature_result process_serial() const;
|
||||
signature_result process_range(uint8_t* start, size_t length) const;
|
||||
signature_result process_range_linear(uint8_t* start, size_t length) const;
|
||||
signature_result process_range_vectorized(uint8_t* start, size_t length) const;
|
||||
|
||||
bool has_sse_support() const;
|
||||
};
|
||||
}
|
||||
|
||||
utils::hook::signature::signature_result operator"" _sig(const char* str, size_t len);
|
||||
|
@ -1,94 +1,94 @@
|
||||
#include "smbios.hpp"
|
||||
#include "memory.hpp"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
#include <intrin.h>
|
||||
|
||||
namespace utils::smbios
|
||||
{
|
||||
namespace
|
||||
{
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4200)
|
||||
struct RawSMBIOSData
|
||||
{
|
||||
BYTE Used20CallingMethod;
|
||||
BYTE SMBIOSMajorVersion;
|
||||
BYTE SMBIOSMinorVersion;
|
||||
BYTE DmiRevision;
|
||||
DWORD Length;
|
||||
BYTE SMBIOSTableData[];
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BYTE type;
|
||||
BYTE length;
|
||||
WORD handle;
|
||||
} dmi_header;
|
||||
#pragma warning(pop)
|
||||
|
||||
std::vector<uint8_t> get_smbios_data()
|
||||
{
|
||||
DWORD size = 0;
|
||||
std::vector<uint8_t> data{};
|
||||
|
||||
size = GetSystemFirmwareTable('RSMB', 0, nullptr, size);
|
||||
data.resize(size);
|
||||
GetSystemFirmwareTable('RSMB', 0, data.data(), size);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
std::string parse_uuid(const uint8_t* data)
|
||||
{
|
||||
if (utils::memory::is_set(data, 0, 16) || utils::memory::is_set(data, -1, 16))
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
char uuid[16] = {0};
|
||||
*reinterpret_cast<unsigned long*>(uuid + 0) =
|
||||
_byteswap_ulong(*reinterpret_cast<const unsigned long*>(data + 0));
|
||||
*reinterpret_cast<unsigned short*>(uuid + 4) =
|
||||
_byteswap_ushort(*reinterpret_cast<const unsigned short*>(data + 4));
|
||||
*reinterpret_cast<unsigned short*>(uuid + 6) =
|
||||
_byteswap_ushort(*reinterpret_cast<const unsigned short*>(data + 6));
|
||||
memcpy(uuid + 8, data + 8, 8);
|
||||
|
||||
return std::string(uuid, sizeof(uuid));
|
||||
}
|
||||
}
|
||||
|
||||
std::string get_uuid()
|
||||
{
|
||||
auto smbios_data = get_smbios_data();
|
||||
auto* raw_data = reinterpret_cast<RawSMBIOSData*>(smbios_data.data());
|
||||
|
||||
auto* data = raw_data->SMBIOSTableData;
|
||||
for (DWORD i = 0; i + sizeof(dmi_header) < raw_data->Length;)
|
||||
{
|
||||
auto* header = reinterpret_cast<dmi_header*>(data + i);
|
||||
if (header->length < 4)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
if (header->type == 0x01 && header->length >= 0x19)
|
||||
{
|
||||
return parse_uuid(data + i + 0x8);
|
||||
}
|
||||
|
||||
i += header->length;
|
||||
while ((i + 1) < raw_data->Length && *reinterpret_cast<uint16_t*>(data + i) != 0)
|
||||
{
|
||||
++i;
|
||||
}
|
||||
|
||||
i += 2;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
#include "smbios.hpp"
|
||||
#include "memory.hpp"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
#include <intrin.h>
|
||||
|
||||
namespace utils::smbios
|
||||
{
|
||||
namespace
|
||||
{
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4200)
|
||||
struct RawSMBIOSData
|
||||
{
|
||||
BYTE Used20CallingMethod;
|
||||
BYTE SMBIOSMajorVersion;
|
||||
BYTE SMBIOSMinorVersion;
|
||||
BYTE DmiRevision;
|
||||
DWORD Length;
|
||||
BYTE SMBIOSTableData[];
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BYTE type;
|
||||
BYTE length;
|
||||
WORD handle;
|
||||
} dmi_header;
|
||||
#pragma warning(pop)
|
||||
|
||||
std::vector<uint8_t> get_smbios_data()
|
||||
{
|
||||
DWORD size = 0;
|
||||
std::vector<uint8_t> data{};
|
||||
|
||||
size = GetSystemFirmwareTable('RSMB', 0, nullptr, size);
|
||||
data.resize(size);
|
||||
GetSystemFirmwareTable('RSMB', 0, data.data(), size);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
std::string parse_uuid(const uint8_t* data)
|
||||
{
|
||||
if (utils::memory::is_set(data, 0, 16) || utils::memory::is_set(data, -1, 16))
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
char uuid[16] = {0};
|
||||
*reinterpret_cast<unsigned long*>(uuid + 0) =
|
||||
_byteswap_ulong(*reinterpret_cast<const unsigned long*>(data + 0));
|
||||
*reinterpret_cast<unsigned short*>(uuid + 4) =
|
||||
_byteswap_ushort(*reinterpret_cast<const unsigned short*>(data + 4));
|
||||
*reinterpret_cast<unsigned short*>(uuid + 6) =
|
||||
_byteswap_ushort(*reinterpret_cast<const unsigned short*>(data + 6));
|
||||
memcpy(uuid + 8, data + 8, 8);
|
||||
|
||||
return std::string(uuid, sizeof(uuid));
|
||||
}
|
||||
}
|
||||
|
||||
std::string get_uuid()
|
||||
{
|
||||
auto smbios_data = get_smbios_data();
|
||||
auto* raw_data = reinterpret_cast<RawSMBIOSData*>(smbios_data.data());
|
||||
|
||||
auto* data = raw_data->SMBIOSTableData;
|
||||
for (DWORD i = 0; i + sizeof(dmi_header) < raw_data->Length;)
|
||||
{
|
||||
auto* header = reinterpret_cast<dmi_header*>(data + i);
|
||||
if (header->length < 4)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
if (header->type == 0x01 && header->length >= 0x19)
|
||||
{
|
||||
return parse_uuid(data + i + 0x8);
|
||||
}
|
||||
|
||||
i += header->length;
|
||||
while ((i + 1) < raw_data->Length && *reinterpret_cast<uint16_t*>(data + i) != 0)
|
||||
{
|
||||
++i;
|
||||
}
|
||||
|
||||
i += 2;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace utils::smbios
|
||||
{
|
||||
std::string get_uuid();
|
||||
}
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace utils::smbios
|
||||
{
|
||||
std::string get_uuid();
|
||||
}
|
||||
|
@ -1,177 +1,177 @@
|
||||
#include "string.hpp"
|
||||
#include <sstream>
|
||||
#include <cstdarg>
|
||||
#include <algorithm>
|
||||
|
||||
#include "nt.hpp"
|
||||
|
||||
namespace utils::string
|
||||
{
|
||||
const char* va(const char* fmt, ...)
|
||||
{
|
||||
static thread_local va_provider<8, 256> provider;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
|
||||
const char* result = provider.get(fmt, ap);
|
||||
|
||||
va_end(ap);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::string> split(const std::string& s, const char delim)
|
||||
{
|
||||
std::stringstream ss(s);
|
||||
std::string item;
|
||||
std::vector<std::string> elems;
|
||||
|
||||
while (std::getline(ss, item, delim))
|
||||
{
|
||||
elems.push_back(item); // elems.push_back(std::move(item)); // if C++11 (based on comment from @mchiasson)
|
||||
}
|
||||
|
||||
return elems;
|
||||
}
|
||||
|
||||
std::string to_lower(std::string text)
|
||||
{
|
||||
std::transform(text.begin(), text.end(), text.begin(), [](const unsigned char input)
|
||||
{
|
||||
return static_cast<char>(std::tolower(input));
|
||||
});
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
std::string to_upper(std::string text)
|
||||
{
|
||||
std::transform(text.begin(), text.end(), text.begin(), [](const unsigned char input)
|
||||
{
|
||||
return static_cast<char>(std::toupper(input));
|
||||
});
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
bool starts_with(const std::string& text, const std::string& substring)
|
||||
{
|
||||
return text.find(substring) == 0;
|
||||
}
|
||||
|
||||
bool ends_with(const std::string& text, const std::string& substring)
|
||||
{
|
||||
if (substring.size() > text.size()) return false;
|
||||
return std::equal(substring.rbegin(), substring.rend(), text.rbegin());
|
||||
}
|
||||
|
||||
std::string dump_hex(const std::string& data, const std::string& separator)
|
||||
{
|
||||
std::string result;
|
||||
|
||||
for (unsigned int i = 0; i < data.size(); ++i)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
result.append(separator);
|
||||
}
|
||||
|
||||
result.append(va("%02X", data[i] & 0xFF));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string get_clipboard_data()
|
||||
{
|
||||
if (OpenClipboard(nullptr))
|
||||
{
|
||||
std::string data;
|
||||
|
||||
auto* const clipboard_data = GetClipboardData(1u);
|
||||
if (clipboard_data)
|
||||
{
|
||||
auto* const cliptext = static_cast<char*>(GlobalLock(clipboard_data));
|
||||
if (cliptext)
|
||||
{
|
||||
data.append(cliptext);
|
||||
GlobalUnlock(clipboard_data);
|
||||
}
|
||||
}
|
||||
CloseClipboard();
|
||||
|
||||
return data;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void strip(const char* in, char* out, size_t max)
|
||||
{
|
||||
if (!in || !out) return;
|
||||
|
||||
max--;
|
||||
size_t current = 0;
|
||||
while (*in != 0 && current < max)
|
||||
{
|
||||
const auto color_index = (*(in + 1) - 48) >= 0xC ? 7 : (*(in + 1) - 48);
|
||||
|
||||
if (*in == '^' && (color_index != 7 || *(in + 1) == '7'))
|
||||
{
|
||||
++in;
|
||||
}
|
||||
else
|
||||
{
|
||||
*out = *in;
|
||||
++out;
|
||||
++current;
|
||||
}
|
||||
|
||||
++in;
|
||||
}
|
||||
|
||||
*out = '\0';
|
||||
}
|
||||
|
||||
std::string convert(const std::wstring& wstr)
|
||||
{
|
||||
std::string result;
|
||||
result.reserve(wstr.size());
|
||||
|
||||
for (const auto& chr : wstr)
|
||||
{
|
||||
result.push_back(static_cast<char>(chr));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::wstring convert(const std::string& str)
|
||||
{
|
||||
std::wstring result;
|
||||
result.reserve(str.size());
|
||||
|
||||
for (const auto& chr : str)
|
||||
{
|
||||
result.push_back(static_cast<wchar_t>(chr));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string replace(std::string str, const std::string& from, const std::string& to)
|
||||
{
|
||||
if (from.empty())
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
size_t start_pos = 0;
|
||||
while ((start_pos = str.find(from, start_pos)) != std::string::npos)
|
||||
{
|
||||
str.replace(start_pos, from.length(), to);
|
||||
start_pos += to.length();
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
||||
#include "string.hpp"
|
||||
#include <sstream>
|
||||
#include <cstdarg>
|
||||
#include <algorithm>
|
||||
|
||||
#include "nt.hpp"
|
||||
|
||||
namespace utils::string
|
||||
{
|
||||
const char* va(const char* fmt, ...)
|
||||
{
|
||||
static thread_local va_provider<8, 256> provider;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
|
||||
const char* result = provider.get(fmt, ap);
|
||||
|
||||
va_end(ap);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::string> split(const std::string& s, const char delim)
|
||||
{
|
||||
std::stringstream ss(s);
|
||||
std::string item;
|
||||
std::vector<std::string> elems;
|
||||
|
||||
while (std::getline(ss, item, delim))
|
||||
{
|
||||
elems.push_back(item); // elems.push_back(std::move(item)); // if C++11 (based on comment from @mchiasson)
|
||||
}
|
||||
|
||||
return elems;
|
||||
}
|
||||
|
||||
std::string to_lower(std::string text)
|
||||
{
|
||||
std::transform(text.begin(), text.end(), text.begin(), [](const unsigned char input)
|
||||
{
|
||||
return static_cast<char>(std::tolower(input));
|
||||
});
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
std::string to_upper(std::string text)
|
||||
{
|
||||
std::transform(text.begin(), text.end(), text.begin(), [](const unsigned char input)
|
||||
{
|
||||
return static_cast<char>(std::toupper(input));
|
||||
});
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
bool starts_with(const std::string& text, const std::string& substring)
|
||||
{
|
||||
return text.find(substring) == 0;
|
||||
}
|
||||
|
||||
bool ends_with(const std::string& text, const std::string& substring)
|
||||
{
|
||||
if (substring.size() > text.size()) return false;
|
||||
return std::equal(substring.rbegin(), substring.rend(), text.rbegin());
|
||||
}
|
||||
|
||||
std::string dump_hex(const std::string& data, const std::string& separator)
|
||||
{
|
||||
std::string result;
|
||||
|
||||
for (unsigned int i = 0; i < data.size(); ++i)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
result.append(separator);
|
||||
}
|
||||
|
||||
result.append(va("%02X", data[i] & 0xFF));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string get_clipboard_data()
|
||||
{
|
||||
if (OpenClipboard(nullptr))
|
||||
{
|
||||
std::string data;
|
||||
|
||||
auto* const clipboard_data = GetClipboardData(1u);
|
||||
if (clipboard_data)
|
||||
{
|
||||
auto* const cliptext = static_cast<char*>(GlobalLock(clipboard_data));
|
||||
if (cliptext)
|
||||
{
|
||||
data.append(cliptext);
|
||||
GlobalUnlock(clipboard_data);
|
||||
}
|
||||
}
|
||||
CloseClipboard();
|
||||
|
||||
return data;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void strip(const char* in, char* out, size_t max)
|
||||
{
|
||||
if (!in || !out) return;
|
||||
|
||||
max--;
|
||||
size_t current = 0;
|
||||
while (*in != 0 && current < max)
|
||||
{
|
||||
const auto color_index = (*(in + 1) - 48) >= 0xC ? 7 : (*(in + 1) - 48);
|
||||
|
||||
if (*in == '^' && (color_index != 7 || *(in + 1) == '7'))
|
||||
{
|
||||
++in;
|
||||
}
|
||||
else
|
||||
{
|
||||
*out = *in;
|
||||
++out;
|
||||
++current;
|
||||
}
|
||||
|
||||
++in;
|
||||
}
|
||||
|
||||
*out = '\0';
|
||||
}
|
||||
|
||||
std::string convert(const std::wstring& wstr)
|
||||
{
|
||||
std::string result;
|
||||
result.reserve(wstr.size());
|
||||
|
||||
for (const auto& chr : wstr)
|
||||
{
|
||||
result.push_back(static_cast<char>(chr));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::wstring convert(const std::string& str)
|
||||
{
|
||||
std::wstring result;
|
||||
result.reserve(str.size());
|
||||
|
||||
for (const auto& chr : str)
|
||||
{
|
||||
result.push_back(static_cast<wchar_t>(chr));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string replace(std::string str, const std::string& from, const std::string& to)
|
||||
{
|
||||
if (from.empty())
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
size_t start_pos = 0;
|
||||
while ((start_pos = str.find(from, start_pos)) != std::string::npos)
|
||||
{
|
||||
str.replace(start_pos, from.length(), to);
|
||||
start_pos += to.length();
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
@ -1,97 +1,97 @@
|
||||
#pragma once
|
||||
#include "memory.hpp"
|
||||
|
||||
template <class Type, size_t n>
|
||||
constexpr auto ARRAY_COUNT(Type (&)[n]) { return n; }
|
||||
|
||||
namespace utils::string
|
||||
{
|
||||
template <size_t Buffers, size_t MinBufferSize>
|
||||
class va_provider final
|
||||
{
|
||||
public:
|
||||
static_assert(Buffers != 0 && MinBufferSize != 0, "Buffers and MinBufferSize mustn't be 0");
|
||||
|
||||
va_provider() : current_buffer_(0)
|
||||
{
|
||||
}
|
||||
|
||||
char* get(const char* format, const va_list ap)
|
||||
{
|
||||
++this->current_buffer_ %= ARRAY_COUNT(this->string_pool_);
|
||||
auto entry = &this->string_pool_[this->current_buffer_];
|
||||
|
||||
if (!entry->size || !entry->buffer)
|
||||
{
|
||||
throw std::runtime_error("String pool not initialized");
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
const int res = vsnprintf_s(entry->buffer, entry->size, _TRUNCATE, format, ap);
|
||||
if (res > 0) break; // Success
|
||||
if (res == 0) return nullptr; // Error
|
||||
|
||||
entry->double_size();
|
||||
}
|
||||
|
||||
return entry->buffer;
|
||||
}
|
||||
|
||||
private:
|
||||
class entry final
|
||||
{
|
||||
public:
|
||||
entry(const size_t _size = MinBufferSize) : size(_size), buffer(nullptr)
|
||||
{
|
||||
if (this->size < MinBufferSize) this->size = MinBufferSize;
|
||||
this->allocate();
|
||||
}
|
||||
|
||||
~entry()
|
||||
{
|
||||
if (this->buffer) memory::get_allocator()->free(this->buffer);
|
||||
this->size = 0;
|
||||
this->buffer = nullptr;
|
||||
}
|
||||
|
||||
void allocate()
|
||||
{
|
||||
if (this->buffer) memory::get_allocator()->free(this->buffer);
|
||||
this->buffer = memory::get_allocator()->allocate_array<char>(this->size + 1);
|
||||
}
|
||||
|
||||
void double_size()
|
||||
{
|
||||
this->size *= 2;
|
||||
this->allocate();
|
||||
}
|
||||
|
||||
size_t size{};
|
||||
char* buffer{nullptr};
|
||||
};
|
||||
|
||||
size_t current_buffer_{};
|
||||
entry string_pool_[Buffers]{};
|
||||
};
|
||||
|
||||
const char* va(const char* fmt, ...);
|
||||
|
||||
std::vector<std::string> split(const std::string& s, char delim);
|
||||
|
||||
std::string to_lower(std::string text);
|
||||
std::string to_upper(std::string text);
|
||||
bool starts_with(const std::string& text, const std::string& substring);
|
||||
bool ends_with(const std::string& text, const std::string& substring);
|
||||
|
||||
std::string dump_hex(const std::string& data, const std::string& separator = " ");
|
||||
|
||||
std::string get_clipboard_data();
|
||||
|
||||
void strip(const char* in, char* out, size_t max);
|
||||
|
||||
std::string convert(const std::wstring& wstr);
|
||||
std::wstring convert(const std::string& str);
|
||||
|
||||
std::string replace(std::string str, const std::string& from, const std::string& to);
|
||||
}
|
||||
#pragma once
|
||||
#include "memory.hpp"
|
||||
|
||||
template <class Type, size_t n>
|
||||
constexpr auto ARRAY_COUNT(Type (&)[n]) { return n; }
|
||||
|
||||
namespace utils::string
|
||||
{
|
||||
template <size_t Buffers, size_t MinBufferSize>
|
||||
class va_provider final
|
||||
{
|
||||
public:
|
||||
static_assert(Buffers != 0 && MinBufferSize != 0, "Buffers and MinBufferSize mustn't be 0");
|
||||
|
||||
va_provider() : current_buffer_(0)
|
||||
{
|
||||
}
|
||||
|
||||
char* get(const char* format, const va_list ap)
|
||||
{
|
||||
++this->current_buffer_ %= ARRAY_COUNT(this->string_pool_);
|
||||
auto entry = &this->string_pool_[this->current_buffer_];
|
||||
|
||||
if (!entry->size || !entry->buffer)
|
||||
{
|
||||
throw std::runtime_error("String pool not initialized");
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
const int res = vsnprintf_s(entry->buffer, entry->size, _TRUNCATE, format, ap);
|
||||
if (res > 0) break; // Success
|
||||
if (res == 0) return nullptr; // Error
|
||||
|
||||
entry->double_size();
|
||||
}
|
||||
|
||||
return entry->buffer;
|
||||
}
|
||||
|
||||
private:
|
||||
class entry final
|
||||
{
|
||||
public:
|
||||
entry(const size_t _size = MinBufferSize) : size(_size), buffer(nullptr)
|
||||
{
|
||||
if (this->size < MinBufferSize) this->size = MinBufferSize;
|
||||
this->allocate();
|
||||
}
|
||||
|
||||
~entry()
|
||||
{
|
||||
if (this->buffer) memory::get_allocator()->free(this->buffer);
|
||||
this->size = 0;
|
||||
this->buffer = nullptr;
|
||||
}
|
||||
|
||||
void allocate()
|
||||
{
|
||||
if (this->buffer) memory::get_allocator()->free(this->buffer);
|
||||
this->buffer = memory::get_allocator()->allocate_array<char>(this->size + 1);
|
||||
}
|
||||
|
||||
void double_size()
|
||||
{
|
||||
this->size *= 2;
|
||||
this->allocate();
|
||||
}
|
||||
|
||||
size_t size{};
|
||||
char* buffer{nullptr};
|
||||
};
|
||||
|
||||
size_t current_buffer_{};
|
||||
entry string_pool_[Buffers]{};
|
||||
};
|
||||
|
||||
const char* va(const char* fmt, ...);
|
||||
|
||||
std::vector<std::string> split(const std::string& s, char delim);
|
||||
|
||||
std::string to_lower(std::string text);
|
||||
std::string to_upper(std::string text);
|
||||
bool starts_with(const std::string& text, const std::string& substring);
|
||||
bool ends_with(const std::string& text, const std::string& substring);
|
||||
|
||||
std::string dump_hex(const std::string& data, const std::string& separator = " ");
|
||||
|
||||
std::string get_clipboard_data();
|
||||
|
||||
void strip(const char* in, char* out, size_t max);
|
||||
|
||||
std::string convert(const std::wstring& wstr);
|
||||
std::wstring convert(const std::string& str);
|
||||
|
||||
std::string replace(std::string str, const std::string& from, const std::string& to);
|
||||
}
|
||||
|
@ -1,116 +1,116 @@
|
||||
#include "thread.hpp"
|
||||
#include "string.hpp"
|
||||
#include "finally.hpp"
|
||||
|
||||
#include <TlHelp32.h>
|
||||
|
||||
namespace utils::thread
|
||||
{
|
||||
/*bool set_name(const HANDLE t, const std::string& name)
|
||||
{
|
||||
const nt::library kernel32("kernel32.dll");
|
||||
if (!kernel32)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto set_description = kernel32.get_proc<HRESULT(WINAPI*)(HANDLE, PCWSTR)>("SetThreadDescription");
|
||||
if (!set_description)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return SUCCEEDED(set_description(t, string::convert(name).data()));
|
||||
}
|
||||
|
||||
bool set_name(const DWORD id, const std::string& name)
|
||||
{
|
||||
auto* const t = OpenThread(THREAD_SET_LIMITED_INFORMATION, FALSE, id);
|
||||
if (!t) return false;
|
||||
|
||||
const auto _ = utils::finally([t]()
|
||||
{
|
||||
CloseHandle(t);
|
||||
});
|
||||
|
||||
return set_name(t, name);
|
||||
}
|
||||
|
||||
bool set_name(std::thread& t, const std::string& name)
|
||||
{
|
||||
return set_name(t.native_handle(), name);
|
||||
}
|
||||
|
||||
bool set_name(const std::string& name)
|
||||
{
|
||||
return set_name(GetCurrentThread(), name);
|
||||
}
|
||||
*/
|
||||
std::vector<DWORD> get_thread_ids()
|
||||
{
|
||||
nt::handle<INVALID_HANDLE_VALUE> h = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, GetCurrentProcessId());
|
||||
if (!h)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
THREADENTRY32 entry{};
|
||||
entry.dwSize = sizeof(entry);
|
||||
if (!Thread32First(h, &entry))
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<DWORD> ids{};
|
||||
|
||||
do
|
||||
{
|
||||
const auto check_size = entry.dwSize < FIELD_OFFSET(THREADENTRY32, th32OwnerProcessID)
|
||||
+ sizeof(entry.th32OwnerProcessID);
|
||||
entry.dwSize = sizeof(entry);
|
||||
|
||||
if (check_size && entry.th32OwnerProcessID == GetCurrentProcessId())
|
||||
{
|
||||
ids.emplace_back(entry.th32ThreadID);
|
||||
}
|
||||
} while (Thread32Next(h, &entry));
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
void for_each_thread(const std::function<void(HANDLE)>& callback, const DWORD access)
|
||||
{
|
||||
const auto ids = get_thread_ids();
|
||||
|
||||
for (const auto& id : ids)
|
||||
{
|
||||
handle thread(id, access);
|
||||
if (thread)
|
||||
{
|
||||
callback(thread);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void suspend_other_threads()
|
||||
{
|
||||
for_each_thread([](const HANDLE thread)
|
||||
{
|
||||
if (GetThreadId(thread) != GetCurrentThreadId())
|
||||
{
|
||||
SuspendThread(thread);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void resume_other_threads()
|
||||
{
|
||||
for_each_thread([](const HANDLE thread)
|
||||
{
|
||||
if (GetThreadId(thread) != GetCurrentThreadId())
|
||||
{
|
||||
ResumeThread(thread);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
#include "thread.hpp"
|
||||
#include "string.hpp"
|
||||
#include "finally.hpp"
|
||||
|
||||
#include <TlHelp32.h>
|
||||
|
||||
namespace utils::thread
|
||||
{
|
||||
/*bool set_name(const HANDLE t, const std::string& name)
|
||||
{
|
||||
const nt::library kernel32("kernel32.dll");
|
||||
if (!kernel32)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto set_description = kernel32.get_proc<HRESULT(WINAPI*)(HANDLE, PCWSTR)>("SetThreadDescription");
|
||||
if (!set_description)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return SUCCEEDED(set_description(t, string::convert(name).data()));
|
||||
}
|
||||
|
||||
bool set_name(const DWORD id, const std::string& name)
|
||||
{
|
||||
auto* const t = OpenThread(THREAD_SET_LIMITED_INFORMATION, FALSE, id);
|
||||
if (!t) return false;
|
||||
|
||||
const auto _ = utils::finally([t]()
|
||||
{
|
||||
CloseHandle(t);
|
||||
});
|
||||
|
||||
return set_name(t, name);
|
||||
}
|
||||
|
||||
bool set_name(std::thread& t, const std::string& name)
|
||||
{
|
||||
return set_name(t.native_handle(), name);
|
||||
}
|
||||
|
||||
bool set_name(const std::string& name)
|
||||
{
|
||||
return set_name(GetCurrentThread(), name);
|
||||
}
|
||||
*/
|
||||
std::vector<DWORD> get_thread_ids()
|
||||
{
|
||||
nt::handle<INVALID_HANDLE_VALUE> h = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, GetCurrentProcessId());
|
||||
if (!h)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
THREADENTRY32 entry{};
|
||||
entry.dwSize = sizeof(entry);
|
||||
if (!Thread32First(h, &entry))
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<DWORD> ids{};
|
||||
|
||||
do
|
||||
{
|
||||
const auto check_size = entry.dwSize < FIELD_OFFSET(THREADENTRY32, th32OwnerProcessID)
|
||||
+ sizeof(entry.th32OwnerProcessID);
|
||||
entry.dwSize = sizeof(entry);
|
||||
|
||||
if (check_size && entry.th32OwnerProcessID == GetCurrentProcessId())
|
||||
{
|
||||
ids.emplace_back(entry.th32ThreadID);
|
||||
}
|
||||
} while (Thread32Next(h, &entry));
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
void for_each_thread(const std::function<void(HANDLE)>& callback, const DWORD access)
|
||||
{
|
||||
const auto ids = get_thread_ids();
|
||||
|
||||
for (const auto& id : ids)
|
||||
{
|
||||
handle thread(id, access);
|
||||
if (thread)
|
||||
{
|
||||
callback(thread);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void suspend_other_threads()
|
||||
{
|
||||
for_each_thread([](const HANDLE thread)
|
||||
{
|
||||
if (GetThreadId(thread) != GetCurrentThreadId())
|
||||
{
|
||||
SuspendThread(thread);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void resume_other_threads()
|
||||
{
|
||||
for_each_thread([](const HANDLE thread)
|
||||
{
|
||||
if (GetThreadId(thread) != GetCurrentThreadId())
|
||||
{
|
||||
ResumeThread(thread);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,47 +1,47 @@
|
||||
#pragma once
|
||||
#include <thread>
|
||||
#include "nt.hpp"
|
||||
|
||||
namespace utils::thread
|
||||
{
|
||||
//bool set_name(HANDLE t, const std::string& name);
|
||||
//bool set_name(DWORD id, const std::string& name);
|
||||
//bool set_name(std::thread& t, const std::string& name);
|
||||
//bool set_name(const std::string& name);
|
||||
|
||||
template <typename ...Args>
|
||||
std::thread create_named_thread(const std::string& name, Args&&... args)
|
||||
{
|
||||
auto t = std::thread(std::forward<Args>(args)...);
|
||||
set_name(t, name);
|
||||
return t;
|
||||
}
|
||||
|
||||
class handle
|
||||
{
|
||||
public:
|
||||
handle(const DWORD thread_id, const DWORD access = THREAD_ALL_ACCESS)
|
||||
: handle_(OpenThread(access, FALSE, thread_id))
|
||||
{
|
||||
}
|
||||
|
||||
operator bool() const
|
||||
{
|
||||
return this->handle_;
|
||||
}
|
||||
|
||||
operator HANDLE() const
|
||||
{
|
||||
return this->handle_;
|
||||
}
|
||||
|
||||
private:
|
||||
nt::handle<> handle_{};
|
||||
};
|
||||
|
||||
std::vector<DWORD> get_thread_ids();
|
||||
void for_each_thread(const std::function<void(HANDLE)>& callback, DWORD access = THREAD_ALL_ACCESS);
|
||||
|
||||
void suspend_other_threads();
|
||||
void resume_other_threads();
|
||||
}
|
||||
#pragma once
|
||||
#include <thread>
|
||||
#include "nt.hpp"
|
||||
|
||||
namespace utils::thread
|
||||
{
|
||||
//bool set_name(HANDLE t, const std::string& name);
|
||||
//bool set_name(DWORD id, const std::string& name);
|
||||
//bool set_name(std::thread& t, const std::string& name);
|
||||
//bool set_name(const std::string& name);
|
||||
|
||||
template <typename ...Args>
|
||||
std::thread create_named_thread(const std::string& name, Args&&... args)
|
||||
{
|
||||
auto t = std::thread(std::forward<Args>(args)...);
|
||||
set_name(t, name);
|
||||
return t;
|
||||
}
|
||||
|
||||
class handle
|
||||
{
|
||||
public:
|
||||
handle(const DWORD thread_id, const DWORD access = THREAD_ALL_ACCESS)
|
||||
: handle_(OpenThread(access, FALSE, thread_id))
|
||||
{
|
||||
}
|
||||
|
||||
operator bool() const
|
||||
{
|
||||
return this->handle_;
|
||||
}
|
||||
|
||||
operator HANDLE() const
|
||||
{
|
||||
return this->handle_;
|
||||
}
|
||||
|
||||
private:
|
||||
nt::handle<> handle_{};
|
||||
};
|
||||
|
||||
std::vector<DWORD> get_thread_ids();
|
||||
void for_each_thread(const std::function<void(HANDLE)>& callback, DWORD access = THREAD_ALL_ACCESS);
|
||||
|
||||
void suspend_other_threads();
|
||||
void resume_other_threads();
|
||||
}
|
||||
|
@ -1,379 +1,406 @@
|
||||
#include "functions.hpp"
|
||||
|
||||
void* RtlAddVectoredExceptionHandler(LONG First, PVECTORED_EXCEPTION_HANDLER Handler) {
|
||||
utils::nt::library ntdll("ntdll.dll");
|
||||
ntdll.invoke<void*>("RtlAddVectoredExceptionHandler", First, Handler);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NTSTATUS NtContinue(PCONTEXT threadContext, BOOLEAN raiseAlert) {
|
||||
utils::nt::library ntdll("ntdll.dll");
|
||||
return ntdll.invoke<NTSTATUS>("NtContinue", threadContext, raiseAlert);
|
||||
}
|
||||
|
||||
#pragma region //game functions
|
||||
|
||||
const char* (*va)(const char* fmt, ...);
|
||||
|
||||
void Live_FakeUserSignIn(int controllerIndex, const char* gamertag) {
|
||||
auto func = reinterpret_cast<void(*)(int, const char*)>(0x1413FDA40_g);
|
||||
func(controllerIndex, gamertag);
|
||||
}
|
||||
|
||||
void R_AddCmdDrawText(const char* text, int maxChars, void /* GfxFont */* font, int fontHeight, float x, float y, float xScale, float yScale, float rotation, const float* color, const void /* FontGlowStyle */* glowStyle, bool usePost) {
|
||||
auto func = reinterpret_cast<void(*)(const char* text, int maxChars, void /* GfxFont */* font, int fontHeight, float x, float y, float xScale, float yScale, float rotation, const float* color, const void /* FontGlowStyle */* glowStyle, bool usePost)>(0x00000001419653E0_g);
|
||||
func(text, maxChars, font, fontHeight, x, y, xScale, yScale, rotation, color, glowStyle, usePost);
|
||||
}
|
||||
|
||||
bool CG_WorldPosToScreenPosReal(int localClientNum, const uintptr_t scrPlace, const float* worldPos, float* outScreenPos) {
|
||||
auto func = reinterpret_cast<bool(*)(int, const uintptr_t, const float*, float*)>(0x141696AA0_g);
|
||||
return func(localClientNum, scrPlace, worldPos, outScreenPos);
|
||||
}
|
||||
|
||||
void CG_DrawRotatedPicPhysical(uintptr_t scrPlace, float x, float y, float width, float height, float angle, const float* color, uintptr_t material) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t scrPlace, float x, float y, float width, float height, float angle, const float* color, uintptr_t material)>(0x141695B20_g);
|
||||
func(scrPlace, x, y, width, height, angle, color, material);
|
||||
}
|
||||
|
||||
uintptr_t FS_ReadFile(const char* qpath, const char** buffer) {
|
||||
auto func = reinterpret_cast<uintptr_t(*)(const char* qpath, const char** buffer)>(0x1413DA530_g);
|
||||
return func(qpath, buffer);
|
||||
}
|
||||
|
||||
const char* Dvar_GetStringSafe(const char* dvar) {
|
||||
auto func = reinterpret_cast<const char* (*)(const char*)>(0x1413E69B0_g);
|
||||
return func(dvar);
|
||||
}
|
||||
|
||||
unsigned int* GetRandSeed() {
|
||||
auto func = reinterpret_cast<unsigned int* (*)()>(0x1413DD630_g);
|
||||
return func();
|
||||
}
|
||||
|
||||
unsigned __int64 Sys_Microseconds() {
|
||||
auto func = reinterpret_cast<unsigned __int64(*)()>(0x14148FC10_g);
|
||||
return func();
|
||||
}
|
||||
|
||||
int I_irand(int min, int max) {
|
||||
auto func = reinterpret_cast<int(*)(int, int)>(0x1413DD8B0_g);
|
||||
return func(min, max);
|
||||
}
|
||||
|
||||
unsigned __int64 I_atoui64_hex(const char* str) {
|
||||
auto func = reinterpret_cast<unsigned __int64(*)(const char*)>(0x1413F3310_g);
|
||||
return func(str);
|
||||
}
|
||||
|
||||
unsigned __int64 I_atoui64(const char* str) {
|
||||
auto func = reinterpret_cast<unsigned __int64(*)(const char*)>(0x1413F3300_g);
|
||||
return func(str);
|
||||
}
|
||||
|
||||
uintptr_t Dvar_FindVarByName(const char* dvarName) {
|
||||
auto func = reinterpret_cast<uintptr_t(*)(const char*)>(0x1413E63A0_g);
|
||||
return func(dvarName);
|
||||
}
|
||||
|
||||
void CL_DrawText(const uintptr_t scrPlace, const char* text, int maxChars, uintptr_t font, float x, float y, int horzAlign, int vertAlign, float xScale, float yScale, const float* color, int style) {
|
||||
auto func = reinterpret_cast<void(*)(const uintptr_t scrPlace, const char* text, int maxChars, uintptr_t font, float x, float y, int horzAlign, int vertAlign, float xScale, float yScale, const float* color, int style)>(0x1415AAAA0_g);
|
||||
func(scrPlace, text, maxChars, font, x, y, horzAlign, vertAlign, xScale, yScale, color, style);
|
||||
}
|
||||
|
||||
dvar_t* Dvar_RegisterString(const char* dvarName, const char* value, unsigned int flags, const char* description) {
|
||||
auto func = reinterpret_cast<dvar_t * (*)(const char* dvarName, const char* value, unsigned int flags, const char* description)>(0x1413E7A70_g);
|
||||
return func(dvarName, value, flags, description);
|
||||
}
|
||||
|
||||
dvar_t* Dvar_RegisterBool(const char* dvarName, bool value, unsigned int flags, const char* description) {
|
||||
auto func = reinterpret_cast<dvar_t * (*)(const char* dvarName, bool value, unsigned int flags, const char* description)>(0x1413E7670_g);
|
||||
return func(dvarName, value, flags, description);
|
||||
}
|
||||
|
||||
void LUI_CoD_LuaCall_ExecNow(uintptr_t luaVM, const char* str) {
|
||||
lua_getfield(luaVM, -10002, "Engine");
|
||||
lua_getfield(luaVM, -1, "DAGFFDGFII");
|
||||
lua_remove(luaVM, -2);
|
||||
lua_pushstring(luaVM, str);
|
||||
LuaShared_PCall(luaVM, 1, 1);
|
||||
}
|
||||
|
||||
bool LUI_LuaCall_Game_IsEntityAlive(uintptr_t luaVM, int entityNum) {
|
||||
lua_getfield(luaVM, -10002, "Game");
|
||||
lua_getfield(luaVM, -1, "JDAIJCDEB");
|
||||
lua_remove(luaVM, -2);
|
||||
lua_pushinteger(luaVM, 0);
|
||||
lua_pushinteger(luaVM, entityNum);
|
||||
LuaShared_PCall(luaVM, 2, 1);
|
||||
return lua_toboolean(luaVM, 0);
|
||||
}
|
||||
|
||||
void Cbuf_AddText(const char* cmd) {
|
||||
uintptr_t luaVM = *reinterpret_cast<uintptr_t*>(0x151868880_g);
|
||||
if (luaVM) {
|
||||
LUI_CoD_LuaCall_ExecNow(luaVM, cmd);
|
||||
}
|
||||
}
|
||||
|
||||
bool lua_toboolean(uintptr_t L, int idx) {
|
||||
auto func = reinterpret_cast<bool(*)(uintptr_t, int)>(0x1420848D0_g);
|
||||
return func(L, idx);
|
||||
}
|
||||
|
||||
void lua_pushboolean(uintptr_t L, int b) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, int)>(0x142083E80_g);
|
||||
func(L, b);
|
||||
}
|
||||
|
||||
void lua_remove(uintptr_t L, int idx) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, int)>(0x142084420_g);
|
||||
func(L, idx);
|
||||
}
|
||||
|
||||
void lua_call(uintptr_t L, int nargs, int nresults) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, int, int)>(0x1420831D0_g);
|
||||
func(L, nargs, nresults);
|
||||
}
|
||||
|
||||
void lua_getfield(uintptr_t L, int idx, const char* k) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, int, const char*)>(0x1420836E0_g);
|
||||
func(L, idx, k);
|
||||
}
|
||||
|
||||
void lua_pushvalue(uintptr_t L, int idx) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, int)>(0x142084200_g);
|
||||
func(L, idx);
|
||||
}
|
||||
|
||||
void lua_pushstring(uintptr_t L, const char* str) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, const char*)>(0x142084120_g);
|
||||
func(L, str);
|
||||
}
|
||||
|
||||
void lua_pushinteger(uintptr_t L, int n) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, int)>(0x142083FE0_g);
|
||||
func(L, n);
|
||||
}
|
||||
|
||||
void lua_settop(uintptr_t L, int idx) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, int)>(0x142084790_g);
|
||||
func(L, idx);
|
||||
}
|
||||
|
||||
int LuaShared_PCall(uintptr_t luaVM, int nargs, int nresults) {
|
||||
auto func = reinterpret_cast<int(*)(uintptr_t, int, int)>(0x1419B7570_g);
|
||||
return func(luaVM, nargs, nresults);
|
||||
}
|
||||
|
||||
bool CG_DObjGetWorldBoneMatrix(uintptr_t pose, uintptr_t obj, int boneIndex, uintptr_t outTagMat, float* outOrigin) {
|
||||
auto func = reinterpret_cast<bool(*)(uintptr_t pose, uintptr_t obj, int boneIndex, uintptr_t outTagMat, float* outOrigin)>(0x1416A59D0_g);
|
||||
return func(pose, obj, boneIndex, outTagMat, outOrigin);
|
||||
}
|
||||
|
||||
void CG_DrawLine(float X1, float Y1, float X2, float Y2, const float* color, float Width) {
|
||||
float X, Y, Angle, L1, L2, H1;
|
||||
H1 = Y2 - Y1;
|
||||
L1 = X2 - X1;
|
||||
L2 = sqrtf(L1 * L1 + H1 * H1);
|
||||
X = X1 + ((L1 - L2) / 2);
|
||||
Y = Y1 + (H1 / 2);
|
||||
Angle = atan(H1 / L1) * (180 / 3.14159265358979323846);
|
||||
CG_DrawRotatedPicPhysical(0x14EF2DEA0_g, X, Y, L2, Width, Angle, color, *reinterpret_cast<uintptr_t*>(0x152C465A0_g));
|
||||
}
|
||||
|
||||
void CG_DrawBone(int entIndex, uintptr_t ent, int from, int to, const float* color) {
|
||||
float bone1[3], bone2[3];
|
||||
float fromPos[2], toPos[2];
|
||||
char tmat33[0x24];
|
||||
short* clientObjMap = (short*)(0x14D45EC60_g);
|
||||
uintptr_t s_objBuf = *reinterpret_cast<uintptr_t*>(0x14D45EC50_g);
|
||||
uintptr_t dobj = s_objBuf + (0x150 * clientObjMap[entIndex]);
|
||||
if (CG_DObjGetWorldBoneMatrix(ent, dobj, from, (uintptr_t)&tmat33, bone1) && CG_DObjGetWorldBoneMatrix(ent, dobj, to, (uintptr_t)&tmat33, bone2)) {
|
||||
if (CG_WorldPosToScreenPosReal(0, 0x14EF2DEA0_g, bone1, fromPos) && CG_WorldPosToScreenPosReal(0, 0x14EF2DEA0_g, bone2, toPos)) {
|
||||
CG_DrawLine(fromPos[0], fromPos[1], toPos[0], toPos[1], color, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CG_DrawBones(int entIndex, uintptr_t ent, const float* color) {
|
||||
//spine
|
||||
CG_DrawBone(entIndex, ent, 41, 35, color);
|
||||
CG_DrawBone(entIndex, ent, 35, 7, color);
|
||||
CG_DrawBone(entIndex, ent, 7, 6, color);
|
||||
CG_DrawBone(entIndex, ent, 6, 30, color);
|
||||
CG_DrawBone(entIndex, ent, 30, 55, color);
|
||||
CG_DrawBone(entIndex, ent, 55, 54, color);
|
||||
CG_DrawBone(entIndex, ent, 54, 53, color);
|
||||
CG_DrawBone(entIndex, ent, 53, 2, color);
|
||||
|
||||
//hips
|
||||
CG_DrawBone(entIndex, ent, 2, 63, color);
|
||||
CG_DrawBone(entIndex, ent, 2, 64, color);
|
||||
}
|
||||
|
||||
bool CheatsOk(int entNum) {
|
||||
SvClient* ms_clients = *reinterpret_cast<SvClient**>(0x14E17F690_g + (8 * entNum));
|
||||
uintptr_t client = g_entities[entNum].get<uintptr_t>(0x150);
|
||||
if (sv_cheats->current.enabled) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
ms_clients->SendServerCommand(1, "f \"Cheats are not enabled on this server!\"");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//ingame removed functions
|
||||
void Cmd_Noclip_f(int entNum)
|
||||
{
|
||||
SvClient* ms_clients = *reinterpret_cast<SvClient**>(0x14E17F690_g + (8 * entNum));
|
||||
uintptr_t client = g_entities[entNum].get<uintptr_t>(0x150);
|
||||
if (client) {
|
||||
int v6 = *reinterpret_cast<int*>(client + 0x5DD0);
|
||||
if ((*reinterpret_cast<int*>(client + 0x5DD0) & 1) != 0) {
|
||||
v6 = *reinterpret_cast<int*>(client + 0x5DD0) & 0xFFFFFFFE;
|
||||
ms_clients->SendServerCommand(1, "f \"Noclip: ^1OFF\"");
|
||||
}
|
||||
else {
|
||||
v6 = *reinterpret_cast<int*>(client + 0x5DD0) | 1;
|
||||
ms_clients->SendServerCommand(1, "f \"Noclip: ^2ON\"");
|
||||
}
|
||||
*reinterpret_cast<int*>(client + 0x5DD0) = v6;
|
||||
}
|
||||
}
|
||||
|
||||
void SV_Cmd_ArgvBuffer(int arg, char* buffer, unsigned __int64 bufferLength) {
|
||||
auto func = reinterpret_cast<void(*)(int, char*, unsigned __int64)>(0x141298B40_g);
|
||||
func(arg, buffer, bufferLength);
|
||||
}
|
||||
|
||||
void Cmd_ArgvBuffer(int arg, char* buffer, int bufferLength) {
|
||||
if (arg >= cmd_args->argc[cmd_args->nesting])
|
||||
strcpy_s(buffer, bufferLength, "");
|
||||
else
|
||||
strcpy_s(buffer, bufferLength, cmd_args->argv[cmd_args->nesting][arg]);
|
||||
}
|
||||
|
||||
int Cmd_Argc() {
|
||||
return cmd_args->argc[cmd_args->nesting];
|
||||
}
|
||||
|
||||
int SV_Cmd_Argc() {
|
||||
auto func = reinterpret_cast<int(*)()>(0x141298AF0_g);
|
||||
return func();
|
||||
}
|
||||
|
||||
void Cmd_AddCommandInternal(const char* cmdName, void(__fastcall* function)(), cmd_function_s* allocedCmd) {
|
||||
auto func = reinterpret_cast<void(*)(const char*, void(__fastcall*)(), cmd_function_s*)>(0x1412965F0_g);
|
||||
func(cmdName, function, allocedCmd);
|
||||
}
|
||||
|
||||
ClActiveClient* GetClActiveClient() {
|
||||
ms_activeClients = *reinterpret_cast<ClActiveClient**>(0x14EE854F8_g);
|
||||
return ms_activeClients;
|
||||
}
|
||||
|
||||
int ClActiveClient_GetCmdNumber(ClActiveClient* activeClient) {
|
||||
return activeClient->cmdNumber ^ ((activeClient->get<int>(0x8700) ^ (activeClient->cmdNumber) * ((activeClient->get<int>(0x8700) ^ activeClient->cmdNumber) + 2)));
|
||||
}
|
||||
|
||||
usercmd_s* CL_GetUserCmd(int cmdNumber) {
|
||||
ms_activeClients = *reinterpret_cast<ClActiveClient**>(0x14EE854F8_g);
|
||||
return &ms_activeClients->cmds[cmdNumber & 0x7F];
|
||||
}
|
||||
|
||||
void AddReliableCommand(uintptr_t _this, const char* commandBuffer, const int reliableCmdSize, int type) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, const char*, const int, int)>(0x1415E0440_g);
|
||||
func(_this, commandBuffer, reliableCmdSize, type);
|
||||
}
|
||||
|
||||
unsigned int MSG_WriteReliableCommandToBuffer(const char* pszCommand, char* pszBuffer, unsigned int iBufferSize) {
|
||||
auto func = reinterpret_cast<unsigned int(*)(const char*, char*, unsigned int)>(0x1412DDBF0_g);
|
||||
return func(pszCommand, pszBuffer, iBufferSize);
|
||||
}
|
||||
|
||||
void CL_Main_AddReliableCommand(const char* cmd) {
|
||||
uintptr_t ms_connections = *reinterpret_cast<uintptr_t*>(0x14EE85570_g);
|
||||
char buf[1024];
|
||||
int cmdSize = MSG_WriteReliableCommandToBuffer(cmd, buf, 1024);
|
||||
AddReliableCommand(ms_connections, buf, cmdSize, 0);
|
||||
}
|
||||
|
||||
bool BG_Weapons_GetFullWeaponForName(const char* name, Weapon* outWeapon, Weapon* (*getWeaponFunc)(Weapon* result, const char*)) {
|
||||
auto func = reinterpret_cast<bool(*)(const char*, Weapon*, Weapon * (*)(Weapon * result, const char*))>(0x141158130_g);
|
||||
return func(name, outWeapon, getWeaponFunc);
|
||||
}
|
||||
|
||||
void Scr_AddString(scrContext_t* scrContext, const char* value) {
|
||||
auto func = reinterpret_cast<void(*)(scrContext_t*, const char*)>(0x141322D90_g);
|
||||
func(scrContext, value);
|
||||
}
|
||||
|
||||
unsigned int GScr_ExecEntThread(gentity_s* ent, int handle, unsigned int paramcount) {
|
||||
auto func = reinterpret_cast<unsigned int(*)(gentity_s*, int, unsigned int)>(0x141257D70_g);
|
||||
return func(ent, handle, paramcount);
|
||||
}
|
||||
|
||||
void Scr_FreeThread(scrContext_t* scrContext, unsigned int handle) {
|
||||
auto func = reinterpret_cast<void(*)(scrContext_t*, unsigned int)>(0x1413242E0_g);
|
||||
func(scrContext, handle);
|
||||
}
|
||||
|
||||
int G_Weapon_GivePlayerWeapon(uintptr_t ps, uintptr_t scrContext, Weapon* weapon, int dualWield, int startInAltMode, int usedBefore) {
|
||||
auto func = reinterpret_cast<int(*)(uintptr_t, uintptr_t, Weapon*, int, int, int)>(0x14127C8B0_g);
|
||||
return func(ps, scrContext, weapon, dualWield, startInAltMode, usedBefore);
|
||||
}
|
||||
|
||||
void G_Items_AddAmmo(uintptr_t ps, Weapon* weapon, bool isAlternate, int count, int fillClip) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, Weapon*, bool, int, int)>(0x141216860_g);
|
||||
func(ps, weapon, isAlternate, count, fillClip);
|
||||
}
|
||||
|
||||
void G_Weapon_SelectWeapon(int clientNum, Weapon* weapon) {
|
||||
auto func = reinterpret_cast<void(*)(int, Weapon*)>(0x14127F840_g);
|
||||
}
|
||||
|
||||
Weapon* BG_FindBaseWeaponForName(Weapon* result, const char* name) {
|
||||
auto func = reinterpret_cast<Weapon * (*)(Weapon*, const char*)>(0x1411570F0_g);
|
||||
return func(result, name);
|
||||
}
|
||||
|
||||
scrContext_t* ScriptContext_Server() {
|
||||
auto func = reinterpret_cast<scrContext_t * (*)()>(0x1412E0E70_g);
|
||||
return func();
|
||||
}
|
||||
|
||||
const char* SL_ConvertToString(int id) {
|
||||
auto func = reinterpret_cast<const char* (*)(int)>(0x14131AA20_g);
|
||||
return func(id);
|
||||
}
|
||||
|
||||
XAssetHeader DB_FindXAssetHeader(XAssetType type, const char* givenName, int allowCreateDefault) {
|
||||
auto func = reinterpret_cast<XAssetHeader(*)(XAssetType, const char*, int)>(0x1411AA890_g);
|
||||
return func(type, givenName, allowCreateDefault);
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
dvar_t* player_name;
|
||||
dvar_t* sv_cheats;
|
||||
dvar_t* spawn_br_gas;
|
||||
dvar_t* show_watermark;
|
||||
dvar_t* player_sustainammo;
|
||||
|
||||
cmd_function_s set_byte_f_VAR;
|
||||
cmd_function_s set_short_f_VAR;
|
||||
cmd_function_s set_int_f_VAR;
|
||||
cmd_function_s set_pointer_f_VAR;
|
||||
cmd_function_s quit_f_VAR;
|
||||
cmd_function_s openmenu_f_VAR;
|
||||
cmd_function_s addbot_f_VAR;
|
||||
cmd_function_s ddldump_f_VAR;
|
||||
cmd_function_s weapondefdump_f_VAR;
|
||||
cmd_function_s view_vehicle_ents_f_VAR;
|
||||
cmd_function_s loadout_save_f_VAR;
|
||||
cmd_function_s FastRestart_f_VAR;
|
||||
|
||||
CmdArgs* cmd_args;
|
||||
|
||||
#include "functions.hpp"
|
||||
|
||||
void* RtlAddVectoredExceptionHandler(LONG First, PVECTORED_EXCEPTION_HANDLER Handler) {
|
||||
utils::nt::library ntdll("ntdll.dll");
|
||||
ntdll.invoke<void*>("RtlAddVectoredExceptionHandler", First, Handler);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NTSTATUS NtContinue(PCONTEXT threadContext, BOOLEAN raiseAlert) {
|
||||
utils::nt::library ntdll("ntdll.dll");
|
||||
return ntdll.invoke<NTSTATUS>("NtContinue", threadContext, raiseAlert);
|
||||
}
|
||||
|
||||
#pragma region //game functions
|
||||
|
||||
const char* (*va)(const char* fmt, ...);
|
||||
|
||||
void Live_FakeUserSignIn(int controllerIndex, const char* gamertag) {
|
||||
auto func = reinterpret_cast<void(*)(int, const char*)>(0x1413FDA40_g);
|
||||
func(controllerIndex, gamertag);
|
||||
}
|
||||
|
||||
void R_AddCmdDrawText(const char* text, int maxChars, void /* GfxFont */* font, int fontHeight, float x, float y, float xScale, float yScale, float rotation, const float* color, const void /* FontGlowStyle */* glowStyle, bool usePost) {
|
||||
auto func = reinterpret_cast<void(*)(const char* text, int maxChars, void /* GfxFont */* font, int fontHeight, float x, float y, float xScale, float yScale, float rotation, const float* color, const void /* FontGlowStyle */* glowStyle, bool usePost)>(0x00000001419653E0_g);
|
||||
func(text, maxChars, font, fontHeight, x, y, xScale, yScale, rotation, color, glowStyle, usePost);
|
||||
}
|
||||
|
||||
bool CG_WorldPosToScreenPosReal(int localClientNum, const uintptr_t scrPlace, const float* worldPos, float* outScreenPos) {
|
||||
auto func = reinterpret_cast<bool(*)(int, const uintptr_t, const float*, float*)>(0x141696AA0_g);
|
||||
return func(localClientNum, scrPlace, worldPos, outScreenPos);
|
||||
}
|
||||
|
||||
void CG_DrawRotatedPicPhysical(uintptr_t scrPlace, float x, float y, float width, float height, float angle, const float* color, uintptr_t material) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t scrPlace, float x, float y, float width, float height, float angle, const float* color, uintptr_t material)>(0x141695B20_g);
|
||||
func(scrPlace, x, y, width, height, angle, color, material);
|
||||
}
|
||||
|
||||
uintptr_t FS_ReadFile(const char* qpath, const char** buffer) {
|
||||
auto func = reinterpret_cast<uintptr_t(*)(const char* qpath, const char** buffer)>(0x1413DA530_g);
|
||||
return func(qpath, buffer);
|
||||
}
|
||||
|
||||
const char* Dvar_GetStringSafe(const char* dvar) {
|
||||
auto func = reinterpret_cast<const char* (*)(const char*)>(0x1413E69B0_g);
|
||||
return func(dvar);
|
||||
}
|
||||
|
||||
bool Dvar_GetBoolSafe(const char* dvar)
|
||||
{
|
||||
auto func = reinterpret_cast<bool(*)(const char*)>(0x1413E6820_g);
|
||||
return func(dvar);
|
||||
}
|
||||
|
||||
int Dvar_GetIntSafe(const char* dvar)
|
||||
{
|
||||
auto func = reinterpret_cast<int(*)(const char* path)>(0x1413E6960_g);
|
||||
return func(dvar);
|
||||
}
|
||||
|
||||
unsigned int* GetRandSeed() {
|
||||
auto func = reinterpret_cast<unsigned int* (*)()>(0x1413DD630_g);
|
||||
return func();
|
||||
}
|
||||
|
||||
unsigned __int64 Sys_Microseconds() {
|
||||
auto func = reinterpret_cast<unsigned __int64(*)()>(0x14148FC10_g);
|
||||
return func();
|
||||
}
|
||||
|
||||
int I_irand(int min, int max) {
|
||||
auto func = reinterpret_cast<int(*)(int, int)>(0x1413DD8B0_g);
|
||||
return func(min, max);
|
||||
}
|
||||
|
||||
unsigned __int64 I_atoui64_hex(const char* str) {
|
||||
auto func = reinterpret_cast<unsigned __int64(*)(const char*)>(0x1413F3310_g);
|
||||
return func(str);
|
||||
}
|
||||
|
||||
unsigned __int64 I_atoui64(const char* str) {
|
||||
auto func = reinterpret_cast<unsigned __int64(*)(const char*)>(0x1413F3300_g);
|
||||
return func(str);
|
||||
}
|
||||
|
||||
uintptr_t Dvar_FindVarByName(const char* dvarName) {
|
||||
auto func = reinterpret_cast<uintptr_t(*)(const char*)>(0x1413E63A0_g);
|
||||
return func(dvarName);
|
||||
}
|
||||
|
||||
void CL_DrawText(const uintptr_t scrPlace, const char* text, int maxChars, uintptr_t font, float x, float y, int horzAlign, int vertAlign, float xScale, float yScale, const float* color, int style) {
|
||||
auto func = reinterpret_cast<void(*)(const uintptr_t scrPlace, const char* text, int maxChars, uintptr_t font, float x, float y, int horzAlign, int vertAlign, float xScale, float yScale, const float* color, int style)>(0x1415AAAA0_g);
|
||||
func(scrPlace, text, maxChars, font, x, y, horzAlign, vertAlign, xScale, yScale, color, style);
|
||||
}
|
||||
|
||||
dvar_t* Dvar_RegisterString(const char* dvarName, const char* value, unsigned int flags, const char* description) {
|
||||
auto func = reinterpret_cast<dvar_t * (*)(const char* dvarName, const char* value, unsigned int flags, const char* description)>(0x1413E7A70_g);
|
||||
return func(dvarName, value, flags, description);
|
||||
}
|
||||
|
||||
dvar_t* Dvar_RegisterBool(const char* dvarName, bool value, unsigned int flags, const char* description) {
|
||||
auto func = reinterpret_cast<dvar_t * (*)(const char* dvarName, bool value, unsigned int flags, const char* description)>(0x1413E7670_g);
|
||||
return func(dvarName, value, flags, description);
|
||||
}
|
||||
|
||||
void LUI_CoD_LuaCall_ExecNow(uintptr_t luaVM, const char* str) {
|
||||
lua_getfield(luaVM, -10002, "Engine");
|
||||
lua_getfield(luaVM, -1, "DAGFFDGFII");
|
||||
lua_remove(luaVM, -2);
|
||||
lua_pushstring(luaVM, str);
|
||||
LuaShared_PCall(luaVM, 1, 1);
|
||||
}
|
||||
|
||||
bool LUI_LuaCall_Game_IsEntityAlive(uintptr_t luaVM, int entityNum) {
|
||||
lua_getfield(luaVM, -10002, "Game");
|
||||
lua_getfield(luaVM, -1, "JDAIJCDEB");
|
||||
lua_remove(luaVM, -2);
|
||||
lua_pushinteger(luaVM, 0);
|
||||
lua_pushinteger(luaVM, entityNum);
|
||||
LuaShared_PCall(luaVM, 2, 1);
|
||||
return lua_toboolean(luaVM, 0);
|
||||
}
|
||||
|
||||
void Cbuf_AddText(const char* cmd) {
|
||||
uintptr_t luaVM = *reinterpret_cast<uintptr_t*>(0x151868880_g);
|
||||
if (luaVM) {
|
||||
LUI_CoD_LuaCall_ExecNow(luaVM, cmd);
|
||||
}
|
||||
}
|
||||
|
||||
bool lua_toboolean(uintptr_t L, int idx) {
|
||||
auto func = reinterpret_cast<bool(*)(uintptr_t, int)>(0x1420848D0_g);
|
||||
return func(L, idx);
|
||||
}
|
||||
|
||||
void lua_pushboolean(uintptr_t L, int b) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, int)>(0x142083E80_g);
|
||||
func(L, b);
|
||||
}
|
||||
|
||||
void lua_remove(uintptr_t L, int idx) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, int)>(0x142084420_g);
|
||||
func(L, idx);
|
||||
}
|
||||
|
||||
void lua_call(uintptr_t L, int nargs, int nresults) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, int, int)>(0x1420831D0_g);
|
||||
func(L, nargs, nresults);
|
||||
}
|
||||
|
||||
void lua_getfield(uintptr_t L, int idx, const char* k) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, int, const char*)>(0x1420836E0_g);
|
||||
func(L, idx, k);
|
||||
}
|
||||
|
||||
void lua_pushvalue(uintptr_t L, int idx) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, int)>(0x142084200_g);
|
||||
func(L, idx);
|
||||
}
|
||||
|
||||
void lua_pushstring(uintptr_t L, const char* str) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, const char*)>(0x142084120_g);
|
||||
func(L, str);
|
||||
}
|
||||
|
||||
void lua_pushinteger(uintptr_t L, int n) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, int)>(0x142083FE0_g);
|
||||
func(L, n);
|
||||
}
|
||||
|
||||
void lua_settop(uintptr_t L, int idx) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, int)>(0x142084790_g);
|
||||
func(L, idx);
|
||||
}
|
||||
|
||||
int LuaShared_PCall(uintptr_t luaVM, int nargs, int nresults) {
|
||||
auto func = reinterpret_cast<int(*)(uintptr_t, int, int)>(0x1419B7570_g);
|
||||
return func(luaVM, nargs, nresults);
|
||||
}
|
||||
|
||||
bool CG_DObjGetWorldBoneMatrix(uintptr_t pose, uintptr_t obj, int boneIndex, uintptr_t outTagMat, float* outOrigin) {
|
||||
auto func = reinterpret_cast<bool(*)(uintptr_t pose, uintptr_t obj, int boneIndex, uintptr_t outTagMat, float* outOrigin)>(0x1416A59D0_g);
|
||||
return func(pose, obj, boneIndex, outTagMat, outOrigin);
|
||||
}
|
||||
|
||||
void CG_DrawLine(float X1, float Y1, float X2, float Y2, const float* color, float Width) {
|
||||
float X, Y, Angle, L1, L2, H1;
|
||||
H1 = Y2 - Y1;
|
||||
L1 = X2 - X1;
|
||||
L2 = sqrtf(L1 * L1 + H1 * H1);
|
||||
X = X1 + ((L1 - L2) / 2);
|
||||
Y = Y1 + (H1 / 2);
|
||||
Angle = atan(H1 / L1) * (180 / 3.14159265358979323846);
|
||||
CG_DrawRotatedPicPhysical(0x14EF2DEA0_g, X, Y, L2, Width, Angle, color, *reinterpret_cast<uintptr_t*>(0x152C465A0_g));
|
||||
}
|
||||
|
||||
void CG_DrawBone(int entIndex, uintptr_t ent, int from, int to, const float* color) {
|
||||
float bone1[3], bone2[3];
|
||||
float fromPos[2], toPos[2];
|
||||
char tmat33[0x24];
|
||||
short* clientObjMap = (short*)(0x14D45EC60_g);
|
||||
uintptr_t s_objBuf = *reinterpret_cast<uintptr_t*>(0x14D45EC50_g);
|
||||
uintptr_t dobj = s_objBuf + (0x150 * clientObjMap[entIndex]);
|
||||
if (CG_DObjGetWorldBoneMatrix(ent, dobj, from, (uintptr_t)&tmat33, bone1) && CG_DObjGetWorldBoneMatrix(ent, dobj, to, (uintptr_t)&tmat33, bone2)) {
|
||||
if (CG_WorldPosToScreenPosReal(0, 0x14EF2DEA0_g, bone1, fromPos) && CG_WorldPosToScreenPosReal(0, 0x14EF2DEA0_g, bone2, toPos)) {
|
||||
CG_DrawLine(fromPos[0], fromPos[1], toPos[0], toPos[1], color, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CG_DrawBones(int entIndex, uintptr_t ent, const float* color) {
|
||||
//spine
|
||||
CG_DrawBone(entIndex, ent, 41, 35, color);
|
||||
CG_DrawBone(entIndex, ent, 35, 7, color);
|
||||
CG_DrawBone(entIndex, ent, 7, 6, color);
|
||||
CG_DrawBone(entIndex, ent, 6, 30, color);
|
||||
CG_DrawBone(entIndex, ent, 30, 55, color);
|
||||
CG_DrawBone(entIndex, ent, 55, 54, color);
|
||||
CG_DrawBone(entIndex, ent, 54, 53, color);
|
||||
CG_DrawBone(entIndex, ent, 53, 2, color);
|
||||
|
||||
//hips
|
||||
CG_DrawBone(entIndex, ent, 2, 63, color);
|
||||
CG_DrawBone(entIndex, ent, 2, 64, color);
|
||||
}
|
||||
|
||||
bool CheatsOk(int entNum) {
|
||||
SvClient* ms_clients = *reinterpret_cast<SvClient**>(0x14E17F690_g + (8 * entNum));
|
||||
uintptr_t client = g_entities[entNum].get<uintptr_t>(0x150);
|
||||
if (sv_cheats->current.enabled) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
ms_clients->SendServerCommand(1, "f \"Cheats are not enabled on this server!\"");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//ingame removed functions
|
||||
void Cmd_Noclip_f(int entNum)
|
||||
{
|
||||
SvClient* ms_clients = *reinterpret_cast<SvClient**>(0x14E17F690_g + (8 * entNum));
|
||||
uintptr_t client = g_entities[entNum].get<uintptr_t>(0x150);
|
||||
if (client) {
|
||||
int v6 = *reinterpret_cast<int*>(client + 0x5DD0);
|
||||
if ((*reinterpret_cast<int*>(client + 0x5DD0) & 1) != 0) {
|
||||
v6 = *reinterpret_cast<int*>(client + 0x5DD0) & 0xFFFFFFFE;
|
||||
ms_clients->SendServerCommand(1, "f \"Noclip: ^1OFF\"");
|
||||
}
|
||||
else {
|
||||
v6 = *reinterpret_cast<int*>(client + 0x5DD0) | 1;
|
||||
ms_clients->SendServerCommand(1, "f \"Noclip: ^2ON\"");
|
||||
}
|
||||
*reinterpret_cast<int*>(client + 0x5DD0) = v6;
|
||||
}
|
||||
}
|
||||
|
||||
void Cmd_God_f(int entNum)
|
||||
{
|
||||
SvClient* ms_clients = *reinterpret_cast<SvClient**>(0x14E17F690_g + (8 * entNum));
|
||||
gentity_s ent = g_entities[entNum];
|
||||
}
|
||||
|
||||
void SV_Cmd_ArgvBuffer(int arg, char* buffer, unsigned __int64 bufferLength) {
|
||||
auto func = reinterpret_cast<void(*)(int, char*, unsigned __int64)>(0x141298B40_g);
|
||||
func(arg, buffer, bufferLength);
|
||||
}
|
||||
|
||||
void Cmd_ArgvBuffer(int arg, char* buffer, int bufferLength) {
|
||||
if (arg >= cmd_args->argc[cmd_args->nesting])
|
||||
strcpy_s(buffer, bufferLength, "");
|
||||
else
|
||||
strcpy_s(buffer, bufferLength, cmd_args->argv[cmd_args->nesting][arg]);
|
||||
}
|
||||
|
||||
int Cmd_Argc() {
|
||||
return cmd_args->argc[cmd_args->nesting];
|
||||
}
|
||||
|
||||
int SV_Cmd_Argc() {
|
||||
auto func = reinterpret_cast<int(*)()>(0x141298AF0_g);
|
||||
return func();
|
||||
}
|
||||
|
||||
void Cmd_AddCommandInternal(const char* cmdName, void(__fastcall* function)(), cmd_function_s* allocedCmd) {
|
||||
auto func = reinterpret_cast<void(*)(const char*, void(__fastcall*)(), cmd_function_s*)>(0x1412965F0_g);
|
||||
func(cmdName, function, allocedCmd);
|
||||
}
|
||||
|
||||
ClActiveClient* GetClActiveClient() {
|
||||
ms_activeClients = *reinterpret_cast<ClActiveClient**>(0x14EE854F8_g);
|
||||
return ms_activeClients;
|
||||
}
|
||||
|
||||
int ClActiveClient_GetCmdNumber(ClActiveClient* activeClient) {
|
||||
return activeClient->cmdNumber ^ ((activeClient->get<int>(0x8700) ^ (activeClient->cmdNumber) * ((activeClient->get<int>(0x8700) ^ activeClient->cmdNumber) + 2)));
|
||||
}
|
||||
|
||||
usercmd_s* CL_GetUserCmd(int cmdNumber) {
|
||||
ms_activeClients = *reinterpret_cast<ClActiveClient**>(0x14EE854F8_g);
|
||||
return &ms_activeClients->cmds[cmdNumber & 0x7F];
|
||||
}
|
||||
|
||||
void AddReliableCommand(uintptr_t _this, const char* commandBuffer, const int reliableCmdSize, int type) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, const char*, const int, int)>(0x1415E0440_g);
|
||||
func(_this, commandBuffer, reliableCmdSize, type);
|
||||
}
|
||||
|
||||
unsigned int MSG_WriteReliableCommandToBuffer(const char* pszCommand, char* pszBuffer, unsigned int iBufferSize) {
|
||||
auto func = reinterpret_cast<unsigned int(*)(const char*, char*, unsigned int)>(0x1412DDBF0_g);
|
||||
return func(pszCommand, pszBuffer, iBufferSize);
|
||||
}
|
||||
|
||||
void CL_Main_AddReliableCommand(const char* cmd) {
|
||||
uintptr_t ms_connections = *reinterpret_cast<uintptr_t*>(0x14EE85570_g);
|
||||
char buf[1024];
|
||||
int cmdSize = MSG_WriteReliableCommandToBuffer(cmd, buf, 1024);
|
||||
AddReliableCommand(ms_connections, buf, cmdSize, 0);
|
||||
}
|
||||
|
||||
bool BG_Weapons_GetFullWeaponForName(const char* name, Weapon* outWeapon, Weapon* (*getWeaponFunc)(Weapon* result, const char*)) {
|
||||
auto func = reinterpret_cast<bool(*)(const char*, Weapon*, Weapon * (*)(Weapon * result, const char*))>(0x141158130_g);
|
||||
return func(name, outWeapon, getWeaponFunc);
|
||||
}
|
||||
|
||||
void Scr_AddString(scrContext_t* scrContext, const char* value) {
|
||||
auto func = reinterpret_cast<void(*)(scrContext_t*, const char*)>(0x141322D90_g);
|
||||
func(scrContext, value);
|
||||
}
|
||||
|
||||
unsigned int GScr_ExecEntThread(gentity_s* ent, int handle, unsigned int paramcount) {
|
||||
auto func = reinterpret_cast<unsigned int(*)(gentity_s*, int, unsigned int)>(0x141257D70_g);
|
||||
return func(ent, handle, paramcount);
|
||||
}
|
||||
|
||||
void Scr_FreeThread(scrContext_t* scrContext, unsigned int handle) {
|
||||
auto func = reinterpret_cast<void(*)(scrContext_t*, unsigned int)>(0x1413242E0_g);
|
||||
func(scrContext, handle);
|
||||
}
|
||||
|
||||
int G_Weapon_GivePlayerWeapon(uintptr_t ps, uintptr_t scrContext, Weapon* weapon, int dualWield, int startInAltMode, int usedBefore) {
|
||||
auto func = reinterpret_cast<int(*)(uintptr_t, uintptr_t, Weapon*, int, int, int)>(0x14127C8B0_g);
|
||||
return func(ps, scrContext, weapon, dualWield, startInAltMode, usedBefore);
|
||||
}
|
||||
|
||||
void G_Items_AddAmmo(uintptr_t ps, Weapon* weapon, bool isAlternate, int count, int fillClip) {
|
||||
auto func = reinterpret_cast<void(*)(uintptr_t, Weapon*, bool, int, int)>(0x141216860_g);
|
||||
func(ps, weapon, isAlternate, count, fillClip);
|
||||
}
|
||||
|
||||
void G_Weapon_SelectWeapon(int clientNum, Weapon* weapon) {
|
||||
auto func = reinterpret_cast<void(*)(int, Weapon*)>(0x14127F840_g);
|
||||
}
|
||||
|
||||
Weapon* BG_FindBaseWeaponForName(Weapon* result, const char* name) {
|
||||
auto func = reinterpret_cast<Weapon * (*)(Weapon*, const char*)>(0x1411570F0_g);
|
||||
return func(result, name);
|
||||
}
|
||||
|
||||
scrContext_t* ScriptContext_Server() {
|
||||
auto func = reinterpret_cast<scrContext_t * (*)()>(0x1412E0E70_g);
|
||||
return func();
|
||||
}
|
||||
|
||||
const char* SL_ConvertToString(int id) {
|
||||
auto func = reinterpret_cast<const char* (*)(int)>(0x14131AA20_g);
|
||||
return func(id);
|
||||
}
|
||||
|
||||
XAssetHeader DB_FindXAssetHeader(XAssetType type, const char* givenName, int allowCreateDefault) {
|
||||
auto func = reinterpret_cast<XAssetHeader(*)(XAssetType, const char*, int)>(0x1411AA890_g);
|
||||
return func(type, givenName, allowCreateDefault);
|
||||
}
|
||||
|
||||
void Com_SetErrorMessage(const char* errorMessage) {
|
||||
auto func = reinterpret_cast<void(*)(const char*)>(0x1412B3710_g);
|
||||
return func(errorMessage);
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
dvar_t* player_name;
|
||||
dvar_t* sv_cheats;
|
||||
dvar_t* spawn_br_gas;
|
||||
dvar_t* show_watermark;
|
||||
dvar_t* player_sustainammo;
|
||||
|
||||
cmd_function_s set_byte_f_VAR;
|
||||
cmd_function_s set_short_f_VAR;
|
||||
cmd_function_s set_int_f_VAR;
|
||||
cmd_function_s set_float_f_VAR;
|
||||
cmd_function_s set_pointer_f_VAR;
|
||||
cmd_function_s quit_f_VAR;
|
||||
cmd_function_s openmenu_f_VAR;
|
||||
cmd_function_s addbot_f_VAR;
|
||||
cmd_function_s ddldump_f_VAR;
|
||||
cmd_function_s weapondefdump_f_VAR;
|
||||
cmd_function_s view_vehicle_ents_f_VAR;
|
||||
cmd_function_s loadout_save_f_VAR;
|
||||
cmd_function_s FastRestart_f_VAR;
|
||||
cmd_function_s MapRestart_f_VAR;
|
||||
cmd_function_s omnvar_set_f_VAR;
|
||||
cmd_function_s omnvar_dump_f_VAR;
|
||||
|
||||
CmdArgs* cmd_args;
|
||||
|
||||
Addresses g_Addrs;
|
@ -1,224 +1,234 @@
|
||||
#pragma once
|
||||
#include "Main.hpp"
|
||||
|
||||
struct gentity_s;
|
||||
|
||||
struct CmdArgs;
|
||||
|
||||
struct Addresses {
|
||||
uintptr_t ModuleBase;
|
||||
uintptr_t jmp_rbx;
|
||||
};
|
||||
|
||||
union DvarValue
|
||||
{
|
||||
bool enabled;
|
||||
int integer;
|
||||
unsigned int unsignedInt;
|
||||
__int64 integer64;
|
||||
unsigned __int64 unsignedInt64;
|
||||
float value;
|
||||
float vector[4];
|
||||
const char* string;
|
||||
unsigned __int8 color[4];
|
||||
};
|
||||
|
||||
struct BbConstUsageFlags
|
||||
{
|
||||
bool initialized;
|
||||
DvarValue codeValue;
|
||||
};
|
||||
|
||||
struct netadr_t;
|
||||
|
||||
struct dvar_t
|
||||
{
|
||||
const char* name;
|
||||
unsigned int checksum;
|
||||
const char* description;
|
||||
unsigned int flags;
|
||||
char level[1];
|
||||
unsigned __int8 type;
|
||||
bool modified;
|
||||
unsigned __int16 hashNext;
|
||||
DvarValue current;
|
||||
DvarValue latched;
|
||||
DvarValue reset;
|
||||
char domain[0x10];
|
||||
BbConstUsageFlags BbConstUsageFlags;
|
||||
};
|
||||
|
||||
struct EncryptionHeader
|
||||
{
|
||||
unsigned int isEncrypted;
|
||||
unsigned __int8 IV[16];
|
||||
};
|
||||
|
||||
struct __declspec(align(8)) XFile
|
||||
{
|
||||
unsigned __int64 size;
|
||||
unsigned __int64 preloadWalkSize;
|
||||
unsigned __int64 blockSize[11];
|
||||
EncryptionHeader encryption;
|
||||
};
|
||||
|
||||
struct DB_FFHeader
|
||||
{
|
||||
unsigned __int64 magic;
|
||||
unsigned int headerVersion;
|
||||
unsigned int xfileVersion;
|
||||
bool dashCompressBuild;
|
||||
bool dashEncryptBuild;
|
||||
unsigned __int8 transientFileType[1];
|
||||
unsigned int residentPartSize;
|
||||
unsigned int residentHash;
|
||||
unsigned int alwaysLoadedPartSize;
|
||||
XFile xfileHeader;
|
||||
};
|
||||
|
||||
struct EncryptionInfo
|
||||
{
|
||||
EncryptionHeader header;
|
||||
unsigned __int8 privateKey[32];
|
||||
};
|
||||
|
||||
struct DBFileHandle
|
||||
{
|
||||
unsigned __int8 fileID[4];
|
||||
unsigned __int64 dcacheFileID;
|
||||
};
|
||||
|
||||
struct cmd_function_s
|
||||
{
|
||||
cmd_function_s* next;
|
||||
const char* name;
|
||||
const char** autoCompleteList;
|
||||
unsigned int autoCompleteListCount;
|
||||
void(__fastcall* function)();
|
||||
};
|
||||
|
||||
struct DBFile
|
||||
{
|
||||
char name[64];
|
||||
DBFileHandle dbFileHandle;
|
||||
bool isSecured;
|
||||
EncryptionInfo encryption;
|
||||
};
|
||||
|
||||
struct Weapon;
|
||||
struct scrContext_t;
|
||||
|
||||
extern dvar_t* player_name;
|
||||
extern dvar_t* sv_cheats;
|
||||
extern dvar_t* spawn_br_gas;
|
||||
extern dvar_t* show_watermark;
|
||||
extern dvar_t* player_sustainammo;
|
||||
|
||||
extern cmd_function_s set_byte_f_VAR;
|
||||
extern cmd_function_s set_short_f_VAR;
|
||||
extern cmd_function_s set_int_f_VAR;
|
||||
extern cmd_function_s set_pointer_f_VAR;
|
||||
extern cmd_function_s quit_f_VAR;
|
||||
extern cmd_function_s openmenu_f_VAR;
|
||||
extern cmd_function_s addbot_f_VAR;
|
||||
extern cmd_function_s ddldump_f_VAR;
|
||||
extern cmd_function_s weapondefdump_f_VAR;
|
||||
extern cmd_function_s view_vehicle_ents_f_VAR;
|
||||
extern cmd_function_s loadout_save_f_VAR;
|
||||
extern cmd_function_s FastRestart_f_VAR;
|
||||
extern CmdArgs* cmd_args;
|
||||
|
||||
void* RtlAddVectoredExceptionHandler(LONG First, PVECTORED_EXCEPTION_HANDLER Handler);
|
||||
NTSTATUS NtContinue(PCONTEXT threadContext, BOOLEAN raiseAlert);
|
||||
|
||||
#pragma region //game functions
|
||||
|
||||
extern const char* (*va)(const char* fmt, ...);
|
||||
|
||||
void Live_FakeUserSignIn(int controllerIndex, const char* gamertag);
|
||||
|
||||
void R_AddCmdDrawText(const char* text, int maxChars, void /* GfxFont */* font, int fontHeight, float x, float y, float xScale, float yScale, float rotation, const float* color, const void /* FontGlowStyle */* glowStyle, bool usePost);
|
||||
|
||||
bool CG_WorldPosToScreenPosReal(int localClientNum, const uintptr_t scrPlace, const float* worldPos, float* outScreenPos);
|
||||
|
||||
void CG_DrawRotatedPicPhysical(uintptr_t scrPlace, float x, float y, float width, float height, float angle, const float* color, uintptr_t material);
|
||||
|
||||
inline bool file_exists(const char* name) {
|
||||
struct stat buffer;
|
||||
return (stat(name, &buffer) == 0);
|
||||
}
|
||||
|
||||
uintptr_t FS_ReadFile(const char* qpath, const char** buffer);
|
||||
const char* Dvar_GetStringSafe(const char* dvar);
|
||||
|
||||
unsigned int* GetRandSeed();
|
||||
unsigned __int64 Sys_Microseconds();
|
||||
int I_irand(int min, int max);
|
||||
unsigned __int64 I_atoui64_hex(const char* str);
|
||||
unsigned __int64 I_atoui64(const char* str);
|
||||
uintptr_t Dvar_FindVarByName(const char* dvarName);
|
||||
|
||||
void CL_DrawText(const uintptr_t scrPlace, const char* text, int maxChars, uintptr_t font, float x, float y, int horzAlign, int vertAlign, float xScale, float yScale, const float* color, int style);
|
||||
dvar_t* Dvar_RegisterString(const char* dvarName, const char* value, unsigned int flags, const char* description);
|
||||
dvar_t* Dvar_RegisterBool(const char* dvarName, bool value, unsigned int flags, const char* description);
|
||||
|
||||
void LUI_CoD_LuaCall_ExecNow(uintptr_t luaVM, const char* str);
|
||||
bool LUI_LuaCall_Game_IsEntityAlive(uintptr_t luaVM, int entityNum);
|
||||
|
||||
void Cbuf_AddText(const char* cmd);
|
||||
|
||||
bool lua_toboolean(uintptr_t L, int idx);
|
||||
|
||||
void lua_pushboolean(uintptr_t L, int b);
|
||||
void lua_remove(uintptr_t L, int idx);
|
||||
void lua_call(uintptr_t L, int nargs, int nresults);
|
||||
void lua_getfield(uintptr_t L, int idx, const char* k);
|
||||
void lua_pushvalue(uintptr_t L, int idx);
|
||||
void lua_pushstring(uintptr_t L, const char* str);
|
||||
void lua_pushinteger(uintptr_t L, int n);
|
||||
void lua_settop(uintptr_t L, int idx);
|
||||
int LuaShared_PCall(uintptr_t luaVM, int nargs, int nresults);
|
||||
|
||||
bool CG_DObjGetWorldBoneMatrix(uintptr_t pose, uintptr_t obj, int boneIndex, uintptr_t outTagMat, float* outOrigin);
|
||||
|
||||
void CG_DrawLine(float X1, float Y1, float X2, float Y2, const float* color, float Width);
|
||||
void CG_DrawBone(int entIndex, uintptr_t ent, int from, int to, const float* color);
|
||||
void CG_DrawBones(int entIndex, uintptr_t ent, const float* color);
|
||||
|
||||
bool CheatsOk(int entNum);
|
||||
|
||||
void Cmd_Noclip_f(int entNum);
|
||||
|
||||
void SV_Cmd_ArgvBuffer(int arg, char* buffer, unsigned __int64 bufferLength);
|
||||
void Cmd_ArgvBuffer(int arg, char* buffer, int bufferLength);
|
||||
int Cmd_Argc();
|
||||
int SV_Cmd_Argc();
|
||||
|
||||
void Cmd_AddCommandInternal(const char* cmdName, void(__fastcall* function)(), cmd_function_s* allocedCmd);
|
||||
|
||||
void AddReliableCommand(uintptr_t _this, const char* commandBuffer, const int reliableCmdSize, int type);
|
||||
unsigned int MSG_WriteReliableCommandToBuffer(const char* pszCommand, char* pszBuffer, unsigned int iBufferSize);
|
||||
|
||||
void CL_Main_AddReliableCommand(const char* cmd);
|
||||
|
||||
bool BG_Weapons_GetFullWeaponForName(const char* name, Weapon* outWeapon, Weapon* (__fastcall* getWeaponFunc)(Weapon* result, const char*));
|
||||
|
||||
void Scr_AddString(scrContext_t* scrContext, const char* value);
|
||||
unsigned int GScr_ExecEntThread(gentity_s* ent, int handle, unsigned int paramcount);
|
||||
void Scr_FreeThread(scrContext_t* scrContext, unsigned int handle);
|
||||
|
||||
int G_Weapon_GivePlayerWeapon(uintptr_t ps, uintptr_t scrContext, Weapon* weapon, int dualWield, int startInAltMode, int usedBefore);
|
||||
void G_Items_AddAmmo(uintptr_t ps, Weapon* weapon, bool isAlternate, int count, int fillClip);
|
||||
|
||||
void G_Weapon_SelectWeapon(int clientNum, Weapon* weapon);
|
||||
Weapon* BG_FindBaseWeaponForName(Weapon* result, const char* name);
|
||||
|
||||
scrContext_t* ScriptContext_Server();
|
||||
|
||||
const char* SL_ConvertToString(int id);
|
||||
|
||||
union XAssetHeader DB_FindXAssetHeader(enum XAssetType type, const char* givenName, int allowCreateDefault);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma once
|
||||
#include "Main.hpp"
|
||||
|
||||
struct gentity_s;
|
||||
|
||||
struct CmdArgs;
|
||||
|
||||
struct Addresses {
|
||||
uintptr_t ModuleBase;
|
||||
uintptr_t jmp_rbx;
|
||||
};
|
||||
|
||||
union DvarValue
|
||||
{
|
||||
bool enabled;
|
||||
int integer;
|
||||
unsigned int unsignedInt;
|
||||
__int64 integer64;
|
||||
unsigned __int64 unsignedInt64;
|
||||
float value;
|
||||
float vector[4];
|
||||
const char* string;
|
||||
unsigned __int8 color[4];
|
||||
};
|
||||
|
||||
struct BbConstUsageFlags
|
||||
{
|
||||
bool initialized;
|
||||
DvarValue codeValue;
|
||||
};
|
||||
|
||||
struct netadr_t;
|
||||
|
||||
struct dvar_t
|
||||
{
|
||||
const char* name;
|
||||
unsigned int checksum;
|
||||
const char* description;
|
||||
unsigned int flags;
|
||||
char level[1];
|
||||
unsigned __int8 type;
|
||||
bool modified;
|
||||
unsigned __int16 hashNext;
|
||||
DvarValue current;
|
||||
DvarValue latched;
|
||||
DvarValue reset;
|
||||
char domain[0x10];
|
||||
BbConstUsageFlags BbConstUsageFlags;
|
||||
};
|
||||
|
||||
struct EncryptionHeader
|
||||
{
|
||||
unsigned int isEncrypted;
|
||||
unsigned __int8 IV[16];
|
||||
};
|
||||
|
||||
struct __declspec(align(8)) XFile
|
||||
{
|
||||
unsigned __int64 size;
|
||||
unsigned __int64 preloadWalkSize;
|
||||
unsigned __int64 blockSize[11];
|
||||
EncryptionHeader encryption;
|
||||
};
|
||||
|
||||
struct DB_FFHeader
|
||||
{
|
||||
unsigned __int64 magic;
|
||||
unsigned int headerVersion;
|
||||
unsigned int xfileVersion;
|
||||
bool dashCompressBuild;
|
||||
bool dashEncryptBuild;
|
||||
unsigned __int8 transientFileType[1];
|
||||
unsigned int residentPartSize;
|
||||
unsigned int residentHash;
|
||||
unsigned int alwaysLoadedPartSize;
|
||||
XFile xfileHeader;
|
||||
};
|
||||
|
||||
struct EncryptionInfo
|
||||
{
|
||||
EncryptionHeader header;
|
||||
unsigned __int8 privateKey[32];
|
||||
};
|
||||
|
||||
struct DBFileHandle
|
||||
{
|
||||
unsigned __int8 fileID[4];
|
||||
unsigned __int64 dcacheFileID;
|
||||
};
|
||||
|
||||
struct cmd_function_s
|
||||
{
|
||||
cmd_function_s* next;
|
||||
const char* name;
|
||||
const char** autoCompleteList;
|
||||
unsigned int autoCompleteListCount;
|
||||
void(__fastcall* function)();
|
||||
};
|
||||
|
||||
struct DBFile
|
||||
{
|
||||
char name[64];
|
||||
DBFileHandle dbFileHandle;
|
||||
bool isSecured;
|
||||
EncryptionInfo encryption;
|
||||
};
|
||||
|
||||
struct Weapon;
|
||||
struct scrContext_t;
|
||||
|
||||
extern dvar_t* player_name;
|
||||
extern dvar_t* sv_cheats;
|
||||
extern dvar_t* spawn_br_gas;
|
||||
extern dvar_t* show_watermark;
|
||||
extern dvar_t* player_sustainammo;
|
||||
|
||||
extern cmd_function_s set_byte_f_VAR;
|
||||
extern cmd_function_s set_short_f_VAR;
|
||||
extern cmd_function_s set_int_f_VAR;
|
||||
extern cmd_function_s set_float_f_VAR;
|
||||
extern cmd_function_s set_pointer_f_VAR;
|
||||
extern cmd_function_s quit_f_VAR;
|
||||
extern cmd_function_s openmenu_f_VAR;
|
||||
extern cmd_function_s addbot_f_VAR;
|
||||
extern cmd_function_s ddldump_f_VAR;
|
||||
extern cmd_function_s weapondefdump_f_VAR;
|
||||
extern cmd_function_s view_vehicle_ents_f_VAR;
|
||||
extern cmd_function_s loadout_save_f_VAR;
|
||||
extern cmd_function_s FastRestart_f_VAR;
|
||||
extern cmd_function_s MapRestart_f_VAR;
|
||||
extern cmd_function_s omnvar_set_f_VAR;
|
||||
extern cmd_function_s omnvar_dump_f_VAR;
|
||||
extern CmdArgs* cmd_args;
|
||||
|
||||
void* RtlAddVectoredExceptionHandler(LONG First, PVECTORED_EXCEPTION_HANDLER Handler);
|
||||
NTSTATUS NtContinue(PCONTEXT threadContext, BOOLEAN raiseAlert);
|
||||
|
||||
#pragma region //game functions
|
||||
|
||||
extern const char* (*va)(const char* fmt, ...);
|
||||
|
||||
void Live_FakeUserSignIn(int controllerIndex, const char* gamertag);
|
||||
|
||||
void R_AddCmdDrawText(const char* text, int maxChars, void /* GfxFont */* font, int fontHeight, float x, float y, float xScale, float yScale, float rotation, const float* color, const void /* FontGlowStyle */* glowStyle, bool usePost);
|
||||
|
||||
bool CG_WorldPosToScreenPosReal(int localClientNum, const uintptr_t scrPlace, const float* worldPos, float* outScreenPos);
|
||||
|
||||
void CG_DrawRotatedPicPhysical(uintptr_t scrPlace, float x, float y, float width, float height, float angle, const float* color, uintptr_t material);
|
||||
|
||||
inline bool file_exists(const char* name) {
|
||||
struct stat buffer;
|
||||
return (stat(name, &buffer) == 0);
|
||||
}
|
||||
|
||||
uintptr_t FS_ReadFile(const char* qpath, const char** buffer);
|
||||
const char* Dvar_GetStringSafe(const char* dvar);
|
||||
bool Dvar_GetBoolSafe(const char* dvar);
|
||||
int Dvar_GetIntSafe(const char* dvar);
|
||||
|
||||
unsigned int* GetRandSeed();
|
||||
unsigned __int64 Sys_Microseconds();
|
||||
int I_irand(int min, int max);
|
||||
unsigned __int64 I_atoui64_hex(const char* str);
|
||||
unsigned __int64 I_atoui64(const char* str);
|
||||
uintptr_t Dvar_FindVarByName(const char* dvarName);
|
||||
|
||||
void CL_DrawText(const uintptr_t scrPlace, const char* text, int maxChars, uintptr_t font, float x, float y, int horzAlign, int vertAlign, float xScale, float yScale, const float* color, int style);
|
||||
dvar_t* Dvar_RegisterString(const char* dvarName, const char* value, unsigned int flags, const char* description);
|
||||
dvar_t* Dvar_RegisterBool(const char* dvarName, bool value, unsigned int flags, const char* description);
|
||||
|
||||
void LUI_CoD_LuaCall_ExecNow(uintptr_t luaVM, const char* str);
|
||||
bool LUI_LuaCall_Game_IsEntityAlive(uintptr_t luaVM, int entityNum);
|
||||
|
||||
void Cbuf_AddText(const char* cmd);
|
||||
|
||||
bool lua_toboolean(uintptr_t L, int idx);
|
||||
|
||||
void lua_pushboolean(uintptr_t L, int b);
|
||||
void lua_remove(uintptr_t L, int idx);
|
||||
void lua_call(uintptr_t L, int nargs, int nresults);
|
||||
void lua_getfield(uintptr_t L, int idx, const char* k);
|
||||
void lua_pushvalue(uintptr_t L, int idx);
|
||||
void lua_pushstring(uintptr_t L, const char* str);
|
||||
void lua_pushinteger(uintptr_t L, int n);
|
||||
void lua_settop(uintptr_t L, int idx);
|
||||
int LuaShared_PCall(uintptr_t luaVM, int nargs, int nresults);
|
||||
|
||||
bool CG_DObjGetWorldBoneMatrix(uintptr_t pose, uintptr_t obj, int boneIndex, uintptr_t outTagMat, float* outOrigin);
|
||||
|
||||
void CG_DrawLine(float X1, float Y1, float X2, float Y2, const float* color, float Width);
|
||||
void CG_DrawBone(int entIndex, uintptr_t ent, int from, int to, const float* color);
|
||||
void CG_DrawBones(int entIndex, uintptr_t ent, const float* color);
|
||||
|
||||
bool CheatsOk(int entNum);
|
||||
|
||||
void Cmd_Noclip_f(int entNum);
|
||||
|
||||
void Cmd_God_f(int entNum);
|
||||
|
||||
void SV_Cmd_ArgvBuffer(int arg, char* buffer, unsigned __int64 bufferLength);
|
||||
void Cmd_ArgvBuffer(int arg, char* buffer, int bufferLength);
|
||||
int Cmd_Argc();
|
||||
int SV_Cmd_Argc();
|
||||
|
||||
void Cmd_AddCommandInternal(const char* cmdName, void(__fastcall* function)(), cmd_function_s* allocedCmd);
|
||||
|
||||
void AddReliableCommand(uintptr_t _this, const char* commandBuffer, const int reliableCmdSize, int type);
|
||||
unsigned int MSG_WriteReliableCommandToBuffer(const char* pszCommand, char* pszBuffer, unsigned int iBufferSize);
|
||||
|
||||
void CL_Main_AddReliableCommand(const char* cmd);
|
||||
|
||||
bool BG_Weapons_GetFullWeaponForName(const char* name, Weapon* outWeapon, Weapon* (__fastcall* getWeaponFunc)(Weapon* result, const char*));
|
||||
|
||||
void Scr_AddString(scrContext_t* scrContext, const char* value);
|
||||
unsigned int GScr_ExecEntThread(gentity_s* ent, int handle, unsigned int paramcount);
|
||||
void Scr_FreeThread(scrContext_t* scrContext, unsigned int handle);
|
||||
|
||||
int G_Weapon_GivePlayerWeapon(uintptr_t ps, uintptr_t scrContext, Weapon* weapon, int dualWield, int startInAltMode, int usedBefore);
|
||||
void G_Items_AddAmmo(uintptr_t ps, Weapon* weapon, bool isAlternate, int count, int fillClip);
|
||||
|
||||
void G_Weapon_SelectWeapon(int clientNum, Weapon* weapon);
|
||||
Weapon* BG_FindBaseWeaponForName(Weapon* result, const char* name);
|
||||
|
||||
scrContext_t* ScriptContext_Server();
|
||||
|
||||
const char* SL_ConvertToString(int id);
|
||||
|
||||
union XAssetHeader DB_FindXAssetHeader(enum XAssetType type, const char* givenName, int allowCreateDefault);
|
||||
|
||||
void Com_SetErrorMessage(const char* errorMessage);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
extern Addresses g_Addrs;
|
@ -48,7 +48,7 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<UseOfMfc>false</UseOfMfc>
|
||||
@ -81,10 +81,12 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<TargetName>discord_game_sdk</TargetName>
|
||||
<LibraryPath>D:\Dokumente\CoDMW19\codUPLOADER\mw19-of-main\lib;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<TargetName>discord_game_sdk</TargetName>
|
||||
<LibraryPath>D:\Dokumente\CoDMW19\codUPLOADER\mw19-of-main\lib;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
@ -136,13 +138,13 @@
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NOMINMAX;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
||||
<AdditionalDependencies>minhook.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
@ -181,7 +183,6 @@
|
||||
<ClInclude Include="common\utils\smbios.hpp" />
|
||||
<ClInclude Include="common\utils\string.hpp" />
|
||||
<ClInclude Include="common\utils\thread.hpp" />
|
||||
<ClInclude Include="csv.hpp" />
|
||||
<ClInclude Include="functions.hpp" />
|
||||
<ClInclude Include="ini.h" />
|
||||
<ClInclude Include="json.hpp" />
|
||||
|
@ -1,143 +1,142 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="common">
|
||||
<UniqueIdentifier>{9ba1aab7-3c29-4043-88a2-0733bdba52af}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="common\exception">
|
||||
<UniqueIdentifier>{67571f10-529c-4ebd-94b6-2cebbbb62a35}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="common\utils">
|
||||
<UniqueIdentifier>{03fd645c-a59f-4d26-950c-b411df71f725}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="hook_lib">
|
||||
<UniqueIdentifier>{997a4fac-6cde-43a6-84df-2e0e58b4b7fc}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="hook_lib\game">
|
||||
<UniqueIdentifier>{0999b80b-b47c-4d8e-8776-f5c778bcac9f}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="common\utils\binary_resource.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\hardware_breakpoint.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\hook.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\http.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\io.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\memory.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\nt.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\signature.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\smbios.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\string.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\exception\minidump.cpp">
|
||||
<Filter>common\exception</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Main.cpp">
|
||||
<Filter>hook_lib</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="functions.cpp">
|
||||
<Filter>hook_lib\game</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\thread.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="structs.cpp">
|
||||
<Filter>hook_lib\game</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="assets.cpp">
|
||||
<Filter>hook_lib\game</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="splashscreen.cpp">
|
||||
<Filter>hook_lib\game</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="common\utils\binary_resource.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\concurrency.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\finally.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\hardware_breakpoint.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\hook.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\http.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\io.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\memory.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\nt.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\signature.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\smbios.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\string.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\exception\minidump.hpp">
|
||||
<Filter>common\exception</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Main.hpp">
|
||||
<Filter>hook_lib</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MinHook.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="functions.hpp">
|
||||
<Filter>hook_lib\game</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\thread.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="structs.h">
|
||||
<Filter>hook_lib\game</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="assets.h">
|
||||
<Filter>hook_lib\game</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ini.h">
|
||||
<Filter>hook_lib\game</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="json.hpp">
|
||||
<Filter>hook_lib\game</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="csv.hpp" />
|
||||
</ItemGroup>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="common">
|
||||
<UniqueIdentifier>{9ba1aab7-3c29-4043-88a2-0733bdba52af}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="common\exception">
|
||||
<UniqueIdentifier>{67571f10-529c-4ebd-94b6-2cebbbb62a35}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="common\utils">
|
||||
<UniqueIdentifier>{03fd645c-a59f-4d26-950c-b411df71f725}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="hook_lib">
|
||||
<UniqueIdentifier>{997a4fac-6cde-43a6-84df-2e0e58b4b7fc}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="hook_lib\game">
|
||||
<UniqueIdentifier>{0999b80b-b47c-4d8e-8776-f5c778bcac9f}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="common\utils\binary_resource.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\hardware_breakpoint.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\hook.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\http.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\io.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\memory.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\nt.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\signature.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\smbios.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\string.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\exception\minidump.cpp">
|
||||
<Filter>common\exception</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Main.cpp">
|
||||
<Filter>hook_lib</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="functions.cpp">
|
||||
<Filter>hook_lib\game</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common\utils\thread.cpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="structs.cpp">
|
||||
<Filter>hook_lib\game</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="assets.cpp">
|
||||
<Filter>hook_lib\game</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="splashscreen.cpp">
|
||||
<Filter>hook_lib\game</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="common\utils\binary_resource.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\concurrency.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\finally.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\hardware_breakpoint.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\hook.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\http.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\io.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\memory.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\nt.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\signature.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\smbios.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\string.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\exception\minidump.hpp">
|
||||
<Filter>common\exception</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Main.hpp">
|
||||
<Filter>hook_lib</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MinHook.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="functions.hpp">
|
||||
<Filter>hook_lib\game</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\utils\thread.hpp">
|
||||
<Filter>common\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="structs.h">
|
||||
<Filter>hook_lib\game</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="assets.h">
|
||||
<Filter>hook_lib\game</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ini.h">
|
||||
<Filter>hook_lib\game</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="json.hpp">
|
||||
<Filter>hook_lib\game</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -1,15 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ShowAllFiles>true</ShowAllFiles>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LocalDebuggerCommand>D:\Games\CODMWDebug\Call of Duty Modern Warfare %282019%29\game_dx12_ship_replay.exe</LocalDebuggerCommand>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LocalDebuggerCommand>D:\Games\CODMWDebug\Call of Duty Modern Warfare %282019%29\game_dx12_ship_replay.exe</LocalDebuggerCommand>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
<LocalDebuggerWorkingDirectory>..\..\..\..\Games\CODMWDebug\Call of Duty Modern Warfare %282019%29</LocalDebuggerWorkingDirectory>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup />
|
||||
</Project>
|
1576
hook_lib/ini.h
1576
hook_lib/ini.h
File diff suppressed because it is too large
Load Diff
49344
hook_lib/json.hpp
49344
hook_lib/json.hpp
File diff suppressed because it is too large
Load Diff
@ -1 +1 @@
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,15 +1,15 @@
|
||||
#pragma once
|
||||
#include "Main.hpp"
|
||||
typedef unsigned char byte;
|
||||
|
||||
size_t operator"" _b(size_t val);
|
||||
size_t reverse_b(size_t val);
|
||||
size_t reverse_b(const void* val);
|
||||
|
||||
size_t operator"" _g(size_t val);
|
||||
size_t reverse_g(size_t val);
|
||||
size_t reverse_g(const void* val);
|
||||
|
||||
extern byte data_buf[0x12856B];
|
||||
|
||||
void set_splashscreen();
|
||||
#pragma once
|
||||
#include "Main.hpp"
|
||||
typedef unsigned char byte;
|
||||
|
||||
size_t operator"" _b(size_t val);
|
||||
size_t reverse_b(size_t val);
|
||||
size_t reverse_b(const void* val);
|
||||
|
||||
size_t operator"" _g(size_t val);
|
||||
size_t reverse_g(size_t val);
|
||||
size_t reverse_g(const void* val);
|
||||
|
||||
extern byte data_buf[1];
|
||||
|
||||
void set_splashscreen();
|
||||
|
@ -1,116 +1,116 @@
|
||||
#include "structs.h"
|
||||
|
||||
|
||||
|
||||
#pragma region //msg_t
|
||||
|
||||
unsigned __int64 MSG_ReadInt64(const msg_t* msg) {
|
||||
auto func = reinterpret_cast<unsigned __int64(*)(const msg_t*)>(0x1412B9270_g);
|
||||
return func(msg);
|
||||
}
|
||||
|
||||
void MSG_WriteInt64(const msg_t* msg, const unsigned __int64 value) {
|
||||
auto func = reinterpret_cast<void(*)(const msg_t*, const unsigned __int64)>(0x1412BA7F0_g);
|
||||
func(msg, value);
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
|
||||
#pragma region //XUID
|
||||
|
||||
void XUID::Deserialize(const msg_t* msg) {
|
||||
this->m_id = MSG_ReadInt64(msg);
|
||||
}
|
||||
|
||||
void XUID::Serialize(const msg_t* msg) {
|
||||
MSG_WriteInt64(msg, this->m_id);
|
||||
}
|
||||
|
||||
XUID* XUID::FromHexString(const char* xuidString) {
|
||||
this->m_id = I_atoui64_hex(xuidString);
|
||||
return this;
|
||||
}
|
||||
|
||||
XUID* XUID::FromMsg(const msg_t* msg) {
|
||||
this->m_id = MSG_ReadInt64(msg);
|
||||
return this;
|
||||
}
|
||||
|
||||
XUID* XUID::FromString(const char* xuidString) {
|
||||
this->m_id = I_atoui64(xuidString);
|
||||
return this;
|
||||
}
|
||||
|
||||
XUID* XUID::FromUInt64(unsigned __int64 id) {
|
||||
this->m_id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
XUID* XUID::FromUniversalId(unsigned __int64 id) {
|
||||
this->m_id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
unsigned __int64 XUID::GetUniversalId() {
|
||||
return this->m_id;
|
||||
}
|
||||
|
||||
bool XUID::IsNull() {
|
||||
return this->m_id == 0;
|
||||
}
|
||||
|
||||
bool XUID::IsValid() {
|
||||
return this->m_id != 0;
|
||||
}
|
||||
|
||||
XUID* XUID::NullXUID() {
|
||||
this->m_id = 0;
|
||||
return this;
|
||||
}
|
||||
|
||||
XUID* XUID::RandomXUID() {
|
||||
unsigned int* RandSeed;
|
||||
unsigned int BackupRandSeed;
|
||||
this->m_id = 0;
|
||||
RandSeed = GetRandSeed();
|
||||
BackupRandSeed = *RandSeed;
|
||||
*RandSeed = Sys_Microseconds();
|
||||
this->m_id = I_irand(1, 0x7FFFFFFF);
|
||||
*RandSeed = BackupRandSeed;
|
||||
return this;
|
||||
}
|
||||
|
||||
const char* XUID::ToDevString() {
|
||||
return va("%zu", this->m_id);
|
||||
}
|
||||
|
||||
const char* XUID::ToHexString() {
|
||||
return va("%zx", this->m_id);
|
||||
}
|
||||
|
||||
const char* XUID::ToString() {
|
||||
return va("%zu", this->m_id);
|
||||
}
|
||||
|
||||
bool XUID::operator !=(const XUID* xuid) {
|
||||
return this->m_id != xuid->m_id;
|
||||
}
|
||||
|
||||
XUID* XUID::operator =(const XUID* xuid) {
|
||||
this->m_id = xuid->m_id;
|
||||
return this;
|
||||
}
|
||||
|
||||
bool XUID::operator ==(const XUID* xuid) {
|
||||
return this->m_id == xuid->m_id;
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
|
||||
ClActiveClient* ms_activeClients;
|
||||
|
||||
clientUIActive_t* clientUIActives;
|
||||
|
||||
gentity_s* g_entities;
|
||||
#include "structs.h"
|
||||
|
||||
|
||||
|
||||
#pragma region //msg_t
|
||||
|
||||
unsigned __int64 MSG_ReadInt64(const msg_t* msg) {
|
||||
auto func = reinterpret_cast<unsigned __int64(*)(const msg_t*)>(0x1412B9270_g);
|
||||
return func(msg);
|
||||
}
|
||||
|
||||
void MSG_WriteInt64(const msg_t* msg, const unsigned __int64 value) {
|
||||
auto func = reinterpret_cast<void(*)(const msg_t*, const unsigned __int64)>(0x1412BA7F0_g);
|
||||
func(msg, value);
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
|
||||
#pragma region //XUID
|
||||
|
||||
void XUID::Deserialize(const msg_t* msg) {
|
||||
this->m_id = MSG_ReadInt64(msg);
|
||||
}
|
||||
|
||||
void XUID::Serialize(const msg_t* msg) {
|
||||
MSG_WriteInt64(msg, this->m_id);
|
||||
}
|
||||
|
||||
XUID* XUID::FromHexString(const char* xuidString) {
|
||||
this->m_id = I_atoui64_hex(xuidString);
|
||||
return this;
|
||||
}
|
||||
|
||||
XUID* XUID::FromMsg(const msg_t* msg) {
|
||||
this->m_id = MSG_ReadInt64(msg);
|
||||
return this;
|
||||
}
|
||||
|
||||
XUID* XUID::FromString(const char* xuidString) {
|
||||
this->m_id = I_atoui64(xuidString);
|
||||
return this;
|
||||
}
|
||||
|
||||
XUID* XUID::FromUInt64(unsigned __int64 id) {
|
||||
this->m_id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
XUID* XUID::FromUniversalId(unsigned __int64 id) {
|
||||
this->m_id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
unsigned __int64 XUID::GetUniversalId() {
|
||||
return this->m_id;
|
||||
}
|
||||
|
||||
bool XUID::IsNull() {
|
||||
return this->m_id == 0;
|
||||
}
|
||||
|
||||
bool XUID::IsValid() {
|
||||
return this->m_id != 0;
|
||||
}
|
||||
|
||||
XUID* XUID::NullXUID() {
|
||||
this->m_id = 0;
|
||||
return this;
|
||||
}
|
||||
|
||||
XUID* XUID::RandomXUID() {
|
||||
unsigned int* RandSeed;
|
||||
unsigned int BackupRandSeed;
|
||||
this->m_id = 0;
|
||||
RandSeed = GetRandSeed();
|
||||
BackupRandSeed = *RandSeed;
|
||||
*RandSeed = Sys_Microseconds();
|
||||
this->m_id = I_irand(1, 0x7FFFFFFF);
|
||||
*RandSeed = BackupRandSeed;
|
||||
return this;
|
||||
}
|
||||
|
||||
const char* XUID::ToDevString() {
|
||||
return va("%zu", this->m_id);
|
||||
}
|
||||
|
||||
const char* XUID::ToHexString() {
|
||||
return va("%zx", this->m_id);
|
||||
}
|
||||
|
||||
const char* XUID::ToString() {
|
||||
return va("%zu", this->m_id);
|
||||
}
|
||||
|
||||
bool XUID::operator !=(const XUID* xuid) {
|
||||
return this->m_id != xuid->m_id;
|
||||
}
|
||||
|
||||
XUID* XUID::operator =(const XUID* xuid) {
|
||||
this->m_id = xuid->m_id;
|
||||
return this;
|
||||
}
|
||||
|
||||
bool XUID::operator ==(const XUID* xuid) {
|
||||
return this->m_id == xuid->m_id;
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
|
||||
ClActiveClient* ms_activeClients;
|
||||
|
||||
clientUIActive_t* clientUIActives;
|
||||
|
||||
gentity_s* g_entities;
|
||||
|
4166
hook_lib/structs.h
4166
hook_lib/structs.h
File diff suppressed because it is too large
Load Diff
BIN
lib/minhook.lib
Normal file
BIN
lib/minhook.lib
Normal file
Binary file not shown.
BIN
lib/minhook_old.lib
Normal file
BIN
lib/minhook_old.lib
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user