Function Wrapping and Replacing Extension

The drwrap DynamoRIO Extension provides function wrapping and replacing support.

Setup

To use drwrap with your client simply include this line in your client's CMakeLists.txt file:

 use_DynamoRIO_extension(clientname drwrap) 

That will automatically set up the include path and library dependence.

Initialize and clean up drwrap by calling drwrap_init() and drwrap_exit().

API

The first step in replacing or wrapping is to determine the address of the target application function. For functions exported by an application library, use dr_get_proc_address() to locate the entry point. For internal functions, use the drsyms Extension.

Function replacing is provided by drwrap_replace(). The replacement function executes as application code and will be passed to the client via the basic block and trace events just like any other application code. The replaced function may still show up in the basic block event as a jump instruction; none of its actual code will execute. To avoid changing application behavior, ensure that the replacement function mirrors the calling convention and other semantics of the original function.

Function wrapping is provided by drwrap_wrap(). A pre-function and post-function callback must be provided. The pre-function callback is invoked prior to every execution of the target function. The callback can examine and change function arguments and can skip the call to the target function (in which case there will be no post-function callback). The post-function callback can examine and change the target function's return value. Information (included copies of the arguments for examination in the post-function) can be passed between the pre- and post-functions via a user-controlled parameter.

Multiple wrap requests are allowed for one target function. Their callbacks are called sequentially in the reverse order of registration. If any pre-function callback asks to skip the function, the remaining pre-function callbacks will not be called, nor will any post-function callback.

LGPL 2.1 License

The drwrap Extension is licensed under the LGPL 2.1 License and NOT the BSD license used for the rest of DynamoRIO.


  DynamoRIO API version 3.2.0 --- Wed Mar 28 12:55:33 2012