views:

305

answers:

3

I have built a shared library (.dll, .so) with VC++2008 and GCC. The problem is that inside both libs it shows the names of private symbols (classes, functions) and they weren't exported.

I don't want my app to display the name of classes/functions that weren't exported. Is any way i can do that?

In GCC i did: Compiled with -fvisibility=hidden and then made public with attribute ((visibility("default")))

In VC++: __declspec(dllexport)

Thanks!

+1  A: 

For GNU tool chains you can use th strip command to remove symbols from object files. It takes various command options to control its behavior. It may do what you want.

Steve K
Already did that. It removes some symbols but not all!
AllDayCpp
A: 

The private keyword when used for access specification only effectively works at compile time and is intended as an aid to programmers, not a security feature - as you have found out the "privacy" is implemented using lexical means .

It's easy to see that this must be so - if you implement two private functions with dependencies between each other in two separate .cpp files, the linker has to find the private names in the resulting object (or library) files.

Bottom line - C++ has no code security features - if you give someone the object code of your program, they will always be able to examine it.

anon
I'm talking about symbols in the ELF or PE executable format. Not the private keyword.
AllDayCpp
So maybe you should remove the C++ tag from your question?
anon
+1  A: 

You can create a header file to obfuscate the internal function and method names you want to be hidden. Ie something like below (need some include guard too)

#define someFunctionName1 sJkahe28273jwknd
#define someFunctionName2 lSKlajdwe98
#define someMethodName1   ksdKLJLKJl22fss
#define someMethodName2   lsk89hHHuhu7g

...and include this in the header files where the real definitions live.

epatel
It isn't pratical to do it in a large project and it pollutes the code with defines..Evil solution..
AllDayCpp
My suggestion is to keep them in a single file..so you don't need to see them. You wont see them in any code later on, only a "include" in some headers. If you need to obfuscate all functions/methods you might need to use some parser to extract them. If you keep it to some important core functionality they should be fine to handle manually. The thing is the code will be the same, the names in the binary will be obfuscated. Instead of using some random identifier one can write some different func/method name hopefully throwing any re-engineer off, ie calculateSecretKey()->prepareNewDatabase()
epatel