Ethernal_Five

[C#] Mono.Cecil Randomize Variables

Mar 11th, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1.     private void ObfuscateCode(string file)
  2.     {
  3.         AssemblyDefinition ASM = AssemblyDefinition.ReadAssembly(file);
  4.         ModuleDefinition MainModule = ASM.MainModule;
  5.         foreach (TypeDefinition T in MainModule.Types)
  6.         {
  7.             T.Name = RandomKey(30);
  8.             foreach (PropertyDefinition P in T.Properties)
  9.             {
  10.                 P.Name = RandomKey(30);
  11.             }
  12.             foreach (FieldDefinition F in T.Fields)
  13.             {
  14.                 F.Name = RandomKey(30);
  15.             }
  16.             if (T.Namespace.Contains(".My") == false)
  17.             {
  18.                 foreach (MethodDefinition M in T.Methods)
  19.                 {
  20.                     if (M.IsConstructor == false)
  21.                     {
  22.                         if (M.IsPInvokeImpl == false)
  23.                         {
  24.                             M.Name = RandomKey(30);
  25.                         }
  26.                     }
  27.                     foreach (ParameterDefinition Param in M.Parameters)
  28.                     {
  29.                         Param.Name = RandomKey(30);
  30.                     }
  31.                 }
  32.             }
  33.         }
  34.         ASM.Write("C:\\Output.exe");
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment