Friday, 13 September 2013

Injecting a class and wrapping a function around strings with Mono.Cecil

Injecting a class and wrapping a function around strings with Mono.Cecil

I'm attempting to make an obfuscator and so far it's going well, right now
I'm trying to encode strings with base64 and then rot13 that just to make
it an extra bit unreadable and hide my sooper sekret strings.
This is what I have for encoding the strings on the obfuscator:
ILProcessor processor = method.Body.GetILProcessor();
foreach (Instruction instruction in processor.Body.Instructions)
{
if (instruction.OpCode == OpCodes.Ldstr)
{
instruction.Operand =
Enc.to64(Enc.Rot((String)instruction.Operand, 0x0D)); //0x0D = 13
}
}
So now what I need to do is inject my Enc class into the root namespace
and since the functions are static I'll be able to use them without
creating an instance of the class. Then what I'll need to do is wrap each
string in two of the functions in Enc to decode the string when the
program is actually used, making
string lel = "topkek";
into
string lel = Enc.from64(Enc.Rot((String)instruction.Operand, 0x0D));
I know how to do neither of these things, so there's where I need your help.
So to recap I need to know how to inject a class (with static functions)
into the root namespace and then wrap all strings in the program with two
functions from said class so that it's unreadable when reflected but
decoded when used.

No comments:

Post a Comment