-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnalyzeAssembly.cs
70 lines (60 loc) · 2.29 KB
/
AnalyzeAssembly.cs
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
using System;
using System.Collections.Generic;
using System.Management.Automation;
using System.Text;
using System.Xml;
namespace Connect.AssemblyAnalyzer
{
[Cmdlet("Analyze", "Assembly")]
public class AnalyzeAssembly : PSCmdlet
{
[Parameter(Position = 0, Mandatory = true, HelpMessage = "Path to the assembly you want to decompile")]
[Alias("APath")]
[ValidateNotNullOrEmpty]
public string Assembly { get; set; }
[Parameter(Position = 1, Mandatory = true, HelpMessage = "Path to the original code of the assembly")]
[ValidateNotNullOrEmpty]
public string CodePath { get; set; }
[Parameter(Position = 2, Mandatory = true, HelpMessage = "Output path where to write the XML file")]
[ValidateNotNullOrEmpty]
public string OutPath { get; set; }
protected override void ProcessRecord()
{
if (!System.IO.File.Exists(Assembly))
{
WriteWarning("Can't find assembly " + Assembly);
return;
}
if (!System.IO.File.Exists(Assembly.Substring(0, Assembly.Length - 4) + ".pdb"))
{
WriteWarning("Can't find pdb file for " + Assembly);
return;
}
WriteVerbose("Processing ... ");
WriteVerbose("Assembly : " + Assembly);
WriteVerbose("Code : " + CodePath);
WriteVerbose("Output : " + OutPath);
XmlDocument doc = new XmlDocument();
doc.AppendChild(doc.CreateXmlDeclaration("1.0", "utf-8", "yes"));
XmlNode root = doc.CreateElement("root");
Common.AddAttribute(ref root, "file", System.IO.Path.GetFileName(Assembly));
doc.AppendChild(root);
DateTime startTime = DateTime.Now;
//try
//{
AssemblyReader assem = new AssemblyReader(Assembly, CodePath);
assem.WriteToDoc(ref root);
TimeSpan timeTaken = DateTime.Now.Subtract(startTime);
Common.AddAttribute(ref root, "generated", startTime.ToString("u"));
Common.AddAttribute(ref root, "generationTime", timeTaken.TotalSeconds.ToString());
string outFile = string.Format("{0}\\{1}_{2}.xml", OutPath, System.IO.Path.GetFileNameWithoutExtension(Assembly), assem.Assembly.Name.Version.ToVersionString());
doc.Save(outFile);
//}
//catch (Exception ex)
//{
// WriteVerbose(ex.Message);
// WriteVerbose(ex.StackTrace);
//}
}
}
}