22 October, 2012

How to get x64 dynamic function table critical section?

There is the standard way to walk on stack under Windows x64: RtlLookupFunctionEntry() and RtlVirtualUnwind() API calls. These methods use additional information to unwind stack: static and dynamic function tables. Static tables are generated by compilers and stored insight DLLs. Dynamic ones generated by application (CLR in fact is part of application) for dynamically created methods.

How RegSvr32 works on x64?

File system redirection works in x64 OS. It means that when you are 32-bits application and try to run %WinDir%\System32\RegSvr32.exe, you run %WinDir%\SysWOW64\RegSvr32.exe in fact. It's very good for compatibility. However, there is the problem when you want to register 64-bits COM DLL from 32-bits process: 32-bits process can't work with 64-bits DLL.

RegSvr32 do the special work to solve this problem. It detects that it works in WOW64 mode and DLL is 64-bit then ... it disable file system redirection for current thread by the Wow64EnableWow64FsRedirection() call and run itself (the command line contains original path: %WinDir%\System32\RegSvr32.exe) with the same arguments. Ta-da... It's beautiful decision!

Update: However, run itself in 64-bits mode will be skipped when 32-bits application loads 64-bits DLL by LoadLibraryEx() call and get the non-right error code - only the ERROR_BAD_EXE_FORMAT (0xC1) error code is expected.

12 October, 2012

WinRT local network isolation

By default only VS2012 deployed applications have the localhost network isolation in disabled state. All other application can't connect to localhost. There are at least two tools to control which application can connect to localhost which not: CheckNetIsolation and EnableLoopback. Here is the way how to do it from you own program: