
{"id":2394,"date":"2017-05-13T01:49:29","date_gmt":"2017-05-13T05:49:29","guid":{"rendered":"http:\/\/www.ikriv.com\/blog\/?p=2394"},"modified":"2017-05-13T01:49:29","modified_gmt":"2017-05-13T05:49:29","slug":"does-that-source-match-the-binary-part-1","status":"publish","type":"post","link":"https:\/\/ikriv.com\/blog\/?p=2394","title":{"rendered":"Does that source match the binary? Part 1"},"content":{"rendered":"<p>A couple of weeks ago I ran into a problem: I had a DLL file, but I was not certain which version of the source code it was compiled from (yes, our release management could use some improvement).<\/p>\n<p>Visual Studio debugger immediately knows if I try to give it a version of a source file that does not match the compiled binary, and shows a warning. But how does it know it?<\/p>\n<p>The information about source files is stored in the PDB file (which must also\u00a0exactly match the binary). PDB file format is not fully documented, but Microsoft provides at least two libraries to read it:\u00a0DIA SDK, that is shipped as part of Visual Studio,and\u00a0<a style=\"font-size: 20px;\" href=\"http:\/\/stackoverflow.com\/questions\/36649271\/check-that-pdb-file-matches-to-the-source\">DiaSymReader<\/a><span style=\"font-size: 20px;\">\u00a0interfaces that are shipped with .NET Framework. Despite being part of .NET framework, DiaSymReader interfaces are native COM interfaces, but Microsoft provides a managed wrapper as a NuGet package.\u00a0<\/span><\/p>\n<p>Astonishingly, for the same PDB file these two libraries produce similar, but slightly different results. It turns out that PDB file may have two kinds of debug information, which I will call &#8220;managed&#8221; and &#8220;unmanaged&#8221;. DIA SDK accesses the &#8220;unmanaged&#8221; part. DiaSymReader accesses the &#8220;managed&#8221; part.<\/p>\n<p>Here&#8217;s the summary of my findings so far:<\/p>\n<p><strong>Native C++ programs:<br \/>\n<\/strong><em>DIA SDK<\/em>: returns list of source files with MD5 checksums.<br \/>\n<em>DiaSymReader<\/em>: does not work with unmanaged programs and returns an error.<\/p>\n<p><strong>Managed programs (C#, VB.NET):<br \/>\n<\/strong><em>DIA SDK<\/em><strong>: <\/strong>returns list of source files, but without checksums.<br \/>\n<em>DiaSymReader<\/em>: returns list of source files with SHA1 checksums (MD5 for Visual Studio 2013 and earlier).<br \/>\n<strong><br \/>\nManaged C++ programs:<br \/>\n<\/strong><em>DIA SDK<\/em>: returns list of source files with MD5 checkums.<br \/>\n<em>DiaSymReader<\/em>: returns list of source files with SHA1 checksums\u00a0(MD5 for Visual Studio 2013 and earlier).<\/p>\n<p>Thus, managed C++ programs compiled by VS2015 contain both SHA1 and MD5 checksums of their source files in the PDB. On top of that Microsoft also has something called &#8220;Portable PDB format&#8221;, but I am not sure about the details yet.<\/p>\n<p>Some other differences: DIA SDK interfaces can open a PDB file directly, or start with a binary and look for \u00a0a matching PDB in a given search path. DiaSymReader only supports the second mode: you cannot open a stand-alone PDB file without the binary.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A couple of weeks ago I ran into a problem: I had a DLL file, but I was not certain which version of the source code it was compiled from <a href=\"https:\/\/ikriv.com\/blog\/?p=2394\" class=\"more-link\">[&hellip;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"Layout":"","footnotes":""},"categories":[1],"tags":[],"class_list":["entry","author-ikriv","post-2394","post","type-post","status-publish","format-standard","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2394","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2394"}],"version-history":[{"count":1,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2394\/revisions"}],"predecessor-version":[{"id":2395,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2394\/revisions\/2395"}],"wp:attachment":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2394"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}