This project is read-only.

Creating Obfuscator Using CCI

Topics: PE Writer
Jan 4, 2010 at 3:34 PM


I'm learning to use CCI for by creating simple Obfuscator.

Before I was using Cecil, and the translation to CCI was not so easy.

In Cecil I can simple set TypeDefinition.Name = "SomeName" to rename some Type, but I don't know how to archive this with CCI.

Can someone give me some advice/hint on that ?



Jan 4, 2010 at 3:52 PM

The basic CCI object model is immutable. The easiest way to modify it is to first create a mutable copy (using the MetadataMutator class in the MetadataMutator project) and then to visit the resulting mutable model with another MetadataMutator that has the flag set to not make a copy.

Note that you can only change the name of named type definitions (INamespaceTypeDefinition and INestedTypeDefinition).

Jan 4, 2010 at 3:59 PM

Hi, thx for the reply.

I'm so new to CCI, can you point some code example for me ?



Jan 4, 2010 at 4:06 PM

Have look at the projects in the samples directory. Also have a look at the project, in particular the ccisharp sample.

I'll see if I can get time to make up a more specific sample for your scenario.

Jan 4, 2010 at 4:14 PM

Thx, I will try to study the example first, :P.

But I have some question, if I have 2 assemblies, A.dll & B.dll.

And A use method DoSomeWork in assembly B, and I rename the DoSomeWork to XY in Assembly B,

how do I fix call DoSomeWork in Assembly A ?



Best Regards,

Fakhru Rahman



Jan 4, 2010 at 4:24 PM

Any time that you change the public surface area of an assembly, for instance by changing the name of a public type, you'll have to fix up all of the client assemblies as well. In general, you cannot do that, so obfuscators have to leave the names of public types and type members alone.

When you can do that, you'd have to rewrite Assembly A and change every reference to DoSomeWork into a reference to XY.

One way to make life simpler, is to first merge all of your assemblies into one assembly, for instance by using ILMerge. Then you can make every type internal and obfuscate to your hearts content.

Jan 4, 2010 at 4:34 PM

"When you can do that, you'd have to rewrite Assembly A and change every reference to DoSomeWork into a reference to XY."


In where CCI for holding MemberReference to other assembly ?

So I can fix the reference, for above scenario ?



I'm sorry if my question didn't quite clear, English is not my daily langguage, :P.

Jan 4, 2010 at 5:37 PM

All references to types and members from other assemblies are represented as reference objects of various types. In this particular instance, you'd need to override the Visit(MethodReference) method in the mutator that rewrites Assembly A and update the Name property of the reference when appropriate.

Jan 5, 2010 at 9:19 AM

I'm sorry, after reading the example, I still don't know how to archive simple renaming with CCI.

Can you please give me small code example for that ?


* Out of topic *

Do you know how value of Type.GUID being constructed, example when calling  typeof([SomeClass]).GUID will output GUID for that type.