Jump to content

Pathrewrite: Difference between revisions

From EDM2
Line 7: Line 7:
In this article I'll try to outline the posibilities from what I used myself and will give a example.
In this article I'll try to outline the posibilities from what I used myself and will give a example.


First lets see what is documented inside the libc pathrewrite.c file:
First lets see what is documented inside the libc hooks.c file:
<pre>
<pre>


/** @page PathRewrite  Path Rewrite Feature
/** @page pg_hooks  Hooks
  *
  *
  * The Path Rewrite Feature was designed as a replacement for the hardcoded
  * Presently this is a simple feature to load and call dlls as specified in
* mapping of /dev/null to nul and /dev/tty to con in __open.c. It allows
  * the LIBC_HOOK_DLLS environment variable.
  * the user of LIBC to automatically rewrite (map) paths given to LIBC APIS.
* The user can dynamically add and remove rewrite rules. The environment
* variable LIBC_PATHREWRITERS can be used to dynamically load DLLs containing
* rewrite rules and add it to the process.
  *
  *
  *
  *
  * @subsection  LIBC_PATHREWRITERS
  * @subsection  LIBC_HOOK_DLLS
  *
  *
  * The format is <dllname>@<export>. LIBC will load <dllname>, resolve <export>
  * The format is <dllname>@<export>[!<type>]. LIBC will load <dllname>,
* and call <export> with pointers to the three __libc_PathRewrite interfaces.
* resolve <export>and call <export> according to the convention of <type>.
* The <export> function will then register and remove rules as it pleases it.
  * Single of double quotes can be applied to the <dllname>. If multiple hooks
  * Single of double quotes can be applied to the <dllname>. Multiple rewriters
  * is desired, they shall be separated by the semicolon, space or tab character.
  * must be separated by space.
 
* Failure to parse this variable, load dlls and resolve functions as specified
* bye this variable will not prevent libc processes from starting. So, do NOT
* count on it as a security measure.
*
* @subsubsection  Types
*
* The default type is 'generic' and means that the libc module handle and
* the address of __libc_Back_ldrSymbol will be passed.
*
* 'pathrewrite' is another type. The parameters here are the three
* __libc_PathRewrite functions. The function should
*
*
* @subsubsection  Examples
  *
  *
  * Examples:
  *  set LIBC_HOOK_DLLS=prwhome.dll@_instprws!pathrewrite
  *      set LIBC_PATHREWRITERS=prwhome.dll@_instprws
  * set LIBC_HOOK_DLLS=/usr/lib/prwhome.dll@_instprws!pathrewrite
  *     set LIBC_PATHREWRITERS=/usr/lib/prwhome.dll@_instprws
  * set LIBC_HOOK_DLLS="c:\My Plugins\prwhome.dll"@_instprws!pathrewrite
  *     set LIBC_PATHREWRITERS="c:\My Plugins\prwhome.dll"@_instprws
  * set LIBC_HOOK_DLLS=prwhome@_insthomeprws!pathrewrite prwhome@_instetcprws!pathrewrite
  *     set LIBC_PATHREWRITERS=prwhome@_insthomeprws prwhome@_instetcprws
  */
  */


</pre>
</pre>
so we need to create a DLL which export a function that sets the rewritten paths.

Revision as of 23:40, 19 June 2006

Using the Innotek Libc pathrewrite function

When porting application from unix flavours you might run into the problem that some parts are hardcoded into the application, most famous is ofcourse /etc.

Libc provides a interface to work around these problems without completely rewriting the application, and thus easying the maintenance for the porter.

In this article I'll try to outline the posibilities from what I used myself and will give a example.

First lets see what is documented inside the libc hooks.c file:


/** @page pg_hooks  Hooks
 *
 * Presently this is a simple feature to load and call dlls as specified in
 * the LIBC_HOOK_DLLS environment variable.
 *
 *
 * @subsection  LIBC_HOOK_DLLS
 *
 * The format is <dllname>@<export>[!<type>]. LIBC will load <dllname>,
 * resolve <export>and call <export> according to the convention of <type>.
 * Single of double quotes can be applied to the <dllname>. If multiple hooks
 * is desired, they shall be separated by the semicolon, space or tab character.

 * Failure to parse this variable, load dlls and resolve functions as specified
 * bye this variable will not prevent libc processes from starting. So, do NOT
 * count on it as a security measure.
 *
 * @subsubsection   Types
 *
 * The default type is 'generic' and means that the libc module handle and
 * the address of __libc_Back_ldrSymbol will be passed.
 *
 * 'pathrewrite' is another type. The parameters here are the three
 * __libc_PathRewrite functions. The function should
 *
 *
 * @subsubsection   Examples
 *
 *  set LIBC_HOOK_DLLS=prwhome.dll@_instprws!pathrewrite
 *  set LIBC_HOOK_DLLS=/usr/lib/prwhome.dll@_instprws!pathrewrite
 *  set LIBC_HOOK_DLLS="c:\My Plugins\prwhome.dll"@_instprws!pathrewrite
 *  set LIBC_HOOK_DLLS=prwhome@_insthomeprws!pathrewrite prwhome@_instetcprws!pathrewrite
 */


so we need to create a DLL which export a function that sets the rewritten paths.