1

在以前版本的 .NET Reflector 中,我能够在函数中获取指令的命名空间,但现在我不能,而且该文档不存在。

Red Gate 的 .NET Reflector 6.8.2.5(最后一个免费版本)

这条线工作但现在不行:指令.Value.declaringtype.namespace.ToString

如何获取指令的命名空间?

谢谢

Private Sub DesassamblerDLL(ByVal strDLLFile As String)
    Dim serviceProvider As New Reflector.ApplicationManager(Nothing)
    Dim assemblyManager As Reflector.CodeModel.IAssemblyManager
    Dim objAssembly As Reflector.CodeModel.IAssembly
    Dim objMod As Reflector.CodeModel.IModule
    Dim typeDeclaration As Reflector.CodeModel.ITypeDeclaration
    Dim methodDeclaration As Reflector.CodeModel.IMethodDeclaration

    assemblyManager = serviceProvider.GetService(GetType(Reflector.CodeModel.IAssemblyManager))
    objAssembly = assemblyManager.LoadFile(strDLLFile)

    For Each objMod In objAssembly.Modules
        For Each typeDeclaration In objMod.Types
            For Each methodDeclaration In typeDeclaration.Methods
                Dim methodBody As Reflector.CodeModel.IMethodBody = methodDeclaration.Body
                If Not methodBody Is Nothing Then
                    Dim instruction As Reflector.CodeModel.IInstruction
                    For Each instruction In methodBody.Instructions
                        str = instruction.Value.declaringtype.namespace.ToString
                    Next
                End If
            Next
        Next
    Next
End Sub
4

1 回答 1

0

我在 Clive 的帮助下从http://forums.reflector.net/questions/2226/namespace-of-an-instruction-net-reflector做到了。

Imports system.Reflection.Emit

Select Case instruction.Code
    Case OpCodes.Call.Value, OpCodes.Calli.Value, OpCodes.Callvirt.Value
        Dim targetMethodReference As Reflector.CodeModel.IMethodReference = instruction.Value
        Dim method As Reflector.CodeModel.IMethodDeclaration = targetMethodReference.Resolve
        Dim typeReference As Reflector.CodeModel.ITypeReference = method.DeclaringType
        ...
End Select
于 2012-04-18T13:11:25.933 回答