DLLã®é (2)
id:NyaRuRu:20060715 ã®ç¶ãï¼
åãã£ããã¨ï¼
Dependency Walker ã¯ç´ æ´ãããï¼
ããã¿ãªããï¼ç®ã®åã®ãã¼ãã¼äººå½¢ã«ã§ã DLL Hell ã説æãã¦ã¿ã¦ãã ããï¼
ãsystem32 ãã£ã¬ã¯ããªã® mfc42.dll ãªã©ãï¼å¤ããã¼ã¸ã§ã³ãæ°ãããã¼ã¸ã§ã³ã®ãã®ã§ç½®ãæãããã¦ãã¾ããã¨ã§ï¼ä»ã¾ã§åãã¦ããã¢ããªã±ã¼ã·ã§ã³ãå®è¡æã¨ã©ã¼ãèµ·ããããã«ãªãç¾è±¡ãã¨ããã®ã§ã¯ã©ããçã¬ããæ°ããã¾ãï¼
Windows ã® DLL ã®ä»çµã¿ï¼ç¹ã« PE ãããã«è¨è¿°ãããããããæé»ã®ãªã³ã¯ãã¯ï¼ãã¼ã¹ãã¡ã¤ã«åããè¨è¿°ããªãããï¼åå空éã®ç«¶åããã¼ãé åºã«ãã£ã¦ã¯ç°¡åã«ç ´ç¶»ãã¦ãã¾ããã¨ãããã¾ãï¼ä¾ãã° "Security.dll" ã¨ããååã® DLL ãå¼ãèµ·ãããæ··ä¹±ã«ã¤ãã¦ï¼The Old New Thing ã§ç´¹ä»ããã¦ãã¾ãï¼
- Don't name your DLL "Security.dll"
- http://blogs.msdn.com/oldnewthing/archive/2004/07/02/171769.aspx
Dependency Walker ã¯ï¼ãã®åå解決ãã·ãã¥ã¬ã¼ããã¦ããã¾ãï¼åã« PE ãã¡ã¤ã«ã®ãããããã³ããã¦ï¼ã©ã® DLL ã«æé»ã«ãªã³ã¯ãã¦ããã調ã¹ãã ããªã dumpbin ã§ååã§ãï¼Dependency Walker ã¯ï¼ããã ãã§ã¯ãªãï¼ãã®ç°å¢ã§ exe ãã¡ã¤ã«ãå®è¡ãããã©ã® DLL ããã¼ãããããã«ã¤ãã¦ï¼ããç¨åº¦ã®æ
å ±ãä¸ãã¦ãããã¨ãããåªãã¦ãã¾ãï¼
ååä½ã£ã SxS ã«ãã ws2_32.dll ã®ç½®ãæããµã³ãã« (id:NyaRuRu:20060711#p1) ãï¼æ¬¡ã®ããã«é
ç½®ãï¼Dependency Walker 2.1.3623 ã« test.exe ãèªã¿è¾¼ã¾ãã¦ã¿ã¾ãï¼ç°å¢ã¯ Windows Vista build 5456 æ¥æ¬èªçã§ãï¼
- d:\test\test.exe
- d:\test\ws2_32.dll
Dependency Walker èµ·åç´å¾ã®ç¶æ ã§ã¯ï¼ã¢ã¸ã¥ã¼ã«ã®ãã¹ã表示ããã¦ãã¾ããï¼
- èµ·åç´å¾ã®ç¶æ
ããã§ï¼F9 ãæ¼ãã¦ãã¹ã表示ããã¾ãï¼
- ãã¹ã表示ãããç¶æ
exe ãã¡ã¤ã«ã¨åããã£ã¬ã¯ããªã«ãã ws2_32.dll ããã¼ãããããã¨ãåããã¾ãï¼
åèã¾ã§ã« Windows 2000 SP4 ã§ã®å®è¡ç»é¢ï¼(ãã ãï¼c:\test ã§ã¯ãªã d:\test ã«é
ç½®ãã¦ãã¾ã)
- ãã¹ã表示ãããç¶æ (Windows 2000 SP4)
Windows 2000 㯠manifest ã使ç¨ãã SxS ã³ã³ãã¼ãã³ãã«å¯¾å¿ãã¦ãã¾ããï¼ããè¦ãã° msvcr80.dll ã®ãã¹ã Vista ç°å¢ã¨ç°ãªã£ã¦ãã¾ãï¼ãã©ã¤ãã¼ã㪠ws2_32.dll ãå¼ã³åºãããã®ã¯ç´ç²ã« DLL ã®æ¤ç´¢é åºã«ãããã®ã¨äºæ³ããã¾ãï¼
ããã確ãããããã« Dependency Walker ã®ã¡ãã¥ã¼ããï¼Options â Configure Module Search Orders ãé¸ãã§ã¿ã¾ãããï¼ã¾ã㯠Vista ç°å¢ã®ãã®ããï¼
- Configure Module Search Orders (Windows Vista build 5456)
test.exe ã® manifest ããã¡ãã¨åæ ããã¦ãã¦ï¼SxS ã³ã³ãã¼ãã³ããæ¤ç´¢é åºã®ä¸ä½ã«æ¥ã¦ãããã¨ãåããã¾ãï¼ã¾ãï¼ws2_32.dll ã KnownDLLs ã¨ãã¦æ±ããã¦ãããã¨*1ã«ã注æãå¿
è¦ã§ãï¼manifest ãã¡ã¤ã«ã§ ws2_32.dll ãæå®ããªãã£ãå ´åï¼ã¢ããªã±ã¼ã·ã§ã³ãã£ã¬ã¯ããªããã KnownDLL ã®æ¹ãæ¤ç´¢é åºã§ä¸ä½ã«ããããï¼ã·ã¹ãã ãã£ã¬ã¯ããªã® ws2_32.dll ããã¼ãããããã¨ã«ãªãã¾ãï¼
次㫠Windows 2000 SP4 ã®å ´åï¼
- Configure Module Search Orders (Windows 2000 SP4)
Windows 2000 㯠manifest ã使ç¨ãã SxS ã³ã³ãã¼ãã³ãã«å¯¾å¿ãã¦ããªãã®ã§ããããæ¤ç´¢é åºããæ¶ãã¦ãã¾ãï¼ä¸æ¹ã§ï¼ws2_32.dll 㯠KnownDLLs ã«å«ã¾ãã¾ããï¼çµæã¨ãã¦ï¼ã¢ããªã±ã¼ã·ã§ã³ãã£ã¬ã¯ããªã® ws2_32.dll ãèªã¿è¾¼ã¾ãããã¨ã«ãªãã¾ã*2ï¼
Dependency Walker ãæ´»ç¨ãããããã°æ¹æ³ãï¼Mozilla ã®éçºè åãè³æã«ç´¹ä»ããã¦ãã¾ãï¼
Dependency Walker (depends.exe) の使用方法
ãã®è³æãèªãã¾ã§ç¥ãã¾ããã§ãããï¼Dependency Walker ã«ã¯ãããã¡ã¤ã«æ©è½ããã£ã¦ï¼ããã»ã¹å®è¡ä¸ã® LoadLibrary ã GetProcAddres ã®å¼åºããããã¯ãï¼ãã®ãã°ããä¾åã°ã©ããåæ§æãããã¨ãã§ããããã§ãï¼ã¾ãï¼ä¸é£ã®ä½æ¥ã¯ CUI ãããããå¦çãããã¨ãã§ããã¨ã®ãã¨ã§ããï¼
ã¨ããããã§ï¼Mozilla ã®éçºè åããã¼ã¸ã«ããããã«ï¼DLL ã®ãã¼ãã§å°ã£ããã¨ãããã°ï¼Dependency Walker ã®ãããã¡ã¤ã«ãã°ãä½æãï¼ãããã¹ãã¨ããã«æãã¦ã¿ãã¨ããæ¹æ³ã¯ï¼ããªãæå¹ããããã¾ããï¼
*1:ãã ãï¼ã¬ã¸ã¹ããªã® KnownDLLs ã®é ç®ã« ws2_32.dll ã¯å«ã¾ãã¦ããªãï¼ãã®æåã¯ï¼http://support.microsoft.com/kb/164501/en-us ã«è¨è¼ããã¦ãããKnownDLL ããæé»ã«ãªã³ã¯ããã DLLãã«ã¤ãã¦ã®è¨è¿°ãåæ ãããã®ã¨èããããï¼ãã ãï¼KnownDLLs ã®æå㯠OS ã«ãã£ã¦å¤åãããã¨ã«ã注æï¼è©³ããã¯ã[http://www.microsoft.com/technet/technetmag/issues/2007/09/WindowsConfidential/default.aspx?loc=jp/:title=]ãåç §ã®ãã¨ï¼
*2:Windows 2000 å½æã¯ï¼ã¢ããªã±ã¼ã·ã§ã³ãã£ã¬ã¯ããªâã«ã¬ã³ããã£ã¬ã¯ããªâã·ã¹ãã ãã£ã¬ã¯ããªã®é ä½ã ã£ããã¨ã«æ³¨æï¼see SafeDllSearchModeï¼id:NyaRuRu:20040931#p2