public void Execute(PandaState pandaState, PandaContext pandaContext)
        {
            CFHelper cFHelper = new CFHelper();

            foreach (TypeDef type in pandaContext.moduleDef.Types)
            {
                foreach (MethodDef method in type.Methods)
                {
                    if (method.HasBody && method.Body.Instructions.Count > 0 && !method.IsConstructor)
                    {
                        if (!cFHelper.HasUnsafeInstructions(method))
                        {
                            if (DnlibUtils.Simplify(method))
                            {
                                Blocks blocks = cFHelper.GetBlocks(method);
                                if (blocks.blocks.Count != 1)
                                {
                                    switch (pandaState)
                                    {
                                    case PandaState.Basic:
                                        toDoSwitcher(cFHelper, method, blocks, pandaContext);
                                        break;

                                    case PandaState.Normal:
                                        toDoBody(cFHelper, method, blocks, pandaContext);
                                        break;
                                    }
                                }
                                DnlibUtils.Optimize(method);
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
 public void Encoding(PandaContext pandaContext)
 {
     foreach (TypeDef type in pandaContext.moduleDef.Types)
     {
         foreach (MethodDef method in type.Methods)
         {
             if (method.Body == null)
             {
                 continue;
             }
             for (int i = 0; i < method.Body.Instructions.Count(); i++)
             {
                 if (method.Body.Instructions[i].OpCode == OpCodes.Ldstr)
                 {
                     String oldString = method.Body.Instructions[i].Operand.ToString();
                     String newString = Convert.ToBase64String(UTF8Encoding.UTF8.GetBytes(oldString));
                     method.Body.Instructions[i].OpCode = OpCodes.Nop;
                     method.Body.Instructions.Insert(i + 1, new Instruction(OpCodes.Call, pandaContext.moduleDef.Import(typeof(System.Text.Encoding).GetMethod("get_UTF8", new Type[] { }))));
                     method.Body.Instructions.Insert(i + 2, new Instruction(OpCodes.Ldstr, newString));
                     method.Body.Instructions.Insert(i + 3, new Instruction(OpCodes.Call, pandaContext.moduleDef.Import(typeof(System.Convert).GetMethod("FromBase64String", new Type[] { typeof(string) }))));
                     method.Body.Instructions.Insert(i + 4, new Instruction(OpCodes.Callvirt, pandaContext.moduleDef.Import(typeof(System.Text.Encoding).GetMethod("GetString", new Type[] { typeof(byte[]) }))));
                     i += 4;
                 }
             }
             DnlibUtils.Optimize(method);
         }
     }
 }