gpt4 book ai didi

c# - 如何使用 MDbg 以编程方式枚举正在运行的 .NET 进程中的类型?

转载 作者:行者123 更新时间:2023-11-30 18:44:31 30 4
gpt4 key购买 nike

我想打印出在运行的 .NET 进程中加载​​的所有不同类型的列表。我的计划是最终基于此构建一个 GUI 应用程序,因此我想通过我的代码而不是第三方工具来执行此操作。我认为我最好的选择是使用 MDbgCore 附加到正在运行的进程,然后使用 MDbgProcess.AppDomains 获取 CorAppDomain 对象,并尝试向下遍历对象模型。

但是,我终生无法停止其他进程并查看任何 AppDomain。我一直在使用如下代码(我基于 Mike Stall's blog 中的代码)

    [MTAThread] // MDbg is MTA threaded
static void Main(string[] args)
{
MDbgEngine debugger = new MDbgEngine();

debugger.Options.StopOnModuleLoad = true;

// Launch the debuggee.
int pid = Process.GetProcessesByName("VS2010Playground")[0].Id;
MDbgProcess proc = debugger.Attach(pid);
if (proc.IsAlive)
{
proc.AsyncStop().WaitOne();

Console.WriteLine(proc.AppDomains.Count);
if (proc.AppDomains.Count > 0)
{
Console.WriteLine(proc.AppDomains[0].CorAppDomain);
}
}

Console.WriteLine("Done!");
}

这打印:

MDbgPlayground.exe
0
Done!

我已经尝试过各种风格的 debugger.Options.Stop*。我想过遍历所有方法并在所有方法上设置断点,但我也无法遍历模块列表。我已经尝试过 debugger.Options.Trace,但这是与使用 TraceListeners 跟踪 MDbg 的执行有关,而不是跟踪目标应用程序。

我在 Release模式下运行我的 noddy 调试器应用程序,在 Debug模式下运行目标。我正在使用 Visual C# 2010,但我已经束手无策了。任何人都可以阐明这一点吗?

最佳答案

只是做一些修补,尝试这样的事情(您可能需要根据需要进行修改)...

        foreach (Process process in Process.GetProcesses())
{
try
{
Assembly test = Assembly.LoadFrom(process.MainModule.FileName);
Console.WriteLine(test.FullName);

foreach (Type type in test.GetTypes())
Console.WriteLine(type.FullName);
}
catch
{
continue;
}
}

关于c# - 如何使用 MDbg 以编程方式枚举正在运行的 .NET 进程中的类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2733038/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com