DLLã®é (3)
å®éã«ããã»ã¹ãèµ·åãã¦ãããã¡ã¤ãªã³ã°ãè¡ãæ©è½ã¨ããã®ã¯ï¼éç解æã®èæ
®æ¼ãã«å¯¾ããããæå³ã§ã®åãæã§ãï¼ãããªåãæãç¨æãã¦ããã¦ãã以ä¸ï¼ãã¾ãéç®±ã®é
ãã¤ã¤ãã¦ãä»æ¹ãããã¾ãããï¼ä¸å¿ Dependency Walker ã®éç解æã«ã¤ãã¦ãå°ãè£è¶³ãã¦ããã¾ãããï¼
Dependency Walker ãããã©ã«ãã§èæ
®ããªãè¦ç´ ãããã¤ãããã¾ã*1ï¼ãããã®è¦ç´ ã«ã¤ãã¦ã¯ï¼Dependency Walker ã® Module Search Orders ãæã§ç·¨éãããã¨ã§ï¼ããªãã®å²åãåæ ããããã¨ãåºæ¥ã¾ãï¼
- DLL æ¤ç´¢ã§ã®ã«ã¬ã³ããã£ã¬ã¯ããªã®åå¨ã¨ï¼ãã®åªå é ä½
- .local ã¨ããæ¡å¼µåãæã£ããã¡ã¤ã«ã¾ãã¯ãã£ã¬ã¯ããªã«ãã DLL/COM リダイレクション
ã¾ãï¼æé»ã®ãªã³ã¯ã§ã¯ãªãï¼LoadLibrary ã«ããå®è¡æã®æ示çãªãã¼ããï¼éç解æãä¸å¯è½ã«è¿ãè¦ç´ ã§ãï¼
ãAdvanced Windows 第4ç(asin:4756138055)ã第22ç« ï½¢DLLã®æ³¨å
¥ã¨APIããã¯ãã«ãããããªï¼è¤éãªæ¹æ³ã«ãã DLL ã®æ³¨å
¥ãè¡ããã¦ããã¨ï¼(éçãªè§£æã§ã¯)äºæããªãåé¡ãçºçããå¯è½æ§ãããã¾ãï¼ã¾ã DllMain ä¸ãã LoadLibrary ãå¼ã³åºãã¨ãã£ãï¼æ¨å¥¨ãããªãè¡çºãè¡ã£ã¦ãã¾ã£ã¦ããä¾ããã°ãã°è¦ããã¾ã*2ï¼
以ä¸ã®æä½ã¯ã大é¨åã®ç¶æ³ã§ãDllMain é¢æ°å é¨ã§å®è¡ããã¨å®å ¨ã§ã¯ãªãã¨æ確ã«èªèããã¦ãã¾ãã
- ç´æ¥çã¾ãã¯éæ¥çãªãLoadLibrary é¢æ°ãLoadLibraryEx é¢æ°ãã¾ã㯠FreeLibrary é¢æ°ã®å¼ã³åºãã
- ã¬ã¸ã¹ããªé¢æ°ã®å¼ã³åºãã
- Kernel32.dll å ã«åå¨ããªãã¤ã³ãã¼ããããé¢æ°ã®å¼ã³åºãã
- ä»ã®ã¹ã¬ããã¾ãã¯ããã»ã¹ã¨ã®éä¿¡ã
ãã®ä»ï¼è¿å¹´ã® Windows ã·ã¹ãã DLL ã§å¤ç¨ããã DLL ã®é
延ãã¼ããäºæ
ãè¤éåããã¦ããè¦å ã® 1 ã¤ã§ãããï¼
ãããªã£ã¦ããã¨ï¼æ£ãã DLL ãå¼ã°ãã¦ãããã©ããã«ã¤ãã¦ã®ãã¹ããã¬ã¼ã ã¯ã¼ã¯ã欲ãããªã£ã¦ãã¾ãï¼è¨å®ãç¶æ³ã®ãã¿ã¼ã³ãé常ã«å¤ãæ¯åè³æã調ã¹ãã ãã§ã¯è¿½ãã¤ããªãã®ã¨ï¼ãããã MSDN ã®æ¸ãæ¹ã«ææ§ãªç¹ãåå¨ããã¨ããçç±ããï¼C# ã§ãå°ç¨è¨èªã§ãä½ã§ãããã§ããï¼ã¨ã«ãããã¹ããèªååããªããã¨ã«ã¯å¯¾å¦ã§ããªãè¦æ¨¡ã ã¨æãã¾ãï¼
Joseph M. Newcomer æ°ã¯ï¼è¤éæªå¥ãª LoadLibrary ã®æåããã¹ãããããã«ï¼LoadLibrary Explorer ã¨ãããã¼ã«ãä½æããã¦ãã¾ãï¼
http://www.flounder.com/loadlibrary_explorer.htm
ãã®ãã¼ã«ã使ãã°ï¼è¤æ°ã®ãã£ã¬ã¯ããªã«ã¿ã¼ã²ãã DLL ãé ç½®ãï¼LoadLibrary API ã§ã©ã® DLL ãèªã¿è¾¼ã¾ããããï¼æ§ã ãªè¨å®ã§å®é¨ãããã¨ãå¯è½ã§ãï¼
æ°ã¯ãã®ãã¼ã«ã使ãï¼å®éã«ããã¥ã¡ã³ãã®ä¸å ·åãããã¤ãçºè¦ããã¨æ¸ããã¦ãã¾ãï¼
Bug summary
Using the LoadLibrary Explorer, I have determined the following bugs appear in the Microsoft documentation:
- Dynamic-Link Library Redirection, the use of the .local file or directory, does not work in Windows XP SP2 or Windows Server 2003.
- SafeDllSearchMode does not work even for load-time dynamic linking
- LOAD_WITH_ALTERED_SEARCH_PATH does not work; if the DLL is not found in the directory with the given path, it does not change the behavior of either implicit or explicit dynamic linking.
ãã ï¼æå ã®ç°å¢ã§è©¦ããéãï¼ãããã®æåã¯ããã¥ã¡ã³ãã®è¨è¿°ã®ææ§ãã«åå ãããããã§ãï¼
- MSDN ã«ã¯ã©ã®æç¹ã§ .local ãã¡ã¤ã«ã¾ãã¯ãã£ã¬ã¯ããªãåå¨ãã¦ããå¿ è¦ãããã®ãè¨è¿°ããªãï¼(LoadLibrary Explorer ã¯ï¼ããã»ã¹èµ·åå¾ã«ãããã®ãã¡ã¤ã«ãä½æãã)
- SafeDllSearchMode ã®è¨å®å¤æ´å¾ï¼ã·ã¹ãã ãåèµ·åããå¿ è¦ãããï¼(LoadLibrary Explorer ã¯ï¼ã¬ã¸ã¹ããªå¤ãå¤æ´ããç´å¾ã«åä½ãæ¤è¨¼ãã¦ãã)
- LoadLibraryEx ã®è§£èª¬ã«ããï¼ä»¥ä¸ã® 2 ã¤ã®ã«ã¼ã«ã®åªå
é ä½ãä¸éæï¼
- 絶対ãã¹ã§æ¸¡ããããã¡ã¤ã«ãåå¨ããªãã£ãå ´å â å¼åºãã¯å¤±æãã
- LOAD_WITH_ALTERED_SEARCH_PATH ãæå®ãããã¨ãï¼æåã®æ¤ç´¢ãã£ã¬ã¯ããªã«ãã¡ã¤ã«ãåå¨ããªãã£ãå ´å â 次ã®æ¤ç´¢ãã£ã¬ã¯ããªãæ¢ã
ä»ã«ã MSDN ã®è¨è¿°ã«ã¯æ°ã«ãªãã¨ããããã£ã¦ï¼å ã»ã©å®é¨ãã¦ããã¨ããï¼ãããªè¨è¿°ã§éåã¨æ··ä¹±ãã¦ãã¾ãã¾ããï¼
Known DLLs cannot be redirected. For a list of known DLLs, see the following registry key:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\KnownDLLs. The system uses Windows File Protection to ensure that system DLLs such as these are not updated or deleted except by operating system (OS) updates such as service packs.
- Windows 2000:
- Known DLLs can be redirected in this OS.
If the application has a manifest, then any .local files are ignored.
- Windows 2000:
- Manifests do not affect DLL redirection.
ç§ã¯æåï¼ãKnown DLLs ã«å«ã¾ãã DLL ã¯ï¼.local ã«ãããªãã¤ã¬ã¯ãããé¤å¤ããããã¨æã£ã¦ããã®ã§ããï¼Windows XP ã§è©¦ãã¦ã Windows Vista ã§è©¦ãã¦ãï¼ãªãã¤ã¬ã¯ãã¯è¡ããã¦ãã¾ãï¼ãããªãä»æ§å¤æ´ãè¡ããã¦ããã®ã§ãªããã°ï¼ãã®è¨è¿°ã¯ï¼ããªãã¤ã¬ã¯ãã¯åããã©ï¼ãªãã¤ã¬ã¯ãå¯è½ãªããã«ã¯è¨è¨ããã¦ããªãããã¨èªã¾ãããå¾ã¾ããï¼ããã¥ã¡ã³ããããã¢ã«ã´ãªãºã ãããããæ¬ä¼¼ã³ã¼ããæ¸ãã¦ãããæ¹ã楽ã ã£ãããç¥ãã¾ããï¼
*1:.NET ã®ã¢ã»ã³ããªã«ãã¯ã¢ããã«ã¤ãã¦ã Dependency Walker ã§ã¯è§£æãé£ãããã¨æãã¾ãï¼ãã ã .NET ã®ä¸çã®ã¿ã§ããã°ï¼è³æããã£ãããã¦ãã¾ããï¼ããç¨è¦å´ãããã¨ã¯ãªãã§ãããï¼ã¾ãï¼æ··åã¢ã¼ãã¢ã»ã³ããªã®è§£æã§ã¯ Dependency Walker ãå½¹ç«ã¤ã¨äºæ³ããã¾ãï¼
*2:ãAdvanced Windows 第4ç(asin:4756138055)ã22.2 ï½¢ã¬ã¸ã¹ããªã使ã£ãDLLã®æ³¨å ¥ãã§ç´¹ä»ããã¦ããããã«ï¼user32.dll ããã®ã«ã¼ã«ãç ´ã£ã¦ãã¾ã£ã¦ããã¨ããä¾ãããã¾ãï¼user32.dll ã¯ï¼DLL_PROCESS_ATTACH éç¥ãåãåãã¨ï¼ã¬ã¸ã¹ããªã® [google:AppInit_DLLs] ã«æå®ããã DLL ãLoadLibrary ã§å¼ã³åºãã¾ãï¼