├── .gitignore ├── .gitmodules ├── LICENSE ├── README.md ├── package ├── cleanercs2.vdf └── config.cfg ├── src ├── cleanercs2.cpp ├── cleanercs2.h ├── network_connection.pb.h └── utils │ ├── module.h │ ├── plat.h │ ├── plat_unix.cpp │ └── plat_win.cpp ├── vendor └── funchook │ ├── LICENSE │ ├── README.md │ ├── include │ └── funchook.h │ └── lib │ ├── Debug │ ├── distorm.lib │ ├── distorm.pdb │ ├── funchook.lib │ ├── funchook.pdb │ ├── libdistorm.a │ └── libfunchook.a │ └── Release │ ├── distorm.lib │ ├── funchook.lib │ ├── libdistorm.a │ └── libfunchook.a └── xmake.lua /.gitignore: -------------------------------------------------------------------------------- 1 | # Xmake cache 2 | .xmake/ 3 | build/ 4 | 5 | # MacOS Cache 6 | .DS_Store 7 | 8 | /.vs/ 9 | /vsxmake2022/ -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "hl2sdk-manifests"] 2 | path = hl2sdk-manifests 3 | url = https://github.com/alliedmodders/hl2sdk-manifests 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CleanerCS2 2 | 3 | A simple Metamod plugin that allows you to filter out console prints with regular expressions. 4 | Supports both Windows and Linux. 5 | 6 | ## Example config 7 | 8 | ``` 9 | // Write regular expression in here to prevent them from being printed in the console 10 | .*UNEXPECTED LONG FRAME DETECTED.* 11 | .*weapon services didn't find a shoot position.* 12 | .*generating substitute command \d+ from \d+.* 13 | ``` 14 | 15 | ## Installation 16 | 17 | 1. Download the latest release from the [releases page](https://github.com/Source2ZE/CleanerCS2/releases/) 18 | 2. Extract the contents of the archive to your server's `addons` directory 19 | 3. Edit the `addons/cleanercs2/config.cfg` file to your liking (see the example config above) 20 | 21 | ## Commands 22 | 23 | - `conclear_reload` - Reloads the configuration file 24 | 25 | ## Building from source 26 | 27 | [Xmake](https://xmake.io/#/getting_started) is used to build the project. 28 | 29 | 1. Clone the repository and its submodules 30 | 2. Run xmake in the root directory of the repository -------------------------------------------------------------------------------- /package/cleanercs2.vdf: -------------------------------------------------------------------------------- 1 | "Metamod Plugin" 2 | { 3 | "alias" "cleanercs2" 4 | "file" "addons\cleanercs2\cleanercs2" 5 | } 6 | -------------------------------------------------------------------------------- /package/config.cfg: -------------------------------------------------------------------------------- 1 | // Write regular expression in here to prevent them from being printed in the console -------------------------------------------------------------------------------- /src/cleanercs2.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ============================================================================= 3 | * CleanerCS2 4 | * Copyright (C) 2024 Poggu 5 | * ============================================================================= 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU General Public License, version 3.0, as published by the 9 | * Free Software Foundation. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | * details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include "cleanercs2.h" 22 | #include 23 | #include 24 | #include "utils/module.h" 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | // bruh 31 | #undef POSIX 32 | #include 33 | 34 | #ifdef _WIN32 35 | #define ROOTBIN "/bin/win64/" 36 | #define GAMEBIN "/csgo/bin/win64/" 37 | #else 38 | #define ROOTBIN "/bin/linuxsteamrt64/" 39 | #define GAMEBIN "/csgo/bin/linuxsteamrt64/" 40 | #endif 41 | 42 | CleanerPlugin g_CleanerPlugin; 43 | IServerGameDLL *server = NULL; 44 | IServerGameClients *gameclients = NULL; 45 | IVEngineServer *engine = NULL; 46 | IGameEventManager2 *gameevents = NULL; 47 | ICvar *icvar = NULL; 48 | 49 | typedef int (*LogDirect_t)(void* loggingSystem, int channel, int severity, LeafCodeInfo_t*, LoggingMetaData_t*, Color, char const*, va_list*); 50 | LogDirect_t g_pLogDirect = nullptr; 51 | funchook_t* g_pHook = nullptr; 52 | 53 | std::vector g_RegexList; 54 | 55 | int Detour_LogDirect(void* loggingSystem, int channel, int severity, LeafCodeInfo_t* leafCode, LoggingMetaData_t* metaData, Color color, char const* str, va_list* args) 56 | { 57 | char buffer[MAX_LOGGING_MESSAGE_LENGTH]; 58 | 59 | if (args) 60 | { 61 | va_list args2; 62 | va_copy(args2, *args); 63 | V_vsnprintf(buffer, sizeof buffer, str, args2); 64 | va_end(args2); 65 | } 66 | 67 | for (auto& regex : g_RegexList) 68 | { 69 | if (RE2::FullMatch(args ? buffer : str, *regex)) 70 | return 0; 71 | } 72 | 73 | return g_pLogDirect(loggingSystem, channel, severity, leafCode, metaData, color, str, args); 74 | } 75 | 76 | bool SetupHook() 77 | { 78 | auto serverModule = new CModule(ROOTBIN, "tier0"); 79 | 80 | int err; 81 | #ifdef WIN32 82 | const byte sig[] = "\x4C\x89\x4C\x24\x20\x44\x89\x44\x24\x18\x89\x54\x24\x10\x55"; 83 | #else 84 | const byte sig[] = "\x55\x89\xD0\x48\x89\xE5\x41\x57\x41\x56\x41\x55"; 85 | #endif 86 | g_pLogDirect = (LogDirect_t)serverModule->FindSignature((byte*)sig, sizeof(sig) - 1, err); 87 | 88 | if (err) 89 | { 90 | META_CONPRINTF("[CleanerCS2] Failed to find signature: %i\n", err); 91 | return false; 92 | } 93 | 94 | auto g_pHook = funchook_create(); 95 | funchook_prepare(g_pHook, (void**)&g_pLogDirect, (void*)Detour_LogDirect); 96 | funchook_install(g_pHook, 0); 97 | 98 | return true; 99 | } 100 | 101 | void LoadConfig() 102 | { 103 | for(auto& regex : g_RegexList) 104 | delete regex; 105 | 106 | g_RegexList.clear(); 107 | 108 | CBufferStringGrowable gameDir; 109 | engine->GetGameDir(gameDir); 110 | 111 | std::filesystem::path cfgPath = gameDir.Get(); 112 | cfgPath /= "addons/cleanercs2/config.cfg"; 113 | 114 | if (!std::filesystem::exists(cfgPath)) 115 | { 116 | std::ofstream cfgFile(cfgPath); 117 | cfgFile.close(); 118 | } 119 | 120 | std::ifstream cfgFile(cfgPath); 121 | 122 | if (cfgFile.is_open()) 123 | { 124 | std::string line; 125 | while (std::getline(cfgFile, line)) 126 | { 127 | if (line[0] == '/' && line[1] == '/') 128 | continue; 129 | 130 | if (line.empty()) 131 | continue; 132 | 133 | // allow CRLF on linux 134 | line.erase(std::remove(line.begin(), line.end(), '\r'), line.end()); 135 | 136 | META_CONPRINTF("Registering regex: %s\n", line.c_str()); 137 | 138 | RE2::Options options; 139 | options.set_dot_nl(true); 140 | 141 | RE2* re = new RE2(line, options); 142 | 143 | if (re->ok()) 144 | g_RegexList.push_back(re); 145 | else 146 | META_CONPRINTF("[CleanerCS2] Failed to parse regex: '%s': %s\n", line.c_str(), re->error().c_str()); 147 | } 148 | cfgFile.close(); 149 | } 150 | else 151 | { 152 | META_CONPRINTF("[CleanerCS2] Failed to open config file\n"); 153 | } 154 | } 155 | 156 | CON_COMMAND_F(conclear_reload, "Reloads the cleaner config", FCVAR_SPONLY | FCVAR_LINKED_CONCOMMAND) 157 | { 158 | LoadConfig(); 159 | } 160 | 161 | PLUGIN_EXPOSE(CleanerPlugin, g_CleanerPlugin); 162 | bool CleanerPlugin::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late) 163 | { 164 | PLUGIN_SAVEVARS(); 165 | 166 | GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); 167 | GET_V_IFACE_CURRENT(GetEngineFactory, icvar, ICvar, CVAR_INTERFACE_VERSION); 168 | GET_V_IFACE_ANY(GetServerFactory, server, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); 169 | GET_V_IFACE_ANY(GetServerFactory, gameclients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS); 170 | GET_V_IFACE_ANY(GetEngineFactory, g_pNetworkServerService, INetworkServerService, NETWORKSERVERSERVICE_INTERFACE_VERSION); 171 | 172 | g_SMAPI->AddListener( this, this ); 173 | 174 | g_pCVar = icvar; 175 | ConVar_Register( FCVAR_RELEASE | FCVAR_CLIENT_CAN_EXECUTE | FCVAR_GAMEDLL ); 176 | 177 | LoadConfig(); 178 | 179 | if (!SetupHook()) 180 | { 181 | META_CONPRINTF("[CleanerCS2] Failed to setup hook\n"); 182 | return false; 183 | } 184 | 185 | return true; 186 | } 187 | 188 | bool CleanerPlugin::Unload(char *error, size_t maxlen) 189 | { 190 | for (auto& regex : g_RegexList) 191 | delete regex; 192 | 193 | g_RegexList.clear(); 194 | 195 | if (g_pHook) 196 | { 197 | funchook_uninstall(g_pHook, 0); 198 | funchook_destroy(g_pHook); 199 | g_pHook = nullptr; 200 | } 201 | 202 | return true; 203 | } 204 | 205 | void CleanerPlugin::AllPluginsLoaded() 206 | { 207 | } 208 | 209 | void CleanerPlugin::OnLevelInit( char const *pMapName, 210 | char const *pMapEntities, 211 | char const *pOldLevel, 212 | char const *pLandmarkName, 213 | bool loadGame, 214 | bool background ) 215 | { 216 | META_CONPRINTF("OnLevelInit(%s)\n", pMapName); 217 | } 218 | 219 | void CleanerPlugin::OnLevelShutdown() 220 | { 221 | META_CONPRINTF("OnLevelShutdown()\n"); 222 | } 223 | 224 | bool CleanerPlugin::Pause(char *error, size_t maxlen) 225 | { 226 | return true; 227 | } 228 | 229 | bool CleanerPlugin::Unpause(char *error, size_t maxlen) 230 | { 231 | return true; 232 | } 233 | 234 | const char *CleanerPlugin::GetLicense() 235 | { 236 | return "GPLv3"; 237 | } 238 | 239 | const char *CleanerPlugin::GetVersion() 240 | { 241 | return "1.0.3"; 242 | } 243 | 244 | const char *CleanerPlugin::GetDate() 245 | { 246 | return __DATE__; 247 | } 248 | 249 | const char *CleanerPlugin::GetLogTag() 250 | { 251 | return "CLEANER"; 252 | } 253 | 254 | const char *CleanerPlugin::GetAuthor() 255 | { 256 | return "Poggu"; 257 | } 258 | 259 | const char *CleanerPlugin::GetDescription() 260 | { 261 | return "Console regex filter"; 262 | } 263 | 264 | const char *CleanerPlugin::GetName() 265 | { 266 | return "CleanerCS2"; 267 | } 268 | 269 | const char *CleanerPlugin::GetURL() 270 | { 271 | return "https://poggu.me"; 272 | } 273 | -------------------------------------------------------------------------------- /src/cleanercs2.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ============================================================================= 3 | * CleanerCS2 4 | * Copyright (C) 2024 Poggu 5 | * ============================================================================= 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU General Public License, version 3.0, as published by the 9 | * Free Software Foundation. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | * details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * this program. If not, see . 18 | */ 19 | 20 | #ifndef _INCLUDE_METAMOD_SOURCE_STUB_PLUGIN_H_ 21 | #define _INCLUDE_METAMOD_SOURCE_STUB_PLUGIN_H_ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | class CleanerPlugin : public ISmmPlugin, public IMetamodListener 28 | { 29 | public: 30 | bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late); 31 | bool Unload(char *error, size_t maxlen); 32 | bool Pause(char *error, size_t maxlen); 33 | bool Unpause(char *error, size_t maxlen); 34 | void AllPluginsLoaded(); 35 | public: //hooks 36 | void OnLevelInit( char const *pMapName, 37 | char const *pMapEntities, 38 | char const *pOldLevel, 39 | char const *pLandmarkName, 40 | bool loadGame, 41 | bool background ); 42 | void OnLevelShutdown(); 43 | public: 44 | const char *GetAuthor(); 45 | const char *GetName(); 46 | const char *GetDescription(); 47 | const char *GetURL(); 48 | const char *GetLicense(); 49 | const char *GetVersion(); 50 | const char *GetDate(); 51 | const char *GetLogTag(); 52 | }; 53 | 54 | extern CleanerPlugin g_CleanerPlugin; 55 | 56 | PLUGIN_GLOBALVARS(); 57 | 58 | #endif //_INCLUDE_METAMOD_SOURCE_STUB_PLUGIN_H_ 59 | -------------------------------------------------------------------------------- /src/network_connection.pb.h: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: network_connection.proto 3 | 4 | #ifndef GOOGLE_PROTOBUF_INCLUDED_network_5fconnection_2eproto 5 | #define GOOGLE_PROTOBUF_INCLUDED_network_5fconnection_2eproto 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #if PROTOBUF_VERSION < 3021000 12 | #error This file was generated by a newer version of protoc which is 13 | #error incompatible with your Protocol Buffer headers. Please update 14 | #error your headers. 15 | #endif 16 | #if 3021008 < PROTOBUF_MIN_PROTOC_VERSION 17 | #error This file was generated by an older version of protoc which is 18 | #error incompatible with your Protocol Buffer headers. Please 19 | #error regenerate this file with a newer version of protoc. 20 | #endif 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include // IWYU pragma: export 30 | #include // IWYU pragma: export 31 | #include 32 | #include 33 | // @@protoc_insertion_point(includes) 34 | #include 35 | #define PROTOBUF_INTERNAL_EXPORT_network_5fconnection_2eproto 36 | PROTOBUF_NAMESPACE_OPEN 37 | namespace internal { 38 | class AnyMetadata; 39 | } // namespace internal 40 | PROTOBUF_NAMESPACE_CLOSE 41 | 42 | // Internal implementation detail -- do not use these members. 43 | struct TableStruct_network_5fconnection_2eproto { 44 | static const uint32_t offsets[]; 45 | }; 46 | extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_network_5fconnection_2eproto; 47 | PROTOBUF_NAMESPACE_OPEN 48 | PROTOBUF_NAMESPACE_CLOSE 49 | 50 | enum ENetworkDisconnectionReason : int { 51 | NETWORK_DISCONNECT_INVALID = 0, 52 | NETWORK_DISCONNECT_SHUTDOWN = 1, 53 | NETWORK_DISCONNECT_DISCONNECT_BY_USER = 2, 54 | NETWORK_DISCONNECT_DISCONNECT_BY_SERVER = 3, 55 | NETWORK_DISCONNECT_LOST = 4, 56 | NETWORK_DISCONNECT_OVERFLOW = 5, 57 | NETWORK_DISCONNECT_STEAM_BANNED = 6, 58 | NETWORK_DISCONNECT_STEAM_INUSE = 7, 59 | NETWORK_DISCONNECT_STEAM_TICKET = 8, 60 | NETWORK_DISCONNECT_STEAM_LOGON = 9, 61 | NETWORK_DISCONNECT_STEAM_AUTHCANCELLED = 10, 62 | NETWORK_DISCONNECT_STEAM_AUTHALREADYUSED = 11, 63 | NETWORK_DISCONNECT_STEAM_AUTHINVALID = 12, 64 | NETWORK_DISCONNECT_STEAM_VACBANSTATE = 13, 65 | NETWORK_DISCONNECT_STEAM_LOGGED_IN_ELSEWHERE = 14, 66 | NETWORK_DISCONNECT_STEAM_VAC_CHECK_TIMEDOUT = 15, 67 | NETWORK_DISCONNECT_STEAM_DROPPED = 16, 68 | NETWORK_DISCONNECT_STEAM_OWNERSHIP = 17, 69 | NETWORK_DISCONNECT_SERVERINFO_OVERFLOW = 18, 70 | NETWORK_DISCONNECT_TICKMSG_OVERFLOW = 19, 71 | NETWORK_DISCONNECT_STRINGTABLEMSG_OVERFLOW = 20, 72 | NETWORK_DISCONNECT_DELTAENTMSG_OVERFLOW = 21, 73 | NETWORK_DISCONNECT_TEMPENTMSG_OVERFLOW = 22, 74 | NETWORK_DISCONNECT_SOUNDSMSG_OVERFLOW = 23, 75 | NETWORK_DISCONNECT_SNAPSHOTOVERFLOW = 24, 76 | NETWORK_DISCONNECT_SNAPSHOTERROR = 25, 77 | NETWORK_DISCONNECT_RELIABLEOVERFLOW = 26, 78 | NETWORK_DISCONNECT_BADDELTATICK = 27, 79 | NETWORK_DISCONNECT_NOMORESPLITS = 28, 80 | NETWORK_DISCONNECT_TIMEDOUT = 29, 81 | NETWORK_DISCONNECT_DISCONNECTED = 30, 82 | NETWORK_DISCONNECT_LEAVINGSPLIT = 31, 83 | NETWORK_DISCONNECT_DIFFERENTCLASSTABLES = 32, 84 | NETWORK_DISCONNECT_BADRELAYPASSWORD = 33, 85 | NETWORK_DISCONNECT_BADSPECTATORPASSWORD = 34, 86 | NETWORK_DISCONNECT_HLTVRESTRICTED = 35, 87 | NETWORK_DISCONNECT_NOSPECTATORS = 36, 88 | NETWORK_DISCONNECT_HLTVUNAVAILABLE = 37, 89 | NETWORK_DISCONNECT_HLTVSTOP = 38, 90 | NETWORK_DISCONNECT_KICKED = 39, 91 | NETWORK_DISCONNECT_BANADDED = 40, 92 | NETWORK_DISCONNECT_KICKBANADDED = 41, 93 | NETWORK_DISCONNECT_HLTVDIRECT = 42, 94 | NETWORK_DISCONNECT_PURESERVER_CLIENTEXTRA = 43, 95 | NETWORK_DISCONNECT_PURESERVER_MISMATCH = 44, 96 | NETWORK_DISCONNECT_USERCMD = 45, 97 | NETWORK_DISCONNECT_REJECTED_BY_GAME = 46, 98 | NETWORK_DISCONNECT_MESSAGE_PARSE_ERROR = 47, 99 | NETWORK_DISCONNECT_INVALID_MESSAGE_ERROR = 48, 100 | NETWORK_DISCONNECT_BAD_SERVER_PASSWORD = 49, 101 | NETWORK_DISCONNECT_DIRECT_CONNECT_RESERVATION = 50, 102 | NETWORK_DISCONNECT_CONNECTION_FAILURE = 51, 103 | NETWORK_DISCONNECT_NO_PEER_GROUP_HANDLERS = 52, 104 | NETWORK_DISCONNECT_RECONNECTION = 53, 105 | NETWORK_DISCONNECT_LOOPSHUTDOWN = 54, 106 | NETWORK_DISCONNECT_LOOPDEACTIVATE = 55, 107 | NETWORK_DISCONNECT_HOST_ENDGAME = 56, 108 | NETWORK_DISCONNECT_LOOP_LEVELLOAD_ACTIVATE = 57, 109 | NETWORK_DISCONNECT_CREATE_SERVER_FAILED = 58, 110 | NETWORK_DISCONNECT_EXITING = 59, 111 | NETWORK_DISCONNECT_REQUEST_HOSTSTATE_IDLE = 60, 112 | NETWORK_DISCONNECT_REQUEST_HOSTSTATE_HLTVRELAY = 61, 113 | NETWORK_DISCONNECT_CLIENT_CONSISTENCY_FAIL = 62, 114 | NETWORK_DISCONNECT_CLIENT_UNABLE_TO_CRC_MAP = 63, 115 | NETWORK_DISCONNECT_CLIENT_NO_MAP = 64, 116 | NETWORK_DISCONNECT_CLIENT_DIFFERENT_MAP = 65, 117 | NETWORK_DISCONNECT_SERVER_REQUIRES_STEAM = 66, 118 | NETWORK_DISCONNECT_STEAM_DENY_MISC = 67, 119 | NETWORK_DISCONNECT_STEAM_DENY_BAD_ANTI_CHEAT = 68, 120 | NETWORK_DISCONNECT_SERVER_SHUTDOWN = 69, 121 | NETWORK_DISCONNECT_REPLAY_INCOMPATIBLE = 71, 122 | NETWORK_DISCONNECT_CONNECT_REQUEST_TIMEDOUT = 72, 123 | NETWORK_DISCONNECT_SERVER_INCOMPATIBLE = 73, 124 | NETWORK_DISCONNECT_LOCALPROBLEM_MANYRELAYS = 74, 125 | NETWORK_DISCONNECT_LOCALPROBLEM_HOSTEDSERVERPRIMARYRELAY = 75, 126 | NETWORK_DISCONNECT_LOCALPROBLEM_NETWORKCONFIG = 76, 127 | NETWORK_DISCONNECT_LOCALPROBLEM_OTHER = 77, 128 | NETWORK_DISCONNECT_REMOTE_TIMEOUT = 79, 129 | NETWORK_DISCONNECT_REMOTE_TIMEOUT_CONNECTING = 80, 130 | NETWORK_DISCONNECT_REMOTE_OTHER = 81, 131 | NETWORK_DISCONNECT_REMOTE_BADCRYPT = 82, 132 | NETWORK_DISCONNECT_REMOTE_CERTNOTTRUSTED = 83, 133 | NETWORK_DISCONNECT_UNUSUAL = 84, 134 | NETWORK_DISCONNECT_INTERNAL_ERROR = 85, 135 | NETWORK_DISCONNECT_REJECT_BADCHALLENGE = 128, 136 | NETWORK_DISCONNECT_REJECT_NOLOBBY = 129, 137 | NETWORK_DISCONNECT_REJECT_BACKGROUND_MAP = 130, 138 | NETWORK_DISCONNECT_REJECT_SINGLE_PLAYER = 131, 139 | NETWORK_DISCONNECT_REJECT_HIDDEN_GAME = 132, 140 | NETWORK_DISCONNECT_REJECT_LANRESTRICT = 133, 141 | NETWORK_DISCONNECT_REJECT_BADPASSWORD = 134, 142 | NETWORK_DISCONNECT_REJECT_SERVERFULL = 135, 143 | NETWORK_DISCONNECT_REJECT_INVALIDRESERVATION = 136, 144 | NETWORK_DISCONNECT_REJECT_FAILEDCHANNEL = 137, 145 | NETWORK_DISCONNECT_REJECT_CONNECT_FROM_LOBBY = 138, 146 | NETWORK_DISCONNECT_REJECT_RESERVED_FOR_LOBBY = 139, 147 | NETWORK_DISCONNECT_REJECT_INVALIDKEYLENGTH = 140, 148 | NETWORK_DISCONNECT_REJECT_OLDPROTOCOL = 141, 149 | NETWORK_DISCONNECT_REJECT_NEWPROTOCOL = 142, 150 | NETWORK_DISCONNECT_REJECT_INVALIDCONNECTION = 143, 151 | NETWORK_DISCONNECT_REJECT_INVALIDCERTLEN = 144, 152 | NETWORK_DISCONNECT_REJECT_INVALIDSTEAMCERTLEN = 145, 153 | NETWORK_DISCONNECT_REJECT_STEAM = 146, 154 | NETWORK_DISCONNECT_REJECT_SERVERAUTHDISABLED = 147, 155 | NETWORK_DISCONNECT_REJECT_SERVERCDKEYAUTHINVALID = 148, 156 | NETWORK_DISCONNECT_REJECT_BANNED = 149, 157 | NETWORK_DISCONNECT_KICKED_TEAMKILLING = 150, 158 | NETWORK_DISCONNECT_KICKED_TK_START = 151, 159 | NETWORK_DISCONNECT_KICKED_UNTRUSTEDACCOUNT = 152, 160 | NETWORK_DISCONNECT_KICKED_CONVICTEDACCOUNT = 153, 161 | NETWORK_DISCONNECT_KICKED_COMPETITIVECOOLDOWN = 154, 162 | NETWORK_DISCONNECT_KICKED_TEAMHURTING = 155, 163 | NETWORK_DISCONNECT_KICKED_HOSTAGEKILLING = 156, 164 | NETWORK_DISCONNECT_KICKED_VOTEDOFF = 157, 165 | NETWORK_DISCONNECT_KICKED_IDLE = 158, 166 | NETWORK_DISCONNECT_KICKED_SUICIDE = 159, 167 | NETWORK_DISCONNECT_KICKED_NOSTEAMLOGIN = 160, 168 | NETWORK_DISCONNECT_KICKED_NOSTEAMTICKET = 161 169 | }; 170 | bool ENetworkDisconnectionReason_IsValid(int value); 171 | constexpr ENetworkDisconnectionReason ENetworkDisconnectionReason_MIN = NETWORK_DISCONNECT_INVALID; 172 | constexpr ENetworkDisconnectionReason ENetworkDisconnectionReason_MAX = NETWORK_DISCONNECT_KICKED_NOSTEAMTICKET; 173 | constexpr int ENetworkDisconnectionReason_ARRAYSIZE = ENetworkDisconnectionReason_MAX + 1; 174 | 175 | const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* ENetworkDisconnectionReason_descriptor(); 176 | template 177 | inline const std::string& ENetworkDisconnectionReason_Name(T enum_t_value) { 178 | static_assert(::std::is_same::value || 179 | ::std::is_integral::value, 180 | "Incorrect type passed to function ENetworkDisconnectionReason_Name."); 181 | return ::PROTOBUF_NAMESPACE_ID::internal::NameOfEnum( 182 | ENetworkDisconnectionReason_descriptor(), enum_t_value); 183 | } 184 | inline bool ENetworkDisconnectionReason_Parse( 185 | ::PROTOBUF_NAMESPACE_ID::ConstStringParam name, ENetworkDisconnectionReason* value) { 186 | return ::PROTOBUF_NAMESPACE_ID::internal::ParseNamedEnum( 187 | ENetworkDisconnectionReason_descriptor(), name, value); 188 | } 189 | // =================================================================== 190 | 191 | 192 | // =================================================================== 193 | 194 | static const int kNetworkConnectionTokenFieldNumber = 50500; 195 | extern ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< ::PROTOBUF_NAMESPACE_ID::EnumValueOptions, 196 | ::PROTOBUF_NAMESPACE_ID::internal::StringTypeTraits, 9, false > 197 | network_connection_token; 198 | 199 | // =================================================================== 200 | 201 | #ifdef __GNUC__ 202 | #pragma GCC diagnostic push 203 | #pragma GCC diagnostic ignored "-Wstrict-aliasing" 204 | #endif // __GNUC__ 205 | #ifdef __GNUC__ 206 | #pragma GCC diagnostic pop 207 | #endif // __GNUC__ 208 | 209 | // @@protoc_insertion_point(namespace_scope) 210 | 211 | 212 | PROTOBUF_NAMESPACE_OPEN 213 | 214 | template <> struct is_proto_enum< ::ENetworkDisconnectionReason> : ::std::true_type {}; 215 | template <> 216 | inline const EnumDescriptor* GetEnumDescriptor< ::ENetworkDisconnectionReason>() { 217 | return ::ENetworkDisconnectionReason_descriptor(); 218 | } 219 | 220 | PROTOBUF_NAMESPACE_CLOSE 221 | 222 | // @@protoc_insertion_point(global_scope) 223 | 224 | #include 225 | #endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_network_5fconnection_2eproto 226 | -------------------------------------------------------------------------------- /src/utils/module.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ============================================================================= 3 | * CS2Fixes 4 | * Copyright (C) 2023 Source2ZE 5 | * ============================================================================= 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU General Public License, version 3.0, as published by the 9 | * Free Software Foundation. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | * details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * this program. If not, see . 18 | */ 19 | 20 | #pragma once 21 | #include "dbg.h" 22 | #include "interface.h" 23 | #include "strtools.h" 24 | #include "plat.h" 25 | 26 | #ifdef _WIN32 27 | #include 28 | #endif 29 | 30 | enum SigError 31 | { 32 | SIG_OK, 33 | SIG_NOT_FOUND, 34 | SIG_FOUND_MULTIPLE, 35 | }; 36 | 37 | class CModule 38 | { 39 | public: 40 | CModule(const char *path, const char *module) : 41 | m_pszModule(module), m_pszPath(path) 42 | { 43 | char szModule[MAX_PATH]; 44 | 45 | V_snprintf(szModule, MAX_PATH, "%s%s%s%s%s", Plat_GetGameDirectory(), path, MODULE_PREFIX, m_pszModule, MODULE_EXT); 46 | 47 | m_hModule = dlmount(szModule); 48 | 49 | if (!m_hModule) 50 | Error("Could not find %s\n", szModule); 51 | 52 | #ifdef _WIN32 53 | MODULEINFO m_hModuleInfo; 54 | GetModuleInformation(GetCurrentProcess(), m_hModule, &m_hModuleInfo, sizeof(m_hModuleInfo)); 55 | 56 | m_base = (void *)m_hModuleInfo.lpBaseOfDll; 57 | m_size = m_hModuleInfo.SizeOfImage; 58 | #else 59 | if (int e = GetModuleInformation(m_hModule, &m_base, &m_size)) 60 | Error("Failed to get module info for %s, error %d\n", szModule, e); 61 | #endif 62 | 63 | ConMsg("Initialized module %s base: 0x%p | size: %lu\n", m_pszModule, m_base, m_size); 64 | } 65 | 66 | void *FindSignature(const byte *pData, size_t iSigLength, int &error) 67 | { 68 | unsigned char *pMemory; 69 | void *return_addr = nullptr; 70 | error = 0; 71 | 72 | pMemory = (byte*)m_base; 73 | 74 | for (size_t i = 0; i < m_size; i++) 75 | { 76 | size_t Matches = 0; 77 | while (*(pMemory + i + Matches) == pData[Matches] || pData[Matches] == '\x2A') 78 | { 79 | Matches++; 80 | if (Matches == iSigLength) 81 | { 82 | if (return_addr) 83 | { 84 | error = SIG_FOUND_MULTIPLE; 85 | return return_addr; 86 | } 87 | 88 | return_addr = (void *)(pMemory + i); 89 | } 90 | } 91 | } 92 | 93 | if (!return_addr) 94 | error = SIG_NOT_FOUND; 95 | 96 | return return_addr; 97 | } 98 | 99 | void *FindInterface(const char *name) 100 | { 101 | CreateInterfaceFn fn = (CreateInterfaceFn)dlsym(m_hModule, "CreateInterface"); 102 | 103 | if (!fn) 104 | Error("Could not find CreateInterface in %s\n", m_pszModule); 105 | 106 | void *pInterface = fn(name, nullptr); 107 | 108 | if (!pInterface) 109 | Error("Could not find %s in %s\n", name, m_pszModule); 110 | 111 | ConMsg("Found interface %s in %s\n", name, m_pszModule); 112 | 113 | return pInterface; 114 | } 115 | 116 | const char *m_pszModule; 117 | const char* m_pszPath; 118 | HINSTANCE m_hModule; 119 | void* m_base; 120 | size_t m_size; 121 | }; -------------------------------------------------------------------------------- /src/utils/plat.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ============================================================================= 3 | * CS2Fixes 4 | * Copyright (C) 2023 Source2ZE 5 | * ============================================================================= 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU General Public License, version 3.0, as published by the 9 | * Free Software Foundation. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | * details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * this program. If not, see . 18 | */ 19 | 20 | #pragma once 21 | #include 22 | #include "metamod_oslink.h" 23 | 24 | struct Module 25 | { 26 | #ifndef _WIN32 27 | void* pHandle; 28 | #endif 29 | uint8_t* pBase; 30 | unsigned int nSize; 31 | }; 32 | 33 | #ifndef _WIN32 34 | int GetModuleInformation(HINSTANCE module, void** base, size_t* length); 35 | #endif 36 | 37 | #ifdef _WIN32 38 | #define MODULE_PREFIX "" 39 | #define MODULE_EXT ".dll" 40 | #else 41 | #define MODULE_PREFIX "lib" 42 | #define MODULE_EXT ".so" 43 | #endif 44 | 45 | void Plat_WriteMemory(void* pPatchAddress, uint8_t *pPatch, int iPatchSize); -------------------------------------------------------------------------------- /src/utils/plat_unix.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ============================================================================= 3 | * CS2Fixes 4 | * Copyright (C) 2023 Source2ZE 5 | * ============================================================================= 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU General Public License, version 3.0, as published by the 9 | * Free Software Foundation. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | * details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * this program. If not, see . 18 | */ 19 | 20 | #ifdef __linux__ 21 | #include "plat.h" 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include "sys/mman.h" 27 | #include 28 | #include 29 | #include 30 | #include "dbg.h" 31 | 32 | #include "tier0/memdbgon.h" 33 | 34 | #define PAGE_SIZE 4096 35 | #define PAGE_ALIGN_UP(x) ((x + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1)) 36 | 37 | struct ModuleInfo 38 | { 39 | const char* path; // in 40 | uint8_t* base; // out 41 | uint size; // out 42 | }; 43 | 44 | // https://github.com/alliedmodders/sourcemod/blob/master/core/logic/MemoryUtils.cpp#L502-L587 45 | int GetModuleInformation(HINSTANCE hModule, void** base, size_t* length) 46 | { 47 | struct link_map* dlmap = (struct link_map*)hModule; 48 | Dl_info info; 49 | Elf64_Ehdr* file; 50 | Elf64_Phdr* phdr; 51 | uint16_t phdrCount; 52 | 53 | if (!dladdr((void*)dlmap->l_addr, &info)) 54 | { 55 | return 1; 56 | } 57 | 58 | if (!info.dli_fbase || !info.dli_fname) 59 | { 60 | return 2; 61 | } 62 | 63 | /* This is for our insane sanity checks :o */ 64 | uintptr_t baseAddr = reinterpret_cast(info.dli_fbase); 65 | file = reinterpret_cast(baseAddr); 66 | 67 | /* Check ELF magic */ 68 | if (memcmp(ELFMAG, file->e_ident, SELFMAG) != 0) 69 | { 70 | return 3; 71 | } 72 | 73 | /* Check ELF version */ 74 | if (file->e_ident[EI_VERSION] != EV_CURRENT) 75 | { 76 | return 4; 77 | } 78 | 79 | /* Check ELF endianness */ 80 | if (file->e_ident[EI_DATA] != ELFDATA2LSB) 81 | { 82 | return 5; 83 | } 84 | 85 | /* Check ELF architecture */ 86 | if (file->e_ident[EI_CLASS] != ELFCLASS64 || file->e_machine != EM_X86_64) 87 | { 88 | return 6; 89 | } 90 | 91 | /* For our purposes, this must be a dynamic library/shared object */ 92 | if (file->e_type != ET_DYN) 93 | { 94 | return 7; 95 | } 96 | 97 | phdrCount = file->e_phnum; 98 | phdr = reinterpret_cast(baseAddr + file->e_phoff); 99 | 100 | for (uint16_t i = 0; i < phdrCount; i++) 101 | { 102 | Elf64_Phdr& hdr = phdr[i]; 103 | 104 | /* We only really care about the segment with executable code */ 105 | if (hdr.p_type == PT_LOAD && hdr.p_flags == (PF_X | PF_R)) 106 | { 107 | /* From glibc, elf/dl-load.c: 108 | * c->mapend = ((ph->p_vaddr + ph->p_filesz + GLRO(dl_pagesize) - 1) 109 | * & ~(GLRO(dl_pagesize) - 1)); 110 | * 111 | * In glibc, the segment file size is aligned up to the nearest page size and 112 | * added to the virtual address of the segment. We just want the size here. 113 | */ 114 | //lib.memorySize = PAGE_ALIGN_UP(hdr.p_filesz); 115 | *length = PAGE_ALIGN_UP(hdr.p_filesz); 116 | *base = (void*)(baseAddr + hdr.p_paddr); 117 | 118 | break; 119 | } 120 | } 121 | 122 | return 0; 123 | } 124 | 125 | static int parse_prot(const char* s) 126 | { 127 | int prot = 0; 128 | 129 | for (; *s; s++) 130 | { 131 | switch (*s) 132 | { 133 | case '-': 134 | break; 135 | case 'r': 136 | prot |= PROT_READ; 137 | break; 138 | case 'w': 139 | prot |= PROT_WRITE; 140 | break; 141 | case 'x': 142 | prot |= PROT_EXEC; 143 | break; 144 | case 's': 145 | break; 146 | case 'p': 147 | break; 148 | default: 149 | break; 150 | } 151 | } 152 | 153 | return prot; 154 | } 155 | 156 | static int get_prot(void* pAddr, size_t nSize) 157 | { 158 | FILE* f = fopen("/proc/self/maps", "r"); 159 | 160 | uintptr_t nAddr = (uintptr_t)pAddr; 161 | 162 | char line[512]; 163 | while (fgets(line, sizeof(line), f)) 164 | { 165 | char start[16]; 166 | char end[16]; 167 | char prot[16]; 168 | 169 | const char* src = line; 170 | 171 | char* dst = start; 172 | while (*src != '-') 173 | *dst++ = *src++; 174 | *dst = 0; 175 | 176 | src++; // skip "-"" 177 | 178 | dst = end; 179 | while (!isspace(*src)) 180 | *dst++ = *src++; 181 | *dst = 0; 182 | 183 | src++; // skip space 184 | 185 | dst = prot; 186 | while (!isspace(*src)) 187 | *dst++ = *src++; 188 | *dst = 0; 189 | 190 | uintptr_t nStart = (uintptr_t)strtoul(start, nullptr, 16); 191 | uintptr_t nEnd = (uintptr_t)strtoul(end, nullptr, 16); 192 | 193 | if (nStart < nAddr && nEnd >(nAddr + nSize)) 194 | { 195 | fclose(f); 196 | return parse_prot(prot); 197 | } 198 | } 199 | 200 | fclose(f); 201 | return 0; 202 | } 203 | 204 | void Plat_WriteMemory(void* pPatchAddress, uint8_t* pPatch, int iPatchSize) 205 | { 206 | int old_prot = get_prot(pPatchAddress, iPatchSize); 207 | 208 | uintptr_t page_size = sysconf(_SC_PAGESIZE); 209 | uint8_t* align_addr = (uint8_t*)((uintptr_t)pPatchAddress & ~(page_size - 1)); 210 | 211 | uint8_t* end = (uint8_t*)pPatchAddress + iPatchSize; 212 | uintptr_t align_size = end - align_addr; 213 | 214 | int result = mprotect(align_addr, align_size, PROT_READ | PROT_WRITE); 215 | 216 | memcpy(pPatchAddress, pPatch, iPatchSize); 217 | 218 | result = mprotect(align_addr, align_size, old_prot); 219 | } 220 | #endif 221 | 222 | -------------------------------------------------------------------------------- /src/utils/plat_win.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ============================================================================= 3 | * CS2Fixes 4 | * Copyright (C) 2023 Source2ZE 5 | * ============================================================================= 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU General Public License, version 3.0, as published by the 9 | * Free Software Foundation. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | * details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * this program. If not, see . 18 | */ 19 | 20 | #include "plat.h" 21 | 22 | #include "tier0/memdbgon.h" 23 | 24 | void Plat_WriteMemory(void* pPatchAddress, uint8_t* pPatch, int iPatchSize) 25 | { 26 | WriteProcessMemory(GetCurrentProcess(), pPatchAddress, (void*)pPatch, iPatchSize, nullptr); 27 | } -------------------------------------------------------------------------------- /vendor/funchook/LICENSE: -------------------------------------------------------------------------------- 1 | Funchook is distributed under the terms of the GNU General Public 2 | License version 2 or later with the following clarification and 3 | special exception. 4 | 5 | Linking this library statically or dynamically with other modules is 6 | making a combined work based on this library. Thus, the terms and 7 | conditions of the GNU General Public License cover the whole 8 | combination. 9 | 10 | As a special exception, the copyright holders of this library give you 11 | permission to link this library with independent modules to produce an 12 | executable, regardless of the license terms of these independent 13 | modules, and to copy and distribute the resulting executable under 14 | terms of your choice, provided that you also meet, for each linked 15 | independent module, the terms and conditions of the license of that 16 | module. An independent module is a module which is not derived from or 17 | based on this library. If you modify this library, you must extend this 18 | exception to your version of the library. 19 | 20 | ===================================================================== 21 | 22 | GNU GENERAL PUBLIC LICENSE 23 | Version 2, June 1991 24 | 25 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 26 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | Everyone is permitted to copy and distribute verbatim copies 28 | of this license document, but changing it is not allowed. 29 | 30 | Preamble 31 | 32 | The licenses for most software are designed to take away your 33 | freedom to share and change it. By contrast, the GNU General Public 34 | License is intended to guarantee your freedom to share and change free 35 | software--to make sure the software is free for all its users. This 36 | General Public License applies to most of the Free Software 37 | Foundation's software and to any other program whose authors commit to 38 | using it. (Some other Free Software Foundation software is covered by 39 | the GNU Lesser General Public License instead.) You can apply it to 40 | your programs, too. 41 | 42 | When we speak of free software, we are referring to freedom, not 43 | price. Our General Public Licenses are designed to make sure that you 44 | have the freedom to distribute copies of free software (and charge for 45 | this service if you wish), that you receive source code or can get it 46 | if you want it, that you can change the software or use pieces of it 47 | in new free programs; and that you know you can do these things. 48 | 49 | To protect your rights, we need to make restrictions that forbid 50 | anyone to deny you these rights or to ask you to surrender the rights. 51 | These restrictions translate to certain responsibilities for you if you 52 | distribute copies of the software, or if you modify it. 53 | 54 | For example, if you distribute copies of such a program, whether 55 | gratis or for a fee, you must give the recipients all the rights that 56 | you have. You must make sure that they, too, receive or can get the 57 | source code. And you must show them these terms so they know their 58 | rights. 59 | 60 | We protect your rights with two steps: (1) copyright the software, and 61 | (2) offer you this license which gives you legal permission to copy, 62 | distribute and/or modify the software. 63 | 64 | Also, for each author's protection and ours, we want to make certain 65 | that everyone understands that there is no warranty for this free 66 | software. If the software is modified by someone else and passed on, we 67 | want its recipients to know that what they have is not the original, so 68 | that any problems introduced by others will not reflect on the original 69 | authors' reputations. 70 | 71 | Finally, any free program is threatened constantly by software 72 | patents. We wish to avoid the danger that redistributors of a free 73 | program will individually obtain patent licenses, in effect making the 74 | program proprietary. To prevent this, we have made it clear that any 75 | patent must be licensed for everyone's free use or not licensed at all. 76 | 77 | The precise terms and conditions for copying, distribution and 78 | modification follow. 79 | 80 | GNU GENERAL PUBLIC LICENSE 81 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 82 | 83 | 0. This License applies to any program or other work which contains 84 | a notice placed by the copyright holder saying it may be distributed 85 | under the terms of this General Public License. The "Program", below, 86 | refers to any such program or work, and a "work based on the Program" 87 | means either the Program or any derivative work under copyright law: 88 | that is to say, a work containing the Program or a portion of it, 89 | either verbatim or with modifications and/or translated into another 90 | language. (Hereinafter, translation is included without limitation in 91 | the term "modification".) Each licensee is addressed as "you". 92 | 93 | Activities other than copying, distribution and modification are not 94 | covered by this License; they are outside its scope. The act of 95 | running the Program is not restricted, and the output from the Program 96 | is covered only if its contents constitute a work based on the 97 | Program (independent of having been made by running the Program). 98 | Whether that is true depends on what the Program does. 99 | 100 | 1. You may copy and distribute verbatim copies of the Program's 101 | source code as you receive it, in any medium, provided that you 102 | conspicuously and appropriately publish on each copy an appropriate 103 | copyright notice and disclaimer of warranty; keep intact all the 104 | notices that refer to this License and to the absence of any warranty; 105 | and give any other recipients of the Program a copy of this License 106 | along with the Program. 107 | 108 | You may charge a fee for the physical act of transferring a copy, and 109 | you may at your option offer warranty protection in exchange for a fee. 110 | 111 | 2. You may modify your copy or copies of the Program or any portion 112 | of it, thus forming a work based on the Program, and copy and 113 | distribute such modifications or work under the terms of Section 1 114 | above, provided that you also meet all of these conditions: 115 | 116 | a) You must cause the modified files to carry prominent notices 117 | stating that you changed the files and the date of any change. 118 | 119 | b) You must cause any work that you distribute or publish, that in 120 | whole or in part contains or is derived from the Program or any 121 | part thereof, to be licensed as a whole at no charge to all third 122 | parties under the terms of this License. 123 | 124 | c) If the modified program normally reads commands interactively 125 | when run, you must cause it, when started running for such 126 | interactive use in the most ordinary way, to print or display an 127 | announcement including an appropriate copyright notice and a 128 | notice that there is no warranty (or else, saying that you provide 129 | a warranty) and that users may redistribute the program under 130 | these conditions, and telling the user how to view a copy of this 131 | License. (Exception: if the Program itself is interactive but 132 | does not normally print such an announcement, your work based on 133 | the Program is not required to print an announcement.) 134 | 135 | These requirements apply to the modified work as a whole. If 136 | identifiable sections of that work are not derived from the Program, 137 | and can be reasonably considered independent and separate works in 138 | themselves, then this License, and its terms, do not apply to those 139 | sections when you distribute them as separate works. But when you 140 | distribute the same sections as part of a whole which is a work based 141 | on the Program, the distribution of the whole must be on the terms of 142 | this License, whose permissions for other licensees extend to the 143 | entire whole, and thus to each and every part regardless of who wrote it. 144 | 145 | Thus, it is not the intent of this section to claim rights or contest 146 | your rights to work written entirely by you; rather, the intent is to 147 | exercise the right to control the distribution of derivative or 148 | collective works based on the Program. 149 | 150 | In addition, mere aggregation of another work not based on the Program 151 | with the Program (or with a work based on the Program) on a volume of 152 | a storage or distribution medium does not bring the other work under 153 | the scope of this License. 154 | 155 | 3. You may copy and distribute the Program (or a work based on it, 156 | under Section 2) in object code or executable form under the terms of 157 | Sections 1 and 2 above provided that you also do one of the following: 158 | 159 | a) Accompany it with the complete corresponding machine-readable 160 | source code, which must be distributed under the terms of Sections 161 | 1 and 2 above on a medium customarily used for software interchange; or, 162 | 163 | b) Accompany it with a written offer, valid for at least three 164 | years, to give any third party, for a charge no more than your 165 | cost of physically performing source distribution, a complete 166 | machine-readable copy of the corresponding source code, to be 167 | distributed under the terms of Sections 1 and 2 above on a medium 168 | customarily used for software interchange; or, 169 | 170 | c) Accompany it with the information you received as to the offer 171 | to distribute corresponding source code. (This alternative is 172 | allowed only for noncommercial distribution and only if you 173 | received the program in object code or executable form with such 174 | an offer, in accord with Subsection b above.) 175 | 176 | The source code for a work means the preferred form of the work for 177 | making modifications to it. For an executable work, complete source 178 | code means all the source code for all modules it contains, plus any 179 | associated interface definition files, plus the scripts used to 180 | control compilation and installation of the executable. However, as a 181 | special exception, the source code distributed need not include 182 | anything that is normally distributed (in either source or binary 183 | form) with the major components (compiler, kernel, and so on) of the 184 | operating system on which the executable runs, unless that component 185 | itself accompanies the executable. 186 | 187 | If distribution of executable or object code is made by offering 188 | access to copy from a designated place, then offering equivalent 189 | access to copy the source code from the same place counts as 190 | distribution of the source code, even though third parties are not 191 | compelled to copy the source along with the object code. 192 | 193 | 4. You may not copy, modify, sublicense, or distribute the Program 194 | except as expressly provided under this License. Any attempt 195 | otherwise to copy, modify, sublicense or distribute the Program is 196 | void, and will automatically terminate your rights under this License. 197 | However, parties who have received copies, or rights, from you under 198 | this License will not have their licenses terminated so long as such 199 | parties remain in full compliance. 200 | 201 | 5. You are not required to accept this License, since you have not 202 | signed it. However, nothing else grants you permission to modify or 203 | distribute the Program or its derivative works. These actions are 204 | prohibited by law if you do not accept this License. Therefore, by 205 | modifying or distributing the Program (or any work based on the 206 | Program), you indicate your acceptance of this License to do so, and 207 | all its terms and conditions for copying, distributing or modifying 208 | the Program or works based on it. 209 | 210 | 6. Each time you redistribute the Program (or any work based on the 211 | Program), the recipient automatically receives a license from the 212 | original licensor to copy, distribute or modify the Program subject to 213 | these terms and conditions. You may not impose any further 214 | restrictions on the recipients' exercise of the rights granted herein. 215 | You are not responsible for enforcing compliance by third parties to 216 | this License. 217 | 218 | 7. If, as a consequence of a court judgment or allegation of patent 219 | infringement or for any other reason (not limited to patent issues), 220 | conditions are imposed on you (whether by court order, agreement or 221 | otherwise) that contradict the conditions of this License, they do not 222 | excuse you from the conditions of this License. If you cannot 223 | distribute so as to satisfy simultaneously your obligations under this 224 | License and any other pertinent obligations, then as a consequence you 225 | may not distribute the Program at all. For example, if a patent 226 | license would not permit royalty-free redistribution of the Program by 227 | all those who receive copies directly or indirectly through you, then 228 | the only way you could satisfy both it and this License would be to 229 | refrain entirely from distribution of the Program. 230 | 231 | If any portion of this section is held invalid or unenforceable under 232 | any particular circumstance, the balance of the section is intended to 233 | apply and the section as a whole is intended to apply in other 234 | circumstances. 235 | 236 | It is not the purpose of this section to induce you to infringe any 237 | patents or other property right claims or to contest validity of any 238 | such claims; this section has the sole purpose of protecting the 239 | integrity of the free software distribution system, which is 240 | implemented by public license practices. Many people have made 241 | generous contributions to the wide range of software distributed 242 | through that system in reliance on consistent application of that 243 | system; it is up to the author/donor to decide if he or she is willing 244 | to distribute software through any other system and a licensee cannot 245 | impose that choice. 246 | 247 | This section is intended to make thoroughly clear what is believed to 248 | be a consequence of the rest of this License. 249 | 250 | 8. If the distribution and/or use of the Program is restricted in 251 | certain countries either by patents or by copyrighted interfaces, the 252 | original copyright holder who places the Program under this License 253 | may add an explicit geographical distribution limitation excluding 254 | those countries, so that distribution is permitted only in or among 255 | countries not thus excluded. In such case, this License incorporates 256 | the limitation as if written in the body of this License. 257 | 258 | 9. The Free Software Foundation may publish revised and/or new versions 259 | of the General Public License from time to time. Such new versions will 260 | be similar in spirit to the present version, but may differ in detail to 261 | address new problems or concerns. 262 | 263 | Each version is given a distinguishing version number. If the Program 264 | specifies a version number of this License which applies to it and "any 265 | later version", you have the option of following the terms and conditions 266 | either of that version or of any later version published by the Free 267 | Software Foundation. If the Program does not specify a version number of 268 | this License, you may choose any version ever published by the Free Software 269 | Foundation. 270 | 271 | 10. If you wish to incorporate parts of the Program into other free 272 | programs whose distribution conditions are different, write to the author 273 | to ask for permission. For software which is copyrighted by the Free 274 | Software Foundation, write to the Free Software Foundation; we sometimes 275 | make exceptions for this. Our decision will be guided by the two goals 276 | of preserving the free status of all derivatives of our free software and 277 | of promoting the sharing and reuse of software generally. 278 | 279 | NO WARRANTY 280 | 281 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 282 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 283 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 284 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 285 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 286 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 287 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 288 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 289 | REPAIR OR CORRECTION. 290 | 291 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 292 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 293 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 294 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 295 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 296 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 297 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 298 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 299 | POSSIBILITY OF SUCH DAMAGES. 300 | 301 | END OF TERMS AND CONDITIONS 302 | 303 | How to Apply These Terms to Your New Programs 304 | 305 | If you develop a new program, and you want it to be of the greatest 306 | possible use to the public, the best way to achieve this is to make it 307 | free software which everyone can redistribute and change under these terms. 308 | 309 | To do so, attach the following notices to the program. It is safest 310 | to attach them to the start of each source file to most effectively 311 | convey the exclusion of warranty; and each file should have at least 312 | the "copyright" line and a pointer to where the full notice is found. 313 | 314 | 315 | Copyright (C) 316 | 317 | This program is free software; you can redistribute it and/or modify 318 | it under the terms of the GNU General Public License as published by 319 | the Free Software Foundation; either version 2 of the License, or 320 | (at your option) any later version. 321 | 322 | This program is distributed in the hope that it will be useful, 323 | but WITHOUT ANY WARRANTY; without even the implied warranty of 324 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 325 | GNU General Public License for more details. 326 | 327 | You should have received a copy of the GNU General Public License along 328 | with this program; if not, write to the Free Software Foundation, Inc., 329 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 330 | 331 | Also add information on how to contact you by electronic and paper mail. 332 | 333 | If the program is interactive, make it output a short notice like this 334 | when it starts in an interactive mode: 335 | 336 | Gnomovision version 69, Copyright (C) year name of author 337 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 338 | This is free software, and you are welcome to redistribute it 339 | under certain conditions; type `show c' for details. 340 | 341 | The hypothetical commands `show w' and `show c' should show the appropriate 342 | parts of the General Public License. Of course, the commands you use may 343 | be called something other than `show w' and `show c'; they could even be 344 | mouse-clicks or menu items--whatever suits your program. 345 | 346 | You should also get your employer (if you work as a programmer) or your 347 | school, if any, to sign a "copyright disclaimer" for the program, if 348 | necessary. Here is a sample; alter the names: 349 | 350 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 351 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 352 | 353 | , 1 April 1989 354 | Ty Coon, President of Vice 355 | 356 | This General Public License does not permit incorporating your program into 357 | proprietary programs. If your program is a subroutine library, you may 358 | consider it more useful to permit linking proprietary applications with the 359 | library. If this is what you want to do, use the GNU Lesser General 360 | Public License instead of this License. 361 | -------------------------------------------------------------------------------- /vendor/funchook/README.md: -------------------------------------------------------------------------------- 1 | Funchook - an API hook library 2 | ============================== 3 | 4 | [![tests](https://github.com/kubo/funchook/actions/workflows/run-tests.yml/badge.svg?branch=master)](https://github.com/kubo/funchook/actions/workflows/run-tests.yml) 5 | 6 | This library depends on one of the following disassemblers. 7 | 8 | On x86_64 and x86 9 | * [diStorm3][] (default) 10 | * [zydis][] (when `-DFUNCHOOK_DISASM=zydis` is passed to the `cmake` command) 11 | * [capstone][] (when `-DFUNCHOOK_DISASM=capstone` is passed to the `cmake` command) 12 | 13 | On arm64 14 | * [capstone][] 15 | 16 | TODO 17 | ---- 18 | 19 | * write documents. 20 | 21 | News 22 | ---- 23 | 24 | ### 2.0.0 (20XX-XX-XX) 25 | 26 | * Add `funchook_prepare_with_params()` to support prehook. 27 | * Add `funchook_get_arg()` to get arguments in prehook. 28 | 29 | ### 1.1.1 (2022-10-02) 30 | 31 | * More permissive check for page allocation mmap ([#25][]) 32 | * Flush instruction cache for arm64. It does nothing for intel CPU. 33 | * Disassember engine 34 | * Upgrade capstone to 4.0.2 35 | * Upgrade distorm to 3.5.2 36 | * CMake 37 | * Allow user to specify FUNCHOOK_CPU explicitly ([#19][]) 38 | * Avoid polluting global include and link dirs ([#20][]) 39 | * Use target based compile options for gcc's -Wall ([#21][]) 40 | * Use ExternalProject_add to download captone only ([#30][]) 41 | * Add option FUNCHOOK_INSTALL ([#31][]) 42 | * Use "FUNCHOOK_CPU MATCHES " ([#32][]) 43 | * Documentation 44 | * added example usage from python ([#22][]) 45 | * Fix tests on Android ([#29][]) 46 | 47 | ### 1.1.0 (2020-03-22) 48 | 49 | * Arm64 Linux support. [capstone][] is used as the disassembler library on arm64. 50 | * Options to use [zydis][] and [capstone][] as a disassembler library on x86_64 and x86. 51 | * `extern "C"` was added in funchook.h for C++. ([#15][]) 52 | * Libc-compatible functions were removed to simplify code. 53 | 54 | ### 1.0.0 (2020-01-19) 55 | 56 | * [diStorm3][] is used as the disassembler library. 57 | * Libc-compatible functions were implemented on Linux in order not to hook function calls issued by funchook itself. 58 | 59 | Supported Platforms 60 | ------------------- 61 | 62 | * Linux x86_64 63 | * Linux x86 64 | * Linux arm64 (since 1.1.0) 65 | * macOS x86_64 (Functions in executables cannot be hooked when Xcode version >= 11.0. (*1)) 66 | * Windows x64 (except C-runtime functions under [Wine][]) 67 | * Windows 32-bit 68 | 69 | *1 [`mprotect`] fails with EACCES. 70 | 71 | Unsupported Platforms 72 | --------------------- 73 | 74 | * macOS arm64 (*1) 75 | 76 | *1 I received a mail that [`mprotect`] failed with `EINVAL`. Apple seems to prevent executable memory regions from being writable. 77 | 78 | Compilation and installation 79 | ----------- 80 | 81 | ### Unix 82 | 83 | ```shell 84 | $ git clone --recursive https://github.com/kubo/funchook.git 85 | $ mkdir build 86 | $ cd build 87 | $ cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/path/to/install/directory ../funchook 88 | $ make 89 | $ make install 90 | ``` 91 | 92 | * Available [`CMAKE_BUILD_TYPE`][] values are empty(default), `Debug`, `Release`, `RelWithDebInfo`(release build with debug information) and `MinSizeRel`. 93 | * When [`CMAKE_INSTALL_PREFIX`][] isn't set, funchook is installed at `/usr/local`. 94 | 95 | installed files: 96 | * `${CMAKE_INSTALL_PREFIX}/include/funchook.h` (header file) 97 | * `${CMAKE_INSTALL_PREFIX}/lib/libfunchook.so` (symbolic link to `libfunchook.so.1`) 98 | * `${CMAKE_INSTALL_PREFIX}/lib/libfunchook.so.1` ([soname][]; symbolic link to `libfunchook.so.1.1.0`) 99 | * `${CMAKE_INSTALL_PREFIX}/lib/libfunchook.so.1.1.0` (shared library) 100 | * `${CMAKE_INSTALL_PREFIX}/lib/libfunchook.a` (static library) 101 | 102 | ### Windows 103 | 104 | Here is an example to compile funchook with Visual Studio 2017 Win64. 105 | Change the argument of `-G` to use other compilers. 106 | 107 | ```shell 108 | $ git clone --recursive https://github.com/kubo/funchook.git 109 | $ mkdir build 110 | $ cd build 111 | $ cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_INSTALL_PREFIX=c:\path\to\install\directory ..\funchook 112 | $ cmake --build . --config Release --target INSTALL 113 | ``` 114 | 115 | * Available `-G` arguments (generators) are listed in the output of `cmake --help`. 116 | * Available `--config` arguments are `Debug`(default), `Release`, `RelWithDebInfo` and `MinSizeRel`. 117 | * When [`CMAKE_INSTALL_PREFIX`][] isn't set, funchook is installed at `c:\Program Files\funchook`. 118 | 119 | installed files: 120 | * `${CMAKE_INSTALL_PREFIX}\include\funchook.h` (header file) 121 | * `${CMAKE_INSTALL_PREFIX}\bin\funchook.dll` (shared library) 122 | * `${CMAKE_INSTALL_PREFIX}\bin\funchook.pdb` (debug file for `funchook.dll` when `--config` is `Debug` or `RelWithDebInfo`) 123 | * `${CMAKE_INSTALL_PREFIX}\lib\funchook.lib` (static library) 124 | * `${CMAKE_INSTALL_PREFIX}\lib\funchook_dll.lib` (import library for `funchook.dll`) 125 | 126 | Example 127 | ------- 128 | 129 | ```c 130 | static ssize_t (*send_func)(int sockfd, const void *buf, size_t len, int flags); 131 | static ssize_t (*recv_func)(int sockfd, void *buf, size_t len, int flags); 132 | 133 | static ssize_t send_hook(int sockfd, const void *buf, size_t len, int flags); 134 | { 135 | ssize_t rv; 136 | 137 | ... do your task: logging, etc. ... 138 | rv = send_func(sockfd, buf, len, flags); /* call the original send(). */ 139 | ... do your task: logging, checking the return value, etc. ... 140 | return rv; 141 | } 142 | 143 | static ssize_t recv_hook(int sockfd, void *buf, size_t len, int flags); 144 | { 145 | ssize_t rv; 146 | 147 | ... do your task: logging, etc. ... 148 | rv = recv_func(sockfd, buf, len, flags); /* call the original recv(). */ 149 | ... do your task: logging, checking received data, etc. ... 150 | return rv; 151 | } 152 | 153 | int install_hooks() 154 | { 155 | funchook_t *funchook = funchook_create(); 156 | int rv; 157 | 158 | /* Prepare hooking. 159 | * The return value is used to call the original send function 160 | * in send_hook. 161 | */ 162 | send_func = send; 163 | rv = funchook_prepare(funchook, (void**)&send_func, send_hook); 164 | if (rv != 0) { 165 | /* error */ 166 | ... 167 | } 168 | 169 | /* ditto */ 170 | recv_func = recv; 171 | rv = funchook_prepare(funchook, (void**)&recv_func, recv_hook); 172 | if (rv != 0) { 173 | /* error */ 174 | ... 175 | } 176 | 177 | /* Install hooks. 178 | * The first 5-byte code of send() and recv() are changed respectively. 179 | */ 180 | rv = funchook_install(funchook, 0); 181 | if (rv != 0) { 182 | /* error */ 183 | ... 184 | } 185 | } 186 | 187 | ``` 188 | 189 | Example - Using Python ctypes 190 | ----------------------------- 191 | ```python 192 | # should work on python 2.7/3 windows/linux 193 | 194 | # load funchook 195 | import ctypes 196 | fh_lib = ctypes.cdll.LoadLibrary('/path/to/funchook/dll/or/so') 197 | 198 | # define signatures 199 | funchook_create = fh_lib.funchook_create 200 | funchook_create.restype = ctypes.c_void_p 201 | funchook_create.argtypes = [] 202 | 203 | funchook_prepare = fh_lib.funchook_prepare 204 | funchook_prepare.restype = ctypes.c_ssize_t 205 | funchook_prepare.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p] 206 | 207 | funchook_install = fh_lib.funchook_install 208 | funchook_install.restype = ctypes.c_ssize_t 209 | funchook_install.argtypes = [ctypes.c_void_p, ctypes.c_int] 210 | 211 | PySys_WriteStdout = ctypes.pythonapi.PySys_WriteStdout 212 | PySys_WriteStdout.restype = None 213 | PySys_WriteStdout.argtypes=[ctypes.c_char_p] 214 | 215 | # must keep those references alive, or stuff will be GC'd and weird errors will occur 216 | global orig_write, hook, orig_write_ptr 217 | 218 | # create hook (this function will replace the original function) 219 | hook_type = ctypes.PYFUNCTYPE(None, ctypes.c_char_p) 220 | orig_write = None 221 | def hook_impl(msg): 222 | print('about to write: ' + str(msg)) # do what we want 223 | orig_write(msg) # call the original function 224 | 225 | hook = hook_type(hook_impl) 226 | 227 | fh = funchook_create() 228 | # create a pointer object with the function address 229 | orig_write_ptr = ctypes.c_void_p(ctypes.c_void_p.from_address(ctypes.addressof(PySys_WriteStdout)).value) 230 | # orig_write_ptr.value will get a ptr to the original PySys_WriteStdout and PySys_WriteStdout will now point to the hook 231 | ret = funchook_prepare(fh, ctypes.addressof(orig_write_ptr), hook) 232 | assert not ret, 'ret is ' + str(ret) 233 | ret = funchook_install(fh, 0) 234 | assert not ret, 'ret is ' + str(ret) 235 | orig_write = hook_type.from_address(ctypes.addressof(orig_write_ptr)) 236 | PySys_WriteStdout(b'hi there\n') 237 | ``` 238 | 239 | License 240 | ------- 241 | 242 | GPLv2 or later with a [GPL linking exception][]. 243 | 244 | You can use funchook in any software. Though funchook is licensed under 245 | the GPL, it doesn't affect outside of funchook due to the linking exception. 246 | You have no need to open your souce code under the GPL except funchook itself. 247 | 248 | If you modify funchook itself and release it, the modifed part must be 249 | open under the GPL with or without the linking exception because funchook 250 | itself is under the GPL. 251 | 252 | [diStorm3][] and [capstone][] are released under the 3-clause BSD license. 253 | [zydis][] is released under the MIT license. They are compatible with the GPL. 254 | 255 | [GPL linking exception]: https://en.wikipedia.org/wiki/GPL_linking_exception 256 | [diStorm3]: https://github.com/gdabah/distorm/ 257 | [zydis]: https://github.com/zyantific/zydis 258 | [capstone]: https://github.com/aquynh/capstone 259 | [Wine]: https://www.winehq.org/ 260 | [`CMAKE_BUILD_TYPE`]: https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html 261 | [`CMAKE_INSTALL_PREFIX`]: https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX.html 262 | [soname]: https://en.wikipedia.org/wiki/Soname 263 | [#15]: https://github.com/kubo/funchook/issues/15 264 | [#19]: https://github.com/kubo/funchook/pull/19 265 | [#20]: https://github.com/kubo/funchook/pull/20 266 | [#21]: https://github.com/kubo/funchook/pull/21 267 | [#22]: https://github.com/kubo/funchook/pull/22 268 | [#25]: https://github.com/kubo/funchook/pull/25 269 | [#29]: https://github.com/kubo/funchook/pull/29 270 | [#30]: https://github.com/kubo/funchook/pull/30 271 | [#31]: https://github.com/kubo/funchook/pull/31 272 | [#32]: https://github.com/kubo/funchook/pull/32 273 | [`mprotect`]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/mprotect.2.html 274 | -------------------------------------------------------------------------------- /vendor/funchook/include/funchook.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Funchook. 3 | * https://github.com/kubo/funchook 4 | * 5 | * Funchook is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the 7 | * Free Software Foundation, either version 2 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * As a special exception, the copyright holders of this library give you 11 | * permission to link this library with independent modules to produce an 12 | * executable, regardless of the license terms of these independent 13 | * modules, and to copy and distribute the resulting executable under 14 | * terms of your choice, provided that you also meet, for each linked 15 | * independent module, the terms and conditions of the license of that 16 | * module. An independent module is a module which is not derived from or 17 | * based on this library. If you modify this library, you may extend this 18 | * exception to your version of the library, but you are not obliged to 19 | * do so. If you do not wish to do so, delete this exception statement 20 | * from your version. 21 | * 22 | * Funchook is distributed in the hope that it will be useful, but WITHOUT 23 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 24 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 25 | * for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with Funchook. If not, see . 29 | */ 30 | #ifndef FUNCHOOK_H 31 | #define FUNCHOOK_H 1 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* 38 | * Only functions with FUNCHOOK_EXPORT are visible from outside of funchook.dll 39 | * or libfunchook.so. Others are invisible. 40 | */ 41 | #ifdef FUNCHOOK_EXPORTS 42 | #if defined(_WIN32) 43 | #define FUNCHOOK_EXPORT __declspec(dllexport) 44 | #elif defined(__GNUC__) 45 | #define FUNCHOOK_EXPORT __attribute__((visibility("default"))) 46 | #endif 47 | #endif /* FUNCHOOK_EXPORTS */ 48 | #ifndef FUNCHOOK_EXPORT 49 | #define FUNCHOOK_EXPORT 50 | #endif 51 | 52 | typedef struct funchook funchook_t; 53 | 54 | #define FUNCHOOK_ERROR_INTERNAL_ERROR -1 55 | #define FUNCHOOK_ERROR_SUCCESS 0 56 | #define FUNCHOOK_ERROR_OUT_OF_MEMORY 1 57 | #define FUNCHOOK_ERROR_ALREADY_INSTALLED 2 58 | #define FUNCHOOK_ERROR_DISASSEMBLY 3 59 | #define FUNCHOOK_ERROR_IP_RELATIVE_OFFSET 4 60 | #define FUNCHOOK_ERROR_CANNOT_FIX_IP_RELATIVE 5 61 | #define FUNCHOOK_ERROR_FOUND_BACK_JUMP 6 62 | #define FUNCHOOK_ERROR_TOO_SHORT_INSTRUCTIONS 7 63 | #define FUNCHOOK_ERROR_MEMORY_ALLOCATION 8 /* memory allocation error */ 64 | #define FUNCHOOK_ERROR_MEMORY_FUNCTION 9 /* other memory function errors */ 65 | #define FUNCHOOK_ERROR_NOT_INSTALLED 10 66 | #define FUNCHOOK_ERROR_NO_AVAILABLE_REGISTERS 11 67 | #define FUNCHOOK_ERROR_NO_SPACE_NEAR_TARGET_ADDR 12 68 | 69 | #define FUNCHOOK_FLAG_THISCALL (1u << 0) 70 | #define FUNCHOOK_FLAG_FASTCALL (1u << 1) 71 | 72 | typedef struct funchook_arg_handle funchook_arg_handle_t; 73 | 74 | typedef struct funchook_info { 75 | void *original_target_func; 76 | void *target_func; 77 | void *trampoline_func; 78 | void *hook_func; 79 | void *user_data; 80 | funchook_arg_handle_t *arg_handle; 81 | } funchook_info_t; 82 | 83 | typedef void (*funchook_hook_t)(funchook_info_t *fi); 84 | 85 | typedef struct { 86 | void *hook_func; 87 | funchook_hook_t prehook; 88 | void *user_data; 89 | unsigned int flags; 90 | } funchook_params_t; 91 | 92 | /** 93 | * Create a funchook handle 94 | * 95 | * @return allocated funchook handle. NULL when out-of-memory. 96 | */ 97 | FUNCHOOK_EXPORT funchook_t *funchook_create(void); 98 | 99 | /** 100 | * Prepare hooking 101 | * 102 | * @param funchook a funchook handle created by funchook_create() 103 | * @param target_func function pointer to be intercepted. The pointer to trampoline function is set on success. 104 | * @param hook_func function pointer which is called istead of target_func 105 | * @return error code. one of FUNCHOOK_ERROR_*. 106 | */ 107 | FUNCHOOK_EXPORT int funchook_prepare(funchook_t *funchook, void **target_func, void *hook_func); 108 | 109 | FUNCHOOK_EXPORT int funchook_prepare_with_params(funchook_t *funchook, 110 | void **target_func, const funchook_params_t *params); 111 | 112 | /** 113 | * Install hooks prepared by funchook_prepare(). 114 | * 115 | * @param funchook a funchook handle created by funchook_create() 116 | * @param flags reserved. Set zero. 117 | * @return error code. one of FUNCHOOK_ERROR_*. 118 | */ 119 | FUNCHOOK_EXPORT int funchook_install(funchook_t *funchook, int flags); 120 | 121 | /** 122 | * Uninstall hooks installed by funchook_install(). 123 | * 124 | * @param funchook a funchook handle created by funchook_create() 125 | * @param flags reserved. Set zero. 126 | * @return error code. one of FUNCHOOK_ERROR_*. 127 | */ 128 | FUNCHOOK_EXPORT int funchook_uninstall(funchook_t *funchook, int flags); 129 | 130 | /** 131 | * Destroy a funchook handle 132 | * 133 | * @param funchook a funchook handle created by funchook_create() 134 | * @return error code. one of FUNCHOOK_ERROR_*. 135 | */ 136 | FUNCHOOK_EXPORT int funchook_destroy(funchook_t *funchook); 137 | 138 | /** 139 | * Get error message 140 | * 141 | * @param funchook a funchook handle created by funchook_create() 142 | * @return pointer to buffer containing error message 143 | */ 144 | FUNCHOOK_EXPORT const char *funchook_error_message(const funchook_t *funchook); 145 | 146 | /** 147 | * Set log file name to debug funchook itself. 148 | * 149 | * @param name log file name 150 | * @return error code. one of FUNCHOOK_ERROR_*. 151 | */ 152 | FUNCHOOK_EXPORT int funchook_set_debug_file(const char *name); 153 | 154 | /* This function is under developemnt. It will be used by C++ template functions later. */ 155 | FUNCHOOK_EXPORT void *funchook_arg_get_int_reg_addr(const funchook_arg_handle_t *arg_handle, int pos); 156 | 157 | /* This function is under developemnt. It will be used by C++ template functions later. */ 158 | FUNCHOOK_EXPORT void *funchook_arg_get_flt_reg_addr(const funchook_arg_handle_t *arg_handle, int pos); 159 | 160 | /* This function is under developemnt. It will be used by C++ template functions later. */ 161 | FUNCHOOK_EXPORT void *funchook_arg_get_stack_addr(const funchook_arg_handle_t *arg_handle, int pos); 162 | 163 | #ifdef __cplusplus 164 | } // extern "C" 165 | #endif 166 | 167 | #endif 168 | -------------------------------------------------------------------------------- /vendor/funchook/lib/Debug/distorm.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Source2ZE/CleanerCS2/4c624fde6bbfbb150b340e17037d20a926226329/vendor/funchook/lib/Debug/distorm.lib -------------------------------------------------------------------------------- /vendor/funchook/lib/Debug/distorm.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Source2ZE/CleanerCS2/4c624fde6bbfbb150b340e17037d20a926226329/vendor/funchook/lib/Debug/distorm.pdb -------------------------------------------------------------------------------- /vendor/funchook/lib/Debug/funchook.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Source2ZE/CleanerCS2/4c624fde6bbfbb150b340e17037d20a926226329/vendor/funchook/lib/Debug/funchook.lib -------------------------------------------------------------------------------- /vendor/funchook/lib/Debug/funchook.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Source2ZE/CleanerCS2/4c624fde6bbfbb150b340e17037d20a926226329/vendor/funchook/lib/Debug/funchook.pdb -------------------------------------------------------------------------------- /vendor/funchook/lib/Debug/libdistorm.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Source2ZE/CleanerCS2/4c624fde6bbfbb150b340e17037d20a926226329/vendor/funchook/lib/Debug/libdistorm.a -------------------------------------------------------------------------------- /vendor/funchook/lib/Debug/libfunchook.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Source2ZE/CleanerCS2/4c624fde6bbfbb150b340e17037d20a926226329/vendor/funchook/lib/Debug/libfunchook.a -------------------------------------------------------------------------------- /vendor/funchook/lib/Release/distorm.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Source2ZE/CleanerCS2/4c624fde6bbfbb150b340e17037d20a926226329/vendor/funchook/lib/Release/distorm.lib -------------------------------------------------------------------------------- /vendor/funchook/lib/Release/funchook.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Source2ZE/CleanerCS2/4c624fde6bbfbb150b340e17037d20a926226329/vendor/funchook/lib/Release/funchook.lib -------------------------------------------------------------------------------- /vendor/funchook/lib/Release/libdistorm.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Source2ZE/CleanerCS2/4c624fde6bbfbb150b340e17037d20a926226329/vendor/funchook/lib/Release/libdistorm.a -------------------------------------------------------------------------------- /vendor/funchook/lib/Release/libfunchook.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Source2ZE/CleanerCS2/4c624fde6bbfbb150b340e17037d20a926226329/vendor/funchook/lib/Release/libfunchook.a -------------------------------------------------------------------------------- /xmake.lua: -------------------------------------------------------------------------------- 1 | add_rules("mode.debug", "mode.release") 2 | add_requires("re2") 3 | 4 | includes("@builtin/xpack") 5 | 6 | local SDK_PATH = os.getenv("HL2SDKCS2") 7 | local MM_PATH = os.getenv("MMSOURCE112") 8 | 9 | target("CleanerCS2-Xmake") 10 | set_kind("shared") 11 | add_files("src/*.cpp") 12 | add_packages("re2") 13 | set_symbols("hidden") 14 | 15 | add_files({ 16 | SDK_PATH.."/tier1/convar.cpp", 17 | SDK_PATH.."/public/tier0/memoverride.cpp", 18 | }) 19 | 20 | if is_plat("windows") then 21 | add_links({ 22 | SDK_PATH.."/lib/public/win64/tier0.lib", 23 | SDK_PATH.."/lib/public/win64/tier1.lib", 24 | SDK_PATH.."/lib/public/win64/interfaces.lib", 25 | SDK_PATH.."/lib/public/win64/mathlib.lib", 26 | }) 27 | else 28 | add_links({ 29 | SDK_PATH.."/lib/linux64/libtier0.so", 30 | SDK_PATH.."/lib/linux64/tier1.a", 31 | SDK_PATH.."/lib/linux64/interfaces.a", 32 | SDK_PATH.."/lib/linux64/mathlib.a", 33 | }) 34 | end 35 | 36 | add_linkdirs({ 37 | "vendor/funchook/lib/Release", 38 | }) 39 | 40 | add_links({ 41 | "funchook", 42 | "distorm", 43 | }) 44 | 45 | if is_plat("windows") then 46 | add_links("psapi"); 47 | add_files("src/utils/plat_win.cpp"); 48 | else 49 | add_files("src/utils/plat_unix.cpp"); 50 | end 51 | 52 | add_includedirs({ 53 | "src", 54 | "vendor/funchook/include", 55 | -- sdk 56 | SDK_PATH, 57 | SDK_PATH.."/thirdparty/protobuf-3.21.8/src", 58 | SDK_PATH.."/common", 59 | SDK_PATH.."/game/shared", 60 | SDK_PATH.."/game/server", 61 | SDK_PATH.."/public", 62 | SDK_PATH.."/public/engine", 63 | SDK_PATH.."/public/mathlib", 64 | SDK_PATH.."/public/tier0", 65 | SDK_PATH.."/public/tier1", 66 | SDK_PATH.."/public/entity2", 67 | SDK_PATH.."/public/game/server", 68 | -- metamod 69 | MM_PATH.."/core", 70 | MM_PATH.."/core/sourcehook", 71 | }) 72 | 73 | if(is_plat("windows")) then 74 | add_defines({ 75 | "COMPILER_MSVC", 76 | "COMPILER_MSVC64", 77 | "PLATFORM_64BITS", 78 | "WIN32", 79 | "WINDOWS", 80 | "CRT_SECURE_NO_WARNINGS", 81 | "CRT_SECURE_NO_DEPRECATE", 82 | "CRT_NONSTDC_NO_DEPRECATE", 83 | "_MBCS", 84 | "META_IS_SOURCE2" 85 | }) 86 | else 87 | add_defines({ 88 | "_LINUX", 89 | "LINUX", 90 | "POSIX", 91 | "GNUC", 92 | "COMPILER_GCC", 93 | "PLATFORM_64BITS", 94 | "META_IS_SOURCE2", 95 | "_GLIBCXX_USE_CXX11_ABI=1" 96 | }) 97 | end 98 | set_languages("cxx17") 99 | 100 | xpack("CleanerCS2") 101 | set_formats("zip") 102 | add_installfiles("build/windows/x64/release/CleanerCS2-Xmake.dll", {filename = "cleanercs2.dll", prefixdir = "cleanercs2"}) 103 | add_installfiles("build/linux/x86_64/release/libCleanerCS2-Xmake.so", {filename = "cleanercs2.so", prefixdir = "cleanercs2"}) 104 | add_installfiles("package/config.cfg", {prefixdir = "cleanercs2"}) 105 | add_installfiles("package/cleanercs2.vdf", {prefixdir = "metamod"}) --------------------------------------------------------------------------------