此文章由原博客迁移而来。

原文地址:https://blog.betaworld.cn/380

原作者:BetaRookie

以下为本文正文部分。

380-1-WinHEC-Aero-Demo.png

我想你们之前都测试过 Longhorn build 4074 和它的 DWM…如果没有,那么这是一个很好的机会让你们了解美丽的 Aero 主题。我将通过不在这里记录整个 Longhorn 主题格式来保持这篇文章的简短。

你可能在网上看到过关于如何将 Jade 主题转换为 Aero 的各种文章,但这篇文章有所不同。

如果您以前看过 PDC 2003 演示的视频,那么我相信您已经注意到 DWM 在用户登录时自动打开… 但是怎么做呢?仅仅将 jade.msstyles 重命名为 aero.msstyles 并不能解决问题。在对主题格式和一些主题相关代码进行反向工程之后,我发现主题文件实际上可以用于自动启用 DWM。在 Jade 主题的 globals 部分下,有一个叫做 UsesCompositionBOOL,它恰好是 FALSE。如果 UsesComposition 设置为 TRUE,则无论何时应用主题,它都会通知主题管理器打开 DWM。由于主题是在启动期间应用的,因此对于 UsesComposition 设置为 TRUE 的主题,DWM 将自动启用。

私有 Aero 主题的另一个功能是 Animated Preview Pane Aurora(APPA)。它使用在 Aero 主题的 PreviewPane.Aurora 部分下定义的 BAML 文件进行显示。它实际上在 Jade 主题中,但 BAML 文件的格式较旧。我们只需将其替换为最新格式的 BAML 文件,然后 APPA 将正确的显示。

jade.msstyles 重命名到 aero.msstyles 的技巧接下来您将看到的显然是绿色的 DWM 窗口框架。有两个 Aero 主题,一个公共主题叫 Jade,一个私有主题叫 Glass。差别是显而易见的,虽然两种宝石(如果你认为玻璃是宝石)都是半透明的,Jade(翡翠)是绿色的而 Glass(玻璃)是清亮的。不用说,重命名一个文件不会让你得到 Glass 的资源。我们知道私有 Aero 主题拥有玻璃般外观的资源,但遗憾的是,它们目前没有被泄露。幸运的是,我们拥有 Longhorn build 5048 的 Aero Glass 资源,可以对其进行 Photoshop 处理,以匹配私有 pre-reset Aero 主题。一旦我们将这些 Jade 资源替换为 Glass 资源,我们将看到窗框被截断:

380-4-Explorer-Frame-Bad.png

380-5-Window-Frame-Bad.png

为什么?由于 .msstyles 文件中每个 STREAM 资源的大小在这些 VARIANT 资源中是硬编码的,并且由于 Jade 资源通常比 Glass 资源小,因此加载程序将只加载和显示这些 Glass 资源的一部分。这就是为什么在安装自制 Aero 主题时,会看到几乎完全透明的窗框。一旦我们将这些硬编码的大小更改为 Glass 资源的大小,所有窗框和其他资源将正常显示,如下面的屏幕截图所示:

380-6-Explorer-Frame-Good.png

380-7-Window-Frame-Good.png

在改变了 UsesComposition、用 Glass 资源取代 Jade 资源并改变了硬编码的大小之后,我们现在有了一个非常接近微软的私有 Aero 主题的主题。尽管微软对 Aero 主题严加保密,他们仍然担心可能的泄露(尽管他们采取了保护措施,该主题仍然泄露给了微软以外的人),因此他们想出了一个方法来禁止微软以外的人使用该主题。他们添加了一个叫做 DemoCheck 的东西,用于检查 Microsoft 网络共享上的某一个文件是否存在。概念很简单-如果找到该文件,则此人是在 Microsoft 工作的员工,因为他们可以访问 Microsoft 的网络共享,否则此人不是来自 Microsoft 的人员,不应被允许使用 Aero 主题。该文件的路径是主题 documentation 部分下名为 DemoCheck 的字符串。如果您试图在没有连接 Microsoft 网络共享的情况下应用私有 Aero 主题,您将看到以下错误:

380-8-DemoCheck-Error.png

为了使我们重建的 Aero 主题尽可能接近微软的私有 Aero 主题,我们需要在主题 documentation 中添加 DemoCheck 字符串。那么我们有一个问题,我们将如何使用这个主题呢?微软留下了一个叫 DemoCheckOverride 的后门,以为没人会发现。您只需浏览到 HKLM\Software\Microsoft\Windows\CurrentVersion\ThemeManager,创建一个名为 DemoCheckOverride 的 Registry DWORD,并将其值设置为 0xFADE(或十进制 64222)。

现在,我们有了一个完全重建的 Aero 主题,但仍然缺少一些其他 Aero 功能,即 Aero Clock Sidebar 板块、Aero/Jade Preview Pane 渐变、Aero Shell 文件夹图标。这些特性的资源在 WinHEC 版本中都是可用的(实际上是从 4066 开始的所有版本),但是加载它们的代码被删除了。幸运的是,可以对 Microsoft.Windows.WCPClient.dll 进行修补,以加载这些 Aero 资源,就像私有演示版本中的资源一样。

380-9-Slate-Sidebar-Clock.png

380-10-Aero-Sidebar-Clock.png

380-11-Slate-Icon-and-Gradient.png

380-12-Aero-Icon-and-Gradient.png

桌面极光更难修复,因为它是使用过时的 XAML 编译的,其中包含运行时错误,Microsoft 故意对其进行了扭曲。可以通过将 Microsoft.Windows.WCPClient.dll 中的 BAML 替换为正常工作的 BAML 来修复此问题,但不幸的是,Microsoft 没有编写用于呈现该 BAML 的代码,或者完全删除了该代码。我已经编写了一个应用程序,它可以在桌面背景上呈现桌面极光效果,就像 Aero Stars 的呈现一样,下面是它的一个快速演示:

下载
相对于在这里那里提供单独的文件,我为 WinHEC 版本(4074)制作了一个“功能包”或“演示包”。它被称为 RealAero,将定期更新。您可以下载以下最新版本:

380-14-demo_files_4074x86fre_v0.20.zip

请确保浏览到 HKLM\Software\Microsoft\Windows\CurrentVersion\ThemeManager,创建一个名为 DemoCheckOverride 的 Registry DWORD,并将其值设置为 0xFADE(或十进制 64222)。如果您没有,那么当您收到拒绝访问错误时,请不要向我哭诉。

对于桌面极光,您需要下载此程序并双击以启动它。只有安装了上述软件包,它才能工作。

380-15-DesktopAurora4074.zip

不用说,RealAero 不仅是为版本 4074 而制作的,其他版本最终也将得到支持。我目前正致力于将 Aero 主题引入 M6 版本,如 4039。以下是一些图片

380-16-4039-Aero-Theme.png

380-17-4039-Aero-Glass.png

380-18-4039-Aero-Logon.png

下页是英文原文 :

380-1-WinHEC-Aero-Demo.png

I guess you’ve all tested Longhorn build 4074 and its DWM before… if not, then this is a good opportunity for you to learn about the beautiful Aero theme. I’ll keep this post short by not documenting the entire Longhorn theme format here.

You may have seen various articles online about how to turn the Jade theme into Aero, but this one is different.

If you watched the video of that PDC 2003 demo before, then I am sure you’ve noticed that DWM was automatically turned on upon user logon… but how? It is not something you get by simply renaming jade.msstyles to aero.msstyles. After reverse engineering the theme format and some theme-related code, I figured out that theme files can actually be used to automatically enable DWM. Under the globals section of the Jade theme, there is a BOOL called UsesComposition, which happens to be FALSE. If UsesComposition is set to TRUE, then it’ll signal the theme manager to turn DWM on whenever the theme is applied. Since themes are applied during startup, DWM will be automatically enabled for themes with UsesComposition set to TRUE.

Another feature of the private Aero theme is the Animated Preview Pane Aurora (APPA). It is rendered using a BAML file defined under the PreviewPane.Aurora section of the Aero theme. It is actually in the Jade theme, but the BAML file is in an older format. We simply need to replace it with a BAML file in the newest format and then APPA will render correctly.

What you’ll see next with the jade.msstyles to aero.msstyles trick is obviously the green DWM window frame. There were two Aero themes, a public one called Jade and a private one called Glass. The difference is obvious, while both gemstones (if you consider glass as one) are translucent, jade is green and glass is clear. Needless to say, renaming a file isn’t going to get you Glass resources. We know that the private Aero theme had glassy-looking resources, but sadly they are currently unleaked. Luckily we do have Longhorn build 5048’s Aero Glass resources, which can be photoshopped to match those from the private pre-reset Aero theme. Once we replace those Jade resources with Glass ones, we will see the window frames being truncated:

380-4-Explorer-Frame-Bad.png

380-5-Window-Frame-Bad.png

Why? Because the size of each STREAM resource in the .msstyles file is hard coded in those VARIANT resources, and since Jade resources are generally smaller than Glass resources, the loader will only load and render the first portion of those Glass resources. This is why when you install a custom Aero theme, you’ll see almost entirely transparent window frames. Once we change those hard coded sizes to the sizes of our Glass resources, all window frames and other resources will render fine just like in the screenshots below:

380-6-Explorer-Frame-Good.png

380-7-Window-Frame-Good.png

After changing UsesComposition, replacing Jade resources with Glass ones and changing those hard coded sizes, we now have a theme that is very close to Microsoft’s private Aero theme. Although Microsoft kept the Aero theme super secret, they still feared possible leakages (despite what they did to protect it, the theme still leaked to people outside of Microsoft), so they came up with a way of disallowing people outside of Microsoft to use the theme. They implemented something called the DemoCheck that checks for the presence of a file on Microsoft’s network share. The concept is simple – if the file is found, then the person is someone working at Microsoft since they can access Microsoft’s network shares, else the person isn’t someone from Microsoft and shouldn’t be allowed to use the Aero theme. The path of that file is a string called DemoCheck under the theme documentation section. This is the error you will see if you attempt to apply the private Aero theme without access to Microsoft’s network share:

380-8-DemoCheck-Error.png

To make our reconstruction of the Aero theme as close to Microsoft’s private Aero theme as possible, we need to add the DemoCheck string to the theme documentation. Then we have a problem, how are we going to use the theme then? Well, they left a backdoor called DemoCheckOverride thinking that nobody would ever find out. All you have to do is browse to HKLM\Software\Microsoft\Windows\CurrentVersion\ThemeManager, create a Registry DWORD called DemoCheckOverride and set its value to 0xFADE (or 64222 in decimal).

Now we have a fully reconstructed Aero theme, but some other Aero features are still missing, namely the Aero Clock Sidebar tile, Aero/Jade Preview Pane gradients and the Aero Shell Folder icons. The resources for those features are all available in the WinHEC build (actually all builds since 4066), but the code for loading them got ifdefed out. Luckily Microsoft.Windows.WCPClient.dll can be patched to load those Aero resources, just like the one from that private demo build.

380-9-Slate-Sidebar-Clock.png

380-10-Aero-Sidebar-Clock.png

380-11-Slate-Icon-and-Gradient.png

380-12-Aero-Icon-and-Gradient.png

Desktop Aurora is a bit harder to fix, because it was compiled using an outdated XAML that contained runtime errors and Microsoft intentionally distorted it. It can be fixed by replacing the BAML inside Microsoft.Windows.WCPClient.dll with a working one, but unfortunately Microsoft either didn’t implement code for rendering it or they removed the code completely. I’ve written an app that renders the Desktop Aurora effects on top of the desktop background just like how Aero Stars are rendered, and here is a quick demo of it:

Download
Instead of providing a file here and there, I made a ‘feature pack’ or a ‘demo pack’ for the WinHEC build (4074). It is called RealAero and will be updated on a regular basis. You may download the latest version below:

380-14-demo_files_4074x86fre_v0.20.zip

Please make sure you browse to HKLM\Software\Microsoft\Windows\CurrentVersion\ThemeManager, create a Registry DWORD called DemoCheckOverride and set its value to 0xFADE (or 64222 in decimal). If you don’t then don’t come crying to me when you get the access denied error.

For Desktop Aurora, you need to download this program and double click to start it. It will work only if you have the above pack installed.

380-15-DesktopAurora4074.zip

Needless to say, RealAero isn’t only for build 4074, other builds will be supported eventually. I am currently working on brining the Aero theme to M6 builds such as build 4039. Here are some pictures:

380-16-4039-Aero-Theme.png

380-17-4039-Aero-Glass.png

380-18-4039-Aero-Logon.png

标签: Longhorn, Aero, DWM, Aurora