Live data from Hacker News

Porting Windows Dynamic Link Libraries to Linux

github.com

21–30 of 44 posts

Re: Porting Windows Dynamic Link Libraries to Linux

#21
post #7

Why not just use full-on WINE? The basic system calls are pretty much fully covered. It seems this duplicates a lot of work.

Are the Windows API implementations of WINE usable by a native Linux program (eg as a library of some sort)? That seems to be the requirement here.

WINE's had this ability for more than a decade -- see winelib.

Re: Porting Windows Dynamic Link Libraries to Linux

#22
post #18

Did this close to twenty years ago. Ported a COM DLL to Linux and one of the executables using it. I implemented everything it needed. COM functions like CoCreateInstance, entry points like DllCanUnloadNow, Windows Sockets and whatnot. The registry API! Ha. I mapped HKEY_CURRENT_USER to configuration files rooted in the user's home directory, and HKEY_LOCAL_MACHINE to /etc. The lib's DllRegisterServer nicely register…

Open Group had COMsource: http://www.opengroup.org/comsource/

Software AG had DCOM (EntireX?) implementation for Solaris/Linux back in the day It was freely downloadable and came with working examples :)

Re: Porting Windows Dynamic Link Libraries to Linux

#26
Note that the author is Tavis Ormandy, the guy who (among many, many other things) discovered one of the worst Windows security vulns, that was patched last month -- and from the README it seems like this is part of the toolchest he used for this particular discovery.

To all people wondering why not wine or winelib - this is for ease of debugging and fuzzing DLLs, not for actually running software. Wine and Winelib bring way too much baggage for those uses.

Re: Porting Windows Dynamic Link Libraries to Linux

#27
If you like this, you might also like the Witchcraft Compiler Collection[1] by Jonathan Brossard.

It approaches from a different angle (relinking), but (as far as I understand it) can help to solve the same problem Tavis tackles. In the end they both allow the dynamic analysis of PE files in Linux. Both tools only work if the architecture is the same in both worlds, I think.

EDIT: [2] is an intro to the Witchcraft Compiler Collection from Black Hat Europe 2016 which is probably more helpful than the link to the repo.

[1] https://github.com/endrazine/wcc/blob/master/README.md

[2] https://www.blackhat.com/docs/eu-16/materials/eu-16-Brossard...

Re: Porting Windows Dynamic Link Libraries to Linux

#28
post #19

This is cool and a lot lighter than WINE, though the important keyword is self-contained Windows libraries. I gather this won't work on DLLs that call any of the plethora of Windows APIs. I'm actually very surprised that any non-trivial DLLs are self-contained in this way, like his example of Windows Defender which I thought would call 1000 Windows API functions.

A bunch of C runtime library and Windows APIs are implemented or stubbed:

* https://github.com/taviso/loadlibrary/tree/master/peloader/w...

* https://github.com/taviso/loadlibrary/blob/master/peloader/c...

Re: Porting Windows Dynamic Link Libraries to Linux

#29
post #12

Did anyone find info on how are user32.dll and kernel32.dll handled ?

There are stubs, or reimplementations on top of the C library, for a relatively small subset of functions: https://github.com/taviso/loadlibrary/tree/master/peloader/w... (see e.g. Files.c in there for an example of mapping Windows API functions to libc).

Re: Porting Windows Dynamic Link Libraries to Linux

#30

This reminds me of a tool Jeff Roberts wrote at RAD Game Tools which would repackage libraries so they were loadable on Linux. At the time the motivation was that MSVC was generating much better code than GCC for Bink, so he'd compile on Windows with MSVC and cross-link to Linux with his custom tool.

Does MSVC still generate better code than GCC ? I do not find any recent benchmark.
Post reply on HN