Skip to main content
Email Password   helpLost your password?

Introduction

A lot of us have tried to create a proxy DLL to replace an existing one and spy other programs' calls. Here is a small program that will create the CPP and DEF for a proxy DLL based on the exports of another DLL. You can use it to generate a template and then edit this template to satisfy your needs.

Background

When creating a proxy DLL, you have to export precisely the same names as exported by the original DLL. This can be painful, for two reasons:

  1. There are too many exports.
  2. There are functions that you don't know what they do; you'd just want to spy on one specific function call.

The second problem is solved with assembly and with the aid of the __declspec(naked) attribute. The program creates function stubs that do nothing but JUMP (not call) to the exported address, so the stack is left as it should be. This allows you to create code only for functions that you actually know what they do.

Using the program

WRAPPIT <dll> <txt> <convention> <point dll name> <cpp> <def>  

Example:

You have WSOCK32.DLL and you want to create a proxy for it, replacing the original DLL as WSOCK32_.DLL. What would you do?

This will:

A single CPP will look like this:

//

#include <windows.h>

#pragma pack(1)
HINSTANCE hLThis = 0;
HINSTANCE hL = 0;
FARPROC p[75] = {0};
// -----------

BOOL WINAPI DllMain(HINSTANCE hInst,DWORD reason,LPVOID)
{
    if (reason == DLL_PROCESS_ATTACH)
    {
        hLThis = hInst;
        hL = LoadLibrary(".\\wsock32_.dll");
        if (!hL) return false;

        p[0] = GetProcAddress(hL,"AcceptEx");
        p[1] = GetProcAddress(hL,"EnumProtocolsA");
        p[2] = GetProcAddress(hL,"EnumProtocolsW");
      ...
    }
    if (reason == DLL_PROCESS_DETACH)
    {
        FreeLibrary(hL);
    }
    return 1;
}

// AcceptEx

extern "C" __declspec(naked) void __stdcall __E__0__()
{
    __asm
    {
        jmp p[0*4];
    }
}

// EnumProtocolsA

extern "C" __declspec(naked) void __stdcall __E__1__()
{
    __asm
    {
        jmp p[1*4];
    }
}

// EnumProtocolsW

extern "C" __declspec(naked) void __stdcall __E__2__()
{
    __asm
    {
        jmp p[2*4];
    }
}
...
//

A single DEF will look like this:

EXPORTS
AcceptEx=__E__0__ @1141
EnumProtocolsA=__E__1__ @1111
EnumProtocolsW=__E__2__ @1112
...

You may now edit CPP/DEF files and reuse them to create your own proxy DLL!

Important!

Once the cpp is ready, you should replace functions that you know how to use. For example, If you want to spy on Wsock32.send():

// send, created by wrappit

extern "C" __declspec(naked) void __stdcall __E__69__()
   {
   __asm
    {
    jmp p[69*4];
    }
 }

// If you want to manipulate it, change to:

extern "C" int __stdcall __E__69__(SOCKET x,char* b,int l,int pr)
  {
  // manipulate here parameters


.....
  // call original send

     typedef int (__stdcall *pS)(SOCKET,char*,int,int);
     pS pps = (pS)p[63*4];
     int rv = pps(x,b,l,pr);

     return rv;
  }

History

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralI cant make it work for ws2_32.dll Pin
Mugiwara
5:44 27 Jul '09  
GeneralRe: I cant make it work for ws2_32.dll Pin
ArielMendoza
22:29 27 Jul '09  
GeneralRe: I cant make it work for ws2_32.dll Pin
Mugiwara
7:03 28 Jul '09  
GeneralRe: I cant make it work for ws2_32.dll Pin
ArielMendoza
10:59 28 Jul '09  
GeneralRe: I cant make it work for ws2_32.dll [modified] Pin
Mugiwara
3:24 29 Jul '09  
GeneralRe: I cant make it work for ws2_32.dll Pin
ArielMendoza
11:40 29 Jul '09  
GeneralNew application Pin
ArielMendoza
1:34 27 Jul '09  
GeneralError in the index Pin
CodeGibbon
2:58 3 Dec '08  
GeneralForwarding function Pin
sparrowIsaBird
14:12 22 Oct '08  
GeneralRe: Forwarding function Pin
Michael Chourdakis
21:32 22 Oct '08  
GeneralRe: Forwarding function Pin
sparrowIsaBird
0:25 23 Oct '08  
GeneralCant create exports.txt :'( Pin
Member 4343919
8:00 15 Jan '08  
GeneralRe: Cant create exports.txt :'( Pin
Michael Chourdakis
9:25 15 Jan '08  
GeneralRelease of Wrappit 2.0 Pin
Michael Chourdakis
8:14 16 Dec '07  
GeneralRe: Release of Wrappit 2.0 Pin
Hernán Di Pietro
19:36 17 Sep '08  
GeneralRe: Release of Wrappit 2.0 Pin
ndataman
6:18 21 Oct '08  
GeneralRe: Release of Wrappit 2.0 Pin
Michael Chourdakis
6:28 21 Oct '08  
GeneralRe: Release of Wrappit 2.0 Pin
ndataman
1:18 22 Oct '08  
GeneralHow to make it work with WinCE? [modified] Pin
Kelvin Foo Chuan Lyi
17:00 10 Sep '07  
GeneralRe: How to make it work with WinCE? Pin
Michael Chourdakis
18:15 10 Sep '07  
GeneralRe: How to make it work with WinCE? Pin
Kelvin Foo Chuan Lyi
6:02 14 Sep '07  
GeneralRe: How to make it work with WinCE? Pin
Michael Chourdakis
6:10 14 Sep '07  
GeneralRe: How to make it work with WinCE? Pin
Michael Chourdakis
7:08 14 Sep '07  
GeneralRe: How to make it work with WinCE? Pin
Michael Chourdakis
7:14 14 Sep '07  
GeneralRe: How to make it work with WinCE? Pin
Kelvin Foo Chuan Lyi
23:55 15 Sep '07  


Last Updated 14 May 2007 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009