Click here to Skip to main content
12,401,173 members (59,237 online)
Click here to Skip to main content
Add your own
alternative version


100 bookmarked

Create your Proxy DLLs automatically

, 14 May 2007
Rate this:
Please Sign up or sign in to vote.
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 you edit this template to satisfy your needs.


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.


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>  
  • <dll> is the new DLL name you want to create. The program can compile the DLL using VC++ or BC++, depending on how you comment or edit lines 233-237:
    // _stprintf(ay,_T("BCC32 -o%s.obj -c %s\r\n"),argv[5],argv[5]);
    _stprintf(ay,_T("CL.EXE /O2 /GL /I \".\" /D \"WIN32\" /D \"NDEBUG\" /D" 
              "\"_WINDOWS\" /D \"_WINDLL\" /FD /EHsc /MT /Fo\".\\%s.obj\" " 
              "/Fd\".\\vc80.pdb\" /W3 /nologo /c /Wp64 /TP " 
              "/errorReport:prompt %s\r\n"),argv[5],argv[5]);
    // _stprintf(ay,_T("ILINK32 -c -Tpd %s.obj,
    //           %s,,,%s\r\n"),argv[5],argv[1],argv[6]);
    _stprintf(ay,_T("LINK.EXE /OUT:\"%s\" /INCREMENTAL:NO /NOLOGO /DLL" 
              " /MANIFEST /DEF:\"%s\" /SUBSYSTEM:WINDOWS /OPT:REF " 
              "%s.obj kernel32.lib user32.lib gdi32.lib winspool.lib " 
              "comdlg32.lib advapi32.lib shell32.lib ole32.lib " 
              "oleaut32.lib uuid.lib odbc32.lib odbccp32.lib\r\n"), 
  • <txt> is a text file containing the exports from the original DLL. You can create this file with either dumpbin:
    dumpbin /exports original.dll > exports.txt

    or with tdump:

    tdump original.dll -ee > exports.txt
  • <convention> is the convention call you want your functions to have. You will usually want to use __stdcall, but it hardly matters what you use because the stub functions immediately jump to the existing code and therefore, they should work with any calling convention.
  • <point dll name> is the DLL name that your proxy DLL will try to load. Make sure you use C++ escape characters like \\.
  • <cpp> is the generated CPP file.
  • <def> is the generated DEF file.


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

  • move wsock32.dll wsock32_.dll
  • dumpbin /exports wsock32_.dll > exports.txt
  • wrappit wsock32.dll exports.txt __stdcall .\\wsock32_.dll wsock32.cpp wsock32.def

This will:

  • Parse the text file for exports and create the DEF. Exported functions by ordinal only are supported.
  • Create the sample CPP code. In the DLL's code DllMain, the original wsock32_dll will be loaded with LoadLibrary(). Then all the original exported functions' addresses will be returned by GetProcAddress and stored in an internal pointer. Then stubs for each function will be created.

A single CPP will look like this:

#include <windows.h>
#pragma pack(1)
FARPROC p[75] = {0};
// -----------
    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)
    return 1;

// AcceptEx
extern "C" __declspec(naked) void __stdcall __E__0__()
        jmp p[0*4];

// EnumProtocolsA
extern "C" __declspec(naked) void __stdcall __E__1__()
        jmp p[1*4];

// EnumProtocolsW
extern "C" __declspec(naked) void __stdcall __E__2__()
        jmp p[2*4];

A single DEF will look like this:

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!


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__()
    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;


  • 14 May, 2007 - Fixed problem occuring when dumpbin.exe generates RVA information as well


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Michael Chourdakis
Greece Greece
I'm working in C++, PHP , Java, Windows, iOS and Android.

I 've a PhD in Digital Signal Processing and I specialize in Pro Audio applications.

My home page:

You may also be interested in...

Comments and Discussions

GeneralRe: fail when proxy msvcr71.dll Pin
g0ug0u23-Jul-07 14:48
memberg0ug0u23-Jul-07 14:48 
GeneralRe: fail when proxy msvcr71.dll Pin
Michael Chourdakis23-Jul-07 22:33
memberMichael Chourdakis23-Jul-07 22:33 
GeneralDLL Export forwarding Pin
Hokei5-Jun-07 9:08
memberHokei5-Jun-07 9:08 
GeneralRe: DLL Export forwarding Pin
Michael Chourdakis5-Jun-07 9:23
memberMichael Chourdakis5-Jun-07 9:23 
GeneralRe: DLL Export forwarding Pin
Hokei5-Jun-07 9:58
memberHokei5-Jun-07 9:58 
GeneralRe: DLL Export forwarding Pin
Michael Chourdakis7-Jun-07 4:03
memberMichael Chourdakis7-Jun-07 4:03 
GeneralRe: DLL Export forwarding Pin
Hokei7-Jun-07 6:08
memberHokei7-Jun-07 6:08 
GeneralHandy tool Pin
lallous21-May-07 21:05
memberlallous21-May-07 21:05 

It is a handy tool and actually I've been meaning to do something like that, but you saved my day! Smile | :)

QuestionLinker that changes the definition function names Pin
realundeadmonkey17-May-07 11:31
memberrealundeadmonkey17-May-07 11:31 
GeneralRe: Linker that changes the definition function names Pin
Draghi217-May-07 23:59
memberDraghi217-May-07 23:59 
GeneralWinsock proxy in vista Pin
Michael Chourdakis13-May-07 4:12
memberMichael Chourdakis13-May-07 4:12 
GeneralAcessing Multible Parameters (Violation Error ) (Wsock32.dll) Pin
Cloather29-May-07 23:40
memberCloather29-May-07 23:40 
GeneralRe: Acessing Multible Parameters (Violation Error ) (Wsock32.dll) Pin
Michael Chourdakis10-May-07 2:46
memberMichael Chourdakis10-May-07 2:46 
GeneralRe: Acessing Multible Parameters (Violation Error ) (Wsock32.dll) Pin
Cloather210-May-07 3:43
memberCloather210-May-07 3:43 
GeneralRe: Acessing Multible Parameters (Violation Error ) (Wsock32.dll) Pin
Cloather210-May-07 20:29
memberCloather210-May-07 20:29 
GeneralRe: Acessing Multible Parameters (Violation Error ) (Wsock32.dll) Pin
Michael Chourdakis11-May-07 9:30
memberMichael Chourdakis11-May-07 9:30 
GeneralIt Wont Compile Pin
Cloather28-May-07 2:11
memberCloather28-May-07 2:11 
GeneralRe: It Wont Compile Pin
Michael Chourdakis8-May-07 3:01
memberMichael Chourdakis8-May-07 3:01 
GeneralRe: It Wont Compile Pin
Cloather28-May-07 3:35
memberCloather28-May-07 3:35 
GeneralRe: It Wont Compile Pin
Cloather29-May-07 7:27
memberCloather29-May-07 7:27 
GeneralProblem Pin
jack12346-Apr-07 1:54
memberjack12346-Apr-07 1:54 
GeneralRe: Problem Pin
Michael Chourdakis6-Apr-07 3:02
memberMichael Chourdakis6-Apr-07 3:02 
GeneralRe: Problem Pin
Rasqual Twilight30-Oct-07 9:53
memberRasqual Twilight30-Oct-07 9:53 
GeneralRe: Problem Pin
Michael Chourdakis30-Oct-07 10:36
memberMichael Chourdakis30-Oct-07 10:36 
QuestionTrying to create proxy for advapi32.dll Pin
ivgeni_b18-Feb-07 3:30
memberivgeni_b18-Feb-07 3:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160721.1 | Last Updated 14 May 2007
Article Copyright 2006 by Michael Chourdakis
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid