├── .clang-format ├── .editorconfig ├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── UWPSpy.sln ├── UWPSpy ├── AboutDlg.cpp ├── AboutDlg.h ├── MainDlg.cpp ├── MainDlg.h ├── UWPSpy.cpp ├── UWPSpy.h ├── UWPSpy.rc ├── UWPSpy.rc2 ├── UWPSpy.vcxproj ├── UWPSpy.vcxproj.filters ├── _exports.def ├── flash_area.cpp ├── flash_area.h ├── module.cpp ├── packages.config ├── res │ ├── UWPSpy.ico │ └── selbox.png ├── resource.h ├── simplefactory.hpp ├── stdafx.cpp ├── stdafx.h ├── tap.cpp ├── tap.hpp ├── targetver.h ├── visualtreewatcher.cpp ├── visualtreewatcher.hpp ├── winrt.hpp └── winui │ └── microsoft.ui.xaml.hosting.desktopwindowxamlsource_winui.h ├── UWPSpyLauncher ├── MainDlg.cpp ├── MainDlg.h ├── UWPSpyLauncher.cpp ├── UWPSpyLauncher.ico ├── UWPSpyLauncher.rc ├── UWPSpyLauncher.rc2 ├── UWPSpyLauncher.vcxproj ├── UWPSpyLauncher.vcxproj.filters ├── packages.config ├── process_spy.cpp ├── process_spy.h ├── res │ ├── UWPSpyLauncher.ico │ └── manifest.manifest ├── resource.h ├── stdafx.cpp ├── stdafx.h └── targetver.h ├── common └── version.h ├── icon.png ├── screenshot-video.png └── screenshot.png /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Chromium 2 | IndentWidth: 4 3 | 4 | # Make sure code like: 5 | # IPC_BEGIN_MESSAGE_MAP() 6 | # IPC_MESSAGE_HANDLER(WidgetHostViewHost_Update, OnUpdate) 7 | # IPC_END_MESSAGE_MAP() 8 | # gets correctly indented. 9 | MacroBlockBegin: "^\ 10 | BEGIN_MSG_MAP|\ 11 | BEGIN_MSG_MAP_EX|\ 12 | BEGIN_DLGRESIZE_MAP$" 13 | MacroBlockEnd: "^\ 14 | END_MSG_MAP|\ 15 | END_DLGRESIZE_MAP$" 16 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Top-most EditorConfig file 2 | root = true 3 | 4 | # Set default charset (what year is it?!) 5 | [*.{c,cpp,h}] 6 | charset = utf-8 7 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.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/master/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 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 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 LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | UWPSpy 635 | Copyright (C) 2023 Ramen Software 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | UWPSpy Copyright (C) 2023 Ramen Software 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 |

UWPSpy

4 |
5 | 6 | An inspection tool for UWP and WinUI 3 applications. Seamlessly view and 7 | manipulate UI elements and their properties in real time. 8 | 9 | [🏠 Homepage](https://ramensoftware.com/uwpspy) 10 | 11 | ![Screenshot](screenshot.png) 12 | 13 | ## Usage 14 | 15 | - Download the latest release from 16 | [here](https://ramensoftware.com/downloads/uwpspy.zip). 17 | - Run **UWPSpy.exe** and select the UWP/WinUI 3 application you want to spy on. 18 | - A window with the application's UI elements will appear for each UI thread of 19 | the target application. 20 | 21 | ## Demo 22 | 23 | [![Demo video](screenshot-video.png)](https://youtu.be/Zxgk_BOVpfk) 24 | *Click on the image to view the demo video on YouTube.* 25 | 26 | ## Supported Windows versions 27 | 28 | UWPSpy uses the [XAML Diagnostic 29 | APIs](https://learn.microsoft.com/en-us/windows/win32/api/xamlom/nf-xamlom-initializexamldiagnosticsex) 30 | which were added in Windows 10, version 1703. Earlier versions of Windows are 31 | not supported. 32 | 33 | ## References 34 | 35 | - The 36 | [`ExplorerTAP`](https://github.com/TranslucentTB/TranslucentTB/tree/release/ExplorerTAP) 37 | part of the [TranslucentTB](https://github.com/TranslucentTB/TranslucentTB) 38 | project. That's the only usage example of the XAML Diagnostic APIs I could 39 | find on the internet. 40 | - [Ahmed Walid (ahmed605)](https://github.com/ahmed605), thanks for helping with 41 | many UWP-related questions. 42 | -------------------------------------------------------------------------------- /UWPSpy.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.6.33723.286 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UWPSpy", "UWPSpy\UWPSpy.vcxproj", "{D5BFF041-D26D-4765-935E-BE0D0D4A6C99}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UWPSpyLauncher", "UWPSpyLauncher\UWPSpyLauncher.vcxproj", "{590CB37A-8E25-4A5D-B358-DE4BAA08DB59}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|ARM64 = Debug|ARM64 13 | Debug|x64 = Debug|x64 14 | Debug|x86 = Debug|x86 15 | Release|ARM64 = Release|ARM64 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {D5BFF041-D26D-4765-935E-BE0D0D4A6C99}.Debug|ARM64.ActiveCfg = Debug|ARM64 21 | {D5BFF041-D26D-4765-935E-BE0D0D4A6C99}.Debug|ARM64.Build.0 = Debug|ARM64 22 | {D5BFF041-D26D-4765-935E-BE0D0D4A6C99}.Debug|x64.ActiveCfg = Debug|x64 23 | {D5BFF041-D26D-4765-935E-BE0D0D4A6C99}.Debug|x64.Build.0 = Debug|x64 24 | {D5BFF041-D26D-4765-935E-BE0D0D4A6C99}.Debug|x86.ActiveCfg = Debug|Win32 25 | {D5BFF041-D26D-4765-935E-BE0D0D4A6C99}.Debug|x86.Build.0 = Debug|Win32 26 | {D5BFF041-D26D-4765-935E-BE0D0D4A6C99}.Release|ARM64.ActiveCfg = Release|ARM64 27 | {D5BFF041-D26D-4765-935E-BE0D0D4A6C99}.Release|ARM64.Build.0 = Release|ARM64 28 | {D5BFF041-D26D-4765-935E-BE0D0D4A6C99}.Release|x64.ActiveCfg = Release|x64 29 | {D5BFF041-D26D-4765-935E-BE0D0D4A6C99}.Release|x64.Build.0 = Release|x64 30 | {D5BFF041-D26D-4765-935E-BE0D0D4A6C99}.Release|x86.ActiveCfg = Release|Win32 31 | {D5BFF041-D26D-4765-935E-BE0D0D4A6C99}.Release|x86.Build.0 = Release|Win32 32 | {590CB37A-8E25-4A5D-B358-DE4BAA08DB59}.Debug|ARM64.ActiveCfg = Debug|ARM64 33 | {590CB37A-8E25-4A5D-B358-DE4BAA08DB59}.Debug|ARM64.Build.0 = Debug|ARM64 34 | {590CB37A-8E25-4A5D-B358-DE4BAA08DB59}.Debug|x64.ActiveCfg = Debug|x64 35 | {590CB37A-8E25-4A5D-B358-DE4BAA08DB59}.Debug|x64.Build.0 = Debug|x64 36 | {590CB37A-8E25-4A5D-B358-DE4BAA08DB59}.Debug|x86.ActiveCfg = Debug|Win32 37 | {590CB37A-8E25-4A5D-B358-DE4BAA08DB59}.Debug|x86.Build.0 = Debug|Win32 38 | {590CB37A-8E25-4A5D-B358-DE4BAA08DB59}.Release|ARM64.ActiveCfg = Release|ARM64 39 | {590CB37A-8E25-4A5D-B358-DE4BAA08DB59}.Release|ARM64.Build.0 = Release|ARM64 40 | {590CB37A-8E25-4A5D-B358-DE4BAA08DB59}.Release|x64.ActiveCfg = Release|x64 41 | {590CB37A-8E25-4A5D-B358-DE4BAA08DB59}.Release|x64.Build.0 = Release|x64 42 | {590CB37A-8E25-4A5D-B358-DE4BAA08DB59}.Release|x86.ActiveCfg = Release|Win32 43 | {590CB37A-8E25-4A5D-B358-DE4BAA08DB59}.Release|x86.Build.0 = Release|Win32 44 | EndGlobalSection 45 | GlobalSection(SolutionProperties) = preSolution 46 | HideSolutionNode = FALSE 47 | EndGlobalSection 48 | GlobalSection(ExtensibilityGlobals) = postSolution 49 | SolutionGuid = {21ADA168-295B-441E-A84F-81A20ABDBAEE} 50 | EndGlobalSection 51 | EndGlobal 52 | -------------------------------------------------------------------------------- /UWPSpy/AboutDlg.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "aboutdlg.h" 4 | 5 | #include "../common/version.h" 6 | 7 | namespace { 8 | 9 | void OpenUrl(HWND hWnd, PCWSTR url) { 10 | if ((INT_PTR)ShellExecute(hWnd, L"open", url, nullptr, nullptr, 11 | SW_SHOWNORMAL) <= 32) { 12 | CString errorMsg; 13 | errorMsg.Format( 14 | L"Failed to open link, you can copy it with Ctrl+C and open it in " 15 | L"a browser manually:\n\n%s", 16 | url); 17 | MessageBox(hWnd, errorMsg, nullptr, MB_ICONHAND); 18 | } 19 | } 20 | 21 | } // namespace 22 | 23 | BOOL CAboutDlg::OnInitDialog(CWindow wndFocus, LPARAM lInitParam) { 24 | // Center the dialog on the screen. 25 | CenterWindow(); 26 | 27 | // Set icons. 28 | m_icon = AtlLoadIconImage(IDR_MAINFRAME, LR_DEFAULTCOLOR, 29 | ::GetSystemMetrics(SM_CXICON), 30 | ::GetSystemMetrics(SM_CYICON)); 31 | SetIcon(m_icon, TRUE); 32 | m_smallIcon = AtlLoadIconImage(IDR_MAINFRAME, LR_DEFAULTCOLOR, 33 | ::GetSystemMetrics(SM_CXSMICON), 34 | ::GetSystemMetrics(SM_CYSMICON)); 35 | SetIcon(m_smallIcon, FALSE); 36 | 37 | CString titleStr; 38 | GetDlgItemText(IDC_ABOUT_TITLE, titleStr); 39 | titleStr.Replace(L"%s", VER_FILE_VERSION_WSTR); 40 | SetDlgItemText(IDC_ABOUT_TITLE, titleStr); 41 | 42 | return TRUE; 43 | } 44 | 45 | void CAboutDlg::OnButtonRamenSoftware(UINT uNotifyCode, 46 | int nID, 47 | CWindow wndCtl) { 48 | OpenUrl(m_hWnd, L"https://ramensoftware.com/"); 49 | } 50 | 51 | void CAboutDlg::OnButtonHomepage(UINT uNotifyCode, int nID, CWindow wndCtl) { 52 | OpenUrl(m_hWnd, L"https://ramensoftware.com/uwpspy"); 53 | } 54 | 55 | void CAboutDlg::OnButtonSourceCode(UINT uNotifyCode, int nID, CWindow wndCtl) { 56 | OpenUrl(m_hWnd, L"https://github.com/m417z/UWPSpy"); 57 | } 58 | 59 | void CAboutDlg::OnOK(UINT uNotifyCode, int nID, CWindow wndCtl) { 60 | EndDialog(nID); 61 | } 62 | 63 | void CAboutDlg::OnCancel(UINT uNotifyCode, int nID, CWindow wndCtl) { 64 | EndDialog(nID); 65 | } 66 | -------------------------------------------------------------------------------- /UWPSpy/AboutDlg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "resource.h" 4 | 5 | class CAboutDlg : public CDialogImpl { 6 | public: 7 | enum { IDD = IDD_ABOUT }; 8 | 9 | private: 10 | BEGIN_MSG_MAP_EX(CAboutDlg) 11 | MSG_WM_INITDIALOG(OnInitDialog) 12 | COMMAND_HANDLER_EX(IDC_ABOUT_BUTTON_RAMEN_SOFTWARE, BN_CLICKED, 13 | OnButtonRamenSoftware) 14 | COMMAND_HANDLER_EX(IDC_ABOUT_BUTTON_HOMEPAGE, BN_CLICKED, 15 | OnButtonHomepage) 16 | COMMAND_HANDLER_EX(IDC_ABOUT_BUTTON_SOURCE_CODE, BN_CLICKED, 17 | OnButtonSourceCode) 18 | COMMAND_ID_HANDLER_EX(IDOK, OnOK) 19 | COMMAND_ID_HANDLER_EX(IDCANCEL, OnCancel) 20 | END_MSG_MAP() 21 | 22 | BOOL OnInitDialog(CWindow wndFocus, LPARAM lInitParam); 23 | void OnButtonRamenSoftware(UINT uNotifyCode, int nID, CWindow wndCtl); 24 | void OnButtonHomepage(UINT uNotifyCode, int nID, CWindow wndCtl); 25 | void OnButtonSourceCode(UINT uNotifyCode, int nID, CWindow wndCtl); 26 | void OnOK(UINT uNotifyCode, int nID, CWindow wndCtl); 27 | void OnCancel(UINT uNotifyCode, int nID, CWindow wndCtl); 28 | 29 | CIcon m_icon, m_smallIcon; 30 | }; 31 | -------------------------------------------------------------------------------- /UWPSpy/MainDlg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "resource.h" 4 | #include "winrt.hpp" 5 | 6 | class CMainDlg : public CDialogImpl, public CDialogResize { 7 | public: 8 | enum { IDD = IDD_MAINDLG }; 9 | 10 | enum { 11 | TIMER_ID_REDRAW_TREE = 1, 12 | TIMER_ID_SET_SELECTED_ELEMENT_INFORMATION, 13 | TIMER_ID_REFRESH_SELECTED_ELEMENT_INFORMATION, 14 | }; 15 | 16 | enum { 17 | UWM_ACTIVATE_WINDOW = WM_APP, 18 | UWM_DESTROY_WINDOW, 19 | }; 20 | 21 | enum class EventId { 22 | Shown, 23 | Hidden, 24 | FinalMessage, 25 | }; 26 | 27 | using OnEventCallback_t = std::function; 28 | 29 | CMainDlg(winrt::com_ptr diagnostics, 30 | OnEventCallback_t eventCallback); 31 | void Hide(); 32 | void Show(); 33 | void ElementAdded(const ParentChildRelation& parentChildRelation, 34 | const VisualElement& element); 35 | void ElementRemoved(InstanceHandle handle); 36 | 37 | private: 38 | BEGIN_MSG_MAP_EX(CMainDlg) 39 | CHAIN_MSG_MAP(CDialogResize) 40 | MSG_WM_INITDIALOG(OnInitDialog) 41 | MSG_WM_DESTROY(OnDestroy) 42 | MSG_WM_TIMER(OnTimer) 43 | MSG_WM_CONTEXTMENU(OnContextMenu) 44 | NOTIFY_HANDLER_EX(IDC_ELEMENT_TREE, TVN_SELCHANGED, 45 | OnElementTreeSelChanged) 46 | COMMAND_ID_HANDLER_EX(IDC_SPLIT_TOGGLE, OnSplitToggle) 47 | NOTIFY_HANDLER_EX(IDC_DETAILS_TABS, TCN_SELCHANGE, 48 | OnDetailsTabsSelChange) 49 | NOTIFY_HANDLER_EX(IDC_ATTRIBUTE_LIST, NM_DBLCLK, OnAttributesListDblClk) 50 | COMMAND_HANDLER_EX(IDC_PROPERTY_NAME, CBN_SELCHANGE, 51 | OnPropertyNameSelChange) 52 | COMMAND_ID_HANDLER_EX(IDC_PROPERTY_IS_XAML, OnPropertyIsXaml) 53 | COMMAND_ID_HANDLER_EX(IDC_PROPERTY_REMOVE, OnPropertyRemove) 54 | COMMAND_ID_HANDLER_EX(IDC_PROPERTY_SET, OnPropertySet) 55 | COMMAND_ID_HANDLER_EX(IDC_COLLAPSE_ALL, OnCollapseAll) 56 | COMMAND_HANDLER_EX(IDC_HIGHLIGHT_SELECTION, BN_CLICKED, 57 | OnHighlightSelection) 58 | COMMAND_HANDLER_EX(IDC_DETAILED_PROPERTIES, BN_CLICKED, 59 | OnDetailedProperties) 60 | COMMAND_ID_HANDLER_EX(ID_APP_ABOUT, OnAppAbout) 61 | COMMAND_ID_HANDLER_EX(IDCANCEL, OnCancel) 62 | MESSAGE_HANDLER_EX(UWM_ACTIVATE_WINDOW, OnActivateWindow) 63 | MESSAGE_HANDLER_EX(UWM_DESTROY_WINDOW, OnDestroyWindow) 64 | // ---------- 65 | ALT_MSG_MAP(1) 66 | MSG_WM_CHAR(ElementTreeOnChar) 67 | END_MSG_MAP() 68 | 69 | struct ResizeData : public CDialogResize { 70 | BEGIN_DLGRESIZE_MAP(ResizeData) 71 | DLGRESIZE_CONTROL(IDC_ELEMENT_TREE, DLSZ_SIZE_X | DLSZ_SIZE_Y) 72 | DLGRESIZE_CONTROL(IDC_SPLIT_TOGGLE, DLSZ_MOVE_X | DLSZ_CENTER_Y) 73 | DLGRESIZE_CONTROL(IDC_CLASS_STATIC, DLSZ_MOVE_X) 74 | DLGRESIZE_CONTROL(IDC_CLASS_EDIT, DLSZ_MOVE_X | DLSZ_SIZE_X) 75 | DLGRESIZE_CONTROL(IDC_NAME_STATIC, DLSZ_MOVE_X) 76 | DLGRESIZE_CONTROL(IDC_NAME_EDIT, DLSZ_MOVE_X | DLSZ_SIZE_X) 77 | DLGRESIZE_CONTROL(IDC_RECT_STATIC, DLSZ_MOVE_X) 78 | DLGRESIZE_CONTROL(IDC_RECT_EDIT, DLSZ_MOVE_X) 79 | DLGRESIZE_CONTROL(IDC_DETAILS_TABS, DLSZ_MOVE_X) 80 | DLGRESIZE_CONTROL(IDC_ATTRIBUTE_LIST, DLSZ_MOVE_X | DLSZ_SIZE_Y) 81 | DLGRESIZE_CONTROL(IDC_VISUAL_STATE_TREE, DLSZ_MOVE_X | DLSZ_SIZE_Y) 82 | DLGRESIZE_CONTROL(IDC_PROPERTY_NAME, DLSZ_MOVE_X | DLSZ_MOVE_Y) 83 | DLGRESIZE_CONTROL(IDC_PROPERTY_VALUE, DLSZ_MOVE_X | DLSZ_MOVE_Y) 84 | DLGRESIZE_CONTROL(IDC_PROPERTY_VALUE_XAML, 85 | DLSZ_MOVE_X | DLSZ_MOVE_Y) 86 | DLGRESIZE_CONTROL(IDC_PROPERTY_IS_XAML, DLSZ_MOVE_X | DLSZ_MOVE_Y) 87 | DLGRESIZE_CONTROL(IDC_PROPERTY_REMOVE, DLSZ_MOVE_X | DLSZ_MOVE_Y) 88 | DLGRESIZE_CONTROL(IDC_PROPERTY_SET, DLSZ_MOVE_X | DLSZ_MOVE_Y) 89 | DLGRESIZE_CONTROL(IDC_COLLAPSE_ALL, DLSZ_MOVE_Y) 90 | DLGRESIZE_CONTROL(IDC_HIGHLIGHT_SELECTION, DLSZ_MOVE_Y) 91 | DLGRESIZE_CONTROL(IDC_DETAILED_PROPERTIES, DLSZ_MOVE_Y) 92 | DLGRESIZE_CONTROL(ID_APP_ABOUT, DLSZ_MOVE_X | DLSZ_MOVE_Y) 93 | END_DLGRESIZE_MAP() 94 | }; 95 | 96 | struct ResizeDataAttributesExpanded 97 | : public CDialogResize { 98 | BEGIN_DLGRESIZE_MAP(ResizeDataAttributesExpanded) 99 | DLGRESIZE_CONTROL(IDC_ELEMENT_TREE, DLSZ_SIZE_Y) 100 | DLGRESIZE_CONTROL(IDC_SPLIT_TOGGLE, DLSZ_CENTER_Y) 101 | DLGRESIZE_CONTROL(IDC_CLASS_STATIC, 0) 102 | DLGRESIZE_CONTROL(IDC_CLASS_EDIT, DLSZ_SIZE_X) 103 | DLGRESIZE_CONTROL(IDC_NAME_STATIC, 0) 104 | DLGRESIZE_CONTROL(IDC_NAME_EDIT, DLSZ_SIZE_X) 105 | DLGRESIZE_CONTROL(IDC_RECT_STATIC, 0) 106 | DLGRESIZE_CONTROL(IDC_RECT_EDIT, DLSZ_SIZE_X) 107 | DLGRESIZE_CONTROL(IDC_DETAILS_TABS, DLSZ_SIZE_X) 108 | DLGRESIZE_CONTROL(IDC_ATTRIBUTE_LIST, DLSZ_SIZE_X | DLSZ_SIZE_Y) 109 | DLGRESIZE_CONTROL(IDC_VISUAL_STATE_TREE, DLSZ_SIZE_X | DLSZ_SIZE_Y) 110 | DLGRESIZE_CONTROL(IDC_PROPERTY_NAME, DLSZ_SIZE_X | DLSZ_MOVE_Y) 111 | DLGRESIZE_CONTROL(IDC_PROPERTY_VALUE, DLSZ_SIZE_X | DLSZ_MOVE_Y) 112 | DLGRESIZE_CONTROL(IDC_PROPERTY_VALUE_XAML, 113 | DLSZ_SIZE_X | DLSZ_MOVE_Y) 114 | DLGRESIZE_CONTROL(IDC_PROPERTY_IS_XAML, DLSZ_MOVE_X | DLSZ_MOVE_Y) 115 | DLGRESIZE_CONTROL(IDC_PROPERTY_REMOVE, DLSZ_MOVE_X | DLSZ_MOVE_Y) 116 | DLGRESIZE_CONTROL(IDC_PROPERTY_SET, DLSZ_MOVE_X | DLSZ_MOVE_Y) 117 | DLGRESIZE_CONTROL(IDC_COLLAPSE_ALL, DLSZ_MOVE_Y) 118 | DLGRESIZE_CONTROL(IDC_HIGHLIGHT_SELECTION, DLSZ_MOVE_Y) 119 | DLGRESIZE_CONTROL(IDC_DETAILED_PROPERTIES, DLSZ_MOVE_Y) 120 | DLGRESIZE_CONTROL(ID_APP_ABOUT, DLSZ_MOVE_X | DLSZ_MOVE_Y) 121 | END_DLGRESIZE_MAP() 122 | }; 123 | 124 | const _AtlDlgResizeMap* GetDlgResizeMap() { 125 | return m_splitModeAttributesExpanded 126 | ? ResizeDataAttributesExpanded::GetDlgResizeMap() 127 | : ResizeData::GetDlgResizeMap(); 128 | } 129 | 130 | struct ElementItem { 131 | InstanceHandle parentHandle; 132 | std::wstring itemTitle; 133 | HTREEITEM treeItem; 134 | }; 135 | 136 | BOOL OnInitDialog(CWindow wndFocus, LPARAM lInitParam); 137 | void OnDestroy(); 138 | void OnTimer(UINT_PTR nIDEvent); 139 | void OnContextMenu(CWindow wnd, CPoint point); 140 | LRESULT OnElementTreeSelChanged(LPNMHDR pnmh); 141 | void OnSplitToggle(UINT uNotifyCode, int nID, CWindow wndCtl); 142 | LRESULT OnDetailsTabsSelChange(LPNMHDR pnmh); 143 | LRESULT OnAttributesListDblClk(LPNMHDR pnmh); 144 | void OnPropertyNameSelChange(UINT uNotifyCode, int nID, CWindow wndCtl); 145 | void OnPropertyIsXaml(UINT uNotifyCode, int nID, CWindow wndCtl); 146 | void OnPropertyRemove(UINT uNotifyCode, int nID, CWindow wndCtl); 147 | void OnPropertySet(UINT uNotifyCode, int nID, CWindow wndCtl); 148 | void OnCollapseAll(UINT uNotifyCode, int nID, CWindow wndCtl); 149 | void OnHighlightSelection(UINT uNotifyCode, int nID, CWindow wndCtl); 150 | void OnDetailedProperties(UINT uNotifyCode, int nID, CWindow wndCtl); 151 | void OnAppAbout(UINT uNotifyCode, int nID, CWindow wndCtl); 152 | void OnCancel(UINT uNotifyCode, int nID, CWindow wndCtl); 153 | LRESULT OnActivateWindow(UINT uMsg, WPARAM wParam, LPARAM lParam); 154 | LRESULT OnDestroyWindow(UINT uMsg, WPARAM wParam, LPARAM lParam); 155 | 156 | void OnFinalMessage(HWND hWnd) override; 157 | 158 | void ElementTreeOnChar(TCHAR chChar, UINT nRepCnt, UINT nFlags); 159 | 160 | void RedrawTreeQueue(); 161 | bool SetSelectedElementInformation(); 162 | bool RefreshSelectedElementInformation(UINT delay = 20); 163 | void ResetAttributesListColumns(); 164 | void PopulateAttributesList(InstanceHandle handle); 165 | void PopulateVisualStatesTree(InstanceHandle handle); 166 | void AddItemToTree(HTREEITEM parentTreeItem, 167 | HTREEITEM insertAfter, 168 | InstanceHandle handle, 169 | ElementItem* elementItem); 170 | InstanceHandle ElementFromPoint(CPoint pt); 171 | InstanceHandle ElementFromPointInSubtree(wux::UIElement subtree, CPoint pt); 172 | InstanceHandle ElementFromPointInSubtree(mux::UIElement subtree, CPoint pt); 173 | bool CreateFlashArea(InstanceHandle handle); 174 | void DestroyFlashArea(); 175 | bool SelectElementFromCursor(); 176 | void OnElementTreeContextMenu(CTreeViewCtrlEx treeView, CPoint point); 177 | void OnAttributesListContextMenu(CListViewCtrl listView, CPoint point); 178 | void OnVisualStateContextMenu(CTreeViewCtrlEx treeView, CPoint point); 179 | 180 | CIcon m_icon, m_smallIcon; 181 | CContainedWindowT m_elementTree; 182 | CSortListViewCtrl m_attributesList; 183 | bool m_listCollapsed = false; 184 | bool m_highlightSelection = true; 185 | bool m_detailedProperties = false; 186 | bool m_splitModeAttributesExpanded = false; 187 | bool m_redrawTreeQueued = false; 188 | bool m_redrawTreeQueuedEnsureSelectionVisible = false; 189 | 190 | winrt::com_ptr m_visualTreeService; 191 | winrt::com_ptr m_xamlDiagnostics; 192 | OnEventCallback_t m_eventCallback; 193 | 194 | std::unordered_map m_elementItems; 195 | 196 | // Note: A parent might be in m_parentToChildren but not in m_elementItems 197 | // at some point if the child is added before its parent. 198 | std::unordered_map> 199 | m_parentToChildren; 200 | 201 | CString m_lastPropertySelection; 202 | 203 | CWindow m_flashAreaWindow; 204 | }; 205 | -------------------------------------------------------------------------------- /UWPSpy/UWPSpy.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "MainDlg.h" 4 | #include "tap.hpp" 5 | 6 | using PFN_INITIALIZE_XAML_DIAGNOSTICS_EX = 7 | decltype(&InitializeXamlDiagnosticsEx); 8 | 9 | CAppModule _Module; 10 | 11 | namespace { 12 | 13 | ATOM RegisterDialogClass(LPCTSTR lpszClassName, HINSTANCE hInstance) { 14 | WNDCLASS wndcls; 15 | ::GetClassInfo(hInstance, MAKEINTRESOURCE(32770), &wndcls); 16 | 17 | // Set our own class name. 18 | wndcls.lpszClassName = lpszClassName; 19 | 20 | // Just register the class. 21 | return ::RegisterClass(&wndcls); 22 | } 23 | 24 | bool GetLoadedDllPath(DWORD processId, 25 | PCWSTR dllName, 26 | WCHAR resultDllPath[MAX_PATH]) { 27 | HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, processId); 28 | if (snapshot == INVALID_HANDLE_VALUE) { 29 | return false; 30 | } 31 | 32 | bool succeeded = false; 33 | 34 | MODULEENTRY32 entry{ 35 | .dwSize = sizeof(entry), 36 | }; 37 | if (Module32First(snapshot, &entry)) { 38 | do { 39 | if (_wcsicmp(entry.szModule, dllName) == 0) { 40 | wcscpy_s(resultDllPath, MAX_PATH, entry.szExePath); 41 | succeeded = true; 42 | break; 43 | } 44 | } while (Module32Next(snapshot, &entry)); 45 | } 46 | 47 | CloseHandle(snapshot); 48 | return succeeded; 49 | } 50 | 51 | HRESULT UwpInitializeXamlDiagnostics(DWORD pid, PCWSTR dllLocation) { 52 | const HMODULE wux(LoadLibraryEx(L"Windows.UI.Xaml.dll", nullptr, 53 | LOAD_LIBRARY_SEARCH_SYSTEM32)); 54 | if (!wux) { 55 | return HRESULT_FROM_WIN32(GetLastError()); 56 | } 57 | 58 | const auto ixde = reinterpret_cast( 59 | GetProcAddress(wux, "InitializeXamlDiagnosticsEx")); 60 | if (!ixde) { 61 | return HRESULT_FROM_WIN32(GetLastError()); 62 | } 63 | 64 | // I didn't find a better way than trying many connections until one works. 65 | // Reference: 66 | // https://github.com/microsoft/microsoft-ui-xaml/blob/d74a0332cf0d5e58f12eddce1070fa7a79b4c2db/src/dxaml/xcp/dxaml/lib/DXamlCore.cpp#L2782 67 | HRESULT hr; 68 | for (int i = 0; i < 10000; i++) { 69 | WCHAR connectionName[256]; 70 | wsprintf(connectionName, L"VisualDiagConnection%d", i + 1); 71 | 72 | hr = ixde(connectionName, pid, L"", dllLocation, CLSID_UWPSpyTAP, 73 | nullptr); 74 | if (hr != HRESULT_FROM_WIN32(ERROR_NOT_FOUND)) { 75 | break; 76 | } 77 | } 78 | 79 | return hr; 80 | } 81 | 82 | HRESULT WinUIInitializeXamlDiagnostics(DWORD pid, PCWSTR dllLocation) { 83 | WCHAR microsoftInternalFrameworkUdkPath[MAX_PATH]; 84 | if (!GetLoadedDllPath(pid, L"Microsoft.Internal.FrameworkUdk.dll", 85 | microsoftInternalFrameworkUdkPath)) { 86 | return HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND); 87 | } 88 | 89 | const HMODULE mux(LoadLibraryEx(microsoftInternalFrameworkUdkPath, nullptr, 90 | LOAD_WITH_ALTERED_SEARCH_PATH)); 91 | if (!mux) { 92 | return HRESULT_FROM_WIN32(GetLastError()); 93 | } 94 | 95 | const auto ixde = reinterpret_cast( 96 | GetProcAddress(mux, "InitializeXamlDiagnosticsEx")); 97 | if (!ixde) { 98 | return HRESULT_FROM_WIN32(GetLastError()); 99 | } 100 | 101 | // In Windows 10 24H2, Explorer creates a new connection identifier for each 102 | // new window, while previous connections are eventually closed. I didn't 103 | // find a better way than trying many connections until one works. 104 | // Reference: 105 | // https://github.com/microsoft/microsoft-ui-xaml/blob/d74a0332cf0d5e58f12eddce1070fa7a79b4c2db/src/dxaml/xcp/dxaml/lib/DXamlCore.cpp#L2782 106 | HRESULT hr; 107 | for (int i = 0; i < 10000; i++) { 108 | WCHAR connectionName[256]; 109 | wsprintf(connectionName, L"WinUIVisualDiagConnection%d", i + 1); 110 | 111 | hr = ixde(connectionName, pid, L"", dllLocation, CLSID_UWPSpyTAP, 112 | nullptr); 113 | if (hr != HRESULT_FROM_WIN32(ERROR_NOT_FOUND)) { 114 | break; 115 | } 116 | } 117 | 118 | return hr; 119 | } 120 | 121 | } // namespace 122 | 123 | BOOL WINAPI DllMain(HINSTANCE hinstDLL, // handle to DLL module 124 | DWORD fdwReason, // reason for calling function 125 | LPVOID lpvReserved) // reserved 126 | { 127 | switch (fdwReason) { 128 | case DLL_PROCESS_ATTACH: { 129 | HRESULT hRes = _Module.Init(nullptr, hinstDLL); 130 | ATLASSERT(SUCCEEDED(hRes)); 131 | 132 | RegisterDialogClass(L"UWPSpy", hinstDLL); 133 | } break; 134 | 135 | case DLL_THREAD_ATTACH: 136 | case DLL_THREAD_DETACH: 137 | break; 138 | 139 | case DLL_PROCESS_DETACH: 140 | UnregisterClass(L"UWPSpy", hinstDLL); 141 | 142 | _Module.Term(); 143 | break; 144 | } 145 | 146 | return TRUE; 147 | } 148 | 149 | HRESULT WINAPI start(DWORD pid, DWORD framework) { 150 | AllowSetForegroundWindow(pid); 151 | 152 | // Calling InitializeXamlDiagnosticsEx the second time will reset the 153 | // existing element tree callbacks. Therefore, first check for existing 154 | // windows for the target process. 155 | 156 | struct EnumWindowsData { 157 | DWORD pid; 158 | BOOL found; 159 | }; 160 | 161 | EnumWindowsData data = {pid, FALSE}; 162 | 163 | EnumWindows( 164 | [](HWND hWnd, LPARAM lParam) -> BOOL { 165 | EnumWindowsData& data = *reinterpret_cast(lParam); 166 | 167 | DWORD windowPid; 168 | if (!GetWindowThreadProcessId(hWnd, &windowPid) || 169 | windowPid != data.pid) { 170 | return TRUE; 171 | } 172 | 173 | WCHAR windowClass[16]; 174 | if (!GetClassName(hWnd, windowClass, ARRAYSIZE(windowClass)) || 175 | _wcsicmp(windowClass, L"UWPSpy") != 0) { 176 | return TRUE; 177 | } 178 | 179 | data.found = TRUE; 180 | PostMessage(hWnd, CMainDlg::UWM_ACTIVATE_WINDOW, 0, 0); 181 | return TRUE; 182 | }, 183 | reinterpret_cast(&data)); 184 | 185 | if (data.found) { 186 | return S_OK; 187 | } 188 | 189 | WCHAR location[MAX_PATH]; 190 | switch (GetModuleFileName(_Module.GetModuleInstance(), location, 191 | ARRAYSIZE(location))) { 192 | case 0: 193 | case ARRAYSIZE(location): 194 | return HRESULT_FROM_WIN32(GetLastError()); 195 | } 196 | 197 | enum Framework : DWORD { 198 | kFrameworkUWP = 1, 199 | kFrameworkWinUI, 200 | }; 201 | 202 | switch (framework) { 203 | case kFrameworkUWP: 204 | return UwpInitializeXamlDiagnostics(pid, location); 205 | 206 | case kFrameworkWinUI: 207 | return WinUIInitializeXamlDiagnostics(pid, location); 208 | } 209 | 210 | return E_INVALIDARG; 211 | } 212 | 213 | BOOL WINAPI isDebugging(DWORD pid) { 214 | struct EnumWindowsData { 215 | DWORD pid; 216 | BOOL found; 217 | }; 218 | 219 | EnumWindowsData data = {pid, FALSE}; 220 | 221 | EnumWindows( 222 | [](HWND hWnd, LPARAM lParam) -> BOOL { 223 | EnumWindowsData& data = *reinterpret_cast(lParam); 224 | 225 | DWORD windowPid; 226 | if (!GetWindowThreadProcessId(hWnd, &windowPid) || 227 | windowPid != data.pid) { 228 | return TRUE; 229 | } 230 | 231 | WCHAR windowClass[16]; 232 | if (!GetClassName(hWnd, windowClass, ARRAYSIZE(windowClass)) || 233 | _wcsicmp(windowClass, L"UWPSpy") != 0) { 234 | return TRUE; 235 | } 236 | 237 | data.found = TRUE; 238 | return FALSE; 239 | }, 240 | reinterpret_cast(&data)); 241 | 242 | return data.found; 243 | } 244 | -------------------------------------------------------------------------------- /UWPSpy/UWPSpy.h: -------------------------------------------------------------------------------- 1 | // UWPSpy.h 2 | -------------------------------------------------------------------------------- /UWPSpy/UWPSpy.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m417z/UWPSpy/887e27500670adcd0cad5d0b9179515164224d79/UWPSpy/UWPSpy.rc -------------------------------------------------------------------------------- /UWPSpy/UWPSpy.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m417z/UWPSpy/887e27500670adcd0cad5d0b9179515164224d79/UWPSpy/UWPSpy.rc2 -------------------------------------------------------------------------------- /UWPSpy/UWPSpy.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Debug 9 | ARM64 10 | 11 | 12 | Debug 13 | Win32 14 | 15 | 16 | Release 17 | ARM64 18 | 19 | 20 | Release 21 | Win32 22 | 23 | 24 | Debug 25 | x64 26 | 27 | 28 | Release 29 | x64 30 | 31 | 32 | 33 | 17.0 34 | {D5BFF041-D26D-4765-935E-BE0D0D4A6C99} 35 | 10.0 36 | 37 | 38 | 39 | DynamicLibrary 40 | true 41 | v143 42 | Unicode 43 | 44 | 45 | DynamicLibrary 46 | false 47 | v143 48 | Unicode 49 | 50 | 51 | DynamicLibrary 52 | true 53 | v143 54 | Unicode 55 | 56 | 57 | DynamicLibrary 58 | true 59 | v143 60 | Unicode 61 | 62 | 63 | DynamicLibrary 64 | false 65 | v143 66 | Unicode 67 | 68 | 69 | DynamicLibrary 70 | false 71 | v143 72 | Unicode 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | true 100 | 101 | 102 | true 103 | 104 | 105 | true 106 | 107 | 108 | false 109 | 110 | 111 | false 112 | 113 | 114 | false 115 | 116 | 117 | 118 | Use 119 | Level3 120 | MultiThreadedDebug 121 | EditAndContinue 122 | EnableFastChecks 123 | Disabled 124 | _WINDOWS;STRICT;_DEBUG;%(PreprocessorDefinitions) 125 | stdcpp20 126 | /utf-8 %(AdditionalOptions) 127 | 128 | 129 | Windows 130 | true 131 | _exports.def 132 | windowscodecs.lib;%(AdditionalDependencies) 133 | 134 | 135 | 0x0409 136 | $(IntDir);%(AdditionalIncludeDirectories) 137 | _DEBUG;%(PreprocessorDefinitions) 138 | 139 | 140 | false 141 | _DEBUG;%(PreprocessorDefinitions) 142 | UWPSpy.h 143 | UWPSpy_i.c 144 | UWPSpy_p.c 145 | true 146 | $(IntDir)/UWPSpy.tlb 147 | 148 | 149 | 150 | 151 | 152 | Use 153 | Level3 154 | MultiThreadedDebug 155 | EditAndContinue 156 | EnableFastChecks 157 | Disabled 158 | _WINDOWS;STRICT;_DEBUG;%(PreprocessorDefinitions) 159 | stdcpp20 160 | /utf-8 %(AdditionalOptions) 161 | 162 | 163 | Windows 164 | true 165 | _exports.def 166 | windowscodecs.lib;%(AdditionalDependencies) 167 | 168 | 169 | 0x0409 170 | $(IntDir);%(AdditionalIncludeDirectories) 171 | _DEBUG;%(PreprocessorDefinitions) 172 | 173 | 174 | false 175 | _DEBUG;%(PreprocessorDefinitions) 176 | UWPSpy.h 177 | UWPSpy_i.c 178 | UWPSpy_p.c 179 | true 180 | $(IntDir)/UWPSpy.tlb 181 | 182 | 183 | 184 | 185 | 186 | 187 | Use 188 | Level3 189 | MultiThreadedDebug 190 | EditAndContinue 191 | EnableFastChecks 192 | Disabled 193 | WIN32;_WINDOWS;STRICT;_DEBUG;%(PreprocessorDefinitions) 194 | stdcpp20 195 | /utf-8 %(AdditionalOptions) 196 | 197 | 198 | Windows 199 | true 200 | _exports.def 201 | windowscodecs.lib;%(AdditionalDependencies) 202 | 203 | 204 | 0x0409 205 | $(IntDir);%(AdditionalIncludeDirectories) 206 | _DEBUG;%(PreprocessorDefinitions) 207 | 208 | 209 | false 210 | Win32 211 | _DEBUG;%(PreprocessorDefinitions) 212 | UWPSpy.h 213 | UWPSpy_i.c 214 | UWPSpy_p.c 215 | true 216 | $(IntDir)/UWPSpy.tlb 217 | 218 | 219 | 220 | 221 | 222 | Use 223 | Level3 224 | MultiThreaded 225 | 226 | WIN32;_WINDOWS;STRICT;NDEBUG;%(PreprocessorDefinitions) 227 | stdcpp20 228 | /utf-8 %(AdditionalOptions) 229 | 230 | 231 | Windows 232 | false 233 | _exports.def 234 | windowscodecs.lib;%(AdditionalDependencies) 235 | 236 | 237 | 0x0409 238 | $(IntDir);%(AdditionalIncludeDirectories) 239 | NDEBUG;%(PreprocessorDefinitions) 240 | 241 | 242 | false 243 | Win32 244 | NDEBUG;%(PreprocessorDefinitions) 245 | UWPSpy.h 246 | UWPSpy_i.c 247 | UWPSpy_p.c 248 | true 249 | $(IntDir)/UWPSpy.tlb 250 | 251 | 252 | 253 | 254 | 255 | Use 256 | Level3 257 | MultiThreaded 258 | 259 | _WINDOWS;STRICT;NDEBUG;%(PreprocessorDefinitions) 260 | stdcpp20 261 | /utf-8 %(AdditionalOptions) 262 | 263 | 264 | Windows 265 | false 266 | _exports.def 267 | windowscodecs.lib;%(AdditionalDependencies) 268 | 269 | 270 | 0x0409 271 | $(IntDir);%(AdditionalIncludeDirectories) 272 | NDEBUG;%(PreprocessorDefinitions) 273 | 274 | 275 | false 276 | NDEBUG;%(PreprocessorDefinitions) 277 | UWPSpy.h 278 | UWPSpy_i.c 279 | UWPSpy_p.c 280 | true 281 | $(IntDir)/UWPSpy.tlb 282 | 283 | 284 | 285 | 286 | 287 | Use 288 | Level3 289 | MultiThreaded 290 | 291 | 292 | _WINDOWS;STRICT;NDEBUG;%(PreprocessorDefinitions) 293 | stdcpp20 294 | /utf-8 %(AdditionalOptions) 295 | 296 | 297 | Windows 298 | false 299 | _exports.def 300 | windowscodecs.lib;%(AdditionalDependencies) 301 | 302 | 303 | 0x0409 304 | $(IntDir);%(AdditionalIncludeDirectories) 305 | NDEBUG;%(PreprocessorDefinitions) 306 | 307 | 308 | false 309 | NDEBUG;%(PreprocessorDefinitions) 310 | UWPSpy.h 311 | UWPSpy_i.c 312 | UWPSpy_p.c 313 | true 314 | $(IntDir)/UWPSpy.tlb 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | Create 326 | Create 327 | Create 328 | Create 329 | Create 330 | Create 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | -------------------------------------------------------------------------------- /UWPSpy/UWPSpy.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {8d665335-f159-4120-bb7b-18585bce53f3} 6 | cpp;c;cxx;def;odl;idl;hpj;bat;asm 7 | 8 | 9 | {1735cd34-a2f0-4331-b4b6-643dae3d52c7} 10 | h;hpp;hxx;hm;inl;inc 11 | 12 | 13 | {4e9a989a-ae54-44d4-853b-bdaffeffa0de} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;jpg;jpeg;jpe;manifest 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | Source Files 41 | 42 | 43 | 44 | 45 | Header Files 46 | 47 | 48 | Header Files 49 | 50 | 51 | Header Files 52 | 53 | 54 | Header Files 55 | 56 | 57 | Header Files 58 | 59 | 60 | Header Files 61 | 62 | 63 | Header Files 64 | 65 | 66 | Header Files 67 | 68 | 69 | Header Files 70 | 71 | 72 | Header Files 73 | 74 | 75 | Header Files 76 | 77 | 78 | 79 | 80 | Resource Files 81 | 82 | 83 | 84 | 85 | Resource Files 86 | 87 | 88 | 89 | 90 | 91 | Source Files 92 | 93 | 94 | Resource Files 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /UWPSpy/_exports.def: -------------------------------------------------------------------------------- 1 | LIBRARY 2 | EXPORTS 3 | DllGetClassObject PRIVATE 4 | DllCanUnloadNow PRIVATE 5 | start @1 6 | isDebugging @2 7 | -------------------------------------------------------------------------------- /UWPSpy/flash_area.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "flash_area.h" 4 | 5 | #include "resource.h" 6 | 7 | // Based on code from WinSpy++. 8 | // https://github.com/m417z/winspy 9 | // www.catch22.net 10 | // Copyright (C) 2012 James Brown 11 | 12 | #define WC_FLASHWINDOW L"FlashAreaClass" 13 | #define ALPHA_LEVEL 128 14 | 15 | // Creates a stream object initialized with the data from an executable 16 | // resource. 17 | IStream* CreateStreamOnResource(HMODULE hModule, PCWSTR lpName, PCWSTR lpType) { 18 | IStream* ipStream = NULL; 19 | 20 | // find the resource 21 | HRSRC hRes = FindResource(hModule, lpName, lpType); 22 | DWORD dwResourceSize; 23 | HGLOBAL hglbImage; 24 | PVOID pvSourceResourceData; 25 | HGLOBAL hgblResourceData; 26 | PVOID pvResourceData; 27 | 28 | if (hRes == NULL) 29 | goto Return; 30 | 31 | // load the resource 32 | dwResourceSize = SizeofResource(hModule, hRes); 33 | hglbImage = LoadResource(hModule, hRes); 34 | 35 | if (hglbImage == NULL) 36 | goto Return; 37 | 38 | // lock the resource, getting a pointer to its data 39 | pvSourceResourceData = LockResource(hglbImage); 40 | 41 | if (pvSourceResourceData == NULL) 42 | goto Return; 43 | 44 | // allocate memory to hold the resource data 45 | hgblResourceData = GlobalAlloc(GMEM_MOVEABLE, dwResourceSize); 46 | 47 | if (hgblResourceData == NULL) 48 | goto Return; 49 | 50 | // get a pointer to the allocated memory 51 | pvResourceData = GlobalLock(hgblResourceData); 52 | 53 | if (pvResourceData == NULL) 54 | goto FreeData; 55 | 56 | // copy the data from the resource to the new memory block 57 | CopyMemory(pvResourceData, pvSourceResourceData, dwResourceSize); 58 | 59 | GlobalUnlock(hgblResourceData); 60 | 61 | // create a stream on the HGLOBAL containing the data 62 | // Specify that the HGLOBAL will be automatically free'd on the last 63 | // Release() 64 | if (SUCCEEDED(CreateStreamOnHGlobal(hgblResourceData, TRUE, &ipStream))) 65 | goto Return; 66 | 67 | FreeData: 68 | 69 | // couldn't create stream; free the memory 70 | GlobalFree(hgblResourceData); 71 | 72 | Return: 73 | 74 | // no need to unlock or free the resource 75 | return ipStream; 76 | } 77 | 78 | // Now that we have an IStream pointer to the data of the image, 79 | // we can use WIC to load that image. An important step in this 80 | // process is to use WICConvertBitmapSource to ensure that the image 81 | // is in a 32bpp format suitable for direct conversion into a DIB. 82 | // This method assumes that the input image is in the PNG format; 83 | // for a splash screen, this is an excellent choice because it allows 84 | // an alpha channel as well as lossless compression of the source image. 85 | // (To make the splash screen image as small as possible, 86 | // I highly recommend the PNGOUT compression utility.) 87 | 88 | // Loads a PNG image from the specified stream (using Windows Imaging 89 | // Component). 90 | IWICBitmapSource* LoadBitmapFromStream(IStream* ipImageStream) { 91 | // initialize return value 92 | IWICBitmapSource* ipBitmap = NULL; 93 | 94 | // load WIC's PNG decoder 95 | IWICBitmapDecoder* ipDecoder = NULL; 96 | IID i = IID_IWICBitmapDecoder; 97 | 98 | if (FAILED(CoCreateInstance(CLSID_WICPngDecoder1, NULL, 99 | CLSCTX_INPROC_SERVER, 100 | i, //__uuidof(ipDecoder) 101 | (void**)&ipDecoder))) { 102 | return ipBitmap; 103 | } 104 | 105 | // load the PNG 106 | if (FAILED(ipDecoder->Initialize(ipImageStream, 107 | WICDecodeMetadataCacheOnLoad))) { 108 | ipDecoder->Release(); 109 | return ipBitmap; 110 | } 111 | 112 | // check for the presence of the first frame in the bitmap 113 | UINT nFrameCount = 0; 114 | 115 | if (FAILED(ipDecoder->GetFrameCount(&nFrameCount)) || nFrameCount != 1) { 116 | ipDecoder->Release(); 117 | return ipBitmap; 118 | } 119 | 120 | // load the first frame (i.e., the image) 121 | IWICBitmapFrameDecode* ipFrame = NULL; 122 | 123 | if (FAILED(ipDecoder->GetFrame(0, &ipFrame))) { 124 | ipDecoder->Release(); 125 | return ipBitmap; 126 | } 127 | 128 | // convert the image to 32bpp BGRA format with pre-multiplied alpha 129 | // (it may not be stored in that format natively in the PNG resource, 130 | // but we need this format to create the DIB to use on-screen) 131 | WICConvertBitmapSource(GUID_WICPixelFormat32bppPBGRA, ipFrame, &ipBitmap); 132 | ipFrame->Release(); 133 | ipDecoder->Release(); 134 | return ipBitmap; 135 | } 136 | 137 | // Creates a 32-bit DIB from the specified WIC bitmap. 138 | HBITMAP CreateHBITMAP(IWICBitmapSource* ipBitmap, PVOID* bits) { 139 | // initialize return value 140 | HBITMAP hbmp = NULL; 141 | 142 | // get image attributes and check for valid image 143 | UINT width = 0; 144 | UINT height = 0; 145 | 146 | if (FAILED(ipBitmap->GetSize(&width, &height)) || width == 0 || 147 | height == 0) { 148 | return hbmp; 149 | } 150 | 151 | // prepare structure giving bitmap information (negative height indicates a 152 | // top-down DIB) 153 | BITMAPINFO bminfo; 154 | 155 | ZeroMemory(&bminfo, sizeof(bminfo)); 156 | 157 | bminfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 158 | bminfo.bmiHeader.biWidth = width; 159 | bminfo.bmiHeader.biHeight = -((LONG)height); 160 | bminfo.bmiHeader.biPlanes = 1; 161 | bminfo.bmiHeader.biBitCount = 32; 162 | bminfo.bmiHeader.biCompression = BI_RGB; 163 | 164 | // create a DIB section that can hold the image 165 | void* pvImageBits = NULL; 166 | 167 | HDC hdcScreen = GetDC(NULL); 168 | hbmp = CreateDIBSection(hdcScreen, &bminfo, DIB_RGB_COLORS, &pvImageBits, 169 | NULL, 0); 170 | ReleaseDC(NULL, hdcScreen); 171 | 172 | if (bits) 173 | *bits = pvImageBits; 174 | 175 | if (hbmp == NULL) { 176 | return hbmp; 177 | } 178 | 179 | // extract the image into the HBITMAP 180 | const UINT cbStride = width * 4; 181 | const UINT cbImage = cbStride * height; 182 | 183 | if (FAILED(ipBitmap->CopyPixels(NULL, cbStride, cbImage, 184 | static_cast(pvImageBits)))) { 185 | // couldn't extract image; delete HBITMAP 186 | DeleteObject(hbmp); 187 | 188 | hbmp = NULL; 189 | } 190 | 191 | return hbmp; 192 | } 193 | 194 | // Loads the PNG bitmap into a 32bit HBITMAP. 195 | HBITMAP LoadPNGImage(HMODULE hModule, UINT id, OUT VOID** bits) { 196 | HBITMAP hbmpSplash = NULL; 197 | 198 | // load the PNG image data into a stream 199 | IStream* ipImageStream = 200 | CreateStreamOnResource(hModule, MAKEINTRESOURCE(id), L"PNG"); 201 | 202 | if (ipImageStream == NULL) { 203 | return hbmpSplash; 204 | } 205 | 206 | // load the bitmap with WIC 207 | IWICBitmapSource* ipBitmap = LoadBitmapFromStream(ipImageStream); 208 | 209 | if (ipBitmap == NULL) { 210 | ipImageStream->Release(); 211 | return hbmpSplash; 212 | } 213 | 214 | // create a HBITMAP containing the image 215 | hbmpSplash = CreateHBITMAP(ipBitmap, bits); 216 | 217 | ipBitmap->Release(); 218 | ipImageStream->Release(); 219 | return hbmpSplash; 220 | } 221 | 222 | int GetRectWidth(RECT* rect) { 223 | return rect->right - rect->left; 224 | } 225 | 226 | int GetRectHeight(RECT* rect) { 227 | return rect->bottom - rect->top; 228 | } 229 | 230 | void UpdateLayeredWindowContent(HWND hwnd, RECT rc, HBITMAP hbmp, BYTE alpha) { 231 | POINT ptZero = {0, 0}; 232 | POINT pt; 233 | SIZE size; 234 | BLENDFUNCTION blend = {AC_SRC_OVER, 0, 0, AC_SRC_ALPHA}; 235 | blend.SourceConstantAlpha = alpha; 236 | 237 | pt.x = rc.left; 238 | pt.y = rc.top; 239 | 240 | size.cx = GetRectWidth(&rc); 241 | size.cy = GetRectHeight(&rc); 242 | 243 | HDC hdcSrc = GetDC(0); 244 | HDC hdcMem = CreateCompatibleDC(hdcSrc); 245 | 246 | HANDLE hbmpOld = SelectObject(hdcMem, hbmp); 247 | 248 | UpdateLayeredWindow(hwnd, hdcSrc, &pt, &size, hdcMem, &ptZero, RGB(0, 0, 0), 249 | &blend, ULW_ALPHA); 250 | 251 | SelectObject(hdcMem, hbmpOld); 252 | DeleteDC(hdcMem); 253 | 254 | ReleaseDC(0, hdcSrc); 255 | } 256 | 257 | HBITMAP ExpandNineGridImage(SIZE outputSize, HBITMAP hbmSrc, RECT edges) { 258 | HDC hdcScreen, hdcDst, hdcSrc; 259 | HBITMAP hbmDst; 260 | void* pBits; 261 | HANDLE hOldSrc, hOldDst; 262 | BITMAP bmSrc; 263 | 264 | // Create a 32bpp DIB of the desired size, this is the output bitmap. 265 | BITMAPINFOHEADER bih = {sizeof(bih)}; 266 | 267 | bih.biWidth = outputSize.cx; 268 | bih.biHeight = outputSize.cy; 269 | bih.biPlanes = 1; 270 | bih.biBitCount = 32; 271 | bih.biCompression = BI_RGB; 272 | bih.biSizeImage = 0; 273 | 274 | hdcScreen = GetDC(0); 275 | hbmDst = CreateDIBSection(hdcScreen, (BITMAPINFO*)&bih, DIB_RGB_COLORS, 276 | &pBits, 0, 0); 277 | 278 | // Determine size of the source image. 279 | GetObject(hbmSrc, sizeof(bmSrc), &bmSrc); 280 | 281 | // Prep DCs 282 | hdcSrc = CreateCompatibleDC(hdcScreen); 283 | hOldSrc = SelectObject(hdcSrc, hbmSrc); 284 | 285 | hdcDst = CreateCompatibleDC(hdcScreen); 286 | hOldDst = SelectObject(hdcDst, hbmDst); 287 | 288 | // Sizes of the nine-grid edges 289 | int cxEdgeL = edges.left; 290 | int cxEdgeR = edges.right; 291 | int cyEdgeT = edges.top; 292 | int cyEdgeB = edges.bottom; 293 | 294 | // Precompute sizes and coordinates of the interior boxes 295 | // (that is, the source and dest rects with the edges subtracted out). 296 | int cxDstInner = outputSize.cx - (cxEdgeL + cxEdgeR); 297 | int cyDstInner = outputSize.cy - (cyEdgeT + cyEdgeB); 298 | int cxSrcInner = bmSrc.bmWidth - (cxEdgeL + cxEdgeR); 299 | int cySrcInner = bmSrc.bmHeight - (cyEdgeT + cyEdgeB); 300 | 301 | int xDst1 = cxEdgeL; 302 | int xDst2 = outputSize.cx - cxEdgeR; 303 | int yDst1 = cyEdgeT; 304 | int yDst2 = outputSize.cy - cyEdgeB; 305 | 306 | int xSrc1 = cxEdgeL; 307 | int xSrc2 = bmSrc.bmWidth - cxEdgeR; 308 | int ySrc1 = cyEdgeT; 309 | int ySrc2 = bmSrc.bmHeight - cyEdgeB; 310 | 311 | // Upper-left corner 312 | BitBlt(hdcDst, 0, 0, cxEdgeL, cyEdgeT, hdcSrc, 0, 0, SRCCOPY); 313 | 314 | // Upper-right corner 315 | BitBlt(hdcDst, xDst2, 0, cxEdgeR, cyEdgeT, hdcSrc, xSrc2, 0, SRCCOPY); 316 | 317 | // Lower-left corner 318 | BitBlt(hdcDst, 0, yDst2, cxEdgeL, cyEdgeB, hdcSrc, 0, ySrc2, SRCCOPY); 319 | 320 | // Lower-right corner 321 | BitBlt(hdcDst, xDst2, yDst2, cxEdgeR, cyEdgeB, hdcSrc, xSrc2, ySrc2, 322 | SRCCOPY); 323 | 324 | // Left side 325 | StretchBlt(hdcDst, 0, yDst1, cxEdgeL, cyDstInner, hdcSrc, 0, ySrc1, cxEdgeL, 326 | cySrcInner, SRCCOPY); 327 | 328 | // Right side 329 | StretchBlt(hdcDst, xDst2, yDst1, cxEdgeR, cyDstInner, hdcSrc, xSrc2, ySrc1, 330 | cxEdgeR, cySrcInner, SRCCOPY); 331 | 332 | // Top side 333 | StretchBlt(hdcDst, xDst1, 0, cxDstInner, cyEdgeT, hdcSrc, xSrc1, 0, 334 | cxSrcInner, cyEdgeT, SRCCOPY); 335 | 336 | // Bottom side 337 | StretchBlt(hdcDst, xDst1, yDst2, cxDstInner, cyEdgeB, hdcSrc, xSrc1, ySrc2, 338 | cxSrcInner, cyEdgeB, SRCCOPY); 339 | 340 | // Middle 341 | StretchBlt(hdcDst, xDst1, yDst1, cxDstInner, cyDstInner, hdcSrc, xSrc1, 342 | ySrc1, cxSrcInner, cySrcInner, SRCCOPY); 343 | 344 | SelectObject(hdcSrc, hOldSrc); 345 | SelectObject(hdcDst, hOldDst); 346 | 347 | DeleteDC(hdcSrc); 348 | DeleteDC(hdcDst); 349 | 350 | ReleaseDC(0, hdcScreen); 351 | 352 | return hbmDst; 353 | } 354 | 355 | HBITMAP MakeFlashWindowBitmap(HMODULE hModule, RECT rc) { 356 | static HBITMAP hbmBox; 357 | 358 | if (hbmBox == 0) { 359 | hbmBox = LoadPNGImage(hModule, IDB_SELBOX, NULL); 360 | } 361 | 362 | RECT edges = {2, 2, 2, 2}; 363 | SIZE size; 364 | 365 | size.cx = GetRectWidth(&rc); 366 | size.cy = GetRectHeight(&rc); 367 | 368 | return ExpandNineGridImage(size, hbmBox, edges); 369 | } 370 | 371 | HWND FlashArea(HWND hParentWnd, HMODULE hModule, const RECT& rc, bool show) { 372 | static BOOL fInitializedWindowClass = FALSE; 373 | 374 | HWND hwnd; 375 | 376 | if (!fInitializedWindowClass) { 377 | WNDCLASSEX wc = {sizeof(wc)}; 378 | 379 | wc.style = 0; 380 | wc.lpszClassName = WC_FLASHWINDOW; 381 | wc.lpfnWndProc = DefWindowProc; 382 | 383 | RegisterClassEx(&wc); 384 | 385 | fInitializedWindowClass = TRUE; 386 | } 387 | 388 | hwnd = CreateWindowEx(WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW | WS_EX_LAYERED, 389 | WC_FLASHWINDOW, 0, WS_POPUP, rc.left, rc.top, 390 | rc.right - rc.left, rc.bottom - rc.top, hParentWnd, 0, 391 | 0, NULL); 392 | 393 | if (hwnd) { 394 | HBITMAP hbmp = MakeFlashWindowBitmap(hModule, rc); 395 | UpdateLayeredWindowContent(hwnd, rc, hbmp, ALPHA_LEVEL); 396 | DeleteObject(hbmp); 397 | 398 | UINT flags = SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE; 399 | if (show) { 400 | flags |= SWP_SHOWWINDOW; 401 | } 402 | 403 | SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, flags); 404 | } 405 | 406 | return hwnd; 407 | } 408 | -------------------------------------------------------------------------------- /UWPSpy/flash_area.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | HWND FlashArea(HWND hParentWnd, HMODULE hModule, const RECT& rc, bool show); 4 | -------------------------------------------------------------------------------- /UWPSpy/module.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "simplefactory.hpp" 4 | #include "tap.hpp" 5 | #include "winrt.hpp" 6 | 7 | _Use_decl_annotations_ STDAPI DllGetClassObject(REFCLSID rclsid, 8 | REFIID riid, 9 | LPVOID* ppv) try { 10 | if (rclsid == CLSID_UWPSpyTAP) { 11 | *ppv = nullptr; 12 | return winrt::make>().as(riid, ppv); 13 | } else { 14 | return CLASS_E_CLASSNOTAVAILABLE; 15 | } 16 | } catch (...) { 17 | return winrt::to_hresult(); 18 | } 19 | 20 | _Use_decl_annotations_ STDAPI DllCanUnloadNow() { 21 | if (winrt::get_module_lock()) { 22 | return S_FALSE; 23 | } else { 24 | return S_OK; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /UWPSpy/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UWPSpy/res/UWPSpy.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m417z/UWPSpy/887e27500670adcd0cad5d0b9179515164224d79/UWPSpy/res/UWPSpy.ico -------------------------------------------------------------------------------- /UWPSpy/res/selbox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m417z/UWPSpy/887e27500670adcd0cad5d0b9179515164224d79/UWPSpy/res/selbox.png -------------------------------------------------------------------------------- /UWPSpy/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by UWPSpy.rc 4 | // 5 | #define IDR_MAINFRAME 128 6 | #define IDD_MAINDLG 129 7 | #define IDB_SELBOX 202 8 | #define IDD_ABOUT 203 9 | #define IDC_ELEMENT_TREE 1000 10 | #define IDC_SPLIT_TOGGLE 1001 11 | #define IDC_CLASS_STATIC 1002 12 | #define IDC_CLASS_EDIT 1003 13 | #define IDC_NAME_STATIC 1004 14 | #define IDC_NAME_EDIT 1005 15 | #define IDC_RECT_STATIC 1006 16 | #define IDC_RECT_EDIT 1007 17 | #define IDC_DETAILS_TABS 1008 18 | #define IDC_ATTRIBUTE_LIST 1009 19 | #define IDC_VISUAL_STATE_TREE 1010 20 | #define IDC_PROPERTY_NAME 1011 21 | #define IDC_PROPERTY_VALUE 1012 22 | #define IDC_PROPERTY_VALUE_XAML 1013 23 | #define IDC_PROPERTY_IS_XAML 1014 24 | #define IDC_PROPERTY_REMOVE 1015 25 | #define IDC_PROPERTY_SET 1016 26 | #define IDC_COLLAPSE_ALL 1017 27 | #define IDC_EXPAND_ALL 1018 28 | #define IDC_HIGHLIGHT_SELECTION 1019 29 | #define IDC_DETAILED_PROPERTIES 1020 30 | #define IDC_ABOUT_TITLE 1021 31 | #define IDC_ABOUT_BUTTON_RAMEN_SOFTWARE 1022 32 | #define IDC_ABOUT_BUTTON_HOMEPAGE 1023 33 | #define IDC_ABOUT_BUTTON_SOURCE_CODE 1024 34 | 35 | // Next default values for new objects 36 | // 37 | #ifdef APSTUDIO_INVOKED 38 | #ifndef APSTUDIO_READONLY_SYMBOLS 39 | #define _APS_NEXT_RESOURCE_VALUE 204 40 | #define _APS_NEXT_COMMAND_VALUE 32775 41 | #define _APS_NEXT_CONTROL_VALUE 1025 42 | #define _APS_NEXT_SYMED_VALUE 100 43 | #endif 44 | #endif 45 | -------------------------------------------------------------------------------- /UWPSpy/simplefactory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "winrt.hpp" 4 | 5 | template 6 | struct SimpleFactory 7 | : winrt::implements, IClassFactory, winrt::non_agile> { 8 | HRESULT STDMETHODCALLTYPE CreateInstance(IUnknown* pUnkOuter, 9 | REFIID riid, 10 | void** ppvObject) override try { 11 | if (!pUnkOuter) { 12 | *ppvObject = nullptr; 13 | return winrt::make().as(riid, ppvObject); 14 | } else { 15 | return CLASS_E_NOAGGREGATION; 16 | } 17 | } catch (...) { 18 | return winrt::to_hresult(); 19 | } 20 | 21 | HRESULT STDMETHODCALLTYPE LockServer(BOOL fLock) noexcept override { 22 | if (fLock) { 23 | ++winrt::get_module_lock(); 24 | } else { 25 | --winrt::get_module_lock(); 26 | } 27 | 28 | return S_OK; 29 | } 30 | }; 31 | -------------------------------------------------------------------------------- /UWPSpy/stdafx.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | -------------------------------------------------------------------------------- /UWPSpy/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "targetver.h" 4 | 5 | // STL 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | // WTL 18 | 19 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 20 | #define NOMINMAX 21 | #define _WTL_NO_CSTRING 22 | #define _WTL_NO_WTYPES 23 | #define _WTL_NO_UNION_CLASSES 24 | #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | extern CAppModule _Module; 33 | 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | // Windows 43 | 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | 57 | // C++/WinRT 58 | 59 | #undef GetCurrentTime 60 | 61 | #include 62 | 63 | #include 64 | #include 65 | #include 66 | #include 67 | #include 68 | #include 69 | #include 70 | 71 | // WinUI 72 | 73 | #include "winui/microsoft.ui.xaml.hosting.desktopwindowxamlsource_winui.h" 74 | 75 | #include 76 | #include 77 | #include 78 | #include 79 | #include 80 | #include 81 | -------------------------------------------------------------------------------- /UWPSpy/tap.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "tap.hpp" 4 | 5 | winrt::weak_ref ExplorerTAP::s_VisualTreeWatcher; 6 | 7 | HRESULT ExplorerTAP::SetSite(IUnknown* pUnkSite) try { 8 | // Only ever 1 VTW at once. 9 | if (auto visualTreeWatcher = s_VisualTreeWatcher.get()) { 10 | visualTreeWatcher->Activate(); 11 | throw winrt::hresult_illegal_method_call(); 12 | } 13 | 14 | site.copy_from(pUnkSite); 15 | 16 | if (site) { 17 | s_VisualTreeWatcher = winrt::make_self(site); 18 | } 19 | 20 | return S_OK; 21 | } catch (...) { 22 | return winrt::to_hresult(); 23 | } 24 | 25 | HRESULT ExplorerTAP::GetSite(REFIID riid, void** ppvSite) noexcept { 26 | return site.as(riid, ppvSite); 27 | } 28 | -------------------------------------------------------------------------------- /UWPSpy/tap.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "visualtreewatcher.hpp" 4 | #include "winrt.hpp" 5 | 6 | // {4CE91FA6-B898-48AC-BE31-A5485A7435E7} 7 | static constexpr CLSID CLSID_UWPSpyTAP = { 8 | 0x4ce91fa6, 9 | 0xb898, 10 | 0x48ac, 11 | {0xbe, 0x31, 0xa5, 0x48, 0x5a, 0x74, 0x35, 0xe7}}; 12 | 13 | class ExplorerTAP 14 | : public winrt::implements { 15 | public: 16 | HRESULT STDMETHODCALLTYPE SetSite(IUnknown* pUnkSite) override; 17 | HRESULT STDMETHODCALLTYPE GetSite(REFIID riid, 18 | void** ppvSite) noexcept override; 19 | 20 | private: 21 | static winrt::weak_ref s_VisualTreeWatcher; 22 | 23 | winrt::com_ptr site; 24 | }; 25 | -------------------------------------------------------------------------------- /UWPSpy/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // // Including SDKDDKVer.h defines the highest available Windows platform. 4 | // If you wish to build your application for a previous Windows platform, 5 | // include WinSDKVer.h and set the _WIN32_WINNT macro to the platform you wish 6 | // to support before including SDKDDKVer.h. 7 | #include 8 | #define _WIN32_WINNT _WIN32_WINNT_WIN10 9 | #include 10 | -------------------------------------------------------------------------------- /UWPSpy/visualtreewatcher.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "visualtreewatcher.hpp" 4 | 5 | #define EXTRA_DEBUG 0 6 | 7 | namespace { 8 | 9 | // https://devblogs.microsoft.com/oldnewthing/20240319-00/?p=109552 10 | template 11 | std::enable_if_t, winrt::com_ptr> 12 | make_com_ptr_from_copy(T* p) { 13 | winrt::com_ptr result; 14 | result.copy_from(p); 15 | return result; 16 | } 17 | 18 | // https://stackoverflow.com/a/10444161 19 | ULONG_PTR EnableVisualStyles() { 20 | TCHAR dir[MAX_PATH]; 21 | ULONG_PTR ulpActivationCookie = FALSE; 22 | ACTCTX actCtx = {sizeof(actCtx), 23 | ACTCTX_FLAG_RESOURCE_NAME_VALID | 24 | ACTCTX_FLAG_SET_PROCESS_DEFAULT | 25 | ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID, 26 | TEXT("shell32.dll"), 27 | 0, 28 | 0, 29 | dir, 30 | (LPCTSTR)124}; 31 | UINT cch = GetSystemDirectory(dir, sizeof(dir) / sizeof(*dir)); 32 | if (cch >= sizeof(dir) / sizeof(*dir)) { 33 | return FALSE; /*shouldn't happen*/ 34 | } 35 | dir[cch] = TEXT('\0'); 36 | ActivateActCtx(CreateActCtx(&actCtx), &ulpActivationCookie); 37 | return ulpActivationCookie; 38 | } 39 | 40 | } // namespace 41 | 42 | VisualTreeWatcher::VisualTreeWatcher(winrt::com_ptr site) 43 | : m_selfPtr(make_com_ptr_from_copy(this)), 44 | m_xamlDiagnostics(site.as()) { 45 | // AdviseVisualTreeChange(); 46 | 47 | // Calling AdviseVisualTreeChange from the current thread causes the app to 48 | // hang on Windows 10 in Advising::RunOnUIThread. Creating a new thread and 49 | // calling it from there fixes it. 50 | HANDLE thread = CreateThread( 51 | nullptr, 0, 52 | [](LPVOID lpParam) -> DWORD { 53 | auto watcher = reinterpret_cast(lpParam); 54 | watcher->AdviseVisualTreeChange(); 55 | return 0; 56 | }, 57 | this, 0, nullptr); 58 | if (thread) { 59 | CloseHandle(thread); 60 | } 61 | } 62 | 63 | void VisualTreeWatcher::Activate() { 64 | std::shared_lock lock(m_dlgMainMutex); 65 | 66 | for (auto& [threadId, dlgMain] : m_dlgMainForEachThread) { 67 | dlgMain.PostMessage(CMainDlg::UWM_ACTIVATE_WINDOW); 68 | } 69 | } 70 | 71 | VisualTreeWatcher::~VisualTreeWatcher() { 72 | while (true) { 73 | HWND hWnd = nullptr; 74 | 75 | { 76 | std::shared_lock lock(m_dlgMainMutex); 77 | 78 | if (!m_dlgMainForEachThread.empty()) { 79 | hWnd = m_dlgMainForEachThread.begin()->second; 80 | } 81 | } 82 | 83 | if (!hWnd) { 84 | break; 85 | } 86 | 87 | if (!SendMessage(hWnd, CMainDlg::UWM_DESTROY_WINDOW, 0, 0)) { 88 | ATLASSERT(FALSE); 89 | } 90 | } 91 | } 92 | 93 | void VisualTreeWatcher::AdviseVisualTreeChange() { 94 | const auto treeService = m_xamlDiagnostics.as(); 95 | winrt::check_hresult(treeService->AdviseVisualTreeChange(this)); 96 | } 97 | 98 | void VisualTreeWatcher::UnadviseVisualTreeChange() { 99 | const auto treeService = m_xamlDiagnostics.as(); 100 | winrt::check_hresult(treeService->UnadviseVisualTreeChange(this)); 101 | m_selfPtr = nullptr; 102 | } 103 | 104 | HRESULT VisualTreeWatcher::OnVisualTreeChange( 105 | ParentChildRelation parentChildRelation, 106 | VisualElement element, 107 | VisualMutationType mutationType) try { 108 | #if EXTRA_DEBUG 109 | try { 110 | WCHAR szBuffer[1025]; 111 | OutputDebugString(L"========================================\n"); 112 | 113 | wsprintf(szBuffer, L"Parent: %p\n", (void*)parentChildRelation.Parent); 114 | OutputDebugString(szBuffer); 115 | wsprintf(szBuffer, L"Child: %p\n", (void*)parentChildRelation.Child); 116 | OutputDebugString(szBuffer); 117 | wsprintf(szBuffer, L"Child index: %u\n", 118 | parentChildRelation.ChildIndex); 119 | OutputDebugString(szBuffer); 120 | wsprintf(szBuffer, L"Handle: %p\n", (void*)element.Handle); 121 | OutputDebugString(szBuffer); 122 | wsprintf(szBuffer, L"Type: %s\n", element.Type); 123 | OutputDebugString(szBuffer); 124 | wsprintf(szBuffer, L"Name: %s\n", element.Name); 125 | OutputDebugString(szBuffer); 126 | wsprintf(szBuffer, L"NumChildren: %u\n", element.NumChildren); 127 | OutputDebugString(szBuffer); 128 | OutputDebugString(L"~~~~~~~~~~\n"); 129 | 130 | switch (mutationType) { 131 | case Add: 132 | OutputDebugString(L"Mutation type: Add\n"); 133 | break; 134 | 135 | case Remove: 136 | OutputDebugString(L"Mutation type: Remove\n"); 137 | break; 138 | 139 | default: 140 | wsprintf(szBuffer, L"Mutation type: %d\n", 141 | static_cast(mutationType)); 142 | OutputDebugString(szBuffer); 143 | break; 144 | } 145 | 146 | wux::FrameworkElement frameworkElement = nullptr; 147 | 148 | const auto inspectable = FromHandle(element.Handle); 149 | frameworkElement = inspectable.try_as(); 150 | 151 | if (frameworkElement) { 152 | wsprintf(szBuffer, L"FrameworkElement address: %p\n", 153 | winrt::get_abi(frameworkElement)); 154 | OutputDebugString(szBuffer); 155 | wsprintf(szBuffer, L"FrameworkElement class: %s\n", 156 | winrt::get_class_name(frameworkElement).c_str()); 157 | OutputDebugString(szBuffer); 158 | wsprintf(szBuffer, L"FrameworkElement name: %s\n", 159 | frameworkElement.Name().c_str()); 160 | OutputDebugString(szBuffer); 161 | } 162 | 163 | if (parentChildRelation.Parent) { 164 | if (frameworkElement) { 165 | wsprintf(szBuffer, L"Real parent address: %p\n", 166 | winrt::get_abi( 167 | frameworkElement.Parent().as())); 168 | OutputDebugString(szBuffer); 169 | } 170 | 171 | const auto inspectable = 172 | FromHandle(parentChildRelation.Parent); 173 | const auto frameworkElement = 174 | inspectable.try_as(); 175 | if (frameworkElement) { 176 | wsprintf(szBuffer, L"Parent FrameworkElement address: %p\n", 177 | winrt::get_abi(frameworkElement)); 178 | OutputDebugString(szBuffer); 179 | wsprintf(szBuffer, L"Parent FrameworkElement class: %s\n", 180 | winrt::get_class_name(frameworkElement).c_str()); 181 | OutputDebugString(szBuffer); 182 | wsprintf(szBuffer, L"Parent FrameworkElement name: %s\n", 183 | frameworkElement.Name().c_str()); 184 | OutputDebugString(szBuffer); 185 | } 186 | } 187 | } catch (...) { 188 | HRESULT hr = winrt::to_hresult(); 189 | WCHAR szBuffer[1025]; 190 | wsprintf(szBuffer, L"Error %X\n", hr); 191 | OutputDebugString(szBuffer); 192 | } 193 | #endif // EXTRA_DEBUG 194 | 195 | auto* dlgMain = DlgMainForCurrentThread(); 196 | 197 | switch (mutationType) { 198 | case Add: 199 | if (dlgMain) { 200 | dlgMain->ElementAdded(parentChildRelation, element); 201 | } 202 | break; 203 | 204 | case Remove: 205 | if (dlgMain) { 206 | dlgMain->ElementRemoved(element.Handle); 207 | } 208 | break; 209 | 210 | default: 211 | ATLASSERT(FALSE); 212 | break; 213 | } 214 | 215 | return S_OK; 216 | } catch (...) { 217 | ATLASSERT(FALSE); 218 | // Returning an error prevents (some?) further messages, always return 219 | // success. 220 | // return winrt::to_hresult(); 221 | return S_OK; 222 | } 223 | 224 | HRESULT VisualTreeWatcher::OnElementStateChanged(InstanceHandle, 225 | VisualElementState, 226 | LPCWSTR) noexcept { 227 | return S_OK; 228 | } 229 | 230 | CMainDlg* VisualTreeWatcher::DlgMainForCurrentThread() { 231 | DWORD dwCurrentThreadId = GetCurrentThreadId(); 232 | 233 | { 234 | std::shared_lock lock(m_dlgMainMutex); 235 | 236 | auto it = m_dlgMainForEachThread.find(dwCurrentThreadId); 237 | if (it != m_dlgMainForEachThread.end()) { 238 | return &it->second; 239 | } 240 | } 241 | 242 | CMainDlg* dlgMain; 243 | 244 | { 245 | std::unique_lock lock(m_dlgMainMutex); 246 | 247 | auto [it, inserted] = m_dlgMainForEachThread.try_emplace( 248 | dwCurrentThreadId, m_xamlDiagnostics, 249 | std::bind(&VisualTreeWatcher::OnDlgMainEvent, this, 250 | std::placeholders::_1, std::placeholders::_2)); 251 | 252 | dlgMain = &it->second; 253 | 254 | if (!inserted) { 255 | ATLASSERT(FALSE); 256 | return dlgMain; 257 | } 258 | } 259 | 260 | HWND hChildWnd = nullptr; 261 | 262 | UINT32 length = 0; 263 | if (GetCurrentPackageFullName(&length, nullptr) != 264 | APPMODEL_ERROR_NO_PACKAGE) { 265 | // Packaged UWP processes seem to lack visual styles, which causes 266 | // artifacts such as black squares and UI flickering. This call fixes 267 | // it. 268 | EnableVisualStyles(); 269 | 270 | // Creating a dialog without a parent causes it to be occluded. Using 271 | // the core window as a parent window fixes it. 272 | if (const auto coreInterop = 273 | winrt::Windows::UI::Core::CoreWindow::GetForCurrentThread() 274 | .try_as()) { 275 | coreInterop->get_WindowHandle(&hChildWnd); 276 | } 277 | } 278 | 279 | if (!dlgMain->Create(hChildWnd)) { 280 | ATLTRACE(L"Main dialog creation failed!\n"); 281 | return nullptr; 282 | } 283 | 284 | dlgMain->ShowWindow(SW_SHOWDEFAULT); 285 | SetForegroundWindow(dlgMain->m_hWnd); 286 | 287 | return dlgMain; 288 | } 289 | 290 | void VisualTreeWatcher::OnDlgMainEvent(HWND hWnd, CMainDlg::EventId eventId) { 291 | if (eventId == CMainDlg::EventId::Hidden) { 292 | OnDlgMainHidden(hWnd); 293 | } else if (eventId == CMainDlg::EventId::FinalMessage) { 294 | OnDlgMainFinalMessage(hWnd); 295 | } 296 | } 297 | 298 | void VisualTreeWatcher::OnDlgMainHidden(HWND hWnd) { 299 | UnloadIfNoMoreVisibleDlgs(); 300 | } 301 | 302 | void VisualTreeWatcher::OnDlgMainFinalMessage(HWND hWnd) { 303 | DWORD dwCurrentThreadId = GetCurrentThreadId(); 304 | 305 | { 306 | std::unique_lock lock(m_dlgMainMutex); 307 | 308 | auto it = m_dlgMainForEachThread.find(dwCurrentThreadId); 309 | if (it == m_dlgMainForEachThread.end()) { 310 | ATLASSERT(FALSE); 311 | return; 312 | } 313 | 314 | m_dlgMainForEachThread.erase(it); 315 | } 316 | 317 | UnloadIfNoMoreVisibleDlgs(); 318 | } 319 | 320 | void VisualTreeWatcher::UnloadIfNoMoreVisibleDlgs() { 321 | if (m_unloading) { 322 | return; 323 | } 324 | 325 | { 326 | std::shared_lock lock(m_dlgMainMutex); 327 | 328 | for (auto& [threadId, dlgMain] : m_dlgMainForEachThread) { 329 | if (dlgMain.IsWindowVisible()) { 330 | return; 331 | } 332 | } 333 | } 334 | 335 | if (m_unloading.exchange(true)) { 336 | return; 337 | } 338 | 339 | // Unload in a new thread to avoid deadlocks and to be able to unload self. 340 | HANDLE thread = CreateThread( 341 | nullptr, 0, 342 | [](LPVOID lpParam) -> DWORD { 343 | auto watcher = reinterpret_cast(lpParam); 344 | watcher->UnadviseVisualTreeChange(); 345 | Sleep(100); 346 | FreeLibraryAndExitThread(_Module.GetModuleInstance(), 0); 347 | }, 348 | this, 0, nullptr); 349 | if (thread) { 350 | CloseHandle(thread); 351 | } 352 | } 353 | -------------------------------------------------------------------------------- /UWPSpy/visualtreewatcher.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MainDlg.h" 4 | #include "winrt.hpp" 5 | 6 | class VisualTreeWatcher : public winrt::implements { 9 | public: 10 | VisualTreeWatcher(winrt::com_ptr site); 11 | 12 | void Activate(); 13 | 14 | VisualTreeWatcher(const VisualTreeWatcher&) = delete; 15 | VisualTreeWatcher& operator=(const VisualTreeWatcher&) = delete; 16 | 17 | VisualTreeWatcher(VisualTreeWatcher&&) = delete; 18 | VisualTreeWatcher& operator=(VisualTreeWatcher&&) = delete; 19 | 20 | ~VisualTreeWatcher(); 21 | 22 | void AdviseVisualTreeChange(); 23 | void UnadviseVisualTreeChange(); 24 | 25 | private: 26 | HRESULT STDMETHODCALLTYPE 27 | OnVisualTreeChange(ParentChildRelation relation, 28 | VisualElement element, 29 | VisualMutationType mutationType) override; 30 | HRESULT STDMETHODCALLTYPE 31 | OnElementStateChanged(InstanceHandle element, 32 | VisualElementState elementState, 33 | LPCWSTR context) noexcept override; 34 | 35 | template 36 | T FromHandle(InstanceHandle handle) { 37 | wf::IInspectable obj; 38 | winrt::check_hresult(m_xamlDiagnostics->GetIInspectableFromHandle( 39 | handle, reinterpret_cast<::IInspectable**>(winrt::put_abi(obj)))); 40 | 41 | return obj.as(); 42 | } 43 | 44 | CMainDlg* DlgMainForCurrentThread(); 45 | void OnDlgMainEvent(HWND hWnd, CMainDlg::EventId eventId); 46 | void OnDlgMainHidden(HWND hWnd); 47 | void OnDlgMainFinalMessage(HWND hWnd); 48 | void UnloadIfNoMoreVisibleDlgs(); 49 | 50 | winrt::com_ptr m_selfPtr; 51 | winrt::com_ptr m_xamlDiagnostics; 52 | 53 | std::shared_mutex m_dlgMainMutex; 54 | std::unordered_map m_dlgMainForEachThread; 55 | 56 | std::atomic m_unloading = false; 57 | }; 58 | -------------------------------------------------------------------------------- /UWPSpy/winrt.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // forward declare namespaces we alias 4 | namespace winrt { 5 | namespace Microsoft::UI::Xaml::Controls {} 6 | namespace Windows { 7 | namespace Foundation::Collections {} 8 | namespace UI::Xaml { 9 | namespace Controls {} 10 | namespace Hosting {} 11 | } 12 | } 13 | } 14 | 15 | // alias some long namespaces for convenience 16 | namespace mux = winrt::Microsoft::UI::Xaml; 17 | namespace muxc = winrt::Microsoft::UI::Xaml::Controls; 18 | namespace wf = winrt::Windows::Foundation; 19 | namespace wfc = wf::Collections; 20 | namespace wux = winrt::Windows::UI::Xaml; 21 | namespace wuxc = wux::Controls; 22 | namespace wuxh = wux::Hosting; 23 | -------------------------------------------------------------------------------- /UWPSpy/winui/microsoft.ui.xaml.hosting.desktopwindowxamlsource_winui.h: -------------------------------------------------------------------------------- 1 | /* Modified manually: renamed from IDesktopWindowXamlSourceNative to 2 | * IDesktopWindowXamlSourceNative_WinUI */ 3 | 4 | /* this ALWAYS GENERATED file contains the definitions for the interfaces */ 5 | 6 | 7 | /* File created by MIDL compiler version 8.01.0622 */ 8 | /* @@MIDL_FILE_HEADING( ) */ 9 | 10 | 11 | 12 | /* verify that the version is high enough to compile this file*/ 13 | #ifndef __REQUIRED_RPCNDR_H_VERSION__ 14 | #define __REQUIRED_RPCNDR_H_VERSION__ 500 15 | #endif 16 | 17 | /* verify that the version is high enough to compile this file*/ 18 | #ifndef __REQUIRED_RPCSAL_H_VERSION__ 19 | #define __REQUIRED_RPCSAL_H_VERSION__ 100 20 | #endif 21 | 22 | #include "rpc.h" 23 | #include "rpcndr.h" 24 | 25 | #ifndef __RPCNDR_H_VERSION__ 26 | #error this stub requires an updated version of 27 | #endif /* __RPCNDR_H_VERSION__ */ 28 | 29 | #ifndef COM_NO_WINDOWS_H 30 | #include "windows.h" 31 | #include "ole2.h" 32 | #endif /*COM_NO_WINDOWS_H*/ 33 | 34 | #ifndef __microsoft2Eui2Examl2Ehosting2Edesktopwindowxamlsource_h__ 35 | #define __microsoft2Eui2Examl2Ehosting2Edesktopwindowxamlsource_h__ 36 | 37 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) 38 | #pragma once 39 | #endif 40 | 41 | /* Forward Declarations */ 42 | 43 | #ifndef __IDesktopWindowXamlSourceNative_WinUI_FWD_DEFINED__ 44 | #define __IDesktopWindowXamlSourceNative_WinUI_FWD_DEFINED__ 45 | typedef interface IDesktopWindowXamlSourceNative_WinUI IDesktopWindowXamlSourceNative_WinUI; 46 | 47 | #endif /* __IDesktopWindowXamlSourceNative_WinUI_FWD_DEFINED__ */ 48 | 49 | 50 | /* header files for imported files */ 51 | #include "oaidl.h" 52 | 53 | #ifdef __cplusplus 54 | extern "C"{ 55 | #endif 56 | 57 | 58 | #ifndef __IDesktopWindowXamlSourceNative_WinUI_INTERFACE_DEFINED__ 59 | #define __IDesktopWindowXamlSourceNative_WinUI_INTERFACE_DEFINED__ 60 | 61 | /* interface IDesktopWindowXamlSourceNative_WinUI */ 62 | /* [unique][local][uuid][object] */ 63 | 64 | 65 | EXTERN_C const IID IID_IDesktopWindowXamlSourceNative_WinUI; 66 | 67 | #if defined(__cplusplus) && !defined(CINTERFACE) 68 | 69 | MIDL_INTERFACE("0aea2f26-facf-4588-8cf4-34555124db32") 70 | IDesktopWindowXamlSourceNative_WinUI : public IUnknown 71 | { 72 | public: 73 | virtual HRESULT STDMETHODCALLTYPE AttachToWindow( 74 | /* [annotation][in] */ 75 | _In_ HWND parentWnd) = 0; 76 | 77 | virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_WindowHandle( 78 | /* [retval][out] */ HWND *hWnd) = 0; 79 | 80 | virtual HRESULT STDMETHODCALLTYPE PreTranslateMessage( 81 | /* [annotation][in] */ 82 | _In_ const MSG *message, 83 | /* [retval][out] */ BOOL *result) = 0; 84 | 85 | }; 86 | 87 | 88 | #else /* C style interface */ 89 | #error "C style interface not supported" 90 | #endif /* C style interface */ 91 | 92 | 93 | 94 | 95 | #endif /* __IDesktopWindowXamlSourceNative_WinUI_INTERFACE_DEFINED__ */ 96 | 97 | 98 | /* Additional Prototypes for ALL interfaces */ 99 | 100 | /* end of Additional Prototypes */ 101 | 102 | #ifdef __cplusplus 103 | } 104 | #endif 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /UWPSpyLauncher/MainDlg.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "MainDlg.h" 4 | 5 | #include "../common/version.h" 6 | #include "process_spy.h" 7 | #include "resource.h" 8 | 9 | namespace { 10 | 11 | void OpenUrl(HWND hWnd, PCWSTR url) { 12 | if ((INT_PTR)ShellExecute(hWnd, L"open", url, nullptr, nullptr, 13 | SW_SHOWNORMAL) <= 32) { 14 | CString errorMsg; 15 | errorMsg.Format( 16 | L"Failed to open link, you can copy it with Ctrl+C and open it in " 17 | L"a browser manually:\n\n%s", 18 | url); 19 | MessageBox(hWnd, errorMsg, nullptr, MB_ICONHAND); 20 | } 21 | } 22 | 23 | } // namespace 24 | 25 | void CSortListViewCtrlCustom::ProcessListOnChar(TCHAR chChar, 26 | UINT nRepCnt, 27 | UINT nFlags) { 28 | if (chChar == 4) { 29 | // Ctrl+D. 30 | GetParent().SendMessage( 31 | CMainDlg::UWM_SELECT_PROCESS_IN_LIST_FROM_CURSOR); 32 | } else { 33 | SetMsgHandled(FALSE); 34 | } 35 | } 36 | 37 | BOOL CMainDlg::OnInitDialog(CWindow wndFocus, LPARAM lInitParam) { 38 | CenterWindow(); 39 | 40 | m_icon.LoadIconMetric(IDR_MAINFRAME, LIM_LARGE); 41 | SetIcon(m_icon, TRUE); 42 | m_smallIcon.LoadIconMetric(IDR_MAINFRAME, LIM_SMALL); 43 | SetIcon(m_smallIcon, FALSE); 44 | 45 | DlgResize_Init(); 46 | 47 | InitProcessList(); 48 | LoadProcessList(); 49 | 50 | CheckDlgButton(IDC_RADIO_UWP, BST_CHECKED); 51 | 52 | return TRUE; 53 | } 54 | 55 | void CMainDlg::OnTimer(UINT_PTR nIDEvent) { 56 | switch (nIDEvent) { 57 | case TIMER_ID_END_DIALOG: 58 | KillTimer(nIDEvent); 59 | EndDialog(0); 60 | break; 61 | } 62 | } 63 | 64 | void CMainDlg::OnOK(UINT uNotifyCode, int nID, CWindow wndCtl) { 65 | int selectedIndex = m_processListSort.GetSelectedIndex(); 66 | if (selectedIndex == -1) { 67 | MessageBox(L"Select a process from the list to spy on", 68 | L"No process selected", MB_ICONWARNING); 69 | return; 70 | } 71 | 72 | ProcessSpyFromList(selectedIndex); 73 | } 74 | 75 | void CMainDlg::OnRefresh(UINT uNotifyCode, int nID, CWindow wndCtl) { 76 | LoadProcessList(); 77 | } 78 | 79 | void CMainDlg::OnAppAbout(UINT uNotifyCode, int nID, CWindow wndCtl) { 80 | PCWSTR content = 81 | L"An inspection tool for UWP and WinUI 3 applications. Seamlessly view " 82 | L"and manipulate UI elements and their properties in real time.\n" 83 | L"\n" 84 | L"By Ramen Software\n" 85 | L"\n" 86 | L"Homepage\n" 87 | L"Source code"; 88 | 89 | TASKDIALOGCONFIG taskDialogConfig{ 90 | .cbSize = sizeof(taskDialogConfig), 91 | .hwndParent = m_hWnd, 92 | .hInstance = _Module.GetModuleInstance(), 93 | .dwFlags = TDF_ENABLE_HYPERLINKS | TDF_ALLOW_DIALOG_CANCELLATION, 94 | .pszWindowTitle = L"About", 95 | .pszMainIcon = MAKEINTRESOURCE(IDR_MAINFRAME), 96 | .pszMainInstruction = L"UWPSpy v" VER_FILE_VERSION_WSTR, 97 | .pszContent = content, 98 | .pfCallback = [](HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, 99 | LONG_PTR lpRefData) -> HRESULT { 100 | switch (msg) { 101 | case TDN_HYPERLINK_CLICKED: 102 | OpenUrl(hwnd, (PCWSTR)lParam); 103 | break; 104 | } 105 | 106 | return S_OK; 107 | }, 108 | }; 109 | 110 | ::TaskDialogIndirect(&taskDialogConfig, nullptr, nullptr, nullptr); 111 | } 112 | 113 | void CMainDlg::OnCancel(UINT uNotifyCode, int nID, CWindow wndCtl) { 114 | EndDialog(nID); 115 | } 116 | 117 | LRESULT CMainDlg::OnListDblClk(LPNMHDR pnmh) { 118 | LPNMITEMACTIVATE lpnmitem = (LPNMITEMACTIVATE)pnmh; 119 | if (lpnmitem->iItem == -1) { 120 | return 0; 121 | } 122 | 123 | ProcessSpyFromList(lpnmitem->iItem); 124 | 125 | return 0; 126 | } 127 | 128 | LRESULT CMainDlg::SelectProcessInListFromCursor(UINT uMsg, 129 | WPARAM wParam, 130 | LPARAM lParam) { 131 | POINT pt; 132 | ::GetCursorPos(&pt); 133 | CWindow wnd = ::WindowFromPoint(pt); 134 | if (!wnd) { 135 | return 0; 136 | } 137 | 138 | DWORD pid = wnd.GetWindowProcessID(); 139 | 140 | CListViewCtrl list(GetDlgItem(IDC_PROCESS_LIST)); 141 | int itemCount = list.GetItemCount(); 142 | for (int i = 0; i < itemCount; i++) { 143 | DWORD itemPid = static_cast(list.GetItemData(i)); 144 | if (itemPid == pid) { 145 | list.SetItemState(i, LVIS_FOCUSED | LVIS_SELECTED, 146 | LVIS_FOCUSED | LVIS_SELECTED); 147 | list.EnsureVisible(i, FALSE); 148 | break; 149 | } 150 | } 151 | 152 | return 0; 153 | } 154 | 155 | void CMainDlg::InitProcessList() { 156 | CListViewCtrl list(GetDlgItem(IDC_PROCESS_LIST)); 157 | 158 | m_processListSort.SubclassWindow(list); 159 | 160 | list.SetExtendedListViewStyle(LVS_EX_HEADERDRAGDROP | LVS_EX_FULLROWSELECT | 161 | LVS_EX_LABELTIP | LVS_EX_DOUBLEBUFFER); 162 | ::SetWindowTheme(list, L"Explorer", nullptr); 163 | 164 | using GetDpiForWindow_t = UINT(WINAPI*)(HWND hwnd); 165 | static GetDpiForWindow_t pGetDpiForWindow = []() { 166 | HMODULE hUser32 = GetModuleHandle(L"user32.dll"); 167 | return (GetDpiForWindow_t)(hUser32 ? GetProcAddress(hUser32, 168 | "GetDpiForWindow") 169 | : nullptr); 170 | }(); 171 | 172 | UINT windowDpi = pGetDpiForWindow ? pGetDpiForWindow(m_hWnd) : 96; 173 | 174 | // Sort PIDs as decimals, signed 128-bit (16-byte) values representing 175 | // 96-bit (12-byte) integer numbers: 176 | // https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/data-types/decimal-data-type 177 | // A bit of an overkill, but LVCOLSORT_LONG is signed 32-bit while PIDs are 178 | // unsigned 32-bit, so it doesn't fit. And a custom type isn't worth the 179 | // effort. 180 | struct { 181 | PCWSTR name; 182 | int width; 183 | WORD sort; 184 | } columns[] = { 185 | {L"Process name", -60, LVCOLSORT_TEXT}, 186 | {L"PID", 60, LVCOLSORT_DECIMAL}, 187 | }; 188 | 189 | for (int i = 0; i < ARRAYSIZE(columns); i++) { 190 | list.InsertColumn(i, columns[i].name); 191 | int width = columns[i].width; 192 | width = MulDiv(width, windowDpi, 96); 193 | if (width < 0) { 194 | CRect listRect; 195 | list.GetClientRect(&listRect); 196 | int scrollbarWidth = ::GetSystemMetrics(SM_CXVSCROLL); 197 | width += listRect.Width() - scrollbarWidth; 198 | if (width < scrollbarWidth) { 199 | width = scrollbarWidth; 200 | } 201 | } 202 | 203 | list.SetColumnWidth(i, width); 204 | m_processListSort.SetColumnSortType(i, columns[i].sort); 205 | } 206 | 207 | m_processListSort.SetSortColumn(0); 208 | } 209 | 210 | void CMainDlg::LoadProcessList() { 211 | m_processListSort.SetRedraw(FALSE); 212 | 213 | m_processListSort.DeleteAllItems(); 214 | 215 | int itemIndex = 0; 216 | 217 | HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); 218 | if (snapshot != INVALID_HANDLE_VALUE) { 219 | PROCESSENTRY32 entry{ 220 | .dwSize = sizeof(entry), 221 | }; 222 | if (Process32First(snapshot, &entry)) { 223 | do { 224 | if (entry.th32ProcessID == 0) { 225 | continue; 226 | } 227 | 228 | WCHAR szPid[16]; 229 | swprintf_s(szPid, L"%u", entry.th32ProcessID); 230 | 231 | m_processListSort.AddItem(itemIndex, 0, entry.szExeFile); 232 | m_processListSort.AddItem(itemIndex, 1, szPid); 233 | m_processListSort.SetItemData(itemIndex, entry.th32ProcessID); 234 | itemIndex++; 235 | } while (Process32Next(snapshot, &entry)); 236 | } 237 | 238 | CloseHandle(snapshot); 239 | } 240 | 241 | m_processListSort.DoSortItems(m_processListSort.GetSortColumn(), 242 | m_processListSort.IsSortDescending()); 243 | 244 | m_processListSort.SetRedraw(TRUE); 245 | m_processListSort.RedrawWindow( 246 | nullptr, nullptr, 247 | RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN); 248 | } 249 | 250 | void CMainDlg::ProcessSpyFromList(int index) { 251 | DWORD pid = static_cast(m_processListSort.GetItemData(index)); 252 | 253 | ProcessSpyFramework framework = kFrameworkUWP; 254 | if (IsDlgButtonChecked(IDC_RADIO_WINUI) != BST_UNCHECKED) { 255 | framework = kFrameworkWinUI; 256 | } 257 | 258 | if (ProcessSpy(m_hWnd, pid, framework)) { 259 | // EndDialog(0); 260 | 261 | // Starting with Windows 11 build 22621.2506, closing the window right 262 | // away makes the inspection fail. Use a timer as a workaround. 263 | SetTimer(TIMER_ID_END_DIALOG, 0); 264 | } 265 | } 266 | -------------------------------------------------------------------------------- /UWPSpyLauncher/MainDlg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "resource.h" 4 | 5 | class CSortListViewCtrlCustom : public CSortListViewCtrl { 6 | BEGIN_MSG_MAP(CSortListViewCtrlCustom) 7 | MSG_WM_CHAR(ProcessListOnChar) 8 | CHAIN_MSG_MAP(CSortListViewCtrl) 9 | END_MSG_MAP() 10 | 11 | void ProcessListOnChar(TCHAR chChar, UINT nRepCnt, UINT nFlags); 12 | }; 13 | 14 | class CMainDlg : public CDialogImpl, public CDialogResize { 15 | public: 16 | enum { IDD = IDD_MAINDLG }; 17 | 18 | enum { 19 | TIMER_ID_END_DIALOG = 1, 20 | }; 21 | 22 | enum { 23 | UWM_SELECT_PROCESS_IN_LIST_FROM_CURSOR = WM_APP, 24 | }; 25 | 26 | BEGIN_DLGRESIZE_MAP(CMainDlg) 27 | DLGRESIZE_CONTROL(IDC_PROCESS_LIST, DLSZ_SIZE_X | DLSZ_SIZE_Y) 28 | DLGRESIZE_CONTROL(IDC_STATIC_FRAMEWORK, DLSZ_MOVE_Y) 29 | DLGRESIZE_CONTROL(IDC_RADIO_UWP, DLSZ_MOVE_Y) 30 | DLGRESIZE_CONTROL(IDC_RADIO_WINUI, DLSZ_MOVE_Y) 31 | DLGRESIZE_CONTROL(IDOK, DLSZ_MOVE_Y) 32 | DLGRESIZE_CONTROL(IDC_REFRESH_BUTTON, DLSZ_MOVE_Y) 33 | DLGRESIZE_CONTROL(ID_APP_ABOUT, DLSZ_MOVE_X | DLSZ_MOVE_Y) 34 | DLGRESIZE_CONTROL(IDCANCEL, DLSZ_MOVE_X | DLSZ_MOVE_Y) 35 | END_DLGRESIZE_MAP() 36 | 37 | private: 38 | BEGIN_MSG_MAP(CMainDlg) 39 | CHAIN_MSG_MAP(CDialogResize) 40 | MSG_WM_INITDIALOG(OnInitDialog) 41 | MSG_WM_TIMER(OnTimer) 42 | COMMAND_ID_HANDLER_EX(ID_APP_ABOUT, OnAppAbout) 43 | COMMAND_ID_HANDLER_EX(IDOK, OnOK) 44 | COMMAND_ID_HANDLER_EX(IDC_REFRESH_BUTTON, OnRefresh) 45 | COMMAND_ID_HANDLER_EX(ID_APP_ABOUT, OnAppAbout) 46 | COMMAND_ID_HANDLER_EX(IDCANCEL, OnCancel) 47 | NOTIFY_HANDLER_EX(IDC_PROCESS_LIST, NM_DBLCLK, OnListDblClk) 48 | MESSAGE_HANDLER_EX(UWM_SELECT_PROCESS_IN_LIST_FROM_CURSOR, 49 | SelectProcessInListFromCursor) 50 | END_MSG_MAP() 51 | 52 | BOOL OnInitDialog(CWindow wndFocus, LPARAM lInitParam); 53 | void OnTimer(UINT_PTR nIDEvent); 54 | void OnOK(UINT uNotifyCode, int nID, CWindow wndCtl); 55 | void OnRefresh(UINT uNotifyCode, int nID, CWindow wndCtl); 56 | void OnAppAbout(UINT uNotifyCode, int nID, CWindow wndCtl); 57 | void OnCancel(UINT uNotifyCode, int nID, CWindow wndCtl); 58 | LRESULT OnListDblClk(LPNMHDR pnmh); 59 | LRESULT SelectProcessInListFromCursor(UINT uMsg, 60 | WPARAM wParam, 61 | LPARAM lParam); 62 | 63 | void InitProcessList(); 64 | void LoadProcessList(); 65 | void ProcessSpyFromList(int index); 66 | 67 | CIcon m_icon, m_smallIcon; 68 | CSortListViewCtrlCustom m_processListSort; 69 | }; 70 | -------------------------------------------------------------------------------- /UWPSpyLauncher/UWPSpyLauncher.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "MainDlg.h" 4 | #include "process_spy.h" 5 | 6 | CAppModule _Module; 7 | 8 | int WINAPI wWinMain(_In_ HINSTANCE hInstance, 9 | _In_opt_ HINSTANCE hPrevInstance, 10 | _In_ LPWSTR lpCmdLine, 11 | _In_ int nCmdShow) { 12 | HRESULT hRes = ::CoInitialize(NULL); 13 | ATLASSERT(SUCCEEDED(hRes)); 14 | 15 | AtlInitCommonControls( 16 | ICC_BAR_CLASSES); // add flags to support other controls 17 | 18 | hRes = _Module.Init(NULL, hInstance); 19 | ATLASSERT(SUCCEEDED(hRes)); 20 | 21 | int nRet = 0; 22 | 23 | DWORD pid = 0; 24 | ProcessSpyFramework framework = kFrameworkUWP; 25 | if (__argc >= 2) { 26 | pid = wcstoul(__wargv[1], nullptr, 0); 27 | 28 | if (__argc >= 3 && _wcsicmp(__wargv[2], L"winui") == 0) { 29 | framework = kFrameworkWinUI; 30 | } 31 | } 32 | 33 | if (pid) { 34 | ProcessSpy(nullptr, pid, framework); 35 | } else { 36 | CMainDlg dlgMain; 37 | nRet = (int)dlgMain.DoModal(); 38 | } 39 | 40 | _Module.Term(); 41 | ::CoUninitialize(); 42 | 43 | return nRet; 44 | } 45 | -------------------------------------------------------------------------------- /UWPSpyLauncher/UWPSpyLauncher.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m417z/UWPSpy/887e27500670adcd0cad5d0b9179515164224d79/UWPSpyLauncher/UWPSpyLauncher.ico -------------------------------------------------------------------------------- /UWPSpyLauncher/UWPSpyLauncher.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "atlres.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (United States) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 20 | #pragma code_page(1252) 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""atlres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "#include ""UWPSpyLauncher.rc2""\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Icon 51 | // 52 | 53 | // Icon with lowest ID value placed first to ensure application icon 54 | // remains consistent on all systems. 55 | IDR_MAINFRAME ICON "res\\UWPSpyLauncher.ico" 56 | 57 | 58 | ///////////////////////////////////////////////////////////////////////////// 59 | // 60 | // Dialog 61 | // 62 | 63 | IDD_MAINDLG DIALOGEX 0, 0, 256, 144 64 | STYLE DS_SETFONT | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME 65 | CAPTION "UWPSpy" 66 | FONT 9, "Segoe UI", 0, 0, 0x0 67 | BEGIN 68 | CONTROL "",IDC_PROCESS_LIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,7,7,242,98 69 | LTEXT "Target framework:",IDC_STATIC_FRAMEWORK,7,110,61,8 70 | CONTROL "UWP",IDC_RADIO_UWP,"Button",BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,71,109,31,10 71 | CONTROL "WinUI 3",IDC_RADIO_WINUI,"Button",BS_AUTORADIOBUTTON,105,109,39,10 72 | DEFPUSHBUTTON "Spy",IDOK,7,123,50,14 73 | PUSHBUTTON "&Refresh",IDC_REFRESH_BUTTON,61,123,50,14 74 | PUSHBUTTON "&About",ID_APP_ABOUT,145,123,50,14 75 | PUSHBUTTON "Exit",IDCANCEL,199,123,50,14 76 | END 77 | 78 | 79 | ///////////////////////////////////////////////////////////////////////////// 80 | // 81 | // DESIGNINFO 82 | // 83 | 84 | #ifdef APSTUDIO_INVOKED 85 | GUIDELINES DESIGNINFO 86 | BEGIN 87 | IDD_MAINDLG, DIALOG 88 | BEGIN 89 | LEFTMARGIN, 7 90 | RIGHTMARGIN, 249 91 | TOPMARGIN, 7 92 | BOTTOMMARGIN, 137 93 | END 94 | END 95 | #endif // APSTUDIO_INVOKED 96 | 97 | 98 | ///////////////////////////////////////////////////////////////////////////// 99 | // 100 | // Accelerator 101 | // 102 | 103 | IDR_MAINFRAME ACCELERATORS 104 | BEGIN 105 | "N", ID_FILE_NEW, VIRTKEY, CONTROL 106 | "O", ID_FILE_OPEN, VIRTKEY, CONTROL 107 | "S", ID_FILE_SAVE, VIRTKEY, CONTROL 108 | "P", ID_FILE_PRINT, VIRTKEY, CONTROL 109 | "Z", ID_EDIT_UNDO, VIRTKEY, CONTROL 110 | "X", ID_EDIT_CUT, VIRTKEY, CONTROL 111 | "C", ID_EDIT_COPY, VIRTKEY, CONTROL 112 | "V", ID_EDIT_PASTE, VIRTKEY, CONTROL 113 | VK_BACK, ID_EDIT_UNDO, VIRTKEY, ALT 114 | VK_DELETE, ID_EDIT_CUT, VIRTKEY, SHIFT 115 | VK_INSERT, ID_EDIT_COPY, VIRTKEY, CONTROL 116 | VK_INSERT, ID_EDIT_PASTE, VIRTKEY, SHIFT 117 | VK_F6, ID_NEXT_PANE, VIRTKEY 118 | VK_F6, ID_PREV_PANE, VIRTKEY, SHIFT 119 | END 120 | 121 | 122 | ///////////////////////////////////////////////////////////////////////////// 123 | // 124 | // AFX_DIALOG_LAYOUT 125 | // 126 | 127 | IDD_MAINDLG AFX_DIALOG_LAYOUT 128 | BEGIN 129 | 0 130 | END 131 | 132 | 133 | ///////////////////////////////////////////////////////////////////////////// 134 | // 135 | // String Table 136 | // 137 | 138 | STRINGTABLE 139 | BEGIN 140 | IDR_MAINFRAME "UWPSpyLauncher" 141 | END 142 | 143 | STRINGTABLE 144 | BEGIN 145 | ID_FILE_NEW "Create a new document\nNew" 146 | ID_FILE_OPEN "Open an existing document\nOpen" 147 | ID_FILE_CLOSE "Close the active document\nClose" 148 | ID_FILE_SAVE "Save the active document\nSave" 149 | ID_FILE_SAVE_AS "Save the active document with a new name\nSave As" 150 | ID_FILE_PAGE_SETUP "Change the printing options\nPage Setup" 151 | ID_FILE_PRINT_SETUP "Change the printer and printing options\nPrint Setup" 152 | ID_FILE_PRINT "Print the active document\nPrint" 153 | ID_FILE_PRINT_PREVIEW "Display full pages\nPrint Preview" 154 | END 155 | 156 | STRINGTABLE 157 | BEGIN 158 | ID_APP_ABOUT "Display program information, version number and copyright\nAbout" 159 | ID_APP_EXIT "Quit the application; prompts to save documents\nExit" 160 | END 161 | 162 | STRINGTABLE 163 | BEGIN 164 | ID_NEXT_PANE "Switch to the next window pane\nNext Pane" 165 | ID_PREV_PANE "Switch back to the previous window pane\nPrevious Pane" 166 | END 167 | 168 | STRINGTABLE 169 | BEGIN 170 | ID_WINDOW_NEW "Open another window for the active document\nNew Window" 171 | ID_WINDOW_ARRANGE "Arrange icons at the bottom of the window\nArrange Icons" 172 | ID_WINDOW_CASCADE "Arrange windows so they overlap\nCascade Windows" 173 | ID_WINDOW_TILE_HORZ "Arrange windows as non-overlapping tiles\nTile Windows" 174 | ID_WINDOW_TILE_VERT "Arrange windows as non-overlapping tiles\nTile Windows" 175 | ID_WINDOW_SPLIT "Split the active window into panes\nSplit" 176 | END 177 | 178 | STRINGTABLE 179 | BEGIN 180 | ID_EDIT_CLEAR "Erase the selection\nErase" 181 | ID_EDIT_CLEAR_ALL "Erase everything\nErase All" 182 | ID_EDIT_COPY "Copy the selection and put it on the Clipboard\nCopy" 183 | ID_EDIT_CUT "Cut the selection and put it on the Clipboard\nCut" 184 | ID_EDIT_FIND "Find the specified text\nFind" 185 | ID_EDIT_PASTE "Insert Clipboard contents\nPaste" 186 | ID_EDIT_REPEAT "Repeat the last action\nRepeat" 187 | ID_EDIT_REPLACE "Replace specific text with different text\nReplace" 188 | ID_EDIT_SELECT_ALL "Select the entire document\nSelect All" 189 | ID_EDIT_UNDO "Undo the last action\nUndo" 190 | ID_EDIT_REDO "Redo the previously undone action\nRedo" 191 | END 192 | 193 | STRINGTABLE 194 | BEGIN 195 | ATL_IDS_SCSIZE "Change the window size" 196 | ATL_IDS_SCMOVE "Change the window position" 197 | ATL_IDS_SCMINIMIZE "Reduce the window to an icon" 198 | ATL_IDS_SCMAXIMIZE "Enlarge the window to full size" 199 | ATL_IDS_SCNEXTWINDOW "Switch to the next document window" 200 | ATL_IDS_SCPREVWINDOW "Switch to the previous document window" 201 | ATL_IDS_SCCLOSE "Close the active window and prompts to save the documents" 202 | END 203 | 204 | STRINGTABLE 205 | BEGIN 206 | ATL_IDS_SCRESTORE "Restore the window to normal size" 207 | ATL_IDS_SCTASKLIST "Activate Task List" 208 | ATL_IDS_MDICHILD "Activate this window" 209 | END 210 | 211 | STRINGTABLE 212 | BEGIN 213 | ATL_IDS_IDLEMESSAGE "Ready" 214 | END 215 | 216 | STRINGTABLE 217 | BEGIN 218 | ATL_IDS_MRU_FILE "Open this document" 219 | END 220 | 221 | #endif // English (United States) resources 222 | ///////////////////////////////////////////////////////////////////////////// 223 | 224 | 225 | 226 | #ifndef APSTUDIO_INVOKED 227 | ///////////////////////////////////////////////////////////////////////////// 228 | // 229 | // Generated from the TEXTINCLUDE 3 resource. 230 | // 231 | #include "UWPSpyLauncher.rc2" 232 | 233 | ///////////////////////////////////////////////////////////////////////////// 234 | #endif // not APSTUDIO_INVOKED 235 | 236 | -------------------------------------------------------------------------------- /UWPSpyLauncher/UWPSpyLauncher.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m417z/UWPSpy/887e27500670adcd0cad5d0b9179515164224d79/UWPSpyLauncher/UWPSpyLauncher.rc2 -------------------------------------------------------------------------------- /UWPSpyLauncher/UWPSpyLauncher.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | ARM64 7 | 8 | 9 | Debug 10 | Win32 11 | 12 | 13 | Release 14 | ARM64 15 | 16 | 17 | Release 18 | Win32 19 | 20 | 21 | Debug 22 | x64 23 | 24 | 25 | Release 26 | x64 27 | 28 | 29 | 30 | 16.0 31 | Win32Proj 32 | {590cb37a-8e25-4a5d-b358-de4baa08db59} 33 | UWPSpyLauncher 34 | 10.0 35 | 36 | 37 | 38 | Application 39 | true 40 | v143 41 | Unicode 42 | 43 | 44 | Application 45 | false 46 | v143 47 | true 48 | Unicode 49 | 50 | 51 | Application 52 | true 53 | v143 54 | Unicode 55 | 56 | 57 | Application 58 | true 59 | v143 60 | Unicode 61 | 62 | 63 | Application 64 | false 65 | v143 66 | true 67 | Unicode 68 | 69 | 70 | Application 71 | false 72 | v143 73 | true 74 | Unicode 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | Level3 108 | true 109 | WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) 110 | true 111 | Use 112 | stdcpp20 113 | MultiThreadedDebug 114 | /utf-8 %(AdditionalOptions) 115 | 116 | 117 | Windows 118 | true 119 | shlwapi.lib;%(AdditionalDependencies) 120 | 121 | 122 | res/manifest.manifest %(AdditionalManifestFiles) 123 | 124 | 125 | 126 | 127 | Level3 128 | true 129 | true 130 | true 131 | WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) 132 | true 133 | Use 134 | stdcpp20 135 | MultiThreaded 136 | /utf-8 %(AdditionalOptions) 137 | 138 | 139 | Windows 140 | true 141 | true 142 | false 143 | shlwapi.lib;%(AdditionalDependencies) 144 | 145 | 146 | res/manifest.manifest %(AdditionalManifestFiles) 147 | 148 | 149 | 150 | 151 | Level3 152 | true 153 | _DEBUG;_WINDOWS;%(PreprocessorDefinitions) 154 | true 155 | Use 156 | stdcpp20 157 | MultiThreadedDebug 158 | /utf-8 %(AdditionalOptions) 159 | 160 | 161 | Windows 162 | true 163 | shlwapi.lib;%(AdditionalDependencies) 164 | 165 | 166 | res/manifest.manifest %(AdditionalManifestFiles) 167 | 168 | 169 | 170 | 171 | Level3 172 | true 173 | _DEBUG;_WINDOWS;%(PreprocessorDefinitions) 174 | true 175 | Use 176 | stdcpp20 177 | MultiThreadedDebug 178 | /utf-8 %(AdditionalOptions) 179 | 180 | 181 | Windows 182 | true 183 | shlwapi.lib;%(AdditionalDependencies) 184 | 185 | 186 | res/manifest.manifest %(AdditionalManifestFiles) 187 | 188 | 189 | 190 | 191 | Level3 192 | true 193 | true 194 | true 195 | NDEBUG;_WINDOWS;%(PreprocessorDefinitions) 196 | true 197 | Use 198 | stdcpp20 199 | MultiThreaded 200 | /utf-8 %(AdditionalOptions) 201 | 202 | 203 | Windows 204 | true 205 | true 206 | false 207 | shlwapi.lib;%(AdditionalDependencies) 208 | 209 | 210 | res/manifest.manifest %(AdditionalManifestFiles) 211 | 212 | 213 | 214 | 215 | Level3 216 | true 217 | true 218 | true 219 | NDEBUG;_WINDOWS;%(PreprocessorDefinitions) 220 | true 221 | Use 222 | stdcpp20 223 | MultiThreaded 224 | /utf-8 %(AdditionalOptions) 225 | 226 | 227 | Windows 228 | true 229 | true 230 | false 231 | shlwapi.lib;%(AdditionalDependencies) 232 | 233 | 234 | res/manifest.manifest %(AdditionalManifestFiles) 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | Create 250 | Create 251 | Create 252 | Create 253 | Create 254 | Create 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 275 | 276 | 277 | 278 | -------------------------------------------------------------------------------- /UWPSpyLauncher/UWPSpyLauncher.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files 35 | 36 | 37 | 38 | 39 | Source Files 40 | 41 | 42 | Source Files 43 | 44 | 45 | Source Files 46 | 47 | 48 | Source Files 49 | 50 | 51 | 52 | 53 | Resource Files 54 | 55 | 56 | 57 | 58 | Resource Files 59 | 60 | 61 | Resource Files 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /UWPSpyLauncher/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /UWPSpyLauncher/process_spy.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "process_spy.h" 4 | 5 | namespace { 6 | 7 | constexpr USHORT kCurrentArch = 8 | #if defined(_M_IX86) 9 | IMAGE_FILE_MACHINE_I386; 10 | #elif defined(_M_X64) 11 | IMAGE_FILE_MACHINE_AMD64; 12 | #elif defined(_M_ARM64) 13 | IMAGE_FILE_MACHINE_ARM64; 14 | #else 15 | #error "Unsupported architecture" 16 | #endif 17 | 18 | USHORT GetProcessArch(HANDLE hProcess) { 19 | PROCESS_MACHINE_INFORMATION pmi; 20 | if (GetProcessInformation(hProcess, ProcessMachineTypeInfo, &pmi, 21 | sizeof(pmi))) { 22 | return pmi.ProcessMachine; 23 | } 24 | 25 | // If GetProcessInformation(ProcessMachineTypeInfo) isn't supported, assume 26 | // only IMAGE_FILE_MACHINE_I386 and IMAGE_FILE_MACHINE_AMD64. 27 | 28 | #ifndef _WIN64 29 | SYSTEM_INFO siSystemInfo; 30 | GetNativeSystemInfo(&siSystemInfo); 31 | if (siSystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL) { 32 | // 32-bit machine, only one option. 33 | return IMAGE_FILE_MACHINE_I386; 34 | } 35 | #endif // _WIN64 36 | 37 | BOOL bIsWow64Process; 38 | if (IsWow64Process(hProcess, &bIsWow64Process) && bIsWow64Process) { 39 | return IMAGE_FILE_MACHINE_I386; 40 | } 41 | 42 | return IMAGE_FILE_MACHINE_AMD64; 43 | } 44 | 45 | bool AllowAppContainerAccess(PCWSTR path) { 46 | PSECURITY_DESCRIPTOR sd = nullptr; 47 | ULONG sd_length = 0; 48 | // Set read and execute access to AppContainers and Low Privilege 49 | // AppContainers. 50 | BOOL success = ConvertStringSecurityDescriptorToSecurityDescriptor( 51 | L"D:(A;;GRGX;;;S-1-15-2-1)(A;;GRGX;;;S-1-15-2-2)", SDDL_REVISION_1, &sd, 52 | &sd_length); 53 | if (success) { 54 | PACL dacl = nullptr; 55 | BOOL present = FALSE, defaulted = FALSE; 56 | success = GetSecurityDescriptorDacl(sd, &present, &dacl, &defaulted); 57 | if (success) { 58 | DWORD result = SetNamedSecurityInfo( 59 | (PWSTR)path, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, nullptr, 60 | nullptr, dacl, nullptr); 61 | if (result == ERROR_SUCCESS) { 62 | success = true; 63 | } 64 | } 65 | 66 | LocalFree(sd); 67 | } 68 | 69 | return success; 70 | } 71 | 72 | } // namespace 73 | 74 | bool ProcessSpy(HWND hWnd, DWORD pid, ProcessSpyFramework framework) { 75 | HANDLE hProcess = 76 | OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid); 77 | if (hProcess) { 78 | USHORT arch = GetProcessArch(hProcess); 79 | CloseHandle(hProcess); 80 | if (arch != kCurrentArch) { 81 | CString message; 82 | message.Format( 83 | L"UWPSpy is not compatible with the target process " 84 | L"architecture.\n" 85 | L"\n" 86 | L"Target process architecture: %X\n" 87 | L"UWPSpy architecture: %X\n" 88 | L"\n" 89 | L"Please use the correct version of UWPSpy.\n" 90 | L"\n" 91 | L"Proceed anyway?", 92 | arch, kCurrentArch); 93 | if (MessageBox(hWnd, message, L"Warning", 94 | MB_ICONWARNING | MB_YESNO) == IDNO) { 95 | return false; 96 | } 97 | } 98 | } 99 | 100 | WCHAR path[MAX_PATH]; 101 | switch (GetModuleFileName(nullptr, path, ARRAYSIZE(path))) { 102 | case 0: 103 | case ARRAYSIZE(path): 104 | MessageBox(hWnd, L"Failed to get module path", L"Error", 105 | MB_ICONERROR); 106 | return false; 107 | } 108 | 109 | PWSTR filename = PathFindFileName(path); 110 | 111 | wcscpy_s(filename, ARRAYSIZE(path) - (filename - path), L"UWPSpy.dll"); 112 | 113 | if (GetFileAttributes(path) == INVALID_FILE_ATTRIBUTES) { 114 | MessageBox(hWnd, L"UWPSpy.dll is missing", L"Error", MB_ICONERROR); 115 | return false; 116 | } 117 | 118 | if (!AllowAppContainerAccess(path)) { 119 | PCWSTR warningMsg = 120 | L"Failed to adjust the file permissions for UWPSpy.dll. A UWP " 121 | L"application running in a sandboxed AppContainer environment " 122 | L"might not be able to load the module.\n" 123 | L"\n" 124 | L"If UWPSpy is running from a USB flash drive or a network drive, " 125 | L"consider copying it to the main system drive and running it from " 126 | L"there.\n" 127 | L"\n" 128 | L"Proceed anyway?"; 129 | if (MessageBox(hWnd, warningMsg, L"Warning", 130 | MB_ICONWARNING | MB_YESNO) == IDNO) { 131 | return false; 132 | } 133 | } 134 | 135 | HMODULE lib = LoadLibrary(path); 136 | if (!lib) { 137 | MessageBox(hWnd, L"Failed to load UWPSpy.dll", L"Error", MB_ICONERROR); 138 | return false; 139 | } 140 | 141 | using isDebugging_proc_t = BOOL(WINAPI*)(DWORD pid); 142 | 143 | isDebugging_proc_t isDebugging = 144 | (isDebugging_proc_t)GetProcAddress(lib, "isDebugging"); 145 | if (isDebugging && isDebugging(pid)) { 146 | PCWSTR warningMsg = 147 | L"UWPSpy is already inspecting the target process. To start a new " 148 | L"inspection session, close all existing UWPSpy windows and try " 149 | L"again.\n" 150 | L"\n" 151 | L"Resume the existing inspection session?"; 152 | if (MessageBox(hWnd, warningMsg, L"Warning", 153 | MB_ICONWARNING | MB_YESNO) == IDNO) { 154 | return false; 155 | } 156 | } 157 | 158 | using start_proc_t = HRESULT(WINAPI*)(DWORD pid, DWORD framework); 159 | 160 | start_proc_t start = (start_proc_t)GetProcAddress(lib, "start"); 161 | if (!start) { 162 | MessageBox(hWnd, L"Failed to find spy function", L"Error", 163 | MB_ICONERROR); 164 | return false; 165 | } 166 | 167 | HRESULT hr = start(pid, framework); 168 | if (FAILED(hr)) { 169 | CString message = 170 | L"Failed to start spying:\n" + AtlGetErrorDescription(hr); 171 | 172 | switch (framework) { 173 | case kFrameworkUWP: 174 | if (hr == HRESULT_FROM_WIN32(ERROR_NOT_FOUND)) { 175 | message += 176 | L"\n\nMake sure that the target process is a UWP " 177 | L"application."; 178 | } 179 | break; 180 | 181 | case kFrameworkWinUI: 182 | if (hr == HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND) || 183 | hr == HRESULT_FROM_WIN32(ERROR_NOT_FOUND)) { 184 | message += 185 | L"\n\nMake sure that the target process is a WinUI 3 " 186 | L"application."; 187 | } 188 | break; 189 | } 190 | 191 | MessageBox(hWnd, message, L"Error", MB_ICONERROR); 192 | return false; 193 | } 194 | 195 | return true; 196 | } 197 | -------------------------------------------------------------------------------- /UWPSpyLauncher/process_spy.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | enum ProcessSpyFramework : DWORD { 4 | kFrameworkUWP = 1, 5 | kFrameworkWinUI, 6 | }; 7 | 8 | bool ProcessSpy(HWND hWnd, DWORD pid, ProcessSpyFramework framework); 9 | -------------------------------------------------------------------------------- /UWPSpyLauncher/res/UWPSpyLauncher.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m417z/UWPSpy/887e27500670adcd0cad5d0b9179515164224d79/UWPSpyLauncher/res/UWPSpyLauncher.ico -------------------------------------------------------------------------------- /UWPSpyLauncher/res/manifest.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | UWPSpy 10 | 11 | 12 | 20 | 21 | 22 | 23 | 24 | true 25 | PerMonitorV2 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 51 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /UWPSpyLauncher/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by UWPSpyLauncher.rc 4 | // 5 | #define IDR_MAINFRAME 128 6 | #define IDD_MAINDLG 129 7 | #define IDC_PROCESS_LIST 1000 8 | #define IDC_STATIC_FRAMEWORK 1001 9 | #define IDC_RADIO_UWP 1002 10 | #define IDC_RADIO_WINUI 1003 11 | #define IDC_REFRESH_BUTTON 1004 12 | 13 | // Next default values for new objects 14 | // 15 | #ifdef APSTUDIO_INVOKED 16 | #ifndef APSTUDIO_READONLY_SYMBOLS 17 | #define _APS_NEXT_RESOURCE_VALUE 200 18 | #define _APS_NEXT_COMMAND_VALUE 32775 19 | #define _APS_NEXT_CONTROL_VALUE 1005 20 | #define _APS_NEXT_SYMED_VALUE 100 21 | #endif 22 | #endif 23 | -------------------------------------------------------------------------------- /UWPSpyLauncher/stdafx.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | -------------------------------------------------------------------------------- /UWPSpyLauncher/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "targetver.h" 4 | 5 | // WTL 6 | 7 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 8 | #define NOMINMAX 9 | #define _WTL_NO_CSTRING 10 | #define _WTL_NO_WTYPES 11 | #define _WTL_NO_UNION_CLASSES 12 | #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | extern CAppModule _Module; 22 | 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | // Windows 32 | 33 | #include 34 | #include 35 | #include 36 | -------------------------------------------------------------------------------- /UWPSpyLauncher/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // // Including SDKDDKVer.h defines the highest available Windows platform. 4 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 5 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 6 | #include 7 | -------------------------------------------------------------------------------- /common/version.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // clang-format off 4 | 5 | // Version 6 | #define VERSION_MAJOR 1 7 | #define VERSION_MINOR 4 8 | #define VERSION_REVISION 0 9 | #define VERSION_BUILD 0 10 | 11 | // etc. 12 | #define STRINGIZE2(s) #s 13 | #define STRINGIZE(s) STRINGIZE2(s) 14 | #define W2(x) L ## x 15 | #define W(x) W2(x) 16 | #define N(x) x 17 | #define LONG_ID(a,b,c,d) (((a)<<24) | ((b)<<16) | ((c)<<8) | (d)) 18 | 19 | #define VER_FILE_VERSION VERSION_MAJOR,VERSION_MINOR,VERSION_REVISION,VERSION_BUILD 20 | 21 | #if VERSION_BUILD == 0 22 | #if VERSION_REVISION == 0 // a.b 23 | #define VER_FILE_VERSION_TSTR(t) t(STRINGIZE(VERSION_MAJOR)) t(".") \ 24 | t(STRINGIZE(VERSION_MINOR)) 25 | #else // a.b.c 26 | #define VER_FILE_VERSION_TSTR(t) t(STRINGIZE(VERSION_MAJOR)) t(".") \ 27 | t(STRINGIZE(VERSION_MINOR)) t(".") \ 28 | t(STRINGIZE(VERSION_REVISION)) 29 | #endif // VERSION_REVISION == 0 30 | #else // a.b.c.d 31 | #define VER_FILE_VERSION_TSTR(t) t(STRINGIZE(VERSION_MAJOR)) t(".") \ 32 | t(STRINGIZE(VERSION_MINOR)) t(".") \ 33 | t(STRINGIZE(VERSION_REVISION)) t(".") \ 34 | t(STRINGIZE(VERSION_BUILD)) 35 | #endif // VERSION_BUILD == 0 36 | 37 | #define VER_FILE_VERSION_STR VER_FILE_VERSION_TSTR(N) 38 | #define VER_FILE_VERSION_WSTR VER_FILE_VERSION_TSTR(W) 39 | 40 | #define VER_FILE_VERSION_LONG LONG_ID(VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION, VERSION_BUILD) 41 | -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m417z/UWPSpy/887e27500670adcd0cad5d0b9179515164224d79/icon.png -------------------------------------------------------------------------------- /screenshot-video.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m417z/UWPSpy/887e27500670adcd0cad5d0b9179515164224d79/screenshot-video.png -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m417z/UWPSpy/887e27500670adcd0cad5d0b9179515164224d79/screenshot.png --------------------------------------------------------------------------------