{"id":5243,"date":"2013-02-14T07:00:00","date_gmt":"2013-02-14T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2013\/02\/14\/if-you-cant-find-the-function-find-the-caller-and-see-what-the-caller-jumps-to\/"},"modified":"2013-02-14T07:00:00","modified_gmt":"2013-02-14T07:00:00","slug":"if-you-cant-find-the-function-find-the-caller-and-see-what-the-caller-jumps-to","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20130214-00\/?p=5243","title":{"rendered":"If you can&#8217;t find the function, find the caller and see what the caller jumps to"},"content":{"rendered":"<p><P>\nYou&#8217;re debugging a program and\nyou want to set a breakpoint on some function,\nsay,\n<CODE>netapi32!Ds&shy;Address&shy;To&shy;Site&shy;NameW<\/CODE>,\nbut when you execute the\n<CODE>bp netapi32!Ds&shy;Address&shy;To&shy;Site&shy;NameW<\/CODE> command in the debugger,\nthe debugger says that there is no such function.\n<\/P>\n<BLOCKQUOTE CLASS=\"q\">\nThe\n<A HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2007\/12\/18\/6794821.aspx\">\n<I>Advanced Windows Debugging<\/I> book<\/A>\nsays that the <CODE>bp<\/CODE> command should set a breakpoint\non the function,\nbut the debugger says that the symbol cannot be found.\nI used the <CODE>x netapi32!*<\/CODE> command to see that\nthe debugger did find a whole bunch of symbols,\nand it says that the symbols were loaded\n(from the\n<A HREF=\"http:\/\/support.microsoft.com\/kb\/311503\">\npublic symbol store<\/A>),\nbut\n<CODE>netapi32!Ds&shy;Address&shy;To&shy;Site&shy;NameW<\/CODE>\nisn&#8217;t among them.\nThe MSDN documentation says that <CODE>Ds&shy;Address&shy;To&shy;Site&shy;NameW<\/CODE> is\nin the <CODE>netapi32.dll<\/CODE>,\nbut it&#8217;s not there!\nI can&#8217;t believe you guys stripped that function out\nof the symbol file,\nsince it&#8217;s a function that people will\nwant to set a breakpoint on.\n<\/BLOCKQUOTE>\n<P>\nOkay, first let&#8217;s\n<A HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2011\/02\/10\/10127054.aspx\">\nrule out the conspiracy theory<\/A>.\nThe symbols were not stripped from the public symbols.\nAnd even if they were,\nthat shouldn&#8217;t stop you, because after all,\nthe <I>loader<\/I> has to be able to find the function\nwhen it loads your program,\nso it&#8217;s gotta be obtainable even without symbols.\n<\/P>\n<P>\nDon&#8217;t be helpless.\nYou already have the tools to figure out where the function is.\n<\/P>\n<P>\nJust write a program that calls the function,\nthen load it into the debugger and see what the\ndestination of the <CODE>call<\/CODE> instruction is.\nYou don&#8217;t even have to pass valid parameters to the\nfunction call,\nsince you&#8217;re never actually executing the code;\nyou&#8217;re just looking at it.\n<\/P>\n<P>\nAnd hey looky-here,\nyou already have a program that calls the function:\nThe program you&#8217;re trying to debug!\nSo let&#8217;s see where it goes.\n<\/P>\n<PRE>\n0:001&gt;u contoso!AwesomeFunction\n&#8230;\n00407352 call [contoso!__imp__DsAddressToSiteNameW (0040f104)]\n&#8230;\n0:001&gt;u poi 0040f104\nlogoncli!DsAddressToSiteNameW:\n7f014710 push ebp\n7f014711 mov esp, ebp\n&#8230;\n<\/PRE>\n<P>\nThere you go.\nThe code for the function is in <CODE>logoncli.dll<\/CODE>.\n<\/P>\n<P>\nWhat happened?\nHow did you end up in <CODE>logoncli.dll<\/CODE>?\n<\/P>\n<P>\nWhat you saw was the effect of a\n<A HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2006\/07\/19\/671238.aspx\">\nDLL forwarder<\/A>.\nThe code for the function\n<CODE>Ds&shy;Address&shy;To&shy;Site&shy;NameW<\/CODE> doesn&#8217;t live in\n<CODE>netapi32.dll<\/CODE>.\nInstead,\n<CODE>netapi32.dll<\/CODE> has an export table entry that says\n&#8220;If anybody comes to me asking for <CODE>Ds&shy;Address&shy;To&shy;Site&shy;NameW<\/CODE>,\nsend them to\n<CODE>logoncli!Ds&shy;Address&shy;To&shy;Site&shy;NameW<\/CODE> instead.&#8221;\n<\/P>\n<P>\nOfficially, the function is in <CODE>netapi32.dll<\/CODE>\nfor linkage purposes,\nbut internally the function has been forwarded to another DLL\nfor implementation.\nIt&#8217;s like a telephone call-forwarding service for DLL functions,\nexcept that instead of forwarding telephone calls,\nit forwards function calls.\nYou publish a phone number in all your marketing materials,\nand behind the scenes, you set up the number to forward\nto the phone of the person responsible for sales.\nThat way,\nif that person quits,\nor the responsibility for selling the product changes,\nyou can just update the call-forwarding table,\nand all the calls get routed to the new person.\n<\/P>\n<P>\nThat&#8217;s what happenned here.\nThe MSDN phone book lists the function as being in\n<CODE>netapi32.dll<\/CODE>,\nand whenever a call comes in,\nit gets forwarded to wherever the implementation happens to be.\nAnd the implementation has moved around over time,\nso you should continue calling\n<CODE>netapi32!Ds&shy;Address&shy;To&shy;Site&shy;NameW<\/CODE>\nand let the call-forwarding do the work of getting you to\nthe implementation.\n<\/P>\n<P>\nDon&#8217;t start calling <CODE>logoncli<\/CODE> directly,\nthinking that you&#8217;re cutting out the middle man,\nor in a future version of Windows,\nyour program may start failing with a\n&#8220;This number is no longer in service&#8221; error,\nlike calling the direct office number for\nthe previous sales representative,\nonly to find that he left the company last month.\n<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>You&#8217;re debugging a program and you want to set a breakpoint on some function, say, netapi32!Ds&shy;Address&shy;To&shy;Site&shy;NameW, but when you execute the bp netapi32!Ds&shy;Address&shy;To&shy;Site&shy;NameW command in the debugger, the debugger says that there is no such function. The Advanced Windows Debugging book says that the bp command should set a breakpoint on the function, but the [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-5243","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>You&#8217;re debugging a program and you want to set a breakpoint on some function, say, netapi32!Ds&shy;Address&shy;To&shy;Site&shy;NameW, but when you execute the bp netapi32!Ds&shy;Address&shy;To&shy;Site&shy;NameW command in the debugger, the debugger says that there is no such function. The Advanced Windows Debugging book says that the bp command should set a breakpoint on the function, but the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/5243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=5243"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/5243\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=5243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=5243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=5243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}