Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[DNLib] Method is not defined in this Module

Featured Replies

Posted

If i try to insert a call after a Instruction im getting a Method is not defined in this Module Exception

using dnlib.DotNet;
using dnlib.DotNet.Emit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace LeafObfuscator.Protection
{
    //TODO: Fix
    class Int32
    {
        public static void encode(ModuleDefMD md)
        {
            Inject.injectmethods(md,Int(md));

            foreach (TypeDef type in md.Types)
            {
                foreach (MethodDef method in type.Methods)
                {
                    CilBody body = method.Body;
                    if (!method.HasBody) { continue; }
                    for (int i = 0; i < body.Instructions.Count; i++)
                    {
                        if (method.Name != "dec")
                        {
                            if (body.Instructions[i].OpCode == OpCodes.Ldc_I4)
                            {

                                body.Instructions[i].Operand = Convert.ToInt32(body.Instructions[i].Operand) - 10;
                                body.Instructions.Insert(i + 1, Instruction.Create(OpCodes.Call, Int(md)));

                            }
                        }
                    }
                }
            }
        }

        private static MethodDef Int(ModuleDefMD md)
        {
            MethodImplAttributes methImplFlags = MethodImplAttributes.IL | MethodImplAttributes.Managed;
            MethodAttributes methFlags = MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.HideBySig | MethodAttributes.ReuseSlot;

            MethodDef inthider = new MethodDefUser("dec",
                        MethodSig.CreateStatic(md.CorLibTypes.Int32, md.CorLibTypes.Int32),
            methImplFlags, methFlags);
            CilBody body = new CilBody();
            inthider.Body = body;

            body.Instructions.Add(Instruction.Create(OpCodes.Ldc_I4, 10));
            body.Instructions.Add(Instruction.Create(OpCodes.Ldarg_0));
            body.Instructions.Add(Instruction.Create(OpCodes.Add));
            body.Instructions.Add(Instruction.Create(OpCodes.Ret));
            return inthider;
        }

    }
}
using dnlib.DotNet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LeafObfuscator.Protection
{
//Injecter
    class Inject
    {
    
    public static MethodDef injectmethods(ModuleDefMD md, MethodDef method)
    {
        foreach (TypeDef type in md.Types)
        {
            if (type.Name == "<Module>")
            {
                MethodDef decmethod = method;
                type.Methods.Add(decmethod);
                return decmethod;
            }
        }
        throw new Exception("failed");
    }
}
}

 

Edited by Leafy

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.