{"id":2418,"date":"2018-12-07T16:32:31","date_gmt":"2018-12-07T08:32:31","guid":{"rendered":"https:\/\/www.aoisnow.net\/blog\/?p=2418"},"modified":"2018-12-07T16:32:31","modified_gmt":"2018-12-07T08:32:31","slug":"tont-40663-%e5%a5%bd%e7%9a%84%e5%85%88%e7%94%9f%ef%bc%8c%e6%b2%a1%e9%97%ae%e9%a2%98%e5%85%88%e7%94%9f","status":"publish","type":"post","link":"https:\/\/www.aoisnow.net\/blog\/archives\/2418","title":{"rendered":"TONT 40663 \u597d\u7684\u5148\u751f\uff0c\u6ca1\u95ee\u9898\u5148\u751f"},"content":{"rendered":"<p>\u5305\u6cbb\u767e\u75c5\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u539f\u6587\u94fe\u63a5\uff1a<a href=\"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20040211-00\/?p=40663\" target=\"_blank\" rel=\"noopener\">https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20040211-00\/?p=40663<\/a><\/p>\n<p>The DirectX video driver interface for Windows 95 had a method that each driver exposed called something like &#8220;DoesDriverSupport(REFGUID guidCapability)&#8221; where we handed it a capability GUID and it said whether or not that feature was supported.<\/p>\n<p>Windows 95\u7684DirectX\u89c6\u9891\u9a71\u52a8\u63a5\u53e3\u4e2d\uff0c\u6bcf\u4e2a\u9a71\u52a8\u90fd\u516c\u5f00\u4e00\u4e2a\u65b9\u6cd5\uff0c\u540d\u5b57\u7c7b\u4f3c\u4e8eDoesDriverSupport(REFGUID guidCapability)\uff08\u9a71\u52a8\u662f\u5426\u652f\u6301\u67d0\u7279\u6027\uff08REFGUID \u76f8\u5173\u7279\u6027GUID\uff09\uff09\uff0c\u4f7f\u7528\u65f6\u4f1a\u4f20\u5165\u4e00\u4e2a\u7279\u6027GUID\uff0c\u800c\u5176\u4f1a\u8fd4\u56de\u8be5\u9a71\u52a8\u5bf9\u6b64\u7279\u6027\u7684\u652f\u6301\u4e0e\u5426\u60c5\u51b5\u3002<\/p>\n<p>There were various capability GUIDs defined, things like GUID_CanStretchAlpha to ask the driver whether it was capable of stretching a bitmap with an alpha channel.<\/p>\n<p>\u7cfb\u7edf\u6709\u4e00\u7cfb\u5217\u9884\u5b9a\u4e49\u7684\u7279\u6027GUID\uff0c\u4f8b\u5982GUID_CanStretchAlpha\u7528\u6765\u8be2\u95ee\u9a71\u52a8\u7a0b\u5e8f\u5176\u662f\u5426\u53ef\u4ee5\u62c9\u4f38\u5e26\u6709Alpha\u901a\u9053\u7684\u4f4d\u56fe\u56fe\u50cf\u3002<\/p>\n<p>There was one driver that returned TRUE when you called DoesDriverSupport(GUID_XYZ), but when DirectDraw tried to use that capability, it failed, and in a pretty spectacular manner.<\/p>\n<p>\u67d0\u4e2a\u9a71\u52a8\u5f53\u8c03\u7528DoesDriverSupport(GUID_XYZ)\u65f6\u8fd4\u56de\u4e86True\uff0c\u4f46\u7b49\u5230DirectDraw\u771f\u7684\u53bb\u8c03\u7528\u8fd9\u4e2a\u7279\u6027\u65f6\uff0c\u5374\u4f1a\u906d\u9047\u5931\u8d25\uff0c\u800c\u4e14\u5931\u8d25\u5f97\u60ca\u5929\u52a8\u5730\u3002<\/p>\n<p>So one of the DirectDraw developers called the vendor and asked them, &#8220;So does your card do XYZ?&#8221;<\/p>\n<p>\u540e\u6765DirectDraw\u5f00\u53d1\u7ec4\u7684\u4e00\u4f4d\u540c\u4e8b\u5411\u786c\u4ef6\u7684\u4f9b\u5e94\u5546\u54a8\u8be2\uff0c\u95ee\u9053\uff1a\u300e\u4f60\u4eec\u7684\u529e\u5361\u652f\u6301XYZ\u5417\uff1f\u300f<\/p>\n<p>Their response: &#8220;What&#8217;s XYZ?&#8221;<\/p>\n<p>\u5bf9\u65b9\u7684\u56de\u7b54\u662f\uff1a\u300eXYZ\u662f\u5565\u73a9\u610f\u513f\uff1f\u300f<\/p>\n<p>Turns out that their driver&#8217;s implementation of DoesDriverSupport was something like this:<\/p>\n<p>\u540e\u6765\u6211\u4eec\u624d\u77e5\u9053\uff0c\u4ed6\u4eec\u7684\u9a71\u52a8\u91cc\u5bf9DoesDriverSupport\u7684\u5b9e\u73b0\u5927\u4f53\u662f\u8fd9\u4e2a\u6837\u5b50\u7684\uff1a<\/p>\n<blockquote><p>BOOL DoesDriverSupport(REFGUID guidCapability)<br \/>\n{<br \/>\nreturn TRUE;<br \/>\n}<\/p><\/blockquote>\n<p>In other words, whenever DirectX asked, &#8220;Can you do this?&#8221; they answered, &#8220;Sure, we do that,&#8221; without even checking what the question was.<\/p>\n<p>\u6362\u53e5\u8bdd\u8bf4\uff0c\u6bcf\u5f53DirectX\u63d0\u95ee\u300e\u4f60\u652f\u6301\u8fd9\u4e2a\u7279\u6027\u4e0d\uff1f\u300f\u7684\u65f6\u5019\uff0c\u9a71\u52a8\u603b\u662f\u4f1a\u56de\u62a5\uff1a\u300e\u597d\u7684\u5148\u751f\uff0c\u6ca1\u95ee\u9898\u5148\u751f\u300f\uff0c\u5b9e\u9645\u4e0a\u5374\u6839\u672c\u4e0d\u5728\u4e4e\u95ee\u9898\u7684\u5185\u5bb9\u3002<\/p>\n<p>(The driver must have been written by the sales department.)<\/p>\n<p>\uff08\u8fd9\u9a71\u52a8\u80af\u5b9a\u662f\u4ed6\u4eec\u7684\u9500\u552e\u90e8\u95e8\u5199\u7684\u3002\uff09<\/p>\n<p>So the DirectDraw folks changed the way they queried for driver capabilities. One of the developers went into his boss&#8217;s office, took a network card, extracted the MAC address, and then smashed the card with a hammer.<\/p>\n<p>\u56e0\u6b64DirectDraw\u7684\u5f00\u53d1\u7ec4\u6539\u53d8\u4e86\u68c0\u6d4b\u9a71\u52a8\u652f\u6301\u7279\u6027\u7684\u65b9\u5f0f\u3002\u5f00\u53d1\u7ec4\u7684\u4e00\u4f4d\u540c\u4e8b\u8d70\u8fdb\u4ed6\u4eec\u7ecf\u7406\u7684\u529e\u516c\u5ba4\uff0c\u62ff\u51fa\u4e00\u5f20\u7f51\u5361\uff0c\u6284\u4e0b\u4e86\u5b83\u7684MAC\u5730\u5740\uff0c\u7136\u540e\u628a\u7f51\u5361\u7528\u9524\u5b50\u7838\u788e\u4e86\u3002<\/p>\n<p>You see, this last step was important: The GUID generation algorithm is based on a combination of time and space. When you ask CoCreateGuid to create a new GUID, it encodes the time of your request in the first part of the GUID and information that uniquely identifies your machine (the network card&#8217;s MAC address, which is required to be unique by the standards that apply to network card).<\/p>\n<p>\u8981\u77e5\u9053\uff0c\u6700\u540e\u4e00\u6b65\u662f\u5f88\u91cd\u8981\u7684\uff1aGUID\u7684\u751f\u6210\u7b97\u6cd5\u57fa\u4e8e\u65f6\u95f4\u548c\u7a7a\u95f4\u7684\u7ec4\u5408\u3002\u5f53\u4f60\u8c03\u7528CoCreateGuid\u6765\u521b\u5efa\u4e00\u4e2a\u65b0\u7684GUID\u65f6\uff0c\u51fd\u6570\u4f1a\u5c06\u4f60\u8c03\u7528\u5b83\u7684\u65f6\u95f4\u7f16\u7801\u8fdbGUID\u7684\u7b2c\u4e00\u90e8\u5206\u4e2d\uff0c\u540c\u65f6\u88ab\u7f16\u7801\u8fdb\u53bb\u7684\u8fd8\u6709\u53ef\u4ee5\u552f\u4e00\u6307\u8ba4\u4f60\u7684\u673a\u5668\u7684\u4fe1\u606f\uff08\u5373\u672c\u673a\u7f51\u5361\u7684MAC\u5730\u5740\uff0c\u8fd9\u4e2a\u5730\u5740\u57fa\u4e8e\u7f51\u5361\u7684\u5236\u9020\u6807\u51c6\uff0c\u5fc5\u987b\u662f\uff08\u5168\u7403\uff09\u552f\u4e00\u7684\u503c\uff09\u3002<\/p>\n<p>By smashing the network card with a hammer, he prevented that network card from ever being used to generate a GUID.<\/p>\n<p>\u901a\u8fc7\u628a\u90a3\u5757\u7f51\u5361\u7528\u9524\u5b50\u7838\u788e\uff0c\u90a3\u5757\u7f51\u5361\uff08\u7684MAC\u5730\u5740\uff09\u5c31\u518d\u4e5f\u4e0d\u80fd\u88ab\u7528\u6765\u751f\u6210GUID\u4e86\u3002<\/p>\n<p>Next, he added code to DirectDraw so that when it starts up, it manufactures a random GUID based on that network card (which &#8211; by its having been destroyed &#8211; can never be validly created) and passes it to DoesDriverSupport. If the driver says, &#8220;Sure, we do that&#8221;, DirectDraw says, &#8220;Aha! Caught you! I will not believe anything you say from now on.&#8221;<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u4ed6\u5728DirectDraw\u4e2d\u589e\u52a0\u4e86\u76f8\u5e94\u7684\u4ee3\u7801\uff0c\u8fd9\u6837\u5728\u5176\u521d\u59cb\u5316\u65f6\uff0cDirectDraw\u5c31\u4f1a\u57fa\u4e8e\u90a3\u5757\uff08\u88ab\u7838\u788e\u7684\uff09\u7f51\u5361\uff08\u7684MAC\u5730\u5740\uff09\u751f\u6210\u4e00\u4e2a\u968f\u673a\u7684GUID\uff08\u9274\u4e8e\u90a3\u5757\u7f51\u5361\u5df2\u7ecf\u88ab\u9500\u6bc1\uff0c\u57fa\u4e8e\u5176\u5730\u5740\u751f\u6210\u7684GUID\u7edf\u7edf\u90fd\u4e0d\u53ef\u80fd\u662f\u6709\u6548\u7684\uff09\uff0c\u7136\u540e\u628a\u8fd9\u4e2aGUID\u4f20\u5165DoesDriverSupport\u91cc\u3002\u5982\u679c\u9a71\u52a8\u56de\u62a5\uff1a\u300e\u597d\u7684\u5148\u751f\uff0c\u6ca1\u95ee\u9898\u5148\u751f\u300f\uff0cDirectDraw\u7acb\u523b\u5c31\u77e5\u9053\uff1a\u300e\u563f\uff0c\u6293\u5230\u4f60\u5566\uff01\u4ece\u73b0\u5728\u5f00\u59cb\u4f60\u8bf4\u4ec0\u4e48\u4e1c\u897f\u6211\u4e5f\u4e0d\u4f1a\u518d\u76f8\u4fe1\u4e86\u3002\u300f<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5305\u6cbb\u767e\u75c5\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-2418","post","type-post","status-publish","format-standard","hentry","category-tont_history"],"_links":{"self":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/posts\/2418","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/comments?post=2418"}],"version-history":[{"count":0,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/posts\/2418\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/media?parent=2418"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/categories?post=2418"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/tags?post=2418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}