Hitmasu / Jitex

A library to modify MSIL and native code at runtime
MIT License
120 stars 15 forks source link

Hook Encoding.GetString #104

Open chinasmu opened 6 months ago

chinasmu commented 6 months ago

I want to hook the two methods of System.Text.Encoding.

public virtual string GetString(byte[] bytes) public virtual string GetString(byte[] bytes, int index, int count)

        JitexManager.MethodResolver += context =>
        {
            Trace.WriteLine($"{context.Method.DeclaringType.Name} {context.Method.Name}" );
        };

There is no output of the two methods. And I try to do the following:

        var methods = Type.GetType("System.Text.Encoding").GetMethods().Where(w => w.Name == "GetString");
        foreach (var method in methods)
        {
            MethodHelper.ForceRecompile(method); //Force recompile
        }

And the app just crashes.

Could you pls show me a good example? Thank you!