├── .gitignore ├── LICENSE ├── README.md └── mods ├── m417z-windhawk-scan-for-processes-event.wh.cpp ├── valinet-chrome-save-to-downloads-directly.wh.cpp ├── valinet-custom-keyboard.wh.cpp ├── valinet-explorer-classic-drive-grouping.wh.cpp ├── valinet-explorer-hide-current-folder-name-in-search-box.wh.cpp ├── valinet-explorer-hide-quick-access-pins.wh.cpp ├── valinet-explorer-old-search-box.wh.cpp ├── valinet-power-button-action.wh.cpp ├── valinet-systray-battery-brightness.wh.cpp ├── valinet-systray-sound-volume.wh.cpp ├── valinet-unserver.wh.cpp ├── valinet-vmware-frame-fix.wh.cpp └── valinet-waves-audio-fix.wh.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.tlog 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 298 | *.vbp 299 | 300 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 301 | *.dsw 302 | *.dsp 303 | 304 | # Visual Studio 6 technical files 305 | *.ncb 306 | *.aps 307 | 308 | # Visual Studio LightSwitch build output 309 | **/*.HTMLClient/GeneratedArtifacts 310 | **/*.DesktopClient/GeneratedArtifacts 311 | **/*.DesktopClient/ModelManifest.xml 312 | **/*.Server/GeneratedArtifacts 313 | **/*.Server/ModelManifest.xml 314 | _Pvt_Extensions 315 | 316 | # Paket dependency manager 317 | .paket/paket.exe 318 | paket-files/ 319 | 320 | # FAKE - F# Make 321 | .fake/ 322 | 323 | # CodeRush personal settings 324 | .cr/personal 325 | 326 | # Python Tools for Visual Studio (PTVS) 327 | __pycache__/ 328 | *.pyc 329 | 330 | # Cake - Uncomment if you are using it 331 | # tools/** 332 | # !tools/packages.config 333 | 334 | # Tabs Studio 335 | *.tss 336 | 337 | # Telerik's JustMock configuration file 338 | *.jmconfig 339 | 340 | # BizTalk build output 341 | *.btp.cs 342 | *.btm.cs 343 | *.odx.cs 344 | *.xsd.cs 345 | 346 | # OpenCover UI analysis results 347 | OpenCover/ 348 | 349 | # Azure Stream Analytics local run output 350 | ASALocalRun/ 351 | 352 | # MSBuild Binary and Structured Log 353 | *.binlog 354 | 355 | # NVidia Nsight GPU debugger configuration file 356 | *.nvuser 357 | 358 | # MFractors (Xamarin productivity tool) working folder 359 | .mfractor/ 360 | 361 | # Local History for Visual Studio 362 | .localhistory/ 363 | 364 | # Visual Studio History (VSHistory) files 365 | .vshistory/ 366 | 367 | # BeatPulse healthcheck temp database 368 | healthchecksdb 369 | 370 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 371 | MigrationBackup/ 372 | 373 | # Ionide (cross platform F# VS Code tools) working folder 374 | .ionide/ 375 | 376 | # Fody - auto-generated XML schema 377 | FodyWeavers.xsd 378 | 379 | # VS Code files for those working on multiple tools 380 | .vscode/* 381 | !.vscode/settings.json 382 | !.vscode/tasks.json 383 | !.vscode/launch.json 384 | !.vscode/extensions.json 385 | *.code-workspace 386 | 387 | # Local History for Visual Studio Code 388 | .history/ 389 | 390 | # Windows Installer files from build outputs 391 | *.cab 392 | *.msi 393 | *.msix 394 | *.msm 395 | *.msp 396 | 397 | # JetBrains Rider 398 | *.sln.iml 399 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # wh-mods 2 | My collection of Windhawk mods 3 | -------------------------------------------------------------------------------- /mods/m417z-windhawk-scan-for-processes-event.wh.cpp: -------------------------------------------------------------------------------- 1 | // ==WindhawkMod== 2 | // @id windhawk-scan-for-processes-event 3 | // @name WindhawkScanForProcesses 4 | // @description An event for Windhawk to scan for new processes 5 | // @version 1.0 6 | // @author m417z 7 | // @github https://github.com/m417z 8 | // @twitter https://twitter.com/m417z 9 | // @homepage https://m417z.com/ 10 | // @include windhawk.exe 11 | // ==/WindhawkMod== 12 | 13 | #include 14 | 15 | #include 16 | 17 | constexpr WCHAR kScanForProcessesEventName[] = L"WindhawkScanForProcesses"; 18 | 19 | HANDLE g_scanForProcessesEvent; 20 | 21 | HANDLE CreateEventForMediumIntegrity(PCWSTR eventName, BOOL manualReset) { 22 | // Allow only EVENT_MODIFY_STATE (0x0002), only for medium integrity. 23 | PCWSTR pszStringSecurityDescriptor = L"D:(A;;0x0002;;;WD)S:(ML;;NW;;;ME)"; 24 | 25 | HLOCAL secDesc; 26 | if (!ConvertStringSecurityDescriptorToSecurityDescriptor( 27 | pszStringSecurityDescriptor, SDDL_REVISION_1, &secDesc, nullptr)) { 28 | return nullptr; 29 | } 30 | 31 | SECURITY_ATTRIBUTES secAttr = {sizeof(SECURITY_ATTRIBUTES)}; 32 | secAttr.lpSecurityDescriptor = secDesc; 33 | secAttr.bInheritHandle = FALSE; 34 | 35 | HANDLE event = CreateEvent(&secAttr, manualReset, FALSE, eventName); 36 | 37 | LocalFree(secDesc); 38 | 39 | return event; 40 | } 41 | 42 | using WaitForMultipleObjectsEx_t = decltype(&WaitForMultipleObjectsEx); 43 | WaitForMultipleObjectsEx_t WaitForMultipleObjectsEx_Original; 44 | DWORD WINAPI WaitForMultipleObjectsEx_Hook(DWORD nCount, 45 | CONST HANDLE* lpHandles, 46 | WINBOOL bWaitAll, 47 | DWORD dwMilliseconds, 48 | WINBOOL bAlertable) { 49 | void* retAddress = __builtin_return_address(0); 50 | 51 | auto original = [&]() { 52 | return WaitForMultipleObjectsEx_Original(nCount, lpHandles, bWaitAll, 53 | dwMilliseconds, bAlertable); 54 | }; 55 | 56 | HMODULE module; 57 | if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | 58 | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, 59 | (PCWSTR)retAddress, &module) || 60 | module != GetModuleHandle(nullptr)) { 61 | return original(); 62 | } 63 | 64 | Wh_Log(L">"); 65 | 66 | if (nCount >= 10 || bWaitAll) { 67 | return original(); 68 | } 69 | 70 | HANDLE handles[10]; 71 | std::copy(lpHandles, lpHandles + nCount, handles); 72 | handles[nCount] = g_scanForProcessesEvent; 73 | 74 | lpHandles = handles; 75 | nCount++; 76 | 77 | DWORD ret = WaitForMultipleObjectsEx_Original(nCount, lpHandles, bWaitAll, 78 | dwMilliseconds, bAlertable); 79 | if (ret == WAIT_OBJECT_0 + nCount - 1) { 80 | Wh_Log(L"Got WindhawkScanForProcesses event"); 81 | ret = WAIT_TIMEOUT; 82 | } 83 | 84 | return ret; 85 | } 86 | 87 | BOOL Wh_ModInit() { 88 | Wh_Log(L">"); 89 | 90 | bool serviceProcess = false; 91 | 92 | int argc; 93 | LPWSTR* argv = CommandLineToArgvW(GetCommandLine(), &argc); 94 | if (!argv) { 95 | Wh_Log(L"CommandLineToArgvW failed"); 96 | return FALSE; 97 | } 98 | 99 | for (int i = 1; i < argc; i++) { 100 | if (wcscmp(argv[i], L"-service") == 0) { 101 | serviceProcess = true; 102 | break; 103 | } 104 | } 105 | 106 | LocalFree(argv); 107 | 108 | if (!serviceProcess) { 109 | return FALSE; 110 | } 111 | 112 | g_scanForProcessesEvent = 113 | CreateEventForMediumIntegrity(kScanForProcessesEventName, FALSE); 114 | if (!g_scanForProcessesEvent) { 115 | Wh_Log(L"CreateEvent failed"); 116 | return FALSE; 117 | } 118 | 119 | Wh_SetFunctionHook((void*)WaitForMultipleObjectsEx, 120 | (void*)WaitForMultipleObjectsEx_Hook, 121 | (void**)&WaitForMultipleObjectsEx_Original); 122 | 123 | return TRUE; 124 | } 125 | 126 | void Wh_ModUninit() { 127 | Wh_Log(L">"); 128 | 129 | if (g_scanForProcessesEvent) { 130 | CloseHandle(g_scanForProcessesEvent); 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /mods/valinet-chrome-save-to-downloads-directly.wh.cpp: -------------------------------------------------------------------------------- 1 | // ==WindhawkMod== 2 | // @id valinet-chrome-save-to-downloads-directly 3 | // @name Chrome: Bypass Save As dialog 4 | // @description Bypass the Save As dialog in Chrome and immediatly save file 5 | // @version 0.1 6 | // @author valinet 7 | // @github https://github.com/valinet 8 | // @include chrome.exe 9 | // @compilerOptions -lcomdlg32 -lOle32 -ldwmapi 10 | // ==/WindhawkMod== 11 | 12 | // ==WindhawkModReadme== 13 | /* 14 | # Chrome: Bypass Save As dialog 15 | Bypass the Save As dialog in Chrome and immediatly save file 16 | */ 17 | // ==/WindhawkModReadme== 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | struct ccomobj { 29 | void** lpVtbl; 30 | }; 31 | 32 | DWORD dwThreadId = 0; 33 | 34 | HWND (*CreateWindowExWFunc)(DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam) = nullptr; 35 | HWND CreateWindowExWHook(DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam) { 36 | return CreateWindowExWFunc(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam); 37 | } 38 | 39 | BOOL CALLBACK EnumButtons(HWND hWnd, LPARAM lp) { 40 | if (GetMenu(hWnd) == reinterpret_cast(IDOK)) { 41 | *(reinterpret_cast(lp)) = hWnd; 42 | return FALSE; 43 | } 44 | return TRUE; 45 | } 46 | 47 | INT_PTR (CALLBACK *DlgProcFunc)(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) = nullptr; 48 | INT_PTR CALLBACK DlgProcHook(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { 49 | if (uMsg == WM_INITDIALOG) { 50 | BOOL cloak = TRUE; 51 | DwmSetWindowAttribute(hWnd, DWMWA_CLOAK, reinterpret_cast(&cloak), sizeof(BOOL)); 52 | } else if (uMsg == WM_SHOWWINDOW) { 53 | HWND hBtnSave = nullptr; 54 | EnumChildWindows(hWnd, &EnumButtons, reinterpret_cast(&hBtnSave)); 55 | if (hBtnSave) { 56 | PostMessageW(hWnd, WM_COMMAND, MAKEWPARAM(IDOK, BN_CLICKED), reinterpret_cast(hBtnSave)); 57 | } 58 | } 59 | return DlgProcFunc(hWnd, uMsg, wParam, lParam); 60 | } 61 | 62 | INT_PTR (*DialogBoxIndirectParamWFunc)(HINSTANCE hInstance, LPCDLGTEMPLATEW hDialogTemplate, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam) = nullptr; 63 | INT_PTR DialogBoxIndirectParamWHook(HINSTANCE hInstance, LPDLGTEMPLATEW hDialogTemplate, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam) { 64 | if (dwThreadId == GetCurrentThreadId()) { 65 | DlgProcFunc = lpDialogFunc; 66 | lpDialogFunc = &DlgProcHook; 67 | dwThreadId = 0; 68 | } 69 | return DialogBoxIndirectParamWFunc(hInstance, hDialogTemplate, hWndParent, lpDialogFunc, dwInitParam); 70 | } 71 | 72 | HRESULT (*IModalWindow_ShowFunc)(void* _this, HWND hWndOwner) = nullptr; 73 | HRESULT IModalWindow_ShowHook(void* _this, HWND hWndOwner) { 74 | dwThreadId = GetCurrentThreadId(); 75 | return IModalWindow_ShowFunc(_this, hWndOwner); 76 | } 77 | 78 | HRESULT (*CoCreateInstanceFunc)(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID riid, LPVOID *ppv) = nullptr; 79 | HRESULT CoCreateInstanceHook(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID riid, LPVOID *ppv) { 80 | if (!(GetAsyncKeyState(VK_MENU) & 0x01) && IsEqualCLSID(rclsid, CLSID_FileSaveDialog) && IsEqualIID(riid, __uuidof(IFileSaveDialog))) { 81 | auto hr = CoCreateInstanceFunc(rclsid, pUnkOuter, dwClsContext, riid, ppv); 82 | if (SUCCEEDED(hr)) { 83 | IFileSaveDialog *pfd = reinterpret_cast(*ppv); 84 | if (pfd) { 85 | struct ccomobj* praw = reinterpret_cast(pfd); 86 | DWORD dwOldProtect = PAGE_EXECUTE_READWRITE; 87 | if (VirtualProtect(praw->lpVtbl + 3, sizeof(void*), dwOldProtect, &dwOldProtect)) { 88 | IModalWindow_ShowFunc = reinterpret_cast(praw->lpVtbl[3]); 89 | praw->lpVtbl[3] = reinterpret_cast(&IModalWindow_ShowHook); 90 | VirtualProtect(praw->lpVtbl + 3, sizeof(void*), dwOldProtect, &dwOldProtect); 91 | } 92 | } 93 | } 94 | return hr; 95 | } 96 | return CoCreateInstanceFunc(rclsid, pUnkOuter, dwClsContext, riid, ppv); 97 | } 98 | 99 | BOOL Wh_ModInit() { 100 | Wh_Log(L"Init"); 101 | //Wh_SetFunctionHook(reinterpret_cast(&CreateWindowExW), reinterpret_cast(&CreateWindowExWHook), reinterpret_cast(&CreateWindowExWFunc)); 102 | Wh_SetFunctionHook(reinterpret_cast(&DialogBoxIndirectParamW), reinterpret_cast(&DialogBoxIndirectParamWHook), reinterpret_cast(&DialogBoxIndirectParamWFunc)); 103 | Wh_SetFunctionHook(reinterpret_cast(&CoCreateInstance), reinterpret_cast(&CoCreateInstanceHook), reinterpret_cast(&CoCreateInstanceFunc)); 104 | return TRUE; 105 | } 106 | 107 | // The mod is being unloaded, free all allocated resources. 108 | void Wh_ModUninit() { 109 | //if (CreateWindowExWFunc) Wh_RemoveFunctionHook(reinterpret_cast(&CreateWindowExW)); 110 | if (DialogBoxIndirectParamWFunc) Wh_RemoveFunctionHook(reinterpret_cast(&DialogBoxIndirectParamW)); 111 | if (CoCreateInstanceFunc) Wh_RemoveFunctionHook(reinterpret_cast(&CoCreateInstance)); 112 | Wh_Log(L"Uninit"); 113 | } 114 | 115 | // The mod setting were changed, reload them. 116 | void Wh_ModSettingsChanged() { 117 | Wh_Log(L"SettingsChanged"); 118 | } 119 | -------------------------------------------------------------------------------- /mods/valinet-custom-keyboard.wh.cpp: -------------------------------------------------------------------------------- 1 | // ==WindhawkMod== 2 | // @id valinet-custom-keyboard 3 | // @name Custom Keyboard Mapping 4 | // @description Hackish way to have different customized key mappings for each physical keyboard. 5 | // @version 0.1 6 | // @author valinet 7 | // @github https://github.com/valinet 8 | // @include windhawk.exe 9 | // @compilerOptions -lWtsapi32 10 | // ==/WindhawkMod== 11 | 12 | // ==WindhawkModReadme== 13 | /* 14 | # Custom Keyboard Mapping 15 | Hackish way to have different customized key mappings for each physical keyboard. 16 | */ 17 | // ==/WindhawkModReadme== 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #define ID_KB_LAPTOP 0x777528c4 34 | #define ID_KB_DESKTOP 0x86893132 35 | 36 | #define Wh_Log_External 37 | #define Wh_Log_Original 38 | //#define Wh_Log_External OutputDebugString 39 | //#define Wh_Log_Original Wh_Log 40 | 41 | #define QWORD INT64 42 | 43 | EXTERN_C IMAGE_DOS_HEADER __ImageBase; 44 | #define HINST_THISCOMPONENT ((HINSTANCE)&__ImageBase) 45 | BOOL(CALLBACK *IsTopLevelWindow)(HWND) = nullptr; 46 | 47 | uint32_t generateIdFromWString(std::wstring& str) { 48 | unsigned int h; 49 | wchar_t *p; 50 | h = 0; 51 | for (p = (wchar_t*)str.data(); *p != '\0'; p++) 52 | h = 31 * h + *p; 53 | return h; // or, h % ARRAY_SIZE; 54 | } 55 | 56 | BOOL IsLocalSystem() { 57 | HANDLE hToken; 58 | UCHAR bTokenUser[sizeof(TOKEN_USER) + 8 + 4 * SID_MAX_SUB_AUTHORITIES]; 59 | PTOKEN_USER pTokenUser = (PTOKEN_USER)bTokenUser; 60 | ULONG cbTokenUser; 61 | SID_IDENTIFIER_AUTHORITY siaNT = SECURITY_NT_AUTHORITY; 62 | PSID pSystemSid; 63 | BOOL bSystem; 64 | 65 | if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) return FALSE; 66 | if (!GetTokenInformation(hToken, TokenUser, pTokenUser, sizeof(bTokenUser), &cbTokenUser)) { 67 | CloseHandle(hToken); 68 | return FALSE; 69 | } 70 | CloseHandle(hToken); 71 | if (!AllocateAndInitializeSid(&siaNT, 1, SECURITY_LOCAL_SYSTEM_RID, 0, 0, 0, 0, 0, 0, 0, &pSystemSid)) return FALSE; 72 | bSystem = EqualSid(pTokenUser->User.Sid, pSystemSid); 73 | FreeSid(pSystemSid); 74 | return bSystem; 75 | } 76 | 77 | struct keyboardData { 78 | uint32_t id; 79 | std::wstring hardwareId; 80 | std::wstring friendlyName; 81 | } currentKeyboard; 82 | std::unordered_map keyboards; 83 | 84 | LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) { 85 | KBDLLHOOKSTRUCT* st = reinterpret_cast(lParam); 86 | if (!(st->flags & LLKHF_INJECTED) && nCode == HC_ACTION && (wParam == WM_KEYDOWN || wParam == WM_KEYUP)) { 87 | if (currentKeyboard.id == ID_KB_LAPTOP && st->vkCode == VK_F12) { 88 | keybd_event(VK_END, 0, wParam == WM_KEYUP ? KEYEVENTF_KEYUP : 0, 0); 89 | return 1; 90 | } else if (currentKeyboard.id == ID_KB_LAPTOP && st->vkCode == VK_END) { 91 | keybd_event(VK_F12, 0, wParam == WM_KEYUP ? KEYEVENTF_KEYUP : 0, 0); 92 | return 1; 93 | } else if (currentKeyboard.id == ID_KB_LAPTOP && st->vkCode == VK_F11) { 94 | keybd_event(VK_HOME, 0, wParam == WM_KEYUP ? KEYEVENTF_KEYUP : 0, 0); 95 | return 1; 96 | } else if (currentKeyboard.id == ID_KB_LAPTOP && st->vkCode == VK_HOME) { 97 | keybd_event(VK_F11, 0, wParam == WM_KEYUP ? KEYEVENTF_KEYUP : 0, 0); 98 | return 1; 99 | } else if (currentKeyboard.id == ID_KB_LAPTOP && st->vkCode == VK_F10) { 100 | keybd_event(VK_PRINT, 0, wParam == WM_KEYUP ? KEYEVENTF_KEYUP : 0, 0); 101 | return 1; 102 | } else if (currentKeyboard.id == ID_KB_LAPTOP && st->vkCode == VK_PRINT) { 103 | keybd_event(VK_F10, 0, wParam == WM_KEYUP ? KEYEVENTF_KEYUP : 0, 0); 104 | return 1; 105 | } else if (st->vkCode == VK_F1) { 106 | keybd_event(VK_MEDIA_PLAY_PAUSE, 0, wParam == WM_KEYUP ? KEYEVENTF_KEYUP : 0, 0); 107 | return 1; 108 | } else if (st->vkCode == VK_F2) { 109 | keybd_event(VK_VOLUME_DOWN, 0, wParam == WM_KEYUP ? KEYEVENTF_KEYUP : 0, 0); 110 | return 1; 111 | } else if (st->vkCode == VK_F3) { 112 | keybd_event(VK_VOLUME_UP, 0, wParam == WM_KEYUP ? KEYEVENTF_KEYUP : 0, 0); 113 | return 1; 114 | } else if (st->vkCode == VK_VOLUME_MUTE) { 115 | keybd_event(VK_F1, 0, wParam == WM_KEYUP ? KEYEVENTF_KEYUP : 0, 0); 116 | return 1; 117 | } else if (st->vkCode == VK_VOLUME_DOWN) { 118 | keybd_event(VK_F2, 0, wParam == WM_KEYUP ? KEYEVENTF_KEYUP : 0, 0); 119 | return 1; 120 | } else if (st->vkCode == VK_VOLUME_UP) { 121 | keybd_event(VK_F3, 0, wParam == WM_KEYUP ? KEYEVENTF_KEYUP : 0, 0); 122 | return 1; 123 | } else if (st->vkCode == VK_CAPITAL) { 124 | if (wParam == WM_KEYUP) keybd_event(VK_F2, 0, KEYEVENTF_KEYUP, 0); 125 | else keybd_event(VK_F2, 0, 0, 0); 126 | return 1; 127 | } 128 | } 129 | return CallNextHookEx(nullptr, nCode, wParam, lParam); 130 | } 131 | 132 | void CALLBACK Wineventproc(HWINEVENTHOOK hWinEventHook, DWORD event, HWND hwnd, LONG idObject, LONG idChild, DWORD idEventThread, DWORD dwmsEventTime) { 133 | if (((event == EVENT_OBJECT_CREATE) && hwnd && idObject == OBJID_WINDOW) || ((event == EVENT_SYSTEM_FOREGROUND) && hwnd && (idObject == OBJID_WINDOW) && IsTopLevelWindow && IsTopLevelWindow(hwnd))) { 134 | if (RegisterWindowMessageW(L"TscShellContainerClass") == GetClassWord(hwnd, GCW_ATOM)) { 135 | PostThreadMessageW(GetCurrentThreadId(), WM_USER, 0, 0); 136 | } 137 | } 138 | } 139 | 140 | extern "C" int procMain(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int nCmdShow) { 141 | int rv = 0xFFFFFFFF; 142 | 143 | SECURITY_DESCRIPTOR sd; 144 | InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION); 145 | SetSecurityDescriptorDacl(&sd, true, nullptr, false); 146 | SECURITY_ATTRIBUTES sa = { }; 147 | sa.nLength = sizeof(sa); 148 | sa.bInheritHandle = false; 149 | sa.lpSecurityDescriptor = &sd; 150 | SetLastError(ERROR_SUCCESS); 151 | HANDLE mutSingleInstance = CreateMutexW(&sa, false, L"Global\\{4B360CA7-967F-4FA2-BC4A-885F1106ACB0}"); 152 | if (GetLastError() == ERROR_ALREADY_EXISTS) { 153 | CloseHandle(mutSingleInstance); 154 | ExitProcess(ERROR_ALREADY_EXISTS); 155 | } 156 | 157 | MSG msg; 158 | PeekMessageW(&msg, nullptr, 0, 0, PM_NOREMOVE); 159 | wchar_t wszMsg[MAX_PATH * 4]; 160 | currentKeyboard.id = ID_KB_LAPTOP; 161 | 162 | BOOL bRegisteredForWTS = WTSRegisterSessionNotification(hWnd, NOTIFY_FOR_ALL_SESSIONS); 163 | swprintf_s(wszMsg, L"WTSRegisterSessionNotification: %d\n", bRegisteredForWTS); 164 | Wh_Log_External(wszMsg); 165 | 166 | DWORD dwProcessSessionId = 0xFFFFFFFF, dwActiveSessionId = WTSGetActiveConsoleSessionId(); 167 | ProcessIdToSessionId(GetCurrentProcessId(), &dwProcessSessionId); 168 | if (dwActiveSessionId != 0xFFFFFFFF && dwProcessSessionId != dwActiveSessionId) { 169 | swprintf_s(wszMsg, L"Did not start in active session, exiting...\n"); 170 | Wh_Log_External(wszMsg); 171 | if (bRegisteredForWTS) WTSUnRegisterSessionNotification(hWnd); 172 | if (mutSingleInstance) CloseHandle(mutSingleInstance); 173 | ExitProcess(rv); 174 | } 175 | 176 | if (!IsTopLevelWindow) { 177 | HMODULE hUser32 = GetModuleHandleW(L"user32"); 178 | if (hUser32) { 179 | IsTopLevelWindow = reinterpret_cast(GetProcAddress(hUser32, "IsTopLevelWindow")); 180 | }; 181 | } 182 | 183 | HHOOK hHook = nullptr; 184 | hHook = SetWindowsHookExW(WH_KEYBOARD_LL, &LowLevelKeyboardProc, hInstance, 0); 185 | swprintf_s(wszMsg, L"SetWindowsHookExW: %d\n", hHook); 186 | Wh_Log_External(wszMsg); 187 | 188 | HWINEVENTHOOK hWinEventHook = nullptr; 189 | hWinEventHook = SetWinEventHook(EVENT_MIN, EVENT_MAX, nullptr, &Wineventproc, 0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS); 190 | swprintf_s(wszMsg, L"SetWinEventHook: %d\n", hWinEventHook); 191 | Wh_Log_External(wszMsg); 192 | 193 | RAWINPUTDEVICE rid{}; 194 | rid.dwFlags = RIDEV_NOLEGACY | RIDEV_INPUTSINK; 195 | rid.usUsagePage = 1; 196 | rid.usUsage = 6; 197 | rid.hwndTarget = hWnd; 198 | swprintf_s(wszMsg, L"RegisterRawInputDevices: %d\n", RegisterRawInputDevices(&rid, 1, sizeof(rid))); 199 | Wh_Log_External(wszMsg); 200 | 201 | HMODULE hHid = nullptr; 202 | hHid = LoadLibraryW(L"Hid.dll"); 203 | BOOLEAN WINAPI (*HidD_GetProductStringFunc)(HANDLE, PVOID, ULONG) = nullptr; 204 | if (hHid) HidD_GetProductStringFunc = reinterpret_cast(GetProcAddress(hHid, "HidD_GetProductString")); 205 | swprintf_s(wszMsg, L"HidD_GetProductStringFunc: %p\n", HidD_GetProductStringFunc); 206 | Wh_Log_External(wszMsg); 207 | 208 | DWORD dwWait = INFINITE; 209 | while (true) { 210 | bool isQuiting = false; 211 | rv = MsgWaitForMultipleObjects(0, nullptr, false, dwWait, QS_ALLINPUT); 212 | if (rv != WAIT_OBJECT_0 && rv != WAIT_TIMEOUT) break; 213 | if (rv == WAIT_TIMEOUT) { 214 | if (hHook) UnhookWindowsHookEx(hHook); 215 | hHook = SetWindowsHookExW(WH_KEYBOARD_LL, &LowLevelKeyboardProc, hInstance, 0); 216 | dwWait = INFINITE; 217 | } 218 | UINT64 rawBuffer[1024 / 8]; 219 | UINT bytes = sizeof(rawBuffer); 220 | auto count = GetRawInputBuffer((PRAWINPUT)rawBuffer, &bytes, sizeof(RAWINPUTHEADER)); 221 | if (count > 0) { 222 | const RAWINPUT* raw = (const RAWINPUT*)rawBuffer; 223 | while (true) { 224 | if (raw->header.dwType == RIM_TYPEKEYBOARD && raw->header.hDevice) { 225 | if (!keyboards.contains(raw->header.hDevice)) { 226 | TCHAR deviceName[MAX_PATH * 4]{}; 227 | UINT size = sizeof(deviceName); 228 | if (GetRawInputDeviceInfoW(raw->header.hDevice, RIDI_DEVICENAME, deviceName, &size) > 0) { 229 | HANDLE HIDHandle = CreateFileW(deviceName, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, NULL); 230 | if (HIDHandle && HIDHandle != INVALID_HANDLE_VALUE) { 231 | wchar_t wszProductString[MAX_PATH * 4]{}; 232 | if (HidD_GetProductStringFunc) HidD_GetProductStringFunc(HIDHandle, wszProductString, sizeof(wszProductString)); 233 | struct keyboardData keyboard; 234 | keyboard.hardwareId = std::wstring(deviceName); 235 | keyboard.id = generateIdFromWString(keyboard.hardwareId); 236 | keyboard.friendlyName = std::wstring(wszProductString); 237 | keyboards.insert({ raw->header.hDevice, keyboard }); 238 | swprintf_s(wszMsg, L">>> adding %x, %x\n", raw->header.hDevice, keyboard.id);// : %x <> %s , %s\n", raw->header.hDevice, keyboard.id, keyboard.friendlyName.c_str(), keyboard.hardwareId.c_str()); 239 | Wh_Log_External(wszMsg); 240 | CloseHandle(HIDHandle); 241 | } 242 | } 243 | } 244 | if (keyboards.contains(raw->header.hDevice)) { 245 | currentKeyboard = keyboards.at(raw->header.hDevice); 246 | swprintf_s(wszMsg, L"keyboard: %x\n", keyboards.at(raw->header.hDevice).id); 247 | Wh_Log_External(wszMsg); 248 | } 249 | } 250 | count--; 251 | if (count <= 0) break; 252 | raw = NEXTRAWINPUTBLOCK(raw); 253 | } 254 | while (PeekMessageW(&msg, 0, WM_INPUT, WM_INPUT, PM_REMOVE)) {}; 255 | } 256 | while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) { 257 | if (msg.message == WM_QUIT) { 258 | swprintf_s(wszMsg, L"Quitting (WM_QUIT)...\n"); 259 | Wh_Log_External(wszMsg); 260 | rv = 0xFFFFFFFF; 261 | isQuiting = true; 262 | break; 263 | } 264 | else if (msg.message == WM_WTSSESSION_CHANGE) { 265 | if (msg.wParam == WTS_CONSOLE_CONNECT || msg.wParam == WTS_SESSION_LOGOFF) { 266 | swprintf_s(wszMsg, L"Quitting (WM_WTSSESSION_CHANGE, %d, %d)...\n", msg.wParam, msg.lParam); 267 | Wh_Log_External(wszMsg); 268 | rv = msg.lParam; 269 | isQuiting = true; 270 | break; 271 | } 272 | } 273 | else if (msg.message == WM_USER) { 274 | dwWait = 100; 275 | } 276 | else { 277 | TranslateMessage(&msg); 278 | DispatchMessageW(&msg); 279 | } 280 | } 281 | if (isQuiting) break; 282 | } 283 | 284 | if (hHid) FreeLibrary(hHid); 285 | if (hWinEventHook) UnhookWinEvent(hWinEventHook); 286 | if (hHook) UnhookWindowsHookEx(hHook); 287 | if (bRegisteredForWTS) WTSUnRegisterSessionNotification(hWnd); 288 | if (mutSingleInstance) CloseHandle(mutSingleInstance); 289 | ExitProcess(rv); 290 | } 291 | 292 | DWORD WINAPI procClose(LPVOID dwMainTid) { 293 | return PostThreadMessageW(reinterpret_cast(dwMainTid), WM_QUIT, 0, 0); 294 | } 295 | 296 | PROCESS_INFORMATION pi{}; 297 | std::mutex mut_pi; 298 | std::thread worker; 299 | 300 | BOOL Wh_ModInit() { 301 | bool isSystemAccount = IsLocalSystem(); 302 | Wh_Log_Original(L"Init %d\n", isSystemAccount); 303 | if (isSystemAccount) { 304 | mut_pi.lock(); 305 | worker = std::thread([](){ 306 | Wh_Log_Original(L"Started worker.\n"); 307 | while (true) { 308 | wchar_t wszPath[MAX_PATH]; 309 | GetWindowsDirectory(wszPath, MAX_PATH); 310 | wchar_t wszArguments[MAX_PATH]{}; 311 | GetModuleFileNameW(HINST_THISCOMPONENT, wszArguments, MAX_PATH); 312 | wchar_t wszCommand[MAX_PATH * 3]; 313 | BOOL amI32Bit = FALSE; 314 | if (!IsWow64Process(GetCurrentProcess(), &amI32Bit) || amI32Bit) swprintf_s(wszCommand, L"\"%s\\SysWOW64\\rundll32.exe\" %s,procMain", wszPath, wszArguments); 315 | else swprintf_s(wszCommand, L"\"%s\\System32\\rundll32.exe\" %s,procMain", wszPath, wszArguments); 316 | Wh_Log_Original(L"%s\n", wszCommand); 317 | HANDLE procInteractiveWinlogon = INVALID_HANDLE_VALUE; 318 | PROCESSENTRY32 entry; 319 | entry.dwSize = sizeof(PROCESSENTRY32); 320 | HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); 321 | if (hSnapshot) { 322 | if (Process32First(hSnapshot, &entry) == TRUE) { 323 | DWORD dwActiveSessionId = WTSGetActiveConsoleSessionId(); 324 | if (dwActiveSessionId == 0xFFFFFFFF) { 325 | Wh_Log_Original(L"No session is active.\n"); 326 | } 327 | while (Process32Next(hSnapshot, &entry) == TRUE) { 328 | if (!wcsicmp(entry.szExeFile, L"winlogon.exe")) { 329 | DWORD dwWinLogonSessionId = 0xFFFFFFFF; 330 | ProcessIdToSessionId(entry.th32ProcessID, &dwWinLogonSessionId); 331 | if (dwActiveSessionId == 0xFFFFFFFF || dwActiveSessionId == dwWinLogonSessionId) { 332 | if ((procInteractiveWinlogon = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, entry.th32ProcessID))) { 333 | BOOL bIs32Bit = FALSE; 334 | if (!IsWow64Process(procInteractiveWinlogon, &bIs32Bit) || bIs32Bit) { 335 | CloseHandle(procInteractiveWinlogon); 336 | procInteractiveWinlogon = INVALID_HANDLE_VALUE; 337 | continue; 338 | } 339 | break; 340 | } 341 | } 342 | } 343 | } 344 | } 345 | CloseHandle(hSnapshot); 346 | } 347 | Wh_Log_Original(L"procInteractiveWinlogon: %p\n", procInteractiveWinlogon); 348 | HANDLE tknInteractive = INVALID_HANDLE_VALUE; 349 | if (procInteractiveWinlogon && procInteractiveWinlogon != INVALID_HANDLE_VALUE) { 350 | HANDLE tknWinlogon = INVALID_HANDLE_VALUE; 351 | if (OpenProcessToken(procInteractiveWinlogon, TOKEN_DUPLICATE, &tknWinlogon) && tknWinlogon && tknWinlogon != INVALID_HANDLE_VALUE) { 352 | SECURITY_ATTRIBUTES tokenAttributes; 353 | ZeroMemory(&tokenAttributes, sizeof(SECURITY_ATTRIBUTES)); 354 | tokenAttributes.nLength = sizeof(SECURITY_ATTRIBUTES); 355 | DuplicateTokenEx(tknWinlogon, 0x10000000, &tokenAttributes, SecurityImpersonation, TokenImpersonation, &tknInteractive); 356 | CloseHandle(tknWinlogon); 357 | } 358 | CloseHandle(procInteractiveWinlogon); 359 | } 360 | Wh_Log_Original(L"tknInteractive: %p\n", tknInteractive); 361 | if (tknInteractive && tknInteractive != INVALID_HANDLE_VALUE) { 362 | STARTUPINFO si{}; 363 | si.cb = sizeof(si); 364 | si.lpDesktop = (LPWSTR)L"WinSta0\\Default"; 365 | CreateProcessAsUserW(tknInteractive, nullptr, wszCommand, nullptr, nullptr, false, INHERIT_CALLER_PRIORITY, nullptr, nullptr, &si, &pi); 366 | CloseHandle(tknInteractive); 367 | mut_pi.unlock(); 368 | WaitForSingleObject(pi.hProcess, INFINITE); 369 | mut_pi.lock(); 370 | DWORD dwExitCode = -1; 371 | GetExitCodeProcess(pi.hProcess, &dwExitCode); 372 | Wh_Log_Original(L"Exited process with %d.\n", dwExitCode); 373 | CloseHandle(pi.hThread); 374 | CloseHandle(pi.hProcess); 375 | mut_pi.unlock(); 376 | break; 377 | } else { 378 | mut_pi.unlock(); 379 | break; 380 | } 381 | } 382 | }); 383 | return TRUE; 384 | } 385 | return FALSE; 386 | } 387 | 388 | void Wh_ModUninit() { 389 | mut_pi.lock(); 390 | if (pi.hThread) { 391 | HANDLE hThread = CreateRemoteThread(pi.hProcess, nullptr, 0, &procClose, reinterpret_cast(GetThreadId(pi.hThread)), 0, nullptr); 392 | if (hThread) { 393 | DWORD dwExitCode = 1; 394 | GetExitCodeProcess(hThread, &dwExitCode); 395 | Wh_Log_Original(L"Exited thread with %d.\n", dwExitCode); 396 | CloseHandle(hThread); 397 | } 398 | } 399 | mut_pi.unlock(); 400 | if (worker.native_handle()) { 401 | worker.join(); 402 | Wh_Log_Original(L"Ended worker.\n"); 403 | } 404 | Wh_Log_Original(L"Uninit"); 405 | } 406 | 407 | void Wh_ModSettingsChanged() { 408 | Wh_Log_Original(L"SettingsChanged"); 409 | } 410 | -------------------------------------------------------------------------------- /mods/valinet-explorer-classic-drive-grouping.wh.cpp: -------------------------------------------------------------------------------- 1 | // ==WindhawkMod== 2 | // @id valinet-explorer-classic-drive-grouping 3 | // @name Explorer: Classic drive grouping 4 | // @description Explorer: Classic drive grouping 5 | // @version 1.5.7 6 | // @author valinet 7 | // @github https://github.com/valinet 8 | // @include * 9 | // @compilerOptions -loleaut32 10 | // ==/WindhawkMod== 11 | 12 | // ==WindhawkModReadme== 13 | /*...*/ 14 | // ==/WindhawkModReadme== 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | std::vector hookedFunctions; 29 | HMODULE hPropsys = nullptr; 30 | HMODULE hShell32 = nullptr; 31 | 32 | #ifdef _WIN64 33 | # define THISCALL __cdecl 34 | # define STHISCALL L"__cdecl" 35 | 36 | # define STDCALL __cdecl 37 | # define SSTDCALL L"__cdecl" 38 | #else 39 | # define THISCALL __thiscall 40 | # define STHISCALL L"__thiscall" 41 | 42 | # define STDCALL __stdcall 43 | # define SSTDCALL L"__stdcall" 44 | #endif 45 | 46 | #define SHARED_SECTION __attribute__((section(".shared"))) 47 | asm(".section .shared,\"dws\"\n"); 48 | 49 | typedef HRESULT (WINAPI *VariantToBuffer_t)(LPVARIANT, void *, UINT); 50 | VariantToBuffer_t VariantToBuffer = nullptr; 51 | 52 | typedef struct tagDRIVEGROUPI18N { 53 | LANGID lid; 54 | WCHAR szHardDisks[256]; 55 | WCHAR szRemovable[256]; 56 | WCHAR szOther[256]; 57 | WCHAR szScanners[256]; 58 | WCHAR szPortableMedia[256]; 59 | WCHAR szPortable[256]; 60 | } DRIVEGROUPI18N; 61 | 62 | typedef const DRIVEGROUPI18N *LPCDRIVEGROUPI18N; 63 | 64 | typedef enum _DRIVEGROUP { 65 | DG_HARDDISKS = 0, 66 | DG_REMOVABLE, 67 | DG_OTHER, 68 | DG_SCANNERS, 69 | DG_PORTABLEMEDIA, 70 | DG_PORTABLE 71 | } DRIVEGROUP; 72 | 73 | #pragma region "Drive grouping localization" 74 | const DRIVEGROUPI18N g_driveGroupI18n[] = { 75 | { 76 | MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_SAUDI_ARABIA), 77 | L"محركات الأقراص الثابتة", 78 | L"أجهزة ذات وحدة تخزين قابلة للنقل", 79 | L"أخرى", 80 | L"الماسحات الضوئية والكاميرات", 81 | L"أجهزة الوسائط المحمولة", 82 | L"الأجهزة المحمولة" 83 | }, 84 | { 85 | MAKELANGID(LANG_BULGARIAN, SUBLANG_DEFAULT), 86 | L"Твърди дискови устройства", 87 | L"Устройства със сменяеми носители", 88 | L"Друго", 89 | L"Скенери и фотоапарати", 90 | L"Преносими мултимедийни устройства", 91 | L"Преносими устройства" 92 | }, 93 | { 94 | MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL), 95 | L"硬碟", 96 | L"裝置中含有卸除式存放裝置", 97 | L"其他", 98 | L"掃描器與數位相機", 99 | L"可攜式媒體裝置", 100 | L"可攜式裝置" 101 | }, 102 | { 103 | MAKELANGID(LANG_CZECH, SUBLANG_DEFAULT), 104 | L"Jednotky pevných disků", 105 | L"Zařízení s vyměnitelným úložištěm", 106 | L"Jiná", 107 | L"Skenery a fotoaparáty", 108 | L"Portable Media Devices", 109 | L"Přenosná zařízení" 110 | }, 111 | { 112 | MAKELANGID(LANG_DANISH, SUBLANG_DEFAULT), 113 | L"Harddiskdrev", 114 | L"Enheder med flytbare medier", 115 | L"Andet", 116 | L"Scannere og kameraer", 117 | L"Bærbare medieenheder", 118 | L"Bærbare enheder" 119 | }, 120 | { 121 | MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN), 122 | L"Festplatten", 123 | L"Geräte mit Wechselmedien", 124 | L"Weitere", 125 | L"Scanner und Kameras", 126 | L"Tragbare Mediengeräte", 127 | L"Tragbare Geräte" 128 | }, 129 | { 130 | MAKELANGID(LANG_GREEK, SUBLANG_DEFAULT), 131 | L"Μονάδες σκληρών δίσκων", 132 | L"Συσκευές με αφαιρούμενα μέσα αποθήκευσης", 133 | L"Άλλα", 134 | L"Σαρωτές και κάμερες", 135 | L"Φορητές συσκευές πολυμέσων", 136 | L"Φορητές συσκευές" 137 | }, 138 | { 139 | MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 140 | L"Hard Disk Drives", 141 | L"Devices with Removable Storage", 142 | L"Other", 143 | L"Scanners and Cameras", 144 | L"Portable Media Devices", 145 | L"Portable Devices" 146 | }, 147 | { 148 | MAKELANGID(LANG_FINNISH, SUBLANG_DEFAULT), 149 | L"Kiintolevyasemat", 150 | L"Laitteet, joissa on siirrettävä tallennusväline", 151 | L"Muu", 152 | L"Skannerit ja kamerat", 153 | L"Kannettavat medialaitteet", 154 | L"Kannettavat laitteet" 155 | }, 156 | { 157 | MAKELANGID(LANG_FRENCH, SUBLANG_FRENCH), 158 | L"Disques durs", 159 | L"Périphériques utilisant des supports de stockage amovibles", 160 | L"Autre", 161 | L"Scanneurs et appareils photo", 162 | L"Appareils mobiles multimédias", 163 | L"Périphériques amovibles" 164 | }, 165 | { 166 | MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT), 167 | L"כוננים קשיחים", 168 | L"התקנים עם אחסון נשלף", 169 | L"אחר", 170 | L"סורקים ומצלמות", 171 | L"מכשירי מדיה ניידים", 172 | L"מכשירים ניידים" 173 | }, 174 | { 175 | MAKELANGID(LANG_HUNGARIAN, SUBLANG_DEFAULT), 176 | L"Merevlemez-meghajtók", 177 | L"Cserélhető adathordozós eszközök", 178 | L"Egyéb", 179 | L"Képolvasók és fényképezőgépek", 180 | L"Hordozható lejátszóeszközök", 181 | L"Hordozható eszközök" 182 | }, 183 | { 184 | MAKELANGID(LANG_ITALIAN, SUBLANG_ITALIAN), 185 | L"Unità disco rigido", 186 | L"Dispositivi con archivi rimovibili", 187 | L"Altro", 188 | L"Scanner e fotocamere digitali", 189 | L"Dispositivi audio/video mobili", 190 | L"Dispositivi portatili" 191 | }, 192 | { 193 | MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT), 194 | L"ハード ディスク ドライブ", 195 | L"リムーバブル記憶域があるデバイス", 196 | L"その他", 197 | L"スキャナーとカメラ", 198 | L"ポータブル メディア デバイス", 199 | L"ポータブル デバイス" 200 | }, 201 | { 202 | MAKELANGID(LANG_KOREAN, SUBLANG_KOREAN), 203 | L"하드 디스크 드라이브", 204 | L"이동식 미디어 장치", 205 | L"기타", 206 | L"스캐너 및 카메라", 207 | L"휴대용 미디어 장치", 208 | L"휴대용 장치" 209 | }, 210 | { 211 | MAKELANGID(LANG_DUTCH, SUBLANG_DUTCH), 212 | L"Hardeschijfstations", 213 | L"Apparaten met verwisselbare opslagmedia", 214 | L"Overige", 215 | L"Scanners en camera's", 216 | L"Draagbare media-apparaten", 217 | L"Draagbare apparaten" 218 | }, 219 | { 220 | MAKELANGID(LANG_NORWEGIAN, SUBLANG_NORWEGIAN_BOKMAL), 221 | L"Harddiskstasjoner", 222 | L"Flyttbare lagringsmedier", 223 | L"Annet", 224 | L"Skannere og kameraer", 225 | L"Bærbare medieenheter", 226 | L"Bærbare enheter" 227 | }, 228 | { 229 | MAKELANGID(LANG_POLISH, SUBLANG_DEFAULT), 230 | L"Dyski twarde", 231 | L"Urządzenia z wymiennymi nośnikami pamięci", 232 | L"Inne", 233 | L"Skanery i aparaty fotograficzne", 234 | L"Przenośne urządzenia multimedialne", 235 | L"Urządzenia przenośne" 236 | }, 237 | { 238 | MAKELANGID(LANG_PORTUGUESE, SUBLANG_PORTUGUESE_BRAZILIAN), 239 | L"Unidades de Disco Rígido", 240 | L"Dispositivos com Armazenamento Removível", 241 | L"Outros", 242 | L"Scanners e Câmeras", 243 | L"Dispositivos de Mídia Portáteis", 244 | L"Dispositivos Portáteis" 245 | }, 246 | { 247 | MAKELANGID(LANG_ROMANIAN, SUBLANG_DEFAULT), 248 | L"Unități de hard disk", 249 | L"Unități cu stocare detașabilă", 250 | L"Altul", 251 | L"Scanere și aparate foto", 252 | L"Dispozitive media portabile", 253 | L"Dispozitive portabile" 254 | }, 255 | { 256 | MAKELANGID(LANG_RUSSIAN, SUBLANG_DEFAULT), 257 | L"Жесткие диски", 258 | L"Устройства со съемными носителями", 259 | L"Другие", 260 | L"Сканеры и камеры", 261 | L"Переносные устройства мультимедиа", 262 | L"Портативные устройства" 263 | }, 264 | { 265 | MAKELANGID(LANG_CROATIAN, SUBLANG_DEFAULT), 266 | L"Pogoni tvrdih diskova", 267 | L"Uređaji s prijenosnom pohranom", 268 | L"Ostalo", 269 | L"Skeneri i kamere", 270 | L"Prijenosni medijski uređaji", 271 | L"Prijenosni uređaji" 272 | }, 273 | { 274 | MAKELANGID(LANG_SLOVAK, SUBLANG_DEFAULT), 275 | L"Jednotky pevného disku", 276 | L"Zariadenia s vymeniteľným ukladacím priestorom", 277 | L"Iné", 278 | L"Skenery a fotoaparáty", 279 | L"Prenosné mediálne zariadenia", 280 | L"Prenosné zariadenia" 281 | }, 282 | { 283 | MAKELANGID(LANG_SWEDISH, SUBLANG_SWEDISH), 284 | L"Hårddiskar", 285 | L"Enheter med flyttbara lagringsmedia", 286 | L"Annan", 287 | L"Skannrar och kameror", 288 | L"Bärbara medieenheter", 289 | L"Bärbara enheter" 290 | }, 291 | { 292 | MAKELANGID(LANG_THAI, SUBLANG_DEFAULT), 293 | L"ฮาร์ดดิสก์ไดรฟ์", 294 | L"อุปกรณ์ที่มีที่เก็บข้อมูลแบบถอดได้", 295 | L"อื่นๆ", 296 | L"สแกนเนอร์และกล้อง", 297 | L"อุปกรณ์สื่อแบบพกพา", 298 | L"อุปกรณ์แบบพกพา" 299 | }, 300 | { 301 | MAKELANGID(LANG_TURKISH, SUBLANG_DEFAULT), 302 | L"Sabit Disk Sürücüleri", 303 | L"Çıkarılabilir Depolama Birimi Olan Aygıtlar", 304 | L"Diğer", 305 | L"Tarayıcılar ve Kameralar", 306 | L"Taşınabilir Medya Aygıtları", 307 | L"Taşınabilir Aygıtlar" 308 | }, 309 | { 310 | MAKELANGID(LANG_UKRAINIAN, SUBLANG_DEFAULT), 311 | L"Жорсткі диски", 312 | L"Пристрої зі знімними носіями", 313 | L"Інше", 314 | L"Сканери та камери", 315 | L"Портативні носії", 316 | L"Портативні пристрої" 317 | }, 318 | { 319 | MAKELANGID(LANG_SLOVENIAN, SUBLANG_DEFAULT), 320 | L"Trdi diski", 321 | L"Naprave z izmenljivimi mediji", 322 | L"Drugo", 323 | L"Optični bralniki in fotoaparati", 324 | L"Prenosne predstavnostne naprave", 325 | L"Prenosne naprave" 326 | }, 327 | { 328 | MAKELANGID(LANG_ESTONIAN, SUBLANG_DEFAULT), 329 | L"Kõvakettad", 330 | L"Irdsalvestiga seadmed", 331 | L"Muu", 332 | L"Skannerid ja kaamerad", 333 | L"Kantavad meediumiseadmed", 334 | L"Kandeseadmed" 335 | }, 336 | { 337 | MAKELANGID(LANG_LATVIAN, SUBLANG_DEFAULT), 338 | L"Cietie diski", 339 | L"Ierīces ar noņemamu krātuvi", 340 | L"Citi", 341 | L"Skeneri un kameras", 342 | L"Portatīvās datu nesēju ierīces", 343 | L"Portatīvās ierīces" 344 | }, 345 | { 346 | MAKELANGID(LANG_LITHUANIAN, SUBLANG_LITHUANIAN), 347 | L"Standieji diskai", 348 | L"Įrenginiai su keičiamąja laikmena", 349 | L"Kita", 350 | L"Skaitytuvai ir fotoaparatai", 351 | L"Nešiojamieji medijos įrenginiai", 352 | L"Nešiojamieji įrenginiai" 353 | }, 354 | { 355 | MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED), 356 | L"硬盘", 357 | L"有可移动存储的设备", 358 | L"其他", 359 | L"扫描仪和照相机", 360 | L"便携媒体设备", 361 | L"便携设备" 362 | }, 363 | { 364 | MAKELANGID(LANG_PORTUGUESE, SUBLANG_PORTUGUESE), 365 | L"Unidades de Disco Rígido", 366 | L"Dispositivos com Armazenamento Amovível", 367 | L"Outro", 368 | L"Scanners e Câmaras", 369 | L"Dispositivos de Multimédia Portáteis", 370 | L"Dispositivos Portáteis" 371 | }, 372 | { 373 | MAKELANGID(LANG_CROATIAN, 0x2), 374 | L"Jedinice čvrstog diska", 375 | L"Uređaji sa prenosivim skladištenjem", 376 | L"Ostalo", 377 | L"Skeneri i fotoaparati", 378 | L"Prenosni medijski uređaji", 379 | L"Prenosni uređaji" 380 | }, 381 | { 382 | MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_MODERN), 383 | L"Unidades de disco duro", 384 | L"Dispositivos con almacenamiento extraíble", 385 | L"Otros", 386 | L"Escáneres y cámaras", 387 | L"Dispositivos multimedia portátiles", 388 | L"Dispositivos portátiles" 389 | }, 390 | }; 391 | #pragma endregion 392 | 393 | LPCDRIVEGROUPI18N GetCurrentDriveLocale(void) { 394 | LANGID lid = GetUserDefaultUILanguage(); 395 | 396 | /* So we can fallback to English without iterating again. */ 397 | LPCDRIVEGROUPI18N en = nullptr; 398 | 399 | for (int i = 0; i < ARRAYSIZE(g_driveGroupI18n); i++) { 400 | if (g_driveGroupI18n[i].lid == MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)) { 401 | en = g_driveGroupI18n + i; 402 | } 403 | if (g_driveGroupI18n[i].lid == lid) { 404 | return g_driveGroupI18n + i; 405 | } 406 | } 407 | 408 | return en; 409 | } 410 | 411 | const struct { DWORD dwDescId; UINT uResId; } g_categoryMap[] = { 412 | { SHDID_FS_DIRECTORY, 9338 }, 413 | { SHDID_COMPUTER_SHAREDDOCS, 9338 }, 414 | { SHDID_COMPUTER_FIXED, DG_HARDDISKS }, 415 | { SHDID_COMPUTER_DRIVE35, DG_REMOVABLE }, 416 | { SHDID_COMPUTER_REMOVABLE, DG_REMOVABLE }, 417 | { SHDID_COMPUTER_CDROM, DG_REMOVABLE }, 418 | { SHDID_COMPUTER_DRIVE525, DG_REMOVABLE }, 419 | { SHDID_COMPUTER_NETDRIVE, 9340 }, 420 | { SHDID_COMPUTER_OTHER, DG_OTHER }, 421 | { SHDID_COMPUTER_RAMDISK, DG_OTHER }, 422 | { SHDID_COMPUTER_IMAGING, DG_SCANNERS }, 423 | { SHDID_COMPUTER_AUDIO, DG_PORTABLEMEDIA }, 424 | { SHDID_MOBILE_DEVICE, DG_PORTABLE } 425 | }; 426 | 427 | void *CStorageSystemTypeCategorizer_GetCategory_addr SHARED_SECTION = nullptr; 428 | HRESULT (STDCALL *CStorageSystemTypeCategorizer_GetCategory_orig)(ICategorizer *, UINT, PCUITEMID_CHILD_ARRAY, DWORD *) = nullptr; 429 | HRESULT STDCALL CStorageSystemTypeCategorizer_GetCategory_hook( 430 | ICategorizer *pThis, 431 | UINT cidl, 432 | PCUITEMID_CHILD_ARRAY apidl, 433 | DWORD *rgCategoryIds 434 | ) { 435 | HRESULT hr = S_OK; 436 | IShellFolder2 *pShellFolder = (IShellFolder2 *)*((INT_PTR *)pThis + 3); 437 | if (pShellFolder) { 438 | for (UINT i = 0; i < cidl; i++) { 439 | rgCategoryIds[i] = DG_OTHER; 440 | 441 | VARIANT v; 442 | VariantInit(&v); 443 | 444 | SHCOLUMNID scid; 445 | scid.fmtid = FMTID_ShellDetails; 446 | scid.pid = PID_DESCRIPTIONID; 447 | 448 | hr = pShellFolder->GetDetailsEx(apidl[i], &scid, &v); 449 | if (SUCCEEDED(hr)) { 450 | SHDESCRIPTIONID shdid; 451 | if (VariantToBuffer && SUCCEEDED(VariantToBuffer(&v, &shdid, sizeof(SHDESCRIPTIONID)))) { 452 | for (UINT j = 0; j < ARRAYSIZE(g_categoryMap); j++) { 453 | if (shdid.dwDescriptionId == g_categoryMap[j].dwDescId) { 454 | rgCategoryIds[i] = g_categoryMap[j].uResId; 455 | break; 456 | } 457 | } 458 | } 459 | } 460 | } 461 | } 462 | 463 | return hr; 464 | } 465 | 466 | void *CStorageSystemTypeCategorizer_CompareCategory_addr SHARED_SECTION = nullptr; 467 | HRESULT (STDCALL *CStorageSystemTypeCategorizer_CompareCategory_orig)(ICategorizer *, CATSORT_FLAGS, DWORD, DWORD) = nullptr; 468 | HRESULT STDCALL CStorageSystemTypeCategorizer_CompareCategory_hook( 469 | ICategorizer *pThis, 470 | CATSORT_FLAGS csfFlags, 471 | DWORD dwCategoryId1, 472 | DWORD dwCategoryId2 473 | ) { 474 | int categoryArraySize = ARRAYSIZE(g_categoryMap); 475 | 476 | int firstPos = -1; 477 | int secondPos = -1; 478 | 479 | for (int i = 0; i < categoryArraySize; i++) { 480 | if (g_categoryMap[i].uResId == dwCategoryId1) { 481 | firstPos = i; 482 | break; 483 | } 484 | } 485 | 486 | for (int i = 0; i < categoryArraySize; i++) { 487 | if (g_categoryMap[i].uResId == dwCategoryId2) { 488 | secondPos = i; 489 | break; 490 | } 491 | } 492 | 493 | int diff = firstPos - secondPos; 494 | 495 | if (diff < 0) { 496 | return 0xFFFF; 497 | } 498 | 499 | return diff > 0; 500 | } 501 | 502 | void *CStorageSystemTypeCategorizer_GetCategoryInfo_addr SHARED_SECTION = nullptr; 503 | HRESULT (STDCALL *CStorageSystemTypeCategorizer_GetCategoryInfo_orig)(ICategorizer *, DWORD, CATEGORY_INFO *) = nullptr; 504 | HRESULT STDCALL CStorageSystemTypeCategorizer_GetCategoryInfo_hook( 505 | ICategorizer *pThis, 506 | DWORD dwCategoryId, 507 | CATEGORY_INFO *pci 508 | ) { 509 | HRESULT hr = CStorageSystemTypeCategorizer_GetCategoryInfo_orig( 510 | pThis, dwCategoryId, pci 511 | ); 512 | if (SUCCEEDED(hr)) { 513 | LPCDRIVEGROUPI18N dgi = GetCurrentDriveLocale(); 514 | LPCWSTR lpszOut = nullptr; 515 | 516 | if (dgi) { 517 | switch ((DRIVEGROUP)dwCategoryId) { 518 | case DG_HARDDISKS: 519 | lpszOut = dgi->szHardDisks; 520 | break; 521 | case DG_REMOVABLE: 522 | lpszOut = dgi->szRemovable; 523 | break; 524 | case DG_OTHER: 525 | lpszOut = dgi->szOther; 526 | break; 527 | case DG_SCANNERS: 528 | lpszOut = dgi->szScanners; 529 | break; 530 | case DG_PORTABLEMEDIA: 531 | lpszOut = dgi->szPortableMedia; 532 | break; 533 | case DG_PORTABLE: 534 | lpszOut = dgi->szPortable; 535 | break; 536 | } 537 | 538 | if (lpszOut) { 539 | wcscpy(pci->wszName, lpszOut); 540 | } 541 | } 542 | } 543 | return hr; 544 | } 545 | 546 | struct CMWF_SYMBOL_HOOK { 547 | std::vector symbols; 548 | void** pOriginalFunction; 549 | void* hookFunction = nullptr; 550 | bool optional = false; 551 | void **pSharedMemoryCache = nullptr; 552 | 553 | template 554 | CMWF_SYMBOL_HOOK( 555 | std::vector symbols, 556 | Prototype **originalFunction, 557 | std::type_identity_t hookFunction = nullptr, 558 | bool optional = false, 559 | void *pSharedMemoryCache = nullptr 560 | ) : symbols(std::move(symbols)), 561 | pOriginalFunction((void **)originalFunction), 562 | hookFunction((void *)hookFunction), 563 | optional(optional), 564 | pSharedMemoryCache((void **)pSharedMemoryCache) {} 565 | 566 | CMWF_SYMBOL_HOOK() = default; 567 | }; 568 | 569 | bool CmwfHookSymbols( 570 | HMODULE module, 571 | const CMWF_SYMBOL_HOOK *symbolHooks, 572 | size_t symbolHooksCount 573 | ) 574 | { 575 | int anyUncachedHooks = 0; 576 | void*** proxyAddresses = reinterpret_cast(calloc(symbolHooksCount, sizeof(void**))); 577 | if (!proxyAddresses) { 578 | return false; 579 | } 580 | WindhawkUtils::SYMBOL_HOOK* proxyHooks = new (std::nothrow) WindhawkUtils::SYMBOL_HOOK[symbolHooksCount]; 581 | if (!proxyHooks) { 582 | free(proxyAddresses); 583 | return false; 584 | } 585 | 586 | for (size_t i = 0; i < symbolHooksCount; i++) { 587 | void *address = nullptr; 588 | if (symbolHooks[i].pSharedMemoryCache && *(symbolHooks[i].pSharedMemoryCache) != nullptr) { 589 | address = *(symbolHooks[i].pSharedMemoryCache); 590 | if (address == nullptr) { 591 | continue; 592 | } 593 | Wh_SetFunctionHook( 594 | address, 595 | symbolHooks[i].hookFunction, 596 | symbolHooks[i].pOriginalFunction 597 | ); 598 | } 599 | else 600 | { 601 | address = nullptr; 602 | anyUncachedHooks++; 603 | 604 | proxyHooks[i] = { 605 | { symbolHooks[i].symbols[0] }, 606 | &proxyAddresses[i], 607 | nullptr, 608 | symbolHooks[i].optional 609 | }; 610 | } 611 | } 612 | 613 | if (anyUncachedHooks) 614 | { 615 | if (!WindhawkUtils::HookSymbols(module, proxyHooks, symbolHooksCount)) { 616 | delete[] proxyHooks; 617 | free(proxyAddresses); 618 | return false; 619 | } 620 | 621 | for (auto curProxyHook = 0; curProxyHook < symbolHooksCount; ++curProxyHook) { 622 | if (proxyAddresses[curProxyHook] == nullptr) { 623 | continue; 624 | } 625 | 626 | if ( 627 | symbolHooks[curProxyHook].pSharedMemoryCache && 628 | *(symbolHooks[curProxyHook].pSharedMemoryCache) == nullptr 629 | ) { 630 | *(symbolHooks[curProxyHook].pSharedMemoryCache) = proxyAddresses[curProxyHook]; 631 | } 632 | 633 | if (symbolHooks[curProxyHook].hookFunction && symbolHooks[curProxyHook].pOriginalFunction) { 634 | if (Wh_SetFunctionHook( 635 | proxyAddresses[curProxyHook], 636 | symbolHooks[curProxyHook].hookFunction, 637 | symbolHooks[curProxyHook].pOriginalFunction 638 | )) { 639 | hookedFunctions.push_back(proxyAddresses[curProxyHook]); 640 | } else { 641 | for (auto i = 0; i < curProxyHook; ++i) { 642 | if (proxyAddresses[i] == nullptr) { 643 | continue; 644 | } 645 | Wh_RemoveFunctionHook(proxyAddresses[i]); 646 | } 647 | hookedFunctions.clear(); 648 | delete[] proxyHooks; 649 | free(proxyAddresses); 650 | return false; 651 | } 652 | } 653 | } 654 | } 655 | 656 | delete[] proxyHooks; 657 | free(proxyAddresses); 658 | return true; 659 | } 660 | 661 | BOOL Wh_ModInit(void) 662 | { 663 | if (!hPropsys) { 664 | hPropsys = LoadLibraryW(L"propsys.dll"); 665 | } 666 | if (!hPropsys) { 667 | Wh_Log(L"Failed to load propsys.dll"); 668 | return FALSE; 669 | } 670 | if (hPropsys) { 671 | VariantToBuffer = (VariantToBuffer_t)GetProcAddress(hPropsys, "VariantToBuffer"); 672 | } 673 | if (!VariantToBuffer) { 674 | Wh_Log(L"Failed to find propsys.dll!VariantToBuffer"); 675 | FreeLibrary(hPropsys); 676 | return FALSE; 677 | } 678 | 679 | if (!hShell32) { 680 | hShell32 = LoadLibraryW(L"shell32.dll"); 681 | } 682 | if (!hShell32) { 683 | Wh_Log(L"Failed to load shell32.dll"); 684 | FreeLibrary(hPropsys); 685 | return FALSE; 686 | } 687 | 688 | const CMWF_SYMBOL_HOOK shHooks[] = { 689 | { 690 | { 691 | L"public: virtual long " 692 | SSTDCALL 693 | L" CStorageSystemTypeCategorizer::GetCategory(unsigned int,struct _ITEMID_CHILD const " 694 | #ifdef _WIN64 695 | L"__unaligned " 696 | #endif 697 | L"* const *,unsigned long *)" 698 | }, 699 | &CStorageSystemTypeCategorizer_GetCategory_orig, 700 | CStorageSystemTypeCategorizer_GetCategory_hook, 701 | false, 702 | &CStorageSystemTypeCategorizer_GetCategory_addr 703 | }, 704 | { 705 | { 706 | L"public: virtual long " 707 | SSTDCALL 708 | L" CStorageSystemTypeCategorizer::CompareCategory(enum CATSORT_FLAGS,unsigned long,unsigned long)" 709 | }, 710 | &CStorageSystemTypeCategorizer_CompareCategory_orig, 711 | CStorageSystemTypeCategorizer_CompareCategory_hook, 712 | false, 713 | &CStorageSystemTypeCategorizer_CompareCategory_addr 714 | }, 715 | { 716 | { 717 | L"public: virtual long " 718 | SSTDCALL 719 | L" CStorageSystemTypeCategorizer::GetCategoryInfo(unsigned long,struct CATEGORY_INFO *)" 720 | }, 721 | &CStorageSystemTypeCategorizer_GetCategoryInfo_orig, 722 | CStorageSystemTypeCategorizer_GetCategoryInfo_hook, 723 | false, 724 | &CStorageSystemTypeCategorizer_GetCategoryInfo_addr 725 | } 726 | }; 727 | 728 | if (!CmwfHookSymbols(hShell32, shHooks, ARRAYSIZE(shHooks))) { 729 | Wh_Log(L"Failed to hook one or more symbol functions in shell32.dll"); 730 | return FALSE; 731 | } 732 | 733 | return TRUE; 734 | } 735 | 736 | void Wh_ModUninit(void) 737 | { 738 | for (auto function : hookedFunctions) { 739 | Wh_RemoveFunctionHook(function); 740 | } 741 | if (hPropsys) { 742 | FreeLibrary(hPropsys); 743 | hPropsys = nullptr; 744 | } 745 | if (hShell32) { 746 | FreeLibrary(hShell32); 747 | hShell32 = nullptr; 748 | } 749 | } 750 | -------------------------------------------------------------------------------- /mods/valinet-explorer-hide-current-folder-name-in-search-box.wh.cpp: -------------------------------------------------------------------------------- 1 | // ==WindhawkMod== 2 | // @id valinet-explorer-hide-current-folder-name-in-search-box 3 | // @name Explorer: Hide current folder name in search box 4 | // @description Explorer: Hide current folder name in search box 5 | // @version 1.5.7 6 | // @author valinet 7 | // @github https://github.com/valinet 8 | // @include * 9 | // @compilerOptions -loleaut32 10 | // ==/WindhawkMod== 11 | 12 | // ==WindhawkModReadme== 13 | /*...*/ 14 | // ==/WindhawkModReadme== 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | std::vector hookedFunctions; 29 | HMODULE hExplorerFrame = nullptr; 30 | 31 | #ifdef _WIN64 32 | # define THISCALL __cdecl 33 | # define STHISCALL L"__cdecl" 34 | 35 | # define STDCALL __cdecl 36 | # define SSTDCALL L"__cdecl" 37 | #else 38 | # define THISCALL __thiscall 39 | # define STHISCALL L"__thiscall" 40 | 41 | # define STDCALL __stdcall 42 | # define SSTDCALL L"__stdcall" 43 | #endif 44 | 45 | #define SHARED_SECTION __attribute__((section(".shared"))) 46 | asm(".section .shared,\"dws\"\n"); 47 | 48 | /* Windows Vista search box placeholder */ 49 | void *CSearchBox_SetCueAndTooltipText_addr SHARED_SECTION = nullptr; 50 | HRESULT (STDCALL *CSearchBox_SetCueAndTooltipText_orig)(void *, LPCWSTR, LPCWSTR) = nullptr; 51 | HRESULT STDCALL CSearchBox_SetCueAndTooltipText_hook( 52 | void *pThis, 53 | LPCWSTR lpszText, 54 | LPCWSTR lpszUnused 55 | ) 56 | { 57 | lpszText = L" Search"; 58 | return CSearchBox_SetCueAndTooltipText_orig(pThis, lpszText, lpszUnused); 59 | } 60 | 61 | struct CMWF_SYMBOL_HOOK { 62 | std::vector symbols; 63 | void** pOriginalFunction; 64 | void* hookFunction = nullptr; 65 | bool optional = false; 66 | void **pSharedMemoryCache = nullptr; 67 | 68 | template 69 | CMWF_SYMBOL_HOOK( 70 | std::vector symbols, 71 | Prototype **originalFunction, 72 | std::type_identity_t hookFunction = nullptr, 73 | bool optional = false, 74 | void *pSharedMemoryCache = nullptr 75 | ) : symbols(std::move(symbols)), 76 | pOriginalFunction((void **)originalFunction), 77 | hookFunction((void *)hookFunction), 78 | optional(optional), 79 | pSharedMemoryCache((void **)pSharedMemoryCache) {} 80 | 81 | CMWF_SYMBOL_HOOK() = default; 82 | }; 83 | 84 | bool CmwfHookSymbols( 85 | HMODULE module, 86 | const CMWF_SYMBOL_HOOK *symbolHooks, 87 | size_t symbolHooksCount 88 | ) 89 | { 90 | int anyUncachedHooks = 0; 91 | void*** proxyAddresses = reinterpret_cast(calloc(symbolHooksCount, sizeof(void**))); 92 | if (!proxyAddresses) { 93 | return false; 94 | } 95 | WindhawkUtils::SYMBOL_HOOK* proxyHooks = new (std::nothrow) WindhawkUtils::SYMBOL_HOOK[symbolHooksCount]; 96 | if (!proxyHooks) { 97 | free(proxyAddresses); 98 | return false; 99 | } 100 | 101 | for (size_t i = 0; i < symbolHooksCount; i++) { 102 | void *address = nullptr; 103 | if (symbolHooks[i].pSharedMemoryCache && *(symbolHooks[i].pSharedMemoryCache) != nullptr) { 104 | address = *(symbolHooks[i].pSharedMemoryCache); 105 | if (address == nullptr) { 106 | continue; 107 | } 108 | Wh_SetFunctionHook( 109 | address, 110 | symbolHooks[i].hookFunction, 111 | symbolHooks[i].pOriginalFunction 112 | ); 113 | } 114 | else 115 | { 116 | address = nullptr; 117 | anyUncachedHooks++; 118 | 119 | proxyHooks[i] = { 120 | { symbolHooks[i].symbols[0] }, 121 | &proxyAddresses[i], 122 | nullptr, 123 | symbolHooks[i].optional 124 | }; 125 | } 126 | } 127 | 128 | if (anyUncachedHooks) 129 | { 130 | if (!WindhawkUtils::HookSymbols(module, proxyHooks, symbolHooksCount)) { 131 | delete[] proxyHooks; 132 | free(proxyAddresses); 133 | return false; 134 | } 135 | 136 | for (auto curProxyHook = 0; curProxyHook < symbolHooksCount; ++curProxyHook) { 137 | if (proxyAddresses[curProxyHook] == nullptr) { 138 | continue; 139 | } 140 | 141 | if ( 142 | symbolHooks[curProxyHook].pSharedMemoryCache && 143 | *(symbolHooks[curProxyHook].pSharedMemoryCache) == nullptr 144 | ) { 145 | *(symbolHooks[curProxyHook].pSharedMemoryCache) = proxyAddresses[curProxyHook]; 146 | } 147 | 148 | if (symbolHooks[curProxyHook].hookFunction && symbolHooks[curProxyHook].pOriginalFunction) { 149 | if (Wh_SetFunctionHook( 150 | proxyAddresses[curProxyHook], 151 | symbolHooks[curProxyHook].hookFunction, 152 | symbolHooks[curProxyHook].pOriginalFunction 153 | )) { 154 | hookedFunctions.push_back(proxyAddresses[curProxyHook]); 155 | } else { 156 | for (auto i = 0; i < curProxyHook; ++i) { 157 | if (proxyAddresses[i] == nullptr) { 158 | continue; 159 | } 160 | Wh_RemoveFunctionHook(proxyAddresses[i]); 161 | } 162 | hookedFunctions.clear(); 163 | delete[] proxyHooks; 164 | free(proxyAddresses); 165 | return false; 166 | } 167 | } 168 | } 169 | } 170 | 171 | delete[] proxyHooks; 172 | free(proxyAddresses); 173 | return true; 174 | } 175 | 176 | BOOL Wh_ModInit(void) 177 | { 178 | if (!hExplorerFrame) { 179 | hExplorerFrame = LoadLibraryW(L"ExplorerFrame.dll"); 180 | } 181 | if (!hExplorerFrame) { 182 | Wh_Log(L"Failed to load ExplorerFrame.dll"); 183 | return FALSE; 184 | } 185 | 186 | const CMWF_SYMBOL_HOOK efHooks[] = { 187 | { 188 | { 189 | L"public: virtual long " 190 | SSTDCALL 191 | L" CSearchBox::SetCueAndTooltipText(unsigned short const *,unsigned short const *)" 192 | }, 193 | &CSearchBox_SetCueAndTooltipText_orig, 194 | CSearchBox_SetCueAndTooltipText_hook, 195 | false, 196 | &CSearchBox_SetCueAndTooltipText_addr 197 | }, 198 | }; 199 | 200 | if (!CmwfHookSymbols(hExplorerFrame, efHooks, ARRAYSIZE(efHooks))) { 201 | Wh_Log(L"Failed to hook one or more symbol functions in ExplorerFrame.dll"); 202 | return FALSE; 203 | } 204 | 205 | return TRUE; 206 | } 207 | 208 | void Wh_ModUninit(void) 209 | { 210 | for (auto function : hookedFunctions) { 211 | Wh_RemoveFunctionHook(function); 212 | } 213 | if (hExplorerFrame) { 214 | FreeLibrary(hExplorerFrame); 215 | hExplorerFrame = nullptr; 216 | } 217 | } 218 | -------------------------------------------------------------------------------- /mods/valinet-explorer-hide-quick-access-pins.wh.cpp: -------------------------------------------------------------------------------- 1 | // ==WindhawkMod== 2 | // @id valinet-explorer-hide-quick-access-pins 3 | // @name Explorer: Hide Quick Access pins 4 | // @description Explorer: Hide Quick Access pins 5 | // @version 1.5.7 6 | // @author valinet 7 | // @github https://github.com/valinet 8 | // @include * 9 | // @compilerOptions -loleaut32 10 | // ==/WindhawkMod== 11 | 12 | // ==WindhawkModReadme== 13 | /*...*/ 14 | // ==/WindhawkModReadme== 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | std::vector hookedFunctions; 29 | HMODULE hExplorerFrame = nullptr; 30 | 31 | #ifdef _WIN64 32 | # define THISCALL __cdecl 33 | # define STHISCALL L"__cdecl" 34 | 35 | # define STDCALL __cdecl 36 | # define SSTDCALL L"__cdecl" 37 | #else 38 | # define THISCALL __thiscall 39 | # define STHISCALL L"__thiscall" 40 | 41 | # define STDCALL __stdcall 42 | # define SSTDCALL L"__stdcall" 43 | #endif 44 | 45 | #define SHARED_SECTION __attribute__((section(".shared"))) 46 | asm(".section .shared,\"dws\"\n"); 47 | 48 | /* Remove pins from Quick access */ 49 | void *CNscTree_SetStateImageList_addr SHARED_SECTION = nullptr; 50 | HRESULT (STDCALL *CNscTree_SetStateImageList_orig)(void *, HIMAGELIST) = nullptr; 51 | HRESULT STDCALL CNscTree_SetStateImageList_hook( 52 | void *pThis, 53 | HIMAGELIST himl 54 | ) 55 | { 56 | return S_OK; 57 | } 58 | 59 | struct CMWF_SYMBOL_HOOK { 60 | std::vector symbols; 61 | void** pOriginalFunction; 62 | void* hookFunction = nullptr; 63 | bool optional = false; 64 | void **pSharedMemoryCache = nullptr; 65 | 66 | template 67 | CMWF_SYMBOL_HOOK( 68 | std::vector symbols, 69 | Prototype **originalFunction, 70 | std::type_identity_t hookFunction = nullptr, 71 | bool optional = false, 72 | void *pSharedMemoryCache = nullptr 73 | ) : symbols(std::move(symbols)), 74 | pOriginalFunction((void **)originalFunction), 75 | hookFunction((void *)hookFunction), 76 | optional(optional), 77 | pSharedMemoryCache((void **)pSharedMemoryCache) {} 78 | 79 | CMWF_SYMBOL_HOOK() = default; 80 | }; 81 | 82 | bool CmwfHookSymbols( 83 | HMODULE module, 84 | const CMWF_SYMBOL_HOOK *symbolHooks, 85 | size_t symbolHooksCount 86 | ) 87 | { 88 | int anyUncachedHooks = 0; 89 | void*** proxyAddresses = reinterpret_cast(calloc(symbolHooksCount, sizeof(void**))); 90 | if (!proxyAddresses) { 91 | return false; 92 | } 93 | WindhawkUtils::SYMBOL_HOOK* proxyHooks = new (std::nothrow) WindhawkUtils::SYMBOL_HOOK[symbolHooksCount]; 94 | if (!proxyHooks) { 95 | free(proxyAddresses); 96 | return false; 97 | } 98 | 99 | for (size_t i = 0; i < symbolHooksCount; i++) { 100 | void *address = nullptr; 101 | if (symbolHooks[i].pSharedMemoryCache && *(symbolHooks[i].pSharedMemoryCache) != nullptr) { 102 | address = *(symbolHooks[i].pSharedMemoryCache); 103 | if (address == nullptr) { 104 | continue; 105 | } 106 | Wh_SetFunctionHook( 107 | address, 108 | symbolHooks[i].hookFunction, 109 | symbolHooks[i].pOriginalFunction 110 | ); 111 | } 112 | else 113 | { 114 | address = nullptr; 115 | anyUncachedHooks++; 116 | 117 | proxyHooks[i] = { 118 | { symbolHooks[i].symbols[0] }, 119 | &proxyAddresses[i], 120 | nullptr, 121 | symbolHooks[i].optional 122 | }; 123 | } 124 | } 125 | 126 | if (anyUncachedHooks) 127 | { 128 | if (!WindhawkUtils::HookSymbols(module, proxyHooks, symbolHooksCount)) { 129 | delete[] proxyHooks; 130 | free(proxyAddresses); 131 | return false; 132 | } 133 | 134 | for (auto curProxyHook = 0; curProxyHook < symbolHooksCount; ++curProxyHook) { 135 | if (proxyAddresses[curProxyHook] == nullptr) { 136 | continue; 137 | } 138 | 139 | if ( 140 | symbolHooks[curProxyHook].pSharedMemoryCache && 141 | *(symbolHooks[curProxyHook].pSharedMemoryCache) == nullptr 142 | ) { 143 | *(symbolHooks[curProxyHook].pSharedMemoryCache) = proxyAddresses[curProxyHook]; 144 | } 145 | 146 | if (symbolHooks[curProxyHook].hookFunction && symbolHooks[curProxyHook].pOriginalFunction) { 147 | if (Wh_SetFunctionHook( 148 | proxyAddresses[curProxyHook], 149 | symbolHooks[curProxyHook].hookFunction, 150 | symbolHooks[curProxyHook].pOriginalFunction 151 | )) { 152 | hookedFunctions.push_back(proxyAddresses[curProxyHook]); 153 | } else { 154 | for (auto i = 0; i < curProxyHook; ++i) { 155 | if (proxyAddresses[i] == nullptr) { 156 | continue; 157 | } 158 | Wh_RemoveFunctionHook(proxyAddresses[i]); 159 | } 160 | hookedFunctions.clear(); 161 | delete[] proxyHooks; 162 | free(proxyAddresses); 163 | return false; 164 | } 165 | } 166 | } 167 | } 168 | 169 | delete[] proxyHooks; 170 | free(proxyAddresses); 171 | return true; 172 | } 173 | 174 | BOOL Wh_ModInit(void) 175 | { 176 | if (!hExplorerFrame) { 177 | hExplorerFrame = LoadLibraryW(L"ExplorerFrame.dll"); 178 | } 179 | if (!hExplorerFrame) { 180 | Wh_Log(L"Failed to load ExplorerFrame.dll"); 181 | return FALSE; 182 | } 183 | 184 | const CMWF_SYMBOL_HOOK efHooks[] = { 185 | { 186 | { 187 | L"public: virtual long " 188 | SSTDCALL 189 | L" CNscTree::SetStateImageList(struct _IMAGELIST *)" 190 | }, 191 | &CNscTree_SetStateImageList_orig, 192 | CNscTree_SetStateImageList_hook, 193 | false, 194 | &CNscTree_SetStateImageList_addr 195 | }, 196 | }; 197 | 198 | if (!CmwfHookSymbols(hExplorerFrame, efHooks, ARRAYSIZE(efHooks))) { 199 | Wh_Log(L"Failed to hook one or more symbol functions in ExplorerFrame.dll"); 200 | return FALSE; 201 | } 202 | 203 | return TRUE; 204 | } 205 | 206 | void Wh_ModUninit(void) 207 | { 208 | for (auto function : hookedFunctions) { 209 | Wh_RemoveFunctionHook(function); 210 | } 211 | if (hExplorerFrame) { 212 | FreeLibrary(hExplorerFrame); 213 | hExplorerFrame = nullptr; 214 | } 215 | } 216 | -------------------------------------------------------------------------------- /mods/valinet-explorer-old-search-box.wh.cpp: -------------------------------------------------------------------------------- 1 | // ==WindhawkMod== 2 | // @id valinet-explorer-old-search-box 3 | // @name Explorer: Old Search box 4 | // @description Explorer: Old Search box 5 | // @version 1.5.7 6 | // @author valinet 7 | // @github https://github.com/valinet 8 | // @include * 9 | // @compilerOptions -loleaut32 10 | // ==/WindhawkMod== 11 | 12 | // ==WindhawkModReadme== 13 | /*...*/ 14 | // ==/WindhawkModReadme== 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | std::vector hookedFunctions; 29 | HMODULE hExplorerFrame = nullptr; 30 | 31 | #ifdef _WIN64 32 | # define THISCALL __cdecl 33 | # define STHISCALL L"__cdecl" 34 | 35 | # define STDCALL __cdecl 36 | # define SSTDCALL L"__cdecl" 37 | #else 38 | # define THISCALL __thiscall 39 | # define STHISCALL L"__thiscall" 40 | 41 | # define STDCALL __stdcall 42 | # define SSTDCALL L"__stdcall" 43 | #endif 44 | 45 | #define SHARED_SECTION __attribute__((section(".shared"))) 46 | asm(".section .shared,\"dws\"\n"); 47 | 48 | /* Old search box */ 49 | void *CUniversalSearchBand_IsModernSearchBoxEnabled_addr SHARED_SECTION = nullptr; 50 | bool (__fastcall *CUniversalSearchBand_IsModernSearchBoxEnabled_orig)(void *) = nullptr; 51 | bool __fastcall CUniversalSearchBand_IsModernSearchBoxEnabled_hook( 52 | void *pThis 53 | ) { 54 | return false; 55 | } 56 | 57 | /* Fix placeholder blanking */ 58 | void *CSearchEditBox_HideSuggestions_addr SHARED_SECTION = nullptr; 59 | HRESULT (THISCALL *CSearchEditBox_HideSuggestions_orig)(void *) = nullptr; 60 | HRESULT THISCALL CSearchEditBox_HideSuggestions_hook( 61 | void *pThis 62 | ) { 63 | return S_OK; 64 | } 65 | 66 | struct CMWF_SYMBOL_HOOK { 67 | std::vector symbols; 68 | void** pOriginalFunction; 69 | void* hookFunction = nullptr; 70 | bool optional = false; 71 | void **pSharedMemoryCache = nullptr; 72 | 73 | template 74 | CMWF_SYMBOL_HOOK( 75 | std::vector symbols, 76 | Prototype **originalFunction, 77 | std::type_identity_t hookFunction = nullptr, 78 | bool optional = false, 79 | void *pSharedMemoryCache = nullptr 80 | ) : symbols(std::move(symbols)), 81 | pOriginalFunction((void **)originalFunction), 82 | hookFunction((void *)hookFunction), 83 | optional(optional), 84 | pSharedMemoryCache((void **)pSharedMemoryCache) {} 85 | 86 | CMWF_SYMBOL_HOOK() = default; 87 | }; 88 | 89 | bool CmwfHookSymbols( 90 | HMODULE module, 91 | const CMWF_SYMBOL_HOOK *symbolHooks, 92 | size_t symbolHooksCount 93 | ) 94 | { 95 | int anyUncachedHooks = 0; 96 | void*** proxyAddresses = reinterpret_cast(calloc(symbolHooksCount, sizeof(void**))); 97 | if (!proxyAddresses) { 98 | return false; 99 | } 100 | WindhawkUtils::SYMBOL_HOOK* proxyHooks = new (std::nothrow) WindhawkUtils::SYMBOL_HOOK[symbolHooksCount]; 101 | if (!proxyHooks) { 102 | free(proxyAddresses); 103 | return false; 104 | } 105 | 106 | for (size_t i = 0; i < symbolHooksCount; i++) { 107 | void *address = nullptr; 108 | if (symbolHooks[i].pSharedMemoryCache && *(symbolHooks[i].pSharedMemoryCache) != nullptr) { 109 | address = *(symbolHooks[i].pSharedMemoryCache); 110 | if (address == nullptr) { 111 | continue; 112 | } 113 | Wh_SetFunctionHook( 114 | address, 115 | symbolHooks[i].hookFunction, 116 | symbolHooks[i].pOriginalFunction 117 | ); 118 | } 119 | else 120 | { 121 | address = nullptr; 122 | anyUncachedHooks++; 123 | 124 | proxyHooks[i] = { 125 | { symbolHooks[i].symbols[0] }, 126 | &proxyAddresses[i], 127 | nullptr, 128 | symbolHooks[i].optional 129 | }; 130 | } 131 | } 132 | 133 | if (anyUncachedHooks) 134 | { 135 | if (!WindhawkUtils::HookSymbols(module, proxyHooks, symbolHooksCount)) { 136 | delete[] proxyHooks; 137 | free(proxyAddresses); 138 | return false; 139 | } 140 | 141 | for (auto curProxyHook = 0; curProxyHook < symbolHooksCount; ++curProxyHook) { 142 | if (proxyAddresses[curProxyHook] == nullptr) { 143 | continue; 144 | } 145 | 146 | if ( 147 | symbolHooks[curProxyHook].pSharedMemoryCache && 148 | *(symbolHooks[curProxyHook].pSharedMemoryCache) == nullptr 149 | ) { 150 | *(symbolHooks[curProxyHook].pSharedMemoryCache) = proxyAddresses[curProxyHook]; 151 | } 152 | 153 | if (symbolHooks[curProxyHook].hookFunction && symbolHooks[curProxyHook].pOriginalFunction) { 154 | if (Wh_SetFunctionHook( 155 | proxyAddresses[curProxyHook], 156 | symbolHooks[curProxyHook].hookFunction, 157 | symbolHooks[curProxyHook].pOriginalFunction 158 | )) { 159 | hookedFunctions.push_back(proxyAddresses[curProxyHook]); 160 | } else { 161 | for (auto i = 0; i < curProxyHook; ++i) { 162 | if (proxyAddresses[i] == nullptr) { 163 | continue; 164 | } 165 | Wh_RemoveFunctionHook(proxyAddresses[i]); 166 | } 167 | hookedFunctions.clear(); 168 | delete[] proxyHooks; 169 | free(proxyAddresses); 170 | return false; 171 | } 172 | } 173 | } 174 | } 175 | 176 | delete[] proxyHooks; 177 | free(proxyAddresses); 178 | return true; 179 | } 180 | 181 | BOOL Wh_ModInit(void) 182 | { 183 | if (!hExplorerFrame) { 184 | hExplorerFrame = LoadLibraryW(L"ExplorerFrame.dll"); 185 | } 186 | if (!hExplorerFrame) { 187 | Wh_Log(L"Failed to load ExplorerFrame.dll"); 188 | return FALSE; 189 | } 190 | 191 | const CMWF_SYMBOL_HOOK efHooks[] = { 192 | { 193 | { 194 | L"private: bool " 195 | STHISCALL 196 | L" CUniversalSearchBand::IsModernSearchBoxEnabled(void)" 197 | }, 198 | &CUniversalSearchBand_IsModernSearchBoxEnabled_orig, 199 | CUniversalSearchBand_IsModernSearchBoxEnabled_hook, 200 | true, 201 | &CUniversalSearchBand_IsModernSearchBoxEnabled_addr 202 | }, 203 | { 204 | { 205 | L"public: long " 206 | STHISCALL 207 | L" CSearchEditBox::HideSuggestions(void)" 208 | }, 209 | &CSearchEditBox_HideSuggestions_orig, 210 | CSearchEditBox_HideSuggestions_hook, 211 | false, 212 | &CSearchEditBox_HideSuggestions_addr 213 | }, 214 | }; 215 | 216 | if (!CmwfHookSymbols(hExplorerFrame, efHooks, ARRAYSIZE(efHooks))) { 217 | Wh_Log(L"Failed to hook one or more symbol functions in ExplorerFrame.dll"); 218 | return FALSE; 219 | } 220 | 221 | return TRUE; 222 | } 223 | 224 | void Wh_ModUninit(void) 225 | { 226 | for (auto function : hookedFunctions) { 227 | Wh_RemoveFunctionHook(function); 228 | } 229 | if (hExplorerFrame) { 230 | FreeLibrary(hExplorerFrame); 231 | hExplorerFrame = nullptr; 232 | } 233 | } 234 | -------------------------------------------------------------------------------- /mods/valinet-power-button-action.wh.cpp: -------------------------------------------------------------------------------- 1 | // ==WindhawkMod== 2 | // @id valinet-power-button-action 3 | // @name Power Button Action 4 | // @description Performs custom actions when chassis power button is pressed 5 | // @version 1.0 6 | // @author valinet 7 | // @github https://github.com/valinet 8 | // @include windhawk.exe 9 | // @compilerOptions -lWtsapi32 -lShlwapi -lOle32 -lOleAut32 -lShell32 10 | // ==/WindhawkMod== 11 | 12 | // ==WindhawkModReadme== 13 | /* 14 | # Power Button Action 15 | Performs custom actions when chassis power button is pressed 16 | */ 17 | // ==/WindhawkModReadme== 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #define Wh_Log_External 40 | #define Wh_Log_Original 41 | //#define Wh_Log_External OutputDebugString 42 | //#define Wh_Log_Original Wh_Log 43 | 44 | #define QWORD INT64 45 | 46 | EXTERN_C IMAGE_DOS_HEADER __ImageBase; 47 | #define HINST_THISCOMPONENT ((HINSTANCE)&__ImageBase) 48 | 49 | DEFINE_GUID(This_CLSID_ShellWindows, 0x9ba05972, 0xf6a8, 0x11cf, 0xa4,0x42, 0x00,0xa0,0xc9,0x0a,0x8f,0x39); 50 | 51 | extern "C" int procMain(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int nCmdShow) { 52 | int rv = 0xFFFFFFFF; 53 | 54 | SECURITY_DESCRIPTOR sd; 55 | InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION); 56 | SetSecurityDescriptorDacl(&sd, true, nullptr, false); 57 | SECURITY_ATTRIBUTES sa = { }; 58 | sa.nLength = sizeof(sa); 59 | sa.bInheritHandle = false; 60 | sa.lpSecurityDescriptor = &sd; 61 | SetLastError(ERROR_SUCCESS); 62 | HANDLE mutSingleInstance = CreateMutexW(&sa, false, L"Global\\{FF8295EF-01FE-40BF-A319-57BC3EDD1FB6}"); 63 | if (GetLastError() == ERROR_ALREADY_EXISTS) { 64 | CloseHandle(mutSingleInstance); 65 | return ERROR_ALREADY_EXISTS; 66 | } 67 | 68 | MSG msg; 69 | PeekMessageW(&msg, nullptr, 0, 0, PM_NOREMOVE); 70 | CoInitialize(0); 71 | wchar_t wszMsg[MAX_PATH * 4]; 72 | 73 | BOOL bRegisteredForWTS = WTSRegisterSessionNotification(hWnd, NOTIFY_FOR_ALL_SESSIONS); 74 | swprintf_s(wszMsg, L"WTSRegisterSessionNotification: %d\n", bRegisteredForWTS); 75 | Wh_Log_External(wszMsg); 76 | 77 | DWORD dwProcessSessionId = 0xFFFFFFFF, dwActiveSessionId = WTSGetActiveConsoleSessionId(); 78 | ProcessIdToSessionId(GetCurrentProcessId(), &dwProcessSessionId); 79 | if (dwActiveSessionId != 0xFFFFFFFF && dwProcessSessionId != dwActiveSessionId) { 80 | swprintf_s(wszMsg, L"Did not start in active session, exiting...\n"); 81 | Wh_Log_External(wszMsg); 82 | if (bRegisteredForWTS) WTSUnRegisterSessionNotification(hWnd); 83 | if (mutSingleInstance) CloseHandle(mutSingleInstance); 84 | return rv; 85 | } 86 | 87 | HANDLE hPowerButtonPressEvent = CreateEventW(nullptr, false, false, L"Global\\{29DFB10F-5CFF-4A9D-B9D1-31B053A1AE95}"); 88 | while (hPowerButtonPressEvent) { 89 | bool isQuiting = false; 90 | rv = MsgWaitForMultipleObjects(1, &hPowerButtonPressEvent, false, INFINITE, QS_ALLINPUT); 91 | if (rv != WAIT_OBJECT_0 && (rv != WAIT_OBJECT_0 + 1)) break; 92 | if (rv == WAIT_OBJECT_0) { 93 | IShellWindows *psw = nullptr; 94 | HRESULT hr = CoCreateInstance(This_CLSID_ShellWindows, NULL, CLSCTX_ALL, IID_PPV_ARGS(&psw)); 95 | if (SUCCEEDED(hr)) { 96 | HWND hwnd = nullptr; 97 | IDispatch* pdisp = nullptr; 98 | VARIANT vEmpty = {}; // VT_EMPTY 99 | if (S_OK == psw->FindWindowSW(&vEmpty, &vEmpty, SWC_DESKTOP, (long*)&hwnd, SWFO_NEEDDISPATCH, &pdisp)) { 100 | IShellBrowser *psb = nullptr; 101 | hr = IUnknown_QueryService(pdisp, SID_STopLevelBrowser, IID_PPV_ARGS(&psb)); 102 | if (SUCCEEDED(hr)) { 103 | IShellView *psv = nullptr; 104 | hr = psb->QueryActiveShellView(&psv); 105 | IDispatch *pdispBackground; 106 | HRESULT hr = psv->GetItemObject(SVGIO_BACKGROUND, IID_PPV_ARGS(&pdispBackground)); 107 | if (SUCCEEDED(hr)) { 108 | IShellFolderViewDual *psfvd = nullptr; 109 | hr = pdispBackground->QueryInterface(IID_PPV_ARGS(&psfvd)); 110 | if (SUCCEEDED(hr)) { 111 | IDispatch *pdisp = nullptr; 112 | hr = psfvd->get_Application(&pdisp); 113 | if (SUCCEEDED(hr)) { 114 | IShellDispatch2 *psd = nullptr; 115 | hr = pdisp->QueryInterface(IID_PPV_ARGS(&psd)); 116 | if (SUCCEEDED(hr)) { 117 | //PVOID OldValue; 118 | //BOOL amI32Bit = FALSE; 119 | //if (!IsWow64Process(GetCurrentProcess(), &amI32Bit) || amI32Bit) Wow64DisableWow64FsRedirection(&OldValue); 120 | wchar_t wszPath[MAX_PATH]; 121 | hr = SHGetFolderPathW(nullptr, CSIDL_SYSTEM, nullptr, SHGFP_TYPE_CURRENT, wszPath); 122 | if (SUCCEEDED(hr)) { 123 | wcscat_s(wszPath, L"\\calc.exe"); 124 | BSTR bstrExe = nullptr; 125 | bstrExe = SysAllocString(wszPath); 126 | BSTR bstrOperation = nullptr; 127 | bstrOperation = SysAllocString(L"open"); 128 | if (bstrExe && bstrOperation) { 129 | VARIANT varOperation; 130 | varOperation.vt = VT_BSTR; 131 | varOperation.bstrVal = bstrOperation; 132 | hr = psd->ShellExecuteW(bstrExe, vEmpty, vEmpty, varOperation, vEmpty); 133 | if (SUCCEEDED(hr)) { 134 | auto start = GetTickCount64(); 135 | HWND hWnd = nullptr; 136 | while (GetClassWord(hWnd = GetForegroundWindow(), GCW_ATOM) != RegisterWindowMessageW(L"CalcFrame")) { 137 | SleepEx(0, true); 138 | if (GetTickCount64() - start > 1000) break; 139 | } 140 | POINT pt{}; 141 | GetCursorPos(&pt); 142 | RECT rc{}; 143 | GetWindowRect(hWnd, &rc); 144 | SetWindowPos(hWnd, nullptr, pt.x - ((rc.right - rc.left) / 2), pt.y - ((rc.bottom - rc.top) / 2), 0, 0, SWP_NOSIZE); 145 | } 146 | } 147 | if (bstrExe) SysFreeString(bstrExe); 148 | if (bstrOperation) SysFreeString(bstrOperation); 149 | } 150 | //if (!IsWow64Process(GetCurrentProcess(), &amI32Bit) || amI32Bit) Wow64RevertWow64FsRedirection(OldValue); 151 | psd->Release(); 152 | } 153 | pdisp->Release(); 154 | } 155 | psfvd->Release(); 156 | } 157 | pdispBackground->Release(); 158 | } 159 | psb->Release(); 160 | } 161 | pdisp->Release(); 162 | } 163 | psw->Release(); 164 | } 165 | swprintf_s(wszMsg, L"Power button pressed\n"); 166 | Wh_Log_External(wszMsg); 167 | } 168 | while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) { 169 | if (msg.message == WM_QUIT) { 170 | swprintf_s(wszMsg, L"Quitting (WM_QUIT)...\n"); 171 | Wh_Log_External(wszMsg); 172 | rv = 0xFFFFFFFF; 173 | isQuiting = true; 174 | break; 175 | } 176 | else if (msg.message == WM_WTSSESSION_CHANGE) { 177 | if (msg.wParam == WTS_CONSOLE_CONNECT || msg.wParam == WTS_SESSION_LOGOFF) { 178 | swprintf_s(wszMsg, L"Quitting (WM_WTSSESSION_CHANGE, %d, %d)...\n", msg.wParam, msg.lParam); 179 | Wh_Log_External(wszMsg); 180 | rv = msg.lParam; 181 | isQuiting = true; 182 | break; 183 | } 184 | } 185 | else { 186 | TranslateMessage(&msg); 187 | DispatchMessageW(&msg); 188 | } 189 | } 190 | if (isQuiting) break; 191 | } 192 | 193 | if (hPowerButtonPressEvent) CloseHandle(hPowerButtonPressEvent); 194 | if (bRegisteredForWTS) WTSUnRegisterSessionNotification(hWnd); 195 | if (mutSingleInstance) CloseHandle(mutSingleInstance); 196 | ExitProcess(rv); 197 | } 198 | 199 | DWORD WINAPI procClose(LPVOID dwMainTid) { 200 | return PostThreadMessageW(reinterpret_cast(dwMainTid), WM_QUIT, 0, 0); 201 | } 202 | 203 | PROCESS_INFORMATION pi{}; 204 | std::mutex mut_pi; 205 | std::thread worker; 206 | 207 | BOOL Wh_ModInit() { 208 | bool serviceProcess = false; 209 | 210 | int argc; 211 | LPWSTR* argv = CommandLineToArgvW(GetCommandLine(), &argc); 212 | if (!argv) { 213 | Wh_Log_Original(L"CommandLineToArgvW failed"); 214 | return FALSE; 215 | } 216 | 217 | for (int i = 1; i < argc; i++) { 218 | if (wcscmp(argv[i], L"-service") == 0) { 219 | serviceProcess = true; 220 | break; 221 | } 222 | } 223 | 224 | LocalFree(argv); 225 | 226 | Wh_Log_Original(L"Init %d\n", serviceProcess); 227 | if (!serviceProcess) { 228 | return FALSE; 229 | } 230 | 231 | mut_pi.lock(); 232 | worker = std::thread([](){ 233 | Wh_Log_Original(L"Started worker.\n"); 234 | while (true) { 235 | wchar_t wszPath[MAX_PATH]; 236 | GetWindowsDirectory(wszPath, MAX_PATH); 237 | wchar_t wszArguments[MAX_PATH]{}; 238 | GetModuleFileNameW(HINST_THISCOMPONENT, wszArguments, MAX_PATH); 239 | wchar_t wszCommand[MAX_PATH * 3]; 240 | BOOL amI32Bit = FALSE; 241 | if (!IsWow64Process(GetCurrentProcess(), &amI32Bit) || amI32Bit) swprintf_s(wszCommand, L"\"%s\\SysWOW64\\rundll32.exe\" %s,procMain", wszPath, wszArguments); 242 | else swprintf_s(wszCommand, L"\"%s\\System32\\rundll32.exe\" %s,procMain", wszPath, wszArguments); 243 | Wh_Log_Original(L"%s\n", wszCommand); 244 | HANDLE procInteractiveWinlogon = INVALID_HANDLE_VALUE; 245 | PROCESSENTRY32 entry; 246 | entry.dwSize = sizeof(PROCESSENTRY32); 247 | HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); 248 | if (hSnapshot) { 249 | if (Process32First(hSnapshot, &entry) == TRUE) { 250 | DWORD dwActiveSessionId = WTSGetActiveConsoleSessionId(); 251 | if (dwActiveSessionId == 0xFFFFFFFF) { 252 | Wh_Log_Original(L"No session is active.\n"); 253 | } 254 | while (Process32Next(hSnapshot, &entry) == TRUE) { 255 | if (!wcsicmp(entry.szExeFile, L"winlogon.exe")) { 256 | DWORD dwWinLogonSessionId = 0xFFFFFFFF; 257 | ProcessIdToSessionId(entry.th32ProcessID, &dwWinLogonSessionId); 258 | if (dwActiveSessionId == 0xFFFFFFFF || dwActiveSessionId == dwWinLogonSessionId) { 259 | if ((procInteractiveWinlogon = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, entry.th32ProcessID))) { 260 | BOOL bIs32Bit = FALSE; 261 | if (!IsWow64Process(procInteractiveWinlogon, &bIs32Bit) || bIs32Bit) { 262 | CloseHandle(procInteractiveWinlogon); 263 | procInteractiveWinlogon = INVALID_HANDLE_VALUE; 264 | continue; 265 | } 266 | break; 267 | } 268 | } 269 | } 270 | } 271 | } 272 | CloseHandle(hSnapshot); 273 | } 274 | Wh_Log_Original(L"procInteractiveWinlogon: %p\n", procInteractiveWinlogon); 275 | HANDLE tknInteractive = INVALID_HANDLE_VALUE; 276 | if (procInteractiveWinlogon && procInteractiveWinlogon != INVALID_HANDLE_VALUE) { 277 | HANDLE tknWinlogon = INVALID_HANDLE_VALUE; 278 | if (OpenProcessToken(procInteractiveWinlogon, TOKEN_DUPLICATE, &tknWinlogon) && tknWinlogon && tknWinlogon != INVALID_HANDLE_VALUE) { 279 | SECURITY_ATTRIBUTES tokenAttributes; 280 | ZeroMemory(&tokenAttributes, sizeof(SECURITY_ATTRIBUTES)); 281 | tokenAttributes.nLength = sizeof(SECURITY_ATTRIBUTES); 282 | DuplicateTokenEx(tknWinlogon, 0x10000000, &tokenAttributes, SecurityImpersonation, TokenImpersonation, &tknInteractive); 283 | CloseHandle(tknWinlogon); 284 | } 285 | CloseHandle(procInteractiveWinlogon); 286 | } 287 | Wh_Log_Original(L"tknInteractive: %p\n", tknInteractive); 288 | if (tknInteractive && tknInteractive != INVALID_HANDLE_VALUE) { 289 | STARTUPINFO si{}; 290 | si.cb = sizeof(si); 291 | si.lpDesktop = (LPWSTR)L"WinSta0\\Default"; 292 | CreateProcessAsUserW(tknInteractive, nullptr, wszCommand, nullptr, nullptr, false, INHERIT_CALLER_PRIORITY, nullptr, nullptr, &si, &pi); 293 | CloseHandle(tknInteractive); 294 | mut_pi.unlock(); 295 | WaitForSingleObject(pi.hProcess, INFINITE); 296 | mut_pi.lock(); 297 | DWORD dwExitCode = -1; 298 | GetExitCodeProcess(pi.hProcess, &dwExitCode); 299 | Wh_Log_Original(L"Exited process with %d.\n", dwExitCode); 300 | CloseHandle(pi.hThread); 301 | CloseHandle(pi.hProcess); 302 | if (dwExitCode == 0xFFFFFFFF) { 303 | mut_pi.unlock(); 304 | break; 305 | } 306 | Sleep(1000); 307 | } else { 308 | mut_pi.unlock(); 309 | break; 310 | } 311 | } 312 | }); 313 | return TRUE; 314 | } 315 | 316 | void Wh_ModUninit() { 317 | mut_pi.lock(); 318 | if (pi.hThread) { 319 | HANDLE hThread = CreateRemoteThread(pi.hProcess, nullptr, 0, &procClose, reinterpret_cast(GetThreadId(pi.hThread)), 0, nullptr); 320 | if (hThread) { 321 | DWORD dwExitCode = 1; 322 | GetExitCodeProcess(hThread, &dwExitCode); 323 | Wh_Log_Original(L"Exited thread with %d.\n", dwExitCode); 324 | CloseHandle(hThread); 325 | } 326 | } 327 | mut_pi.unlock(); 328 | if (worker.native_handle()) { 329 | worker.join(); 330 | Wh_Log_Original(L"Ended worker.\n"); 331 | } 332 | Wh_Log_Original(L"Uninit"); 333 | } 334 | 335 | void Wh_ModSettingsChanged() { 336 | Wh_Log_Original(L"SettingsChanged"); 337 | } 338 | -------------------------------------------------------------------------------- /mods/valinet-systray-battery-brightness.wh.cpp: -------------------------------------------------------------------------------- 1 | // ==WindhawkMod== 2 | // @id valinet-systray-battery-brightness 3 | // @name Systray Battery Brightness 4 | // @description Change display brightness by scrolling over the battery icon. 5 | // @version 0.1 6 | // @author valinet 7 | // @github https://github.com/valinet 8 | // @include explorer.exe 9 | // @compilerOptions -lcomctl32 -lDxva2 10 | // ==/WindhawkMod== 11 | 12 | // ==WindhawkModReadme== 13 | /* 14 | # Systray Battery Brightness 15 | Change display brightness by scrolling over the battery icon. 16 | */ 17 | // ==/WindhawkModReadme== 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #define UID_TRAYICONVOLUME 100 27 | #define GUID_TRAYICONVOLUME { 0x7820AE73, 0x23E3, 0x4229, { 0x82, 0xC1, 0xE4, 0x1C, 0xB6, 0x7D, 0x5B, 0x9C } }; 28 | 29 | #define UID_TRAYICONPOWER 1225 30 | #define GUID_TRAYICONPOWER { 0x7820AE75, 0x23E3, 0x4229, { 0x82, 0xC1, 0xE4, 0x1C, 0xB6, 0x7D, 0x5B, 0x9C } }; 31 | 32 | #define UID_TRAYICONHOTPLUG 1226 33 | #define GUID_TRAYICONHOTPLUG { 0x7820AE78, 0x23E3, 0x4229, { 0x82, 0xC1, 0xE4, 0x1C, 0xB6, 0x7D, 0x5B, 0x9C } }; 34 | 35 | bool subclassed = false; 36 | HWND hWnd = nullptr; 37 | int brightness = 0; 38 | #define STEP 5 39 | 40 | BOOL CALLBACK MonitorBrightness(HMONITOR unnamedParam1, HDC unnamedParam2, LPRECT unnamedParam3, LPARAM unnamedParam4) { 41 | LPPHYSICAL_MONITOR pPhysicalMonitors = nullptr; 42 | DWORD cPhysicalMonitors = 0; 43 | BOOL bSuccess = GetNumberOfPhysicalMonitorsFromHMONITOR(unnamedParam1, &cPhysicalMonitors); 44 | if (bSuccess) { 45 | pPhysicalMonitors = (LPPHYSICAL_MONITOR)malloc(cPhysicalMonitors * sizeof(PHYSICAL_MONITOR)); 46 | if (pPhysicalMonitors != NULL) { 47 | bSuccess = GetPhysicalMonitorsFromHMONITOR(unnamedParam1, cPhysicalMonitors, pPhysicalMonitors); 48 | if (unnamedParam4 > 100) { 49 | DWORD min, max, cur = 0; 50 | GetMonitorBrightness(pPhysicalMonitors[0].hPhysicalMonitor, &min, &cur, &max); 51 | DWORD* c = (DWORD*)unnamedParam4; 52 | *c = cur; 53 | return false; 54 | } 55 | SetMonitorBrightness(pPhysicalMonitors[0].hPhysicalMonitor, unnamedParam4); 56 | bSuccess = DestroyPhysicalMonitors(cPhysicalMonitors, pPhysicalMonitors); 57 | free(pPhysicalMonitors); 58 | } 59 | } 60 | return true; 61 | } 62 | 63 | LRESULT WINAPI SubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, DWORD_PTR dwRefData) { 64 | if (uMsg == WM_MOUSEWHEEL || uMsg == WM_MOUSEHWHEEL) { 65 | NOTIFYICONIDENTIFIER nid {}; 66 | nid.cbSize = sizeof(nid); 67 | nid.hWnd = hWnd; 68 | nid.uID = UID_TRAYICONPOWER; 69 | nid.guidItem = GUID_TRAYICONPOWER; 70 | RECT rc{}; 71 | POINT pt{}; 72 | GetCursorPos(&pt); 73 | if (SUCCEEDED(Shell_NotifyIconGetRect(&nid, &rc)) && PtInRect(&rc, pt)) { 74 | int factor = GET_WHEEL_DELTA_WPARAM(wParam) / 120; 75 | brightness += (factor * STEP); 76 | if (brightness < 0) brightness = 0; 77 | else if (brightness > 100) brightness = 100; 78 | EnumDisplayMonitors(nullptr, nullptr, MonitorBrightness, static_cast(brightness)); 79 | } 80 | } else if (uMsg == WM_DESTROY) { 81 | subclassed = false; 82 | } 83 | return DefSubclassProc(hWnd, uMsg, wParam, lParam); 84 | } 85 | 86 | BOOL Wh_ModInit() { 87 | Wh_Log(L"Init"); 88 | std::thread([](){ 89 | auto start = GetTickCount64(); 90 | while (true) { 91 | hWnd = FindWindowW(L"Shell_TrayWnd", nullptr); 92 | if (hWnd) { 93 | hWnd = FindWindowExW(hWnd, nullptr, L"TrayNotifyWnd", nullptr); 94 | if (hWnd) { 95 | hWnd = FindWindowExW(hWnd, nullptr, L"SysPager", nullptr); 96 | if (hWnd) { 97 | hWnd = FindWindowExW(hWnd, nullptr, L"ToolbarWindow32", nullptr); 98 | } 99 | } 100 | } 101 | if (hWnd || GetTickCount64() - start > 5000) break; 102 | } 103 | if (hWnd) { 104 | DWORD dwProcessId = 0; 105 | GetWindowThreadProcessId(hWnd, &dwProcessId); 106 | if (dwProcessId == GetCurrentProcessId()) { 107 | EnumDisplayMonitors(nullptr, nullptr, MonitorBrightness, reinterpret_cast(&brightness)); 108 | subclassed = WindhawkUtils::SetWindowSubclassFromAnyThread(hWnd, &SubclassProc, 0); 109 | } 110 | } 111 | }).detach(); 112 | return TRUE; 113 | } 114 | 115 | void Wh_ModUninit() { 116 | if (subclassed) WindhawkUtils::RemoveWindowSubclassFromAnyThread(hWnd, &SubclassProc); 117 | Wh_Log(L"Uninit"); 118 | } 119 | 120 | void Wh_ModSettingsChanged() { 121 | Wh_Log(L"SettingsChanged"); 122 | } 123 | -------------------------------------------------------------------------------- /mods/valinet-systray-sound-volume.wh.cpp: -------------------------------------------------------------------------------- 1 | // ==WindhawkMod== 2 | // @id valinet-systray-sound-volume 3 | // @name Systray Sound Volume 4 | // @description Change system volume by scrolling over the sound icon. 5 | // @version 0.1 6 | // @author valinet 7 | // @github https://github.com/valinet 8 | // @include explorer.exe 9 | // @compilerOptions -lcomctl32 10 | // ==/WindhawkMod== 11 | 12 | // ==WindhawkModReadme== 13 | /* 14 | # Systray Sound Volume 15 | Change system volume by scrolling over the sound icon. 16 | */ 17 | // ==/WindhawkModReadme== 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #define UID_TRAYICONVOLUME 100 25 | #define GUID_TRAYICONVOLUME { 0x7820AE73, 0x23E3, 0x4229, { 0x82, 0xC1, 0xE4, 0x1C, 0xB6, 0x7D, 0x5B, 0x9C } }; 26 | 27 | #define UID_TRAYICONPOWER 1225 28 | #define GUID_TRAYICONPOWER { 0x7820AE75, 0x23E3, 0x4229, { 0x82, 0xC1, 0xE4, 0x1C, 0xB6, 0x7D, 0x5B, 0x9C } }; 29 | 30 | #define UID_TRAYICONHOTPLUG 1226 31 | #define GUID_TRAYICONHOTPLUG { 0x7820AE78, 0x23E3, 0x4229, { 0x82, 0xC1, 0xE4, 0x1C, 0xB6, 0x7D, 0x5B, 0x9C } }; 32 | 33 | bool subclassed = false; 34 | HWND hWnd = nullptr; 35 | 36 | LRESULT WINAPI SubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, DWORD_PTR dwRefData) { 37 | if (uMsg == WM_MOUSEWHEEL || uMsg == WM_MOUSEHWHEEL) { 38 | NOTIFYICONIDENTIFIER nid {}; 39 | nid.cbSize = sizeof(nid); 40 | nid.hWnd = hWnd; 41 | nid.uID = UID_TRAYICONVOLUME; 42 | nid.guidItem = GUID_TRAYICONVOLUME; 43 | RECT rc{}; 44 | POINT pt{}; 45 | GetCursorPos(&pt); 46 | if (SUCCEEDED(Shell_NotifyIconGetRect(&nid, &rc)) && PtInRect(&rc, pt)) { 47 | int factor = GET_WHEEL_DELTA_WPARAM(wParam) / 120; 48 | int normFactor = factor < 0 ? -factor : factor; 49 | for (int i = 0; i < normFactor; ++i) { 50 | WPARAM wParam = (WPARAM)FindWindowW(L"ProgMan", NULL); 51 | LPARAM lParam = factor > 0 ? APPCOMMAND_VOLUME_UP : APPCOMMAND_VOLUME_DOWN; 52 | SendMessageW(reinterpret_cast(wParam), WM_APPCOMMAND, wParam, lParam * 65536); 53 | } 54 | } 55 | } else if (uMsg == WM_DESTROY) { 56 | subclassed = false; 57 | } 58 | return DefSubclassProc(hWnd, uMsg, wParam, lParam); 59 | } 60 | 61 | BOOL Wh_ModInit() { 62 | Wh_Log(L"Init"); 63 | std::thread([](){ 64 | auto start = GetTickCount64(); 65 | while (true) { 66 | hWnd = FindWindowW(L"Shell_TrayWnd", nullptr); 67 | if (hWnd) { 68 | hWnd = FindWindowExW(hWnd, nullptr, L"TrayNotifyWnd", nullptr); 69 | if (hWnd) { 70 | hWnd = FindWindowExW(hWnd, nullptr, L"SysPager", nullptr); 71 | if (hWnd) { 72 | hWnd = FindWindowExW(hWnd, nullptr, L"ToolbarWindow32", nullptr); 73 | } 74 | } 75 | } 76 | if (hWnd || GetTickCount64() - start > 5000) break; 77 | } 78 | if (hWnd) { 79 | DWORD dwProcessId = 0; 80 | GetWindowThreadProcessId(hWnd, &dwProcessId); 81 | if (dwProcessId == GetCurrentProcessId()) { 82 | subclassed = WindhawkUtils::SetWindowSubclassFromAnyThread(hWnd, &SubclassProc, 0); 83 | } 84 | } 85 | }).detach(); 86 | return TRUE; 87 | } 88 | 89 | void Wh_ModUninit() { 90 | if (subclassed) WindhawkUtils::RemoveWindowSubclassFromAnyThread(hWnd, &SubclassProc); 91 | Wh_Log(L"Uninit"); 92 | } 93 | 94 | void Wh_ModSettingsChanged() { 95 | Wh_Log(L"SettingsChanged"); 96 | } 97 | -------------------------------------------------------------------------------- /mods/valinet-unserver.wh.cpp: -------------------------------------------------------------------------------- 1 | // ==WindhawkMod== 2 | // @id valinet-unserver 3 | // @name Treat server OS as client OS 4 | // @description Make server OS report as client OS for specific programs. 5 | // @version 0.1 6 | // @author valinet 7 | // @github https://github.com/valinet 8 | // @homepage https://valinet.ro 9 | // @include RuntimeBroker.exe 10 | // @include taskmgr.exe 11 | // @include disk_image.exe 12 | // @compilerOptions -lshlwapi 13 | // ==/WindhawkMod== 14 | 15 | #include 16 | #include 17 | std::vector runtimeBrokerHooksPackageName = { 18 | std::wstring(L"microsoft.windows.startmenuexperiencehost") 19 | }; 20 | 21 | // ==WindhawkModReadme== 22 | /* 23 | # Treat server OS as client OS 24 | Make server OS report as client OS for specific apps. 25 | */ 26 | // ==/WindhawkModReadme== 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #ifndef STATUS_SUCCESS 44 | #define STATUS_SUCCESS ((NTSTATUS)0x00000000L) 45 | #endif 46 | 47 | #ifndef STATUS_BUFFER_TOO_SMALL 48 | #define STATUS_BUFFER_TOO_SMALL ((NTSTATUS)0xC0000023L) 49 | #endif 50 | 51 | void* memmem(void* haystack, size_t haystacklen, const char* pattern, const char* mask) { 52 | char* text = (char*)haystack; 53 | size_t needlelen = strlen(mask); 54 | char* rv = NULL; 55 | 56 | size_t* out = (size_t*)calloc(needlelen, sizeof(size_t)); 57 | if (!out) return nullptr; 58 | size_t j, i; 59 | 60 | j = 0, i = 1; 61 | while (i < needlelen) { 62 | if (text[j] != text[i]) { 63 | if (j > 0) { 64 | j = out[j - 1]; 65 | continue; 66 | } 67 | else j--; 68 | } 69 | j++; 70 | out[i] = j; 71 | i++; 72 | } 73 | 74 | i = 0, j = 0; 75 | for (i = 0; i <= haystacklen - needlelen; i++) { 76 | if (mask[j] == 'x' ? text[i] == pattern[j] : true) { 77 | j++; 78 | if (j == needlelen) { 79 | rv = text + (int)(i - needlelen + 1); //match++; j = out[j - 1]; 80 | break; 81 | } 82 | } 83 | else { 84 | if (j != 0) { 85 | j = out[j - 1]; 86 | i--; 87 | } 88 | } 89 | } 90 | 91 | free(out); 92 | return (void*)rv; 93 | } 94 | 95 | // https://stackoverflow.com/questions/937044/determine-path-to-registry-key-from-hkey-handle-in-c 96 | std::wstring GetPathFromHKEY(HKEY key) { 97 | std::wstring keyPath; 98 | if (key != NULL) { 99 | HMODULE dll = GetModuleHandleW(L"ntdll.dll"); 100 | if (dll != NULL) { 101 | typedef NTSTATUS (__stdcall *NtQueryKeyType)( 102 | HANDLE KeyHandle, 103 | int KeyInformationClass, 104 | PVOID KeyInformation, 105 | ULONG Length, 106 | PULONG ResultLength); 107 | NtQueryKeyType func = reinterpret_cast(GetProcAddress(dll, "NtQueryKey")); 108 | if (func != NULL) { 109 | DWORD size = 0; 110 | NTSTATUS result = func(key, 3, 0, 0, &size); 111 | if (result == STATUS_BUFFER_TOO_SMALL) { 112 | size = size + 2; 113 | wchar_t* buffer = new (std::nothrow) wchar_t[size/sizeof(wchar_t)]; // size is in bytes 114 | if (buffer != NULL) { 115 | result = func(key, 3, buffer, size, &size); 116 | if (result == STATUS_SUCCESS) { 117 | buffer[size / sizeof(wchar_t)] = L'\0'; 118 | keyPath = std::wstring(buffer + 2); 119 | } 120 | delete[] buffer; 121 | } 122 | } 123 | } 124 | } 125 | } 126 | return keyPath; 127 | } 128 | 129 | LSTATUS (*RegQueryValueExWFunc)(HKEY hKey, LPCWSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData); 130 | LSTATUS RegQueryValueExWHook(HKEY hKey, LPCWSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData) { 131 | Wh_Log(L"RegQueryValueExWHook\n"); 132 | std::wstring path; 133 | if (!wcsicmp(lpValueName, L"ProductType") && (path = GetPathFromHKEY(hKey), !wcsicmp(path.c_str(), L"\\REGISTRY\\MACHINE\\SYSTEM\\ControlSet001\\Control\\ProductOptions"))) { 134 | DWORD len = 20; 135 | wchar_t buffer[len]; 136 | auto rv = RegQueryValueExWFunc(hKey, lpValueName, lpReserved, lpType, (LPBYTE)buffer, &len); 137 | if (lpData) wcscpy(((wchar_t*)lpData), L"WinNT"); 138 | if (lpcbData) *lpcbData = 12; 139 | return rv; 140 | } 141 | auto rv = RegQueryValueExWFunc(hKey, lpValueName, lpReserved, lpType, lpData, lpcbData); 142 | return rv; 143 | } 144 | 145 | NTSTATUS (*RtlGetVersionFunc)(PRTL_OSVERSIONINFOEXW lpVersionInformation) = nullptr; 146 | NTSTATUS RtlGetVersionHook(PRTL_OSVERSIONINFOEXW lpVersionInformation) { 147 | Wh_Log(L"RtlGetVersionHook\n"); 148 | auto rv = RtlGetVersionFunc(lpVersionInformation); 149 | if (lpVersionInformation->dwOSVersionInfoSize == sizeof(RTL_OSVERSIONINFOEXW)) { 150 | lpVersionInformation->wProductType = VER_NT_WORKSTATION; 151 | } 152 | return rv; 153 | } 154 | 155 | BOOL (*GetVersionExFunc)(LPOSVERSIONINFOEXW lpVersionInformation) = nullptr; 156 | BOOL GetVersionExWHook(LPOSVERSIONINFOEXW lpVersionInformation) { 157 | Wh_Log(L"GetVersionExWHook\n"); 158 | auto rv = GetVersionExFunc(lpVersionInformation); 159 | if (lpVersionInformation->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXW)) { 160 | lpVersionInformation->wProductType = VER_NT_WORKSTATION; 161 | } 162 | return rv; 163 | } 164 | 165 | BOOL(*IsOSFunc)(DWORD dwOS) = nullptr; 166 | BOOL IsOSHook(DWORD dwOS) { 167 | Wh_Log(L"IsOSHook\n"); 168 | if (dwOS == OS_ANYSERVER) return FALSE; 169 | return IsOSFunc(dwOS); 170 | } 171 | 172 | BOOL(*IsWindowsServerFunc)() = nullptr; 173 | BOOL IsWindowsServerHook() { 174 | Wh_Log(L"IsWindowsServerHook\n"); 175 | return FALSE; 176 | } 177 | 178 | void PatchKUserSharedDataAccesses() { 179 | // This function tries to redirect memory reads of KUSER_SHARED_DATA 180 | // KUSER_SHARED_DATA is a section mapped into all processes at a fixed 181 | // address (0x7FFE0000) which caches various frequently accessed info 182 | // about the OS, including the product type. Client should read 1, while 183 | // Server reads a 3. Here, we try to redirect memory accesses from the 184 | // NtProductType field to the ComPlusPackage fiels, which should always 185 | // be 1. 186 | auto p = GetModuleHandle(nullptr); 187 | MODULEINFO mi; 188 | K32GetModuleInformation(GetCurrentProcess(), p, &mi, sizeof(MODULEINFO)); 189 | char bytes[] = { '\x64', '\x02', '\xFE', '\x7F'}; 190 | int len = sizeof(bytes); 191 | void *newPattern = p; 192 | auto count = 0; 193 | while ((newPattern = memmem(newPattern, mi.SizeOfImage - ((char*)newPattern - (char*)p), bytes, "xxxx"))) { 194 | MEMORY_BASIC_INFORMATION info {}; 195 | if (VirtualQueryEx(GetCurrentProcess(), reinterpret_cast(newPattern), &info, sizeof(info)) == sizeof(info) && 196 | info.State == MEM_COMMIT && 197 | ((info.Protect & PAGE_EXECUTE) || (info.Protect & PAGE_EXECUTE_READ) || (info.Protect & PAGE_EXECUTE_READWRITE) || (info.Protect & PAGE_EXECUTE_WRITECOPY))) { 198 | int idx = 0; 199 | for (auto i = 0; i < 6; ++i) { 200 | WH_DISASM_RESULT result; 201 | Wh_Disasm((char*)newPattern - i, &result); 202 | if (strstr(result.text, "[0x000000007FFE0264]")) { 203 | idx = i + 1; 204 | std::string s(result.text); 205 | std::wstring ws(s.size(), L' '); 206 | ws.resize(std::mbstowcs(&ws[0], s.c_str(), s.size())); 207 | Wh_Log(L">> Potential instruction: \"%s\"\n", ws.c_str()); 208 | break; 209 | } 210 | } 211 | if (idx) { 212 | ++count; 213 | DWORD dwOldProtect = PAGE_EXECUTE_READWRITE; 214 | VirtualProtect(newPattern, 4, dwOldProtect, &dwOldProtect); 215 | ((char*)newPattern)[0] = 0xE0; 216 | ((char*)newPattern)[1] = 0x02; 217 | VirtualProtect(newPattern, 4, dwOldProtect, &dwOldProtect); 218 | WH_DISASM_RESULT result; 219 | Wh_Disasm((char*)newPattern - idx + 1, &result); 220 | if (strstr(result.text, "[0x000000007FFE")) { 221 | std::string s(result.text); 222 | std::wstring ws(s.size(), L' '); 223 | ws.resize(std::mbstowcs(&ws[0], s.c_str(), s.size())); 224 | Wh_Log(L">> Resulting instruction: \"%s\"\n", ws.c_str()); 225 | } 226 | } 227 | } 228 | newPattern = (char*)newPattern + len; 229 | } 230 | Wh_Log(L"Performed %d patches.\n", count); 231 | } 232 | 233 | BOOL Wh_ModInit() { 234 | Wh_Log(L"Init\n"); 235 | #ifdef _WIN64 236 | const size_t OFFSET_SAME_TEB_FLAGS = 0x17EE; 237 | #else 238 | const size_t OFFSET_SAME_TEB_FLAGS = 0x0FCA; 239 | #endif 240 | bool isInitialThread = *(USHORT*)((BYTE*)NtCurrentTeb() + OFFSET_SAME_TEB_FLAGS) & 0x0400; 241 | Wh_Log(L"isInitialThread=%d", isInitialThread); 242 | wchar_t wszMyPath[MAX_PATH]{}; 243 | GetModuleFileNameW(nullptr, wszMyPath, MAX_PATH); 244 | auto wszMyExeName = wcsrchr(wszMyPath, L'\\'); 245 | if (wszMyExeName && !wcsicmp(wszMyExeName, L"\\RuntimeBroker.exe")) { 246 | bool ok = false; 247 | HMODULE hNtDll = GetModuleHandleW(L"ntdll.dll"); 248 | if (hNtDll) { 249 | auto RtlQueryPackageIdentity = GetProcAddress(hNtDll, "RtlQueryPackageIdentity"); 250 | if (RtlQueryPackageIdentity) { 251 | HANDLE hProcess = GetCurrentProcess(); 252 | if (hProcess) { 253 | HANDLE hToken = INVALID_HANDLE_VALUE; 254 | OpenProcessToken(hProcess, TOKEN_QUERY, &hToken); 255 | if (hToken && hToken != INVALID_HANDLE_VALUE) { 256 | SIZE_T dwPackageName = MAX_PATH; 257 | wchar_t wszPackageName[MAX_PATH]{}; 258 | BOOLEAN bIsPackaged = FALSE; 259 | int rv = ((int(*)(HANDLE, PWSTR, PSIZE_T, PWSTR, PSIZE_T, PBOOLEAN))RtlQueryPackageIdentity)(hToken, wszPackageName, &dwPackageName, nullptr, nullptr, &bIsPackaged); 260 | if (rv == 0 && bIsPackaged) { 261 | for (wchar_t* p = wszPackageName; *p != L'\0'; ++p) if (p[0] >= L'A' && p[0] <= L'Z') p[0] += (L'a' - L'A'); 262 | for (auto& packageName : runtimeBrokerHooksPackageName) { 263 | if (!wcsncmp(wszPackageName, packageName.c_str(), packageName.length())) { 264 | ok = true; 265 | break; 266 | } 267 | } 268 | } 269 | CloseHandle(hToken); 270 | } 271 | CloseHandle(hProcess); 272 | } 273 | } 274 | } 275 | if (!ok) return FALSE; 276 | } 277 | auto isUpxCompressed = [](){ 278 | HMODULE hModule = GetModuleHandleW(nullptr); 279 | if (hModule) { 280 | PIMAGE_DOS_HEADER dosHeader = (PIMAGE_DOS_HEADER)hModule; 281 | if (dosHeader) { 282 | PIMAGE_NT_HEADERS ntHeaders = (PIMAGE_NT_HEADERS)((BYTE*)hModule + dosHeader->e_lfanew); 283 | if (ntHeaders) { 284 | PIMAGE_SECTION_HEADER sectionHeaders = (PIMAGE_SECTION_HEADER)((BYTE*)&ntHeaders->OptionalHeader + ntHeaders->FileHeader.SizeOfOptionalHeader); 285 | if (sectionHeaders) { 286 | for (int i = 0; i < ntHeaders->FileHeader.NumberOfSections; i++) { 287 | if (std::string((char*)sectionHeaders[i].Name) == "UPX0") { 288 | return true; 289 | } 290 | } 291 | } 292 | } 293 | } 294 | } 295 | return false; 296 | }(); 297 | Wh_Log(L"isUpxCompressed=%d\n", isUpxCompressed); 298 | if (!isUpxCompressed) PatchKUserSharedDataAccesses(); 299 | else { 300 | HANDLE hFirstThread = INVALID_HANDLE_VALUE; 301 | DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &hFirstThread, 0, false, DUPLICATE_SAME_ACCESS); 302 | if (hFirstThread && hFirstThread != INVALID_HANDLE_VALUE) std::thread([hFirstThread](){ 303 | bool suspended = false; 304 | 305 | // Wait for UPX to unpack executable 306 | auto start = GetTickCount64(); 307 | while (true) { 308 | PCONTEXT pContext = nullptr; 309 | unsigned long len = 4096; 310 | char buffer[len]; 311 | InitializeContext(reinterpret_cast(buffer), CONTEXT_FULL, &pContext, &len); 312 | GetThreadContext(hFirstThread, pContext); 313 | MEMORY_BASIC_INFORMATION info {}; 314 | #ifdef _WIN64 315 | if (VirtualQueryEx(GetCurrentProcess(), reinterpret_cast(pContext->Rip), &info, sizeof(info)) == sizeof(info) && info.State == MEM_COMMIT && info.Protect == PAGE_EXECUTE_READWRITE) { 316 | #else 317 | if (VirtualQueryEx(GetCurrentProcess(), reinterpret_cast(pContext->Eip), &info, sizeof(info)) == sizeof(info) && info.State == MEM_COMMIT && info.Protect == PAGE_EXECUTE_READWRITE) { 318 | #endif 319 | suspended = true; 320 | SuspendThread(hFirstThread); 321 | break; 322 | } 323 | if (GetTickCount64() - start > 2000) break; 324 | } 325 | PatchKUserSharedDataAccesses(); 326 | if (suspended) ResumeThread(hFirstThread); 327 | CloseHandle(hFirstThread); 328 | }).detach(); 329 | } 330 | Wh_SetFunctionHook(reinterpret_cast(&RegQueryValueExW), reinterpret_cast(&RegQueryValueExWHook), reinterpret_cast(&RegQueryValueExWFunc)); 331 | Wh_SetFunctionHook(reinterpret_cast(&GetVersionExW), reinterpret_cast(&GetVersionExWHook), reinterpret_cast(&GetVersionExFunc)); 332 | Wh_SetFunctionHook(reinterpret_cast(&IsOS), reinterpret_cast(&IsOSHook), reinterpret_cast(&IsOSFunc)); 333 | Wh_SetFunctionHook(reinterpret_cast(&IsWindowsServer), reinterpret_cast(&IsWindowsServerHook), reinterpret_cast(&IsWindowsServerFunc)); 334 | Wh_SetFunctionHook(reinterpret_cast(GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlGetVersion")), reinterpret_cast(&RtlGetVersionHook), reinterpret_cast(&RtlGetVersionFunc)); 335 | return TRUE; 336 | } 337 | 338 | void Wh_ModUninit() { 339 | if (RegQueryValueExWFunc) Wh_RemoveFunctionHook(reinterpret_cast(&RegQueryValueExW)); 340 | if (GetVersionExFunc) Wh_RemoveFunctionHook(reinterpret_cast(&GetVersionExW)); 341 | if (IsOSFunc) Wh_RemoveFunctionHook(reinterpret_cast(&IsOS)); 342 | if (IsWindowsServerFunc) Wh_RemoveFunctionHook(reinterpret_cast(&IsWindowsServer)); 343 | if (RtlGetVersionFunc) Wh_RemoveFunctionHook(reinterpret_cast(GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlGetVersion"))); 344 | Wh_Log(L"Uninit"); 345 | } 346 | 347 | void Wh_ModSettingsChanged() { 348 | Wh_Log(L"SettingsChanged"); 349 | } 350 | -------------------------------------------------------------------------------- /mods/valinet-vmware-frame-fix.wh.cpp: -------------------------------------------------------------------------------- 1 | // ==WindhawkMod== 2 | // @id valinet-vmware-frame-fix 3 | // @name VMware: Fix window frame 4 | // @description VMware: Fix window frame 5 | // @version 0.1 6 | // @author valinet 7 | // @github https://github.com/valinet 8 | // @homepage https://valinet.ro 9 | // @include vmware.exe 10 | // @compilerOptions -lcomctl32 11 | // ==/WindhawkMod== 12 | 13 | // ==WindhawkModReadme== 14 | /*...*/ 15 | // ==/WindhawkModReadme== 16 | 17 | #include 18 | 19 | HWND subclassed = nullptr; 20 | LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, DWORD_PTR dwRefData) { 21 | if (uMsg == WM_NCCALCSIZE || uMsg == WM_NCPAINT || uMsg == WM_NCACTIVATE) { 22 | return DefWindowProcW(hWnd, uMsg, wParam, lParam); 23 | } 24 | return DefSubclassProc(hWnd, uMsg, wParam, lParam); 25 | } 26 | 27 | using GetClientRect_t = decltype(&GetClientRect); 28 | GetClientRect_t GetClientRectFunc; 29 | BOOL WINAPI GetClientRectHook(HWND hWnd, LPRECT lpRect) { 30 | if (!subclassed && GetClassWord(hWnd, GCW_ATOM) == RegisterWindowMessageW(L"VMUIFrame") && WindhawkUtils::SetWindowSubclassFromAnyThread(hWnd, WndProc, 0)) { 31 | subclassed = hWnd; 32 | } 33 | return GetClientRectFunc(hWnd, lpRect); 34 | } 35 | 36 | BOOL Wh_ModInit() { 37 | subclassed = FindWindowExW(nullptr, nullptr, L"VMUIFrame", nullptr); 38 | if (subclassed) { 39 | if (!WindhawkUtils::SetWindowSubclassFromAnyThread(subclassed, WndProc, 0)) subclassed = nullptr; 40 | } else { 41 | Wh_SetFunctionHook(reinterpret_cast(&GetClientRect), reinterpret_cast(&GetClientRectHook), reinterpret_cast(&GetClientRectFunc)); 42 | } 43 | return TRUE; 44 | } 45 | 46 | void Wh_ModUninit() { 47 | if (GetClientRectFunc) Wh_RemoveFunctionHook(reinterpret_cast(&GetClientRect)); 48 | if (subclassed) WindhawkUtils::RemoveWindowSubclassFromAnyThread(subclassed, WndProc); 49 | } 50 | -------------------------------------------------------------------------------- /mods/valinet-waves-audio-fix.wh.cpp: -------------------------------------------------------------------------------- 1 | // ==WindhawkMod== 2 | // @id valinet-waves-audio-fix 3 | // @name Waves Audio Fix 4 | // @description Fix crash of audio service due to Waves Audio under certain setups, like running Windows Server OS. 5 | // @version 0.1 6 | // @author valinet 7 | // @github https://github.com/valinet 8 | // @homepage https://valinet.ro 9 | // @include audiodg.exe 10 | // ==/WindhawkMod== 11 | 12 | // ==WindhawkModReadme== 13 | /* 14 | # Waves Audio Fix 15 | Fix crash of audio service due to Waves Audio under certain setups, like running Windows Server OS. 16 | */ 17 | // ==/WindhawkModReadme== 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | PVOID pHandler = nullptr; 24 | 25 | bool patch(char* pAddr, const wchar_t* wszModule, int pEquals) { 26 | auto pWaves = GetModuleHandleW(wszModule); 27 | if (pWaves) { 28 | if (pAddr - reinterpret_cast(pWaves) == pEquals) { 29 | DWORD dwOldProtect = PAGE_EXECUTE_READWRITE; 30 | if (VirtualProtect(pAddr, 6, dwOldProtect, &dwOldProtect)) { 31 | pAddr[0] = 0x48; pAddr[1] = 0x31; pAddr[2] = 0xc0; // xor rax, rax 32 | pAddr[3] = 0x48; pAddr[4] = 0xff; pAddr[5] = 0xc8; // dec rax 33 | VirtualProtect(pAddr, 6, dwOldProtect, &dwOldProtect); 34 | return true; 35 | } 36 | } 37 | } 38 | return false; 39 | } 40 | 41 | LONG NTAPI OnVex(PEXCEPTION_POINTERS ExceptionInfo) { 42 | if (ExceptionInfo->ExceptionRecord->ExceptionCode == STATUS_ACCESS_VIOLATION && ( 43 | patch(reinterpret_cast(ExceptionInfo->ExceptionRecord->ExceptionAddress), L"MaxxAudioRenderAVX64.dll", 0x157c47) || 44 | patch(reinterpret_cast(ExceptionInfo->ExceptionRecord->ExceptionAddress), L"MaxxAudioRender64.dll", 0x15c787) || 45 | patch(reinterpret_cast(ExceptionInfo->ExceptionRecord->ExceptionAddress), L"MaxxAudioCapture64.dll", 0x11618a))) { 46 | return EXCEPTION_CONTINUE_EXECUTION; 47 | } 48 | return EXCEPTION_CONTINUE_SEARCH; 49 | } 50 | 51 | // The mod is being initialized, load settings, hook functions, and do other 52 | // initialization stuff if required. 53 | BOOL Wh_ModInit() { 54 | pHandler = AddVectoredExceptionHandler(true, OnVex); 55 | Wh_Log(L"Init: %p\n", pHandler); 56 | return TRUE; 57 | } 58 | 59 | // The mod is being unloaded, free all allocated resources. 60 | void Wh_ModUninit() { 61 | if (pHandler) RemoveVectoredExceptionHandler(pHandler); 62 | Wh_Log(L"Uninit"); 63 | } 64 | 65 | // The mod setting were changed, reload them. 66 | void Wh_ModSettingsChanged() { 67 | Wh_Log(L"SettingsChanged"); 68 | } 69 | --------------------------------------------------------------------------------