0

I'm designing a small utility to help out with build systems. The idea is that the utility will launch each instance of each compiler and output a log of all the files that the compiler opens during the compilation. Something like:

track-files cc -c -o foo.o foo.c

Then track-files executes cc and outputs all the .h (and other) files that cc opened. But cc might be any compiler (or even an interpreter or just a program that does some kind of text transformation).

A similar idea is described in Paul D Smith's Advanced Auto-Dependency tutorial and attributed to Han-Wen Nienhuys.

On Linux, FreeBSD, Solaris and HPUX I think I can use LD_PRELOAD. On AIX I can use LDR_PRELOAD and on OSX I can use DYLD_INSERT_LIBRARIES. On most of those systems I can also use strace if LD_PRELOAD-like tricks don't work.

The one OS where I have no clue how to proceed is Windows. I've been looking around and everything I've found so far seems, ..., unsatisfactory.

The only answer to LD_PRELOAD equivalent for Windows to preload shared libraries suggests AppInit_DLLs, but points out they are deprecated and/or disabled after Vista (because they were broken).

The accepted answer on interposers on Windows points to Microsoft Research's Detours but that is proprietary (and they charge big bucks (USD10000!!!) for 64-bit support) so that would make my utility worthless for just about everyone (including me). The other answer mentions something called WinAPI Override, but that's apparently 32-bit only.

There's surely some dependable, non-proprietary, programmatic way to do this on Windows. Some tracing API perhaps? I'd be happy with support only for more recent versions of Windows (Windows 7 and 8, for example).

Community
  • 1
  • 1
Wandering Logic
  • 3,323
  • 1
  • 20
  • 25
  • 1
    Something like [this](http://www.codeproject.com/Articles/2082/API-hooking-revealed) perhaps is what you are looking for? I haven't heard anything about it being 32 bit only, though I imagine you can only hook 64 bit processes with a 64 bit program (likewise for 32 bit). – Matt May 06 '14 at 23:48
  • 1
    It can certainly be done, because Process Monitor does it; using a file system filter driver, I think. – Harry Johnston May 06 '14 at 23:50

2 Answers2

1

After not finding any free & good solutions to this problem I've coded my own solution. It uses Process Monitor since I believe that has better coverage for all types of system calls and historical stability. It configures, manages, and then filters the Procmon log files. It's new but works for my setup. You can find it here. Suggestions and comments appreciated.

BeingQuisitive
  • 158
  • 1
  • 10
0

MSBuild uses Tracker.exe https://msdn.microsoft.com/en-us/library/microsoft.build.utilities.filetracker%28v=vs.121%29.aspx on Windows which does what you describe and generates .tlog files. (I don't know of a way to do it programmatically easily/directly though.)

(Also not sure it's a great solution for a build tool; e.g. cl.exe writes pdbs via mspdbsrv.exe which isn't in the same process tree, so I think it'd miss that.)

sgraham
  • 113
  • 1
  • 5