title: Interposing of OS X system calls
body: <p>I need to interpose <em>(get my functions called instead of the original functions)</em> some OS X system calls to overcome a flaw in a piece of closed-source software.</p>
  
  <p>Preferably, the resulting solution would work under 10.5 (Leopard) and newer, but I <em>might</em> be able to require 10.6 (Snow Leopard) if the argument were strong enough.</p>
  
  <p>Preferably, the resulting solution would be an executable, but I might settle for a script.</p>
  
  <p>Preferably, the resulting solution would be able to interpose <em>("steal the vectors")</em> even after the target application is running, but I could settle for a technology that must inject itself as the application is loading.</p>
  
  <p>Preferably, the resulting solution would be developed in C or C++, but I could settle for Objective-C or something else.</p>
  
  <p>So far, I've experimented with:</p>
  
  <p>1) <strong>DTrace</strong> scripting, which has taught me a lot, but the limitations of the D language <em>(limited flow control, etc.)</em> make it a major pain for what I'm doing, not to mention that the result would be a script, which isn't as tidy and self-contained as what I'm shooting for.</p>
  
  <p>2) <strong>DYLD_INSERT_LIBRARIES</strong> interposition, which is slick in many ways, but perhaps due to namespace flattening <em>(I won't pretend to deeply understand what this means)</em>, it works nicely against simpler executables, but makes my target application choke, even when I build a do-nothing library that doesn't actually interpose any calls.</p>
  
  <p>My latest idea is to experiment with <strong>mach_star</strong> (<a href="https://github.com/rentzsch/mach_star/" rel="noreferrer">https://github.com/rentzsch/mach_star</a>), but I'm stopping here first, to ask the Stack Overflow community which invariably knows more than do I...</p>
  
  <p>...should I be looking at something besides mach_star next?</p>