Ejemplo n.º 1
0
        private static void DecryptMethods(MethodDef methodDef, MethodBase invokeMethod, object fieldInstance)
        {
            var instructions = methodDef.Body.Instructions;

            if (instructions.Count < 9)
            {
                return;
            }
            if (instructions[0].OpCode != OpCodes.Ldsfld)
            {
                return;
            }
            if (((FieldDef)instructions[0].Operand).FullName != "i <Module>::Invoke")
            {
                return;
            }

            ToRemove.Add(instructions[3].Operand);

            int index = instructions[1].GetLdcI4Value();

            var dynamicMethodBodyReader = new DynamicMethodBodyReader(methodDef.Module, invokeMethod.Invoke(fieldInstance, new object[] { index }));

            dynamicMethodBodyReader.Read();

            methodDef.FreeMethodBody();
            methodDef.Body = dynamicMethodBodyReader.GetMethod().Body;
        }
Ejemplo n.º 2
0
 //TODO: Move this method
 public static void FreeMethodBody(MethodDef method)
 {
     if (method != null) {
         if (!MethodAnnotations.Instance.IsBodyModified(method))
             method.FreeMethodBody();
     }
 }
Ejemplo n.º 3
0
        void IndexCil(MethodDef md)
        {
            var mid  = (int)md.MDToken.Raw;
            var mcil = ExtractCil(md);

            Claim.yea(CilIndex.TryAdd(mid, mcil));
            md.FreeMethodBody();
        }
Ejemplo n.º 4
0
 //TODO: Move this method
 public static void FreeMethodBody(MethodDef method)
 {
     if (method != null)
     {
         if (!MethodAnnotations.Instance.IsBodyModified(method))
         {
             method.FreeMethodBody();
         }
     }
 }
 internal void WriteMethod(MethodDef oldMethodDef, MethodDef newMethodDef)
 {
     if (oldMethodDef == null)
     {
         Console.WriteLine("[!] Failed to write " + newMethodDef);
         return;
     }
     oldMethodDef.FreeMethodBody();
     oldMethodDef.Body = newMethodDef.Body;
 }
Ejemplo n.º 6
0
    internal void WriteMethod(MethodDef methodDef)
    {
        MethodDef executingMethod = Script.currentMethod;

        if (executingMethod == null)
        {
            Console.WriteLine("[!] Failed to write " + methodDef);
            return;
        }
        Script.currentMethod = null;
        executingMethod.FreeMethodBody();
        executingMethod.Body = methodDef.Body;
    }
Ejemplo n.º 7
0
        internal void WriteMethod(MethodDef methodDef)
        {
            MethodDef method = Program._executingMethod;

            if (method == null)
            {
                Console.WriteLine("Failed to write " + methodDef);
                return;
            }

            Program._executingMethod = null;

            method.FreeMethodBody();
            method.Body = methodDef.Body;
        }
Ejemplo n.º 8
0
        private static void DecryptMethods(MethodDef methodDef, MethodBase invokeMethod, object fieldInstance)
        {
            if (!methodDef.HasBody)
            {
                return;
            }

            var instructions = methodDef.Body.Instructions;

            if (instructions.Count > 2 &&
                instructions[0].OpCode.Code == Code.Ldsfld &&
                instructions[0].Operand.ToString().Contains("Invoke") &&
                instructions[1].IsLdcI4())
            {
                try
                {
                    var mdToken = ((IType)methodDef.Body.Instructions[3].Operand).MDToken.ToInt32();
                    JunkTypes.Add(methodDef.DeclaringType.NestedTypes.FirstOrDefault(net => net.MDToken.ToInt32() == mdToken));

                    Hooks.MethodBase = Assembly.ManifestModule.ResolveMethod(methodDef.MDToken.ToInt32());

                    var index  = instructions[1].GetLdcI4Value();
                    var method = invokeMethod.Invoke(fieldInstance, new object[] { index });

                    var reader = new DynamicMethodBodyReader(Module, method);
                    reader.Read();

                    methodDef.FreeMethodBody();
                    methodDef.Body = reader.GetMethod().Body;
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error: {ex.Message}{Environment.NewLine}Method: {methodDef.FullName}{Environment.NewLine}MDToken: 0x{methodDef.MDToken}{Environment.NewLine}");
                }
            }
        }