WinDepends icon indicating copy to clipboard operation
WinDepends copied to clipboard

Does not handle forwarders.

Open MarekKnapek opened this issue 1 year ago • 3 comments

Describe the bug

  • When a module depends on another module (such as an *.exe depends on a *.dll, or a *.dll depends on a *.dll) it can depend on a name or on an ordinal. But it is possible that this name or ordinal is not actually inside the target *.dll, it is not exported as an address. The target *.dll could forward its own export to yet another *.dll.
  • Example: program.exe depends on liba.dll, because it wants to use funca.
  • But liba.dll exports funca not as an address, but as a forwarder. It forwards it to libb.funcb.
  • Thus, program.exe depends on funcb from libb.dll statically at start-up time.
  • Your program does not take this into account.

To Reproduce Steps to reproduce the behavior:

  • compile program.exe, liba.dll and libb.dll
  • open program.exe in your tool

Expected behavior

  • program.exe depends on liba.dll which itself depends on libb.dll

Actual behavior

  • program.exe depends on liba.dll only

Screenshots

  • none

Desktop (please complete the following information):

  • Windows Server 2022 x64, all updates
  • Microsoft Windows [Version 10.0.20348.3932]

Additional context

  • the https://github.com/lucasg/Dependencies program does not show this correctly
  • the https://github.com/MarekKnapek/DependencyViewer program does not show this correctly
  • the https://www.dependencywalker.com program is stuck consuming 100% of single CPU

Files

program.cpp

#include <iostream>

extern "C" [[nodiscard]] __declspec(dllimport) int __stdcall funca(int a, int b) noexcept;

int main()
{
	int sum = funca(2, 3);
	std::cout << "The result is " << sum << ".\n";
}

liba.asm

.386
.model flat, stdcall

option prologue:none
option epilogue:none

.code

entry proc instance:dword, reason:dword, reserved:dword
	mov eax, 1
	ret
entry endp

end

liba.def

LIBRARY liba
EXPORTS
	funca=libb.funcb

libb.asm

.386
.model flat, stdcall

option prologue:none
option epilogue:none

.code

entry proc instance:dword, reason:dword, reserved:dword
	mov eax, 1
 ret
entry endp

funcb proc a:dword, b:dword
	mov eax, [esp + 4]
	mov ecx, [esp + 8]
	add eax, ecx
	retn 8
funcb endp

end

libb.def

LIBRARY libb
EXPORTS
	funcb

build.bat

rem Use the x86 (32-bit) vcvarsall environment.

ml /c /coff libb.asm
link /SUBSYSTEM:CONSOLE /DLL /ENTRY:entry /DEF:libb.def libb.obj

ml /c /coff liba.asm
link /SUBSYSTEM:CONSOLE /DLL /ENTRY:entry /DEF:liba.def liba.obj libb.lib

cl /c /EHsc program.cpp
link /SUBSYSTEM:CONSOLE program.obj liba.lib

MarekKnapek avatar Aug 08 '25 15:08 MarekKnapek

Update: After quite long time (more than 30min) the original Dependency Walker is un-stuck and it correctly shows the dependency.

MarekKnapek avatar Aug 08 '25 15:08 MarekKnapek

Image

MarekKnapek avatar Aug 08 '25 15:08 MarekKnapek

Closed, discussion continues in #39

hfiref0x avatar Dec 27 '25 04:12 hfiref0x