-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
103 lines (90 loc) · 4.03 KB
/
Program.cs
File metadata and controls
103 lines (90 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System;
using System.Reflection;
namespace EcmaResearchTool
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Welcome to the ECMA Research Tool...");
// loads all the dlls from a given folder and identifies the management agent
if (args.Length != 1)
{
Console.WriteLine("No dll folder path specified as argument. Quitting.");
return;
}
// load each dll into memory
List<Assembly> assemblies = new List<Assembly>();
foreach (var dll in Directory.GetFiles(args[0]))
assemblies.Add(Assembly.LoadFrom(dll));
// enumerate the assemblies and find which one is the ECMA 2.x management agent
// and which one contains the MIM libraries
Assembly managementAgentAssembly = null;
Assembly metaDirectoryAssembly = null;
Type[] managementAgentInterfaces = null;
Type managementAgentType = null;
List<string> ecmaInterfaces = new List<string>()
{
"IMAExtensible2CallExport",
"IMAExtensible2CallImport",
"IMAExtensible2FileExport",
"IMAExtensible2FileImport",
"IMAExtensible2GetCapabilities",
"IMAExtensible2GetCapabilitiesEx",
"IMAExtensible2GetHierarchy",
"IMAExtensible2GetParameters",
"IMAExtensible2GetParametersEx",
"IMAExtensible2GetPartitions",
"IMAExtensible2GetSchema",
"IMAExtensible2Password"
};
foreach (var assembly in assemblies)
{
if (assembly.ExportedTypes.Any(q => q.Namespace == "Microsoft.MetadirectoryServices"))
{
metaDirectoryAssembly = assembly;
Console.WriteLine($"Found the library: {assembly.FullName}");
}
foreach (var type in assembly.ExportedTypes)
{
var typeInterfaces = type.GetInterfaces();
if (typeInterfaces.Any(i => ecmaInterfaces.Contains(i.Name)))
{
managementAgentInterfaces = typeInterfaces;
managementAgentAssembly = assembly;
managementAgentType = type;
Console.WriteLine($"Found the Management Agent dll: {assembly.FullName}");
Console.WriteLine($"The Management Agent class is: {type.Name}");
Console.WriteLine("It implements the following ECMA interfaces:");
foreach (var implementedInterface in managementAgentInterfaces.Where(i => ecmaInterfaces.Contains(i.Name)))
Console.WriteLine($"\t{implementedInterface}");
break;
}
}
}
if (managementAgentAssembly == null || managementAgentInterfaces == null || managementAgentType == null)
{
Console.Error.WriteLine("No ECMA 2.0 Management Agent found in the folder! Exiting");
return;
}
if (metaDirectoryAssembly == null)
{
Console.Error.WriteLine("No Microsoft.MetadirectoryServices type found in folder dlls! Exiting");
return;
}
// now inspect management agent parameters
if (managementAgentInterfaces.Any(i => i.Name == "IMAExtensible2GetParametersEx"))
{
ManagementAgentParametersEx.Get(managementAgentType, metaDirectoryAssembly);
}
if (managementAgentInterfaces.Any(i => i.Name == "IMAExtensible2GetParameters"))
{
ManagementAgentParameters.Get(managementAgentType, metaDirectoryAssembly);
}
return;
}
}
}