GithubHelp home page GithubHelp logo

Comments (4)

gitlsl avatar gitlsl commented on August 24, 2024 1

It work fine now, thank you, We can do more something magical

from jitex.

Hitmasu avatar Hitmasu commented on August 24, 2024

That's because GetManifestResourceStream is a R2R method and called before even Jitex load.

Normally, that can be resolved in this way:

MethodHelper.DisableR2R(method);
MethodHelper.ForceRecompile(method);

However, ForceRecompile did not worked for this method...

I'll open a bug and try to fix it.

from jitex.

Hitmasu avatar Hitmasu commented on August 24, 2024

"Fixed" on version 6.4.2.

However, GetManifestResourceStream is used internally on Jitex and as i said before, GetManifestResourceStream is a ReadyToRun method and called before Jitex load. To intercept him, you need prepare InterceptCall (intercepting any method before GetManifestResourceStream), disable ReadyToRun and force recompile on next call.

Below, you can see a example how to intercept, get and change parameter value:

//Get RuntimeAssembly.GetManifestResourceStream(string)
MethodInfo method = Type.GetType("System.Reflection.RuntimeAssembly")
    .GetMethods(BindingFlags.Public | BindingFlags.Instance).Where(w => w.Name == "GetManifestResourceStream").ElementAt(1);

JitexManager.MethodResolver += context =>
{
    if (context.Method == method || context.Method.Name.Contains(nameof(MethodStubIntercept)))
        context.InterceptCall();
};

JitexManager.Interceptor += async context =>
{
    //Just ignore our MethodStubIntercept
    if (context.Method.Name.Contains(nameof(MethodStubIntercept)))
        return;

    string resourceName = context.GetParameterValue<string>(0);
    Console.WriteLine("Resource name: " + resourceName); //show parameter value
    context.SetParameterValue(0, "app.manifest"); //Change parameter value from "---" to "app.manifest"
};

//Just to prepare InterceptCall
MethodStubIntercept();

MethodHelper.DisableReadyToRun(method); //Disable ReadyToRun on method
MethodHelper.ForceRecompile(method); //Force recompile

Assembly.GetExecutingAssembly().GetManifestResourceStream("----"); //returns GetManifestResourceStream("app.manifest") 

[MethodImpl(MethodImplOptions.NoInlining)]
static void MethodStubIntercept() { }

In most of cases, you don't need to prepare InterceptCall, however in this case, you need to do that.

Let me know if works for you.

from jitex.

Hitmasu avatar Hitmasu commented on August 24, 2024

Just a adjusment on my response.

If you don't need intercept call, you can do just this:

//Get RuntimeAssembly.GetManifestResourceStream(string)
MethodInfo method = Type.GetType("System.Reflection.RuntimeAssembly")
    .GetMethods(BindingFlags.Public | BindingFlags.Instance).Where(w => w.Name == "GetManifestResourceStream").ElementAt(1);

JitexManager.MethodResolver += context =>
{
    Console.WriteLine(context.Method.Name);
};

MethodStubIntercept();

MethodHelper.DisableReadyToRun(method); //Disable ReadyToRun on method
MethodHelper.ForceRecompile(method); //Force recompile

Assembly.GetExecutingAssembly().GetManifestResourceStream("----");

[MethodImpl(MethodImplOptions.NoInlining)]
static void MethodStubIntercept() { }

from jitex.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.