Jump to content
Tuts 4 You
Sign in to follow this  
Kaidoz

dnLib Inject MethodDef in TypeDef

Rate this topic

Recommended Posts

Kaidoz

Hey everyone. I try inject Method in TypeDef, but i cant do. Maybe anybody help me?
My code:
 

        try
        {
            ModuleDefMD typeModule = ModuleDefMD.Load(typeof(Encrypt).Module);
            var mthDef = typeModule.ResolveMethod(MDToken.ToRID(typeof(Encrypt).GetMethods().Where(x => x.Name == "EncryptOrDecrypt").First().MetadataToken));
            foreach (var d in module.Types)
                if (d.HasMethods)
                {
                    d.Methods.Add(mthDef);
                }


            foreach (MethodDef md in module.GlobalType.Methods)
            {
                if (md.Name == ".ctor")
                {
                    module.GlobalType.Remove(md);
                    break;
                }
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...