Skip to content
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

CIL View: 64-bit process support #58

Open
1 of 3 tasks
MSDN-WhiteKnight opened this issue Mar 4, 2021 · 0 comments
Open
1 of 3 tasks

CIL View: 64-bit process support #58

MSDN-WhiteKnight opened this issue Mar 4, 2021 · 0 comments

Comments

@MSDN-WhiteKnight
Copy link
Owner

MSDN-WhiteKnight commented Mar 4, 2021

  • Step 1: Fetch 64-bit process modules using WMI, open modules as files
  • Step 2: Create separate 64-bit process using ClrMD to fetch modules
  • Step 3: Make separate process fetch all information (dynamic methods, threads)

Fetching modules using WMI

string[] GetProcessModules(int id)
{
        List<string> res = new List<string>();
        
        string query = "references of {win32_process.Handle="+id.ToString()+
            "} WHERE ResultClass = CIM_ProcessExecutable";
        
        using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query))
        using (ManagementObjectCollection results = searcher.Get())
        {
            foreach (ManagementObject x in results)
            {
                var antecedent = new ManagementObject((string)x["Antecedent"]);
                if (antecedent["Name"] == null) continue;
                string name = antecedent["Name"].ToString();
                res.Add(name);
            }
        }            

        return res.ToArray();
}

In .NET 3.5, every managed module has corresponding .ni.dll native module loaded via LoadLibrary. In .NET 4.0 and newer, some modules might be memory-mapped rather then loaded from native image file.

Fetching modules using ClrMD

Version 1.1.142101+

StringBuilder sb = new StringBuilder(1000);
using (DataTarget dt = DataTarget.AttachToProcess(8036, false))
{
            ClrInfo ci = dt.ClrVersions[0];
            ClrRuntime clr = ci.CreateRuntime();

            foreach (ClrModule module in clr.EnumerateModules())
            {
                if (module.IsPEFile) sb.AppendLine(module.Name);
            }
 }
MSDN-WhiteKnight added a commit that referenced this issue Mar 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant