views:

554

answers:

6

I don't want user to see all the exporting functions through Dependence in my DLL, is there a way to do it? I complie my DLL with C++ and MS Visual Studio.

A: 

A really simple way is to wrap it in a packer like UPX.
What you see exported is just the stuff UPX uses to unpack the file into memory

shoosh
And a really easy way around that is to un-UPX the file. :-)
Head Geek
As long as you actually call a function, you can circumvent any attempt to hide it. un-UPXing a PE is less trivial than using depends.
shoosh
A: 

No, the whole point of having exports is so that they are VISIBLE.

That's the short answer. The long answer involves .def files. You can tell the linker to turn your C functions into indexes using a definition file.

jmucchiello
+3  A: 

Use a *.def file and use the NONAME attribute to prevent the name's being exported: see Exporting Functions from a DLL by Ordinal Rather Than by Name ... there's an an example here.

ChrisW
+3  A: 

This is really awkward, but if you don't want others to even see the ordinals, you can wrap your functions with COM. A COM DLL only exposes the common COM functions, so yours will be hidden. Then, there are techniques to use the DLL without registering it first, so no information about the COM class you'll be using could be found in the system. It's definitively a weird reason to use COM, but the request is quite uncommon as well...

eran
You can do something very similar without being COM: define your API as an abstract (i.e. pure virtual) C++ interface, and export a single function which returns a pointer to (an object which implements) that interface.
ChrisW
Indeed... that would make a simpler solution.
eran
+1  A: 

Another option may be to create an exported function which will return an array of addresses of the functions which you would like to hide - once you have these addresses, you can call them directly

static void** Funcs = {&foo, &foo1, &foo2, 0};

__declspec (dllexport) void* GetFuncs (void)
{
   return &Funcs;
}

in your executable you can do the following

void** Funcs = GetFuncs();

(*Funcs[0]) (1, 2, 3);
Danny Shumer
+1 for sample code and cleverness.
RBerteig
+1  A: 

IMO using NONAME is useless for this purpose - it does not hide dependencies. Dependencies would still be shown (by using ordinals). And your basic users would still be able to get to them via GetProcAddress.

I think you'll have to use more sophisticated approach - e.g. solutions proposed by eran.

Andrey