-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
can not catch Assembly.GetCallingAssembly().GetManifestResourceStream() #78
Comments
That's because GetManifestResourceStream is a R2R method and called before even Jitex load. Normally, that can be resolved in this way:
However, ForceRecompile did not worked for this method... I'll open a bug and try to fix it. |
"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. |
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() { } |
It work fine now, thank you, We can do more something magical |
I use latest 6.4.1 .net core is 6.0
I want to Interceptor GetManifestResourceStream return my Stream
but result is
are there something I got miss? waiting for your help
The text was updated successfully, but these errors were encountered: