使用dependency walker定位windows下程序启动失败原因

一、问题
执行一个windows文件启动失败,弹窗内容如下:
使用dependency walker定位windows下程序启动失败原因 - Tsecer - Tsecer的回音岛
 
---------------------------
ShaderCompileWorker.exe - 应用程序错误
---------------------------
应用程序无法正常启动(0xc000007b)。请单击“确定”关闭应用程序。 
---------------------------
确定   
---------------------------
 
二、使用dependency walker看输出
 
从输出上可以看到有些DLL在系统中无法找到一些DLL,搜索网上的资料提示要安装vc_redistributable,安装之后依然无效。
使用dependency walker定位windows下程序启动失败原因 - Tsecer - Tsecer的回音岛
 
Using Dependency Walker

Here I intend to give you an overview of one of the ways you could use Dependency Walker to pinpoint the module that is causing issues. I had to tamper with one of my System Dlls to artificially reproduce the problem so your log files will be different but you'll be generating and reading the logs in a similar way on your computer.

  1. Download Dependency Walker 2.2 x64 from here: Link
  2. Extract depends22_x64.zip to C:DWalker
  3. Open a command window as administrator (Start Menu -> type “cmd” in the search box and right click on cmd.exe and select Run as Administrator)
  4. Enter the following command to switch to the folder we extracted Dependency Walker to: cd C:DWalker
  5. Enter the following command to have the tool generate logs while running Unreal Engine Launcher(Note: I have my Unreal engine installed to the default location, you would replace c:Program FilesUnreal Engine in the command below with your install location):
    depends.exe /c /f:1 /pb /pp:1 /pg:1 /ot:Log.txt "c:Program FilesUnreal EngineLauncherEngineBinariesWin64UnrealEngineLauncher.exe"
  6. This will run Unreal Engine Launcher and you'll see the familiar 0xc000007b error message. Click OK to dismiss it as usual.
  7. You should now have a Log.txt file in the C:DWalker folder. In the next section I'll go over what to look for in this log to pinpoint the problem module.
 
三、看输出日志
 
从输出描述中看,可以看到c:windowssystem32XINPUT1_3.DLL文件的前缀输出中没有[6],说明它不是64bits,所以要把该文件替换为64位。
********************************| Module List |*********************************
*                                                                              *
* Legend: D  Delay Load Module   ?  Missing Module           6  64-bit Module  *
*         *  Dynamic Module      !  Invalid Module                             *
*                                E  Import/Export Mismatch or Load Failure     *
*                                                                              *
********************************************************************************
 
       Module                                                                                                                         File Time Stamp   Link Time Stamp   File Size   Attr.  Link Checksum  Real Checksum  CPU  Subsystem  Symbols     Preferred Base      Actual Base         Virtual Size  Load Order  File Ver            Product Ver       Image Ver    Linker Ver  OS Ver  Subsystem Ver
-----  -----------------------------------------------------------------------------------------------------------------------------  ----------------  ----------------  ----------  -----  -------------  -------------  ---  ---------  ----------  ------------------  ------------------  ------------  ----------  ------------------  ----------------  -----------  ----------  ------  -------------
 
[D 6]  c:windowssystem32WTSAPI32.DLL                                                                                               2009/07/14  9:41  2009/07/14  9:34      54,272  A      0x00016A1E     0x00016A1E     x64  Console    CV          0x000007FF70580000  Unknown             0x00011000    Not Loaded  6.1.7600.16385      6.1.7600.16385    6.1          9.0         6.1     6.1
[   ]  c:windowssystem32XINPUT1_3.DLL                                                                                              2017/07/18 16:31  2007/04/05  9:39      81,768  A      0x0001A809     0x0001A809     x86  GUI        CV          0x--------00400000  0x--------000D0000  0x00016000    67          9.18.944.0          9.18.944.0        5.2          7.10        5.2     4.0
[D 6]  c:windowssystem32XMLLITE.DLL        
 
再使用dependency walker的可视化界面打开依赖,这时候可以注意到XINPUT1_3.DLL加载的系统版本号和其它不同
使用dependency walker定位windows下程序启动失败原因 - Tsecer - Tsecer的回音岛
 
下面的可以看到,5.2属于XP系统的64位版本
Windows Server 2003 R2 5.2
Windows Server 2003 5.2
Windows XP 64-Bit Edition 5.2
 
四、修改
使用WIN7 环境下的XINPUT1_3.DLL替换c:windowssystem32XINPUT1_3.DLL,之后可以正常启动
 
五、总结
关键的问题是这个使用命令行看完整输出,因为这个错误的dll使用dependency walker是不会列出来的。
原文地址:https://www.cnblogs.com/tsecer/p/10487774.html