How to hide C ++ source code from client

I want to send some components to my customers. The reasons why I want to provide the source code are as follows:

1) My class is template. The client can use any template argument, so I cannot precompile and send the .o file.

2) The client can use different versions of the compiler for gcc than mine. So I want it to compile at the end.

Now I can’t reveal my source code for obvious reasons. The maximum I can do is open the .h file. Any ideas how I can achieve this. I am thinking of some hooks in gcc that support decryption before compilation, etc. Is it possible?

In short, I want him to be able to compile this code without looking inside.

+3
source share
7 answers

Contract = good, obfuscation = ungood.

However, you can always make some kind of PIMPL idiom to serve your client with binary files and just template wrappers in the headers. The idea is to use a “untyped” separately compiled implementation, where the generic shell simply provides type safety for client code. The way it was often done before compilers began to understand how to optimize templates, that is, to avoid marking up machine code code, but it only provides some degree of protection against the trivial theft of copy and paste, and not protection from anyone wanting to delve into the machine the code.

, ?

+11

Alf: - , . . wikipedia, Google, void*...

, , . , "" ++ , , ... , .

+5

-, , . , , GCC "decrypt before compile", , GCC , .

, , . ( , , . , , )

" ", , , . , ?

:

  • , ( ) , , .
+3
+1

1) . , .o.

2) gcc, . , .

. , , .h. , . gcc, .. ?

, , , .

2) A) ABI, , / , , B) , .., . . , , . , . A), "C", , B).

, ? GCC , , , , , ( /).

. , , - , . , , , ( , - ), .

Re templated code - C-, . ( , , , , ), B).

... , , . , , . , , , , .

+1
source

Gcc 4.5 seems to come with plugins. Thus, you can provide your own .so, which, for example, will be called before the start of the compilation stage. That way you can have all kinds of tricks (decrypting the source file) there neatly hidden. This would also be a portable solution since no changes are made to g ++.

This is exactly what I was looking for. You can read more here: http://www.codesynthesis.com/~boris/blog/2010/05/03/parsing-cxx-with-gcc-plugin-part-1/

0
source

Source: https://habr.com/ru/post/1769278/


All Articles