user1578532
user1578532

Reputation:

Is it possible to obfuscate raw C# source code?

I have seen many C# obfuscators, and they all need an assembly (.exe, .dll, etc.) Why isn't it possible to just obfuscate the source code? Like you can do with javascript for example: http://www.javascriptobfuscator.com

Upvotes: 4

Views: 1294

Answers (3)

gap
gap

Reputation: 2796

I agree with @dystroy, in that you obfuscate what you release.

But to directly answer the question posed-- b/c so few people release C# code.

If you need to release C# code, AND you wish to obfuscate it, I recommend a one-two punch of:

  1. Make "internal" all types not needed to be "public"
  2. Compile your assembly containing the source code to be released
  3. Use RedGate SmartAssembly to obfuscate that assembly.
  4. Use JetBrains dotPeek to reveal the obfuscated source code, and dump to disk.
  5. Zip obfuscated source code and release it.

Upvotes: 0

Tigran
Tigran

Reputation: 62248

It doesn't make any sense to obfuscate source code. That's because source code is shared for maintainance or experience sharing. That's why obfuscation targets deployable artifacts, like exe or dll...

In case of JavaScript the code itself is deployable artifact, so for Java Script it has a perfect meaning for intellectual property protection.

Upvotes: 4

Denys Séguret
Denys Séguret

Reputation: 382092

You obfuscate what you release to the customer, not what you have to keep clear so that you can maintain it.

You release javascript files, you obfuscate them (and keep the non obfuscated ones to maintain the application). So you have two sets of javascript files : the source and the released. If there was a distinct released compiled format, this would probably be the obfuscation target.

You release .class files, not .java files, so you obfuscate the .class.

You release exe, not c or c# files, so you obfuscate the exe.

Other concrete reasons :

  • a C or C# file (or java) may be used in different applications. And the content that may be stripped or changed will be different depending on the application
  • a C, C# or java file contains items necessary for the compilation that can't be stripped only in one file : you have to obfuscate the whole set (for example, if you rename a class or a visible field, you usually maintain in memory a table while obfuscating).

Upvotes: 2

Related Questions