Home All Groups Group Topic Archive Search About

call exported dll method in signed assembly from win32 app

Author
14 Jul 2006 12:04 PM
Stefan
hi,

i have a old win32 application (SiCtrl.exe written in Delphi) and a
..net 2.0 dll Win Control Library (B.dll) implementing some
WinForms dialogs.

the requirement is that SICtrl.exe can show a Form from B.dll.
(unmanaged->managed).
my research showed that there are 2 possible solitions:
1) via COM/Managed Bridge
2) via C++ Class Library containg exported functions.

i choose the 2nd solution because the user should be able to execute
SICtrl.exe without installation or admin rights (COM requires
installation in gac and registration).

i created a c++ Class Library Wrapper.DLL with clr support
(Wrapper.dll). Everything works fine until deployment.

Deployment of the Application should be in a intranet-environment:
Shared Folder on network-share containing:
    - SICtrl.exe
    - B.dll
    - Wrapper.dll

Executing Wrapper.dll causes a security problem because by default no
managed code can be executed from a network share.

i gave FullTrust Permission to the Network Share and it works.

but, this solution is not the best solution, because somewone can place
malicious code into this share and the user has the permission to
execute it ( i know someone can place a malicious win32 executable to
share too, but thats not the question).

my 2nd try was to use a strong name and give permission to company's
public-key.

- Create a Key CompanyKey.snk
- Sign B.dll and Wrapper.dll with CompanyKey.snk
- Create a Code Group "Company Zone" with Membership Condition via
Strong Name (only public-key not name and version).

everything works if i execute B.dll from a managed application (e.g.
ManagedSiCtrl.exe).

but when called from SiCtrl.exe it fails while loading wrapper.dll
(breakpoint in wrapper.dll never reached).

See the Debug Output at the end of the mail.


I suppose there is a (security ?) problem when calling a signed c++ dll
from unmanaged code. because when i leave the wrapper.dll unsigned
everything works fine (of course, permission to execute code from
network share must be given).

Any Ideas why the unmanaged application crashes when loading the Signed,
  Managed dll ?
Is there a workaround, solution ?

Thanks,

Stefan



The function in unmanaged code is defined as followed:

-- SNIP --

  extern "C"
  {

   __declspec(dllexport) void __cdecl InitializeBridge(char *culture,
char *connectionString)
   { //<<-- Breakpoint never called here.
      //SiloDotNetBridge::InitializeBridge(gcnew String(culture), gcnew
String(connectionString));
   }

}

-- SNIP ---


Show quote
> 'SICtrl.exe': Loaded 'D:\Projekte\Silo38\Bin\SICtrl.exe', Binary was not built with debug information.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\user32.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\oleaut32.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\ole32.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\version.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\comctl32.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\winspool.drv', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\shell32.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\shlwapi.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\comdlg32.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\winmm.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'D:\Projekte\Silo38\Bin\SiloDotNetBridge.dll', Symbols loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\mscoree.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9\comctl32.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.DebugCRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_f75eb16c\msvcr80d.dll', Symbols loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.DebugCRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_f75eb16c\msvcm80d.dll', Symbols loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\uxtheme.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\MSCTF.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\olepro32.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\msimg32.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\hhctrl.ocx', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\mui\0007\hhctrlui.dll', Binary was not built with debug information.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\clbcatq.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\comres.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\Programme\Gemeinsame Dateien\System\ado\msado15.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\msdart.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\xpsp2res.dll', Binary was not built with debug information.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\mswstr10.dll', No symbols loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\secur32.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\Programme\Gemeinsame Dateien\System\Ole DB\oledb32.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\Programme\Gemeinsame Dateien\System\Ole DB\oledb32r.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\Programme\Gemeinsame Dateien\System\Ole DB\sqloledb.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\Programme\Gemeinsame Dateien\System\Ole DB\msdatl3.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\netapi32.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\comsvcs.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\colbact.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\mtxclu.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\wsock32.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\ws2_32.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\ws2help.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\clusapi.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\resutils.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\userenv.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\dbnetlib.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\security.dll', Binary was not built with debug information.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\msv1_0.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\iphlpapi.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\ntdsapi.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\dnsapi.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\wldap32.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\crypt32.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\msasn1.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\mswsock.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\hnetcfg.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\wshtcpip.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\winrnr.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\rasadhlp.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\schannel.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\rsaenh.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\system32\dssenh.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\Programme\Gemeinsame Dateien\System\Ole DB\sqloledb.rll', Binary was not built with debug information.
> 'SICtrl.exe': Loaded 'C:\Programme\Gemeinsame Dateien\System\msadc\msadce.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\Programme\Gemeinsame Dateien\System\msadc\msadcer.dll', Binary was not built with debug information.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll', Exports loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_0de06acd\msvcr80.dll', Symbols loaded.
> 'SICtrl.exe': Loaded 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Culture.dll', Exports loaded.
> 'SICtrl.exe': Unloaded 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Culture.dll'
> 'SICtrl.exe': Loaded 'C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\87595a4ae69cb74a999de88a3be01f86\mscorlib.ni.dll', No symbols loaded.
> 'SICtrl.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
> First-chance exception at 0x7c81eb33 (kernel32.dll) in SICtrl.exe: Microsoft C++ exception: HRException at memory location 0x0015f7a8..
> First-chance exception at 0x7c81eb33 (kernel32.dll) in SICtrl.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000..
> First-chance exception at 0x7c81eb33 (kernel32.dll) in SICtrl.exe: Microsoft C++ exception: EEFileLoadException at memory location 0x0015ef2c..
> First-chance exception at 0x7c81eb33 (kernel32.dll) in SICtrl.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000..
> First-chance exception at 0x7c81eb33 (kernel32.dll) in SICtrl.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000..
> 'SICtrl.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\mscorlib.resources\2.0.0.0_de_b77a5c561934e089\mscorlib.resources.dll', No symbols loaded.
> First-chance exception at 0x7c95eafa (ntdll.dll) in SICtrl.exe: 0xC0000025: Windows cannot continue from this exception.
> First-chance exception at 0x7c95eafa (ntdll.dll) in SICtrl.exe: 0xC0000025: Windows cannot continue from this exception.
> First-chance exception at 0x7c95eafa (ntdll.dll) in SICtrl.exe: 0xC0000025: Windows cannot continue from this exception.
> First-chance exception at 0x7c95eafa (ntdll.dll) in SICtrl.exe: 0xC0000025: Windows cannot continue from this exception.
> First-chance exception at 0x7c95eafa (ntdll.dll) in SICtrl.exe: 0xC0000025: Windows cannot continue from this exception.
.... First-change exception is repeated until ...
Show quote
> First-chance exception at 0x78158563 (msvcr80.dll) in SICtrl.exe: 0xC00000FD: Stack overflow.
> First-chance exception at 0x7c95eafa (ntdll.dll) in SICtrl.exe: 0xC0000025: Windows cannot continue from this exception.
> First-chance exception at 0x7c95eafa (ntdll.dll) in SICtrl.exe: 0xC0000025: Windows cannot continue from this exception.
> First-chance exception at 0x7c95eafa (ntdll.dll) in SICtrl.exe: 0xC0000025: Windows cannot continue from this exception.
> First-chance exception at 0x7c95eafa (ntdll.dll) in SICtrl.exe: 0xC0000025: Windows cannot continue from this exception.
> First-chance exception at 0x7c95eafa (ntdll.dll) in SICtrl.exe: 0xC0000025: Windows cannot continue from this exception.
> First-chance exception at 0x7c95eafa (ntdll.dll) in SICtrl.exe: 0xC0000025: Windows cannot continue from this exception.
> First-chance exception at 0x7c95eafa (ntdll.dll) in SICtrl.exe: 0xC0000025: Windows cannot continue from this exception.
> First-chance exception at 0x7c95eafa (ntdll.dll) in SICtrl.exe: 0xC0000025: Windows cannot continue from this exception.
> First-chance exception at 0x7c95eafa (ntdll.dll) in SICtrl.exe: 0xC0000025: Windows cannot continue from this exception.
> First-chance exception at 0x7c8024e5 (kernel32.dll) in SICtrl.exe: 0xC0000005: Access violation writing location 0x00030f84.
> Unhandled exception at 0x7c8024e5 (kernel32.dll) in SICtrl.exe: 0xC0000005: Access violation writing location 0x00030f84.

Author
18 Jul 2006 7:00 AM
Stefan
Hello again,

I have posted a bug/feedback in ms connect too.

https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=163741

But Microsoft answers is short (nothing) right now. They only changed
the status from open to by-design. No comment why.

I still looking for a reason/workaround.

AddThis Social Bookmark Button