我是本地人吗?在运行时查询 [英] Im running native? query at runtime

查看:77
本文介绍了我是本地人吗?在运行时查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何准确的方法来确定程序集(实际上是当前的流程/程序集)是否正在运行GACed/MSIL或本机?

我已经使用fuslogvw.exe实用程序成功测试了一些程序集,并且可以手动确定运行的程序是否从本机映像加载,但是我希望能够在runtine上确定.
到目前为止,我已经测试了一些方法,但是似乎没有一个有效.

1)clrjit.dl l模块的存在已加载...错误,总是已加载,本机或已加盖.

2)已加载mscorjit.dll模块的存在...错误,从不加载或至少不作为过程模块的一部分

3)如果Reflection.Assembly.GetExecutingAssembly.GlobalAssemblyCache是错误的,因为它表明组件是否在GAC中,但不是它的本机...或者至少不是,它总是对我返回false.


Is there any accurate way to determine if an assembly (actually, the current process/assembly) is running GACed/MSIL or Native ?

I have successfully tested a few assemblies with the fuslogvw.exe utility, and I can determine manually if the running program was loaded from a native image or not, but I want to be able to determine that at runtine.

So far, I have tested a few approaches, but none of them seems to be valid.

1) Existence of the clrjit.dll module Loaded... wrong, it''s ALWAYS loaded, native or gaced.

2) Existence of the mscorjit.dll module loaded... wrong, its NEVER loaded, or at least, not as a part of the process modules

3) If Reflection.Assembly.GetExecutingAssembly.GlobalAssemblyCache , wrong, as it tells if the assemly is in the GAC, but not if its native or not... or at least, its always returning false on me.


Has anyone else got any approach with success on this?

推荐答案

好像没有人知道一个优雅或准确的解决方案,但是我想出了一种方法,可能并不明亮,但至少看起来是准确的.我决定与所有人分享.

根据我的研究,.ni会部分识别.NET本机映像.名称,因此,System.Forms.dll具有System.Forms.ni.dll本机映像,然后MyApplication.exe具有MyApplication.ni.exe本机映像(如果存在).

另外,给我们另一个提示,我们知道所有本地映像都位于%windir%下的程序集目录中.

现在,我们可以查询应用程序加载的所有模块,并查看其中一个模块是否为我们的本机文件"应用程序名称.

Looks like no one knows of an elegant or accurate solution, but i have come with an approach, that might not be bright, but at least seems to be accurate, somehow. and i decided to share it with everyone.

According to my researches, .NET native images are identified, in a partial way, by the .ni. name, so, System.Forms.dll has a System.Forms.ni.dll native image, and then, MyApplication.exe has an MyApplication.ni.exe native image, if exist.

Also, to give us another hint, we know that all native images are located on the assembly directory under the %windir%.

Now, we can just query all the modules loaded by our application, and see if one of them is "our native file" application name.

Dim ImNative As Boolean = False
Dim MyFile As String = IO.Path.GetFileName(Application.ExecutablePath).ToLower.Replace(".exe", ".ni.exe").Trim
For Each m As ProcessModule In Process.GetCurrentProcess.Modules
  If MyFile.ToLower = IO.Path.GetFileName(m.FileName).ToLower AndAlso m.FileName.ToLower.Contains("\assembly\nativeimages") Then
    ImNative = True : Exit For
  End If
Next

If ImNative Then Msgbox("Yes, you are running a native image of this assembly.")


这篇关于我是本地人吗?在运行时查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆