Browse Source

#2516: Add ILSpy.AddIn.slnf, ILSpy.Wpf.slnf and ILSpy.XPlat.slnf; replaces Frontends.sln

pull/2523/head
Siegfried Pammer 4 years ago
parent
commit
d2b3abb276
  1. 44
      Frontends.sln
  2. 132
      ICSharpCode.Decompiler.Console/IlspyCmdProgram.cs
  3. 17
      ICSharpCode.Decompiler.Console/TypesParser.cs
  4. 6
      ICSharpCode.Decompiler.Console/ValidationAttributes.cs
  5. 27
      ICSharpCode.Decompiler.PowerShell/GetDecompiledProjectCmdlet.cs
  6. 15
      ICSharpCode.Decompiler.PowerShell/GetDecompiledSourceCmdlet.cs
  7. 11
      ICSharpCode.Decompiler.PowerShell/GetDecompiledTypesCmdlet.cs
  8. 8
      ICSharpCode.Decompiler.PowerShell/GetDecompilerCmdlet.cs
  9. 5
      ICSharpCode.Decompiler.PowerShell/GetDecompilerVersion.cs
  10. 17
      ICSharpCode.Decompiler.PowerShell/TypesParser.cs
  11. 18
      ILSpy.AddIn.slnf
  12. 17
      ILSpy.Wpf.slnf
  13. 11
      ILSpy.XPlat.slnf
  14. 12
      ILSpy.sln

44
Frontends.sln

@ -1,44 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2005
MinimumVisualStudioVersion = 15.0
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "doc", "doc", "{F45DB999-7E72-4000-B5AD-3A7B485A0896}"
ProjectSection(SolutionItems) = preProject
doc\Command Line.txt = doc\Command Line.txt
doc\ILAst.txt = doc\ILAst.txt
doc\IntPtr.txt = doc\IntPtr.txt
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ICSharpCode.Decompiler.Console", "ICSharpCode.Decompiler.Console\ICSharpCode.Decompiler.Console.csproj", "{8FDA011E-FAF8-4C1F-A695-21E2C6B5375F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ICSharpCode.Decompiler.PowerShell", "ICSharpCode.Decompiler.PowerShell\ICSharpCode.Decompiler.PowerShell.csproj", "{FF7D6041-3C52-47D1-A32A-0BFE8EE4EEEB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.Decompiler", "ICSharpCode.Decompiler\ICSharpCode.Decompiler.csproj", "{526B267D-1904-4E9E-80DB-BB2259ADCF6C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8FDA011E-FAF8-4C1F-A695-21E2C6B5375F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8FDA011E-FAF8-4C1F-A695-21E2C6B5375F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8FDA011E-FAF8-4C1F-A695-21E2C6B5375F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8FDA011E-FAF8-4C1F-A695-21E2C6B5375F}.Release|Any CPU.Build.0 = Release|Any CPU
{FF7D6041-3C52-47D1-A32A-0BFE8EE4EEEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FF7D6041-3C52-47D1-A32A-0BFE8EE4EEEB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF7D6041-3C52-47D1-A32A-0BFE8EE4EEEB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FF7D6041-3C52-47D1-A32A-0BFE8EE4EEEB}.Release|Any CPU.Build.0 = Release|Any CPU
{526B267D-1904-4E9E-80DB-BB2259ADCF6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{526B267D-1904-4E9E-80DB-BB2259ADCF6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{526B267D-1904-4E9E-80DB-BB2259ADCF6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{526B267D-1904-4E9E-80DB-BB2259ADCF6C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C764218F-7633-4412-923D-558CE7EE0560}
EndGlobalSection
EndGlobal

132
ICSharpCode.Decompiler.Console/IlspyCmdProgram.cs

@ -5,17 +5,19 @@ using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.IO.MemoryMappedFiles; using System.IO.MemoryMappedFiles;
using System.Linq; using System.Linq;
using McMaster.Extensions.CommandLineUtils;
using ICSharpCode.Decompiler.CSharp;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.Disassembler;
using System.Threading;
using System.Reflection.Metadata; using System.Reflection.Metadata;
using System.Reflection.PortableExecutable; using System.Reflection.PortableExecutable;
using System.Threading;
using ICSharpCode.Decompiler.CSharp;
using ICSharpCode.Decompiler.CSharp.ProjectDecompiler;
using ICSharpCode.Decompiler.DebugInfo; using ICSharpCode.Decompiler.DebugInfo;
using ICSharpCode.Decompiler.Disassembler;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.PdbProvider; using ICSharpCode.Decompiler.PdbProvider;
using ICSharpCode.Decompiler.CSharp.ProjectDecompiler; using ICSharpCode.Decompiler.TypeSystem;
using McMaster.Extensions.CommandLineUtils;
// ReSharper disable All // ReSharper disable All
namespace ICSharpCode.Decompiler.Console namespace ICSharpCode.Decompiler.Console
@ -86,45 +88,65 @@ Remarks:
TextWriter output = System.Console.Out; TextWriter output = System.Console.Out;
bool outputDirectorySpecified = !string.IsNullOrEmpty(OutputDirectory); bool outputDirectorySpecified = !string.IsNullOrEmpty(OutputDirectory);
try { try
if (CreateCompilableProjectFlag) { {
if (CreateCompilableProjectFlag)
{
return DecompileAsProject(InputAssemblyName, OutputDirectory); return DecompileAsProject(InputAssemblyName, OutputDirectory);
} else if (EntityTypes.Any()) { }
else if (EntityTypes.Any())
{
var values = EntityTypes.SelectMany(v => v.Split(',', ';')).ToArray(); var values = EntityTypes.SelectMany(v => v.Split(',', ';')).ToArray();
HashSet<TypeKind> kinds = TypesParser.ParseSelection(values); HashSet<TypeKind> kinds = TypesParser.ParseSelection(values);
if (outputDirectorySpecified) { if (outputDirectorySpecified)
{
string outputName = Path.GetFileNameWithoutExtension(InputAssemblyName); string outputName = Path.GetFileNameWithoutExtension(InputAssemblyName);
output = File.CreateText(Path.Combine(OutputDirectory, outputName) + ".list.txt"); output = File.CreateText(Path.Combine(OutputDirectory, outputName) + ".list.txt");
} }
return ListContent(InputAssemblyName, output, kinds); return ListContent(InputAssemblyName, output, kinds);
} else if (ShowILCodeFlag || ShowILSequencePointsFlag) { }
if (outputDirectorySpecified) { else if (ShowILCodeFlag || ShowILSequencePointsFlag)
{
if (outputDirectorySpecified)
{
string outputName = Path.GetFileNameWithoutExtension(InputAssemblyName); string outputName = Path.GetFileNameWithoutExtension(InputAssemblyName);
output = File.CreateText(Path.Combine(OutputDirectory, outputName) + ".il"); output = File.CreateText(Path.Combine(OutputDirectory, outputName) + ".il");
} }
return ShowIL(InputAssemblyName, output); return ShowIL(InputAssemblyName, output);
} else if (CreateDebugInfoFlag) { }
else if (CreateDebugInfoFlag)
{
string pdbFileName = null; string pdbFileName = null;
if (outputDirectorySpecified) { if (outputDirectorySpecified)
{
string outputName = Path.GetFileNameWithoutExtension(InputAssemblyName); string outputName = Path.GetFileNameWithoutExtension(InputAssemblyName);
pdbFileName = Path.Combine(OutputDirectory, outputName) + ".pdb"; pdbFileName = Path.Combine(OutputDirectory, outputName) + ".pdb";
} else { }
else
{
pdbFileName = Path.ChangeExtension(InputAssemblyName, ".pdb"); pdbFileName = Path.ChangeExtension(InputAssemblyName, ".pdb");
} }
return GeneratePdbForAssembly(InputAssemblyName, pdbFileName, app); return GeneratePdbForAssembly(InputAssemblyName, pdbFileName, app);
} else if (ShowVersion) { }
else if (ShowVersion)
{
string vInfo = "ilspycmd: " + typeof(ILSpyCmdProgram).Assembly.GetName().Version.ToString() + string vInfo = "ilspycmd: " + typeof(ILSpyCmdProgram).Assembly.GetName().Version.ToString() +
Environment.NewLine Environment.NewLine
+ "ICSharpCode.Decompiler: " + + "ICSharpCode.Decompiler: " +
typeof(FullTypeName).Assembly.GetName().Version.ToString(); typeof(FullTypeName).Assembly.GetName().Version.ToString();
output.WriteLine(vInfo); output.WriteLine(vInfo);
} else if (DumpPackageFlag) { }
else if (DumpPackageFlag)
{
return DumpPackageAssemblies(InputAssemblyName, OutputDirectory, app); return DumpPackageAssemblies(InputAssemblyName, OutputDirectory, app);
} else { }
if (outputDirectorySpecified) { else
{
if (outputDirectorySpecified)
{
string outputName = Path.GetFileNameWithoutExtension(InputAssemblyName); string outputName = Path.GetFileNameWithoutExtension(InputAssemblyName);
output = File.CreateText(Path.Combine(OutputDirectory, output = File.CreateText(Path.Combine(OutputDirectory,
(string.IsNullOrEmpty(TypeName) ? outputName : TypeName) + ".decompiled.cs")); (string.IsNullOrEmpty(TypeName) ? outputName : TypeName) + ".decompiled.cs"));
@ -132,10 +154,14 @@ Remarks:
return Decompile(InputAssemblyName, output, TypeName); return Decompile(InputAssemblyName, output, TypeName);
} }
} catch (Exception ex) { }
catch (Exception ex)
{
app.Error.WriteLine(ex.ToString()); app.Error.WriteLine(ex.ToString());
return ProgramExitCodes.EX_SOFTWARE; return ProgramExitCodes.EX_SOFTWARE;
} finally { }
finally
{
output.Close(); output.Close();
} }
@ -156,7 +182,8 @@ Remarks:
{ {
var module = new PEFile(assemblyFileName); var module = new PEFile(assemblyFileName);
var resolver = new UniversalAssemblyResolver(assemblyFileName, false, module.Reader.DetectTargetFrameworkId()); var resolver = new UniversalAssemblyResolver(assemblyFileName, false, module.Reader.DetectTargetFrameworkId());
foreach (var path in ReferencePaths) { foreach (var path in ReferencePaths)
{
resolver.AddSearchDirectory(path); resolver.AddSearchDirectory(path);
} }
return new CSharpDecompiler(assemblyFileName, resolver, GetSettings(module)) { return new CSharpDecompiler(assemblyFileName, resolver, GetSettings(module)) {
@ -168,7 +195,8 @@ Remarks:
{ {
CSharpDecompiler decompiler = GetDecompiler(assemblyFileName); CSharpDecompiler decompiler = GetDecompiler(assemblyFileName);
foreach (var type in decompiler.TypeSystem.MainModule.TypeDefinitions) { foreach (var type in decompiler.TypeSystem.MainModule.TypeDefinitions)
{
if (!kinds.Contains(type.Kind)) if (!kinds.Contains(type.Kind))
continue; continue;
output.WriteLine($"{type.Kind} {type.FullName}"); output.WriteLine($"{type.Kind} {type.FullName}");
@ -180,8 +208,7 @@ Remarks:
{ {
var module = new PEFile(assemblyFileName); var module = new PEFile(assemblyFileName);
output.WriteLine($"// IL code: {module.Name}"); output.WriteLine($"// IL code: {module.Name}");
var disassembler = new ReflectionDisassembler(new PlainTextOutput(output), CancellationToken.None) var disassembler = new ReflectionDisassembler(new PlainTextOutput(output), CancellationToken.None) {
{
DebugInfo = TryLoadPDB(module), DebugInfo = TryLoadPDB(module),
ShowSequencePoints = ShowILSequencePointsFlag, ShowSequencePoints = ShowILSequencePointsFlag,
}; };
@ -193,7 +220,8 @@ Remarks:
{ {
var module = new PEFile(assemblyFileName); var module = new PEFile(assemblyFileName);
var resolver = new UniversalAssemblyResolver(assemblyFileName, false, module.Reader.DetectTargetFrameworkId()); var resolver = new UniversalAssemblyResolver(assemblyFileName, false, module.Reader.DetectTargetFrameworkId());
foreach (var path in ReferencePaths) { foreach (var path in ReferencePaths)
{
resolver.AddSearchDirectory(path); resolver.AddSearchDirectory(path);
} }
var decompiler = new WholeProjectDecompiler(GetSettings(module), resolver, resolver, TryLoadPDB(module)); var decompiler = new WholeProjectDecompiler(GetSettings(module), resolver, resolver, TryLoadPDB(module));
@ -205,9 +233,12 @@ Remarks:
{ {
CSharpDecompiler decompiler = GetDecompiler(assemblyFileName); CSharpDecompiler decompiler = GetDecompiler(assemblyFileName);
if (typeName == null) { if (typeName == null)
{
output.Write(decompiler.DecompileWholeModuleAsString()); output.Write(decompiler.DecompileWholeModuleAsString());
} else { }
else
{
var name = new FullTypeName(typeName); var name = new FullTypeName(typeName);
output.Write(decompiler.DecompileTypeAsString(name)); output.Write(decompiler.DecompileTypeAsString(name));
} }
@ -221,12 +252,14 @@ Remarks:
PEStreamOptions.PrefetchEntireImage, PEStreamOptions.PrefetchEntireImage,
metadataOptions: MetadataReaderOptions.None); metadataOptions: MetadataReaderOptions.None);
if (!PortablePdbWriter.HasCodeViewDebugDirectoryEntry(module)) { if (!PortablePdbWriter.HasCodeViewDebugDirectoryEntry(module))
{
app.Error.WriteLine($"Cannot create PDB file for {assemblyFileName}, because it does not contain a PE Debug Directory Entry of type 'CodeView'."); app.Error.WriteLine($"Cannot create PDB file for {assemblyFileName}, because it does not contain a PE Debug Directory Entry of type 'CodeView'.");
return ProgramExitCodes.EX_DATAERR; return ProgramExitCodes.EX_DATAERR;
} }
using (FileStream stream = new FileStream(pdbFileName, FileMode.OpenOrCreate, FileAccess.Write)) { using (FileStream stream = new FileStream(pdbFileName, FileMode.OpenOrCreate, FileAccess.Write))
{
var decompiler = GetDecompiler(assemblyFileName); var decompiler = GetDecompiler(assemblyFileName);
PortablePdbWriter.WritePdb(module, decompiler, GetSettings(module), stream); PortablePdbWriter.WritePdb(module, decompiler, GetSettings(module), stream);
} }
@ -236,27 +269,36 @@ Remarks:
int DumpPackageAssemblies(string packageFileName, string outputDirectory, CommandLineApplication app) int DumpPackageAssemblies(string packageFileName, string outputDirectory, CommandLineApplication app)
{ {
using (var memoryMappedPackage = MemoryMappedFile.CreateFromFile(packageFileName, FileMode.Open, null, 0, MemoryMappedFileAccess.Read)) { using (var memoryMappedPackage = MemoryMappedFile.CreateFromFile(packageFileName, FileMode.Open, null, 0, MemoryMappedFileAccess.Read))
using (var packageView = memoryMappedPackage.CreateViewAccessor(0, 0, MemoryMappedFileAccess.Read)) { {
if (!SingleFileBundle.IsBundle(packageView, out long bundleHeaderOffset)) { using (var packageView = memoryMappedPackage.CreateViewAccessor(0, 0, MemoryMappedFileAccess.Read))
{
if (!SingleFileBundle.IsBundle(packageView, out long bundleHeaderOffset))
{
app.Error.WriteLine($"Cannot dump assembiles for {packageFileName}, because it is not a single file bundle."); app.Error.WriteLine($"Cannot dump assembiles for {packageFileName}, because it is not a single file bundle.");
return ProgramExitCodes.EX_DATAERR; return ProgramExitCodes.EX_DATAERR;
} }
var manifest = SingleFileBundle.ReadManifest(packageView, bundleHeaderOffset); var manifest = SingleFileBundle.ReadManifest(packageView, bundleHeaderOffset);
foreach (var entry in manifest.Entries) { foreach (var entry in manifest.Entries)
{
Stream contents; Stream contents;
if (entry.CompressedSize == 0) { if (entry.CompressedSize == 0)
{
contents = new UnmanagedMemoryStream(packageView.SafeMemoryMappedViewHandle, entry.Offset, entry.Size); contents = new UnmanagedMemoryStream(packageView.SafeMemoryMappedViewHandle, entry.Offset, entry.Size);
} else { }
else
{
Stream compressedStream = new UnmanagedMemoryStream(packageView.SafeMemoryMappedViewHandle, entry.Offset, entry.CompressedSize); Stream compressedStream = new UnmanagedMemoryStream(packageView.SafeMemoryMappedViewHandle, entry.Offset, entry.CompressedSize);
Stream decompressedStream = new MemoryStream((int)entry.Size); Stream decompressedStream = new MemoryStream((int)entry.Size);
using (var deflateStream = new DeflateStream(compressedStream, CompressionMode.Decompress)) { using (var deflateStream = new DeflateStream(compressedStream, CompressionMode.Decompress))
{
deflateStream.CopyTo(decompressedStream); deflateStream.CopyTo(decompressedStream);
} }
if (decompressedStream.Length != entry.Size) { if (decompressedStream.Length != entry.Size)
{
app.Error.WriteLine($"Corrupted single-file entry '${entry.RelativePath}'. Declared decompressed size '${entry.Size}' is not the same as actual decompressed size '${decompressedStream.Length}'."); app.Error.WriteLine($"Corrupted single-file entry '${entry.RelativePath}'. Declared decompressed size '${entry.Size}' is not the same as actual decompressed size '${decompressedStream.Length}'.");
return ProgramExitCodes.EX_DATAERR; return ProgramExitCodes.EX_DATAERR;
} }
@ -265,7 +307,8 @@ Remarks:
contents = decompressedStream; contents = decompressedStream;
} }
using (var fileStream = File.Create(Path.Combine(outputDirectory, entry.RelativePath))) { using (var fileStream = File.Create(Path.Combine(outputDirectory, entry.RelativePath)))
{
contents.CopyTo(fileStream); contents.CopyTo(fileStream);
} }
} }
@ -277,7 +320,8 @@ Remarks:
IDebugInfoProvider TryLoadPDB(PEFile module) IDebugInfoProvider TryLoadPDB(PEFile module)
{ {
if (InputPDBFile.IsSet) { if (InputPDBFile.IsSet)
{
if (InputPDBFile.Value == null) if (InputPDBFile.Value == null)
return DebugInfoUtils.LoadSymbols(module); return DebugInfoUtils.LoadSymbols(module);
return DebugInfoUtils.FromFile(module, InputPDBFile.Value); return DebugInfoUtils.FromFile(module, InputPDBFile.Value);

17
ICSharpCode.Decompiler.Console/TypesParser.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.Decompiler.Console namespace ICSharpCode.Decompiler.Console
@ -11,9 +12,12 @@ namespace ICSharpCode.Decompiler.Console
{ {
var possibleValues = new Dictionary<string, TypeKind>(StringComparer.OrdinalIgnoreCase) { ["class"] = TypeKind.Class, ["struct"] = TypeKind.Struct, ["interface"] = TypeKind.Interface, ["enum"] = TypeKind.Enum, ["delegate"] = TypeKind.Delegate }; var possibleValues = new Dictionary<string, TypeKind>(StringComparer.OrdinalIgnoreCase) { ["class"] = TypeKind.Class, ["struct"] = TypeKind.Struct, ["interface"] = TypeKind.Interface, ["enum"] = TypeKind.Enum, ["delegate"] = TypeKind.Delegate };
HashSet<TypeKind> kinds = new HashSet<TypeKind>(); HashSet<TypeKind> kinds = new HashSet<TypeKind>();
if (values.Length == 1 && !possibleValues.Keys.Any(v => values[0].StartsWith(v, StringComparison.OrdinalIgnoreCase))) { if (values.Length == 1 && !possibleValues.Keys.Any(v => values[0].StartsWith(v, StringComparison.OrdinalIgnoreCase)))
foreach (char ch in values[0]) { {
switch (ch) { foreach (char ch in values[0])
{
switch (ch)
{
case 'c': case 'c':
kinds.Add(TypeKind.Class); kinds.Add(TypeKind.Class);
break; break;
@ -31,8 +35,11 @@ namespace ICSharpCode.Decompiler.Console
break; break;
} }
} }
} else { }
foreach (var value in values) { else
{
foreach (var value in values)
{
string v = value; string v = value;
while (v.Length > 0 && !possibleValues.ContainsKey(v)) while (v.Length > 0 && !possibleValues.ContainsKey(v))
v = v.Remove(v.Length - 1); v = v.Remove(v.Length - 1);

6
ICSharpCode.Decompiler.Console/ValidationAttributes.cs

@ -13,8 +13,10 @@ namespace ICSharpCode.Decompiler.Console
protected override ValidationResult IsValid(object value, ValidationContext context) protected override ValidationResult IsValid(object value, ValidationContext context)
{ {
if (value is ILSpyCmdProgram obj) { if (value is ILSpyCmdProgram obj)
if (obj.CreateCompilableProjectFlag && string.IsNullOrEmpty(obj.OutputDirectory)) { {
if (obj.CreateCompilableProjectFlag && string.IsNullOrEmpty(obj.OutputDirectory))
{
return new ValidationResult("--project cannot be used unless --outputdir is also specified"); return new ValidationResult("--project cannot be used unless --outputdir is also specified");
} }
} }

27
ICSharpCode.Decompiler.PowerShell/GetDecompiledProjectCmdlet.cs

@ -4,6 +4,7 @@ using System.IO;
using System.Management.Automation; using System.Management.Automation;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using ICSharpCode.Decompiler.CSharp; using ICSharpCode.Decompiler.CSharp;
using ICSharpCode.Decompiler.CSharp.ProjectDecompiler; using ICSharpCode.Decompiler.CSharp.ProjectDecompiler;
using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.Metadata;
@ -29,7 +30,8 @@ namespace ICSharpCode.Decompiler.PowerShell
public void Report(DecompilationProgress value) public void Report(DecompilationProgress value)
{ {
lock (syncObject) { lock (syncObject)
{
completed++; completed++;
progress = new ProgressRecord(1, "Decompiling " + fileName, $"Completed {completed} of {value.TotalNumberOfFiles}: {value.Status}") { progress = new ProgressRecord(1, "Decompiling " + fileName, $"Completed {completed} of {value.TotalNumberOfFiles}: {value.Status}") {
PercentComplete = (int)(completed * 100.0 / value.TotalNumberOfFiles) PercentComplete = (int)(completed * 100.0 / value.TotalNumberOfFiles)
@ -40,28 +42,35 @@ namespace ICSharpCode.Decompiler.PowerShell
protected override void ProcessRecord() protected override void ProcessRecord()
{ {
string path = GetUnresolvedProviderPathFromPSPath(LiteralPath); string path = GetUnresolvedProviderPathFromPSPath(LiteralPath);
if (!Directory.Exists(path)) { if (!Directory.Exists(path))
{
WriteObject("Destination directory must exist prior to decompilation"); WriteObject("Destination directory must exist prior to decompilation");
return; return;
} }
try { try
{
var task = Task.Run(() => DoDecompile(path)); var task = Task.Run(() => DoDecompile(path));
int timeout = 100; int timeout = 100;
// Give the decompiler some time to spin up all threads // Give the decompiler some time to spin up all threads
Thread.Sleep(timeout); Thread.Sleep(timeout);
while (!task.IsCompleted) { while (!task.IsCompleted)
{
ProgressRecord progress; ProgressRecord progress;
lock (syncObject) { lock (syncObject)
{
progress = this.progress; progress = this.progress;
this.progress = null; this.progress = null;
} }
if (progress != null) { if (progress != null)
{
timeout = 100; timeout = 100;
WriteProgress(progress); WriteProgress(progress);
} else { }
else
{
Thread.Sleep(timeout); Thread.Sleep(timeout);
timeout = Math.Min(1000, timeout * 2); timeout = Math.Min(1000, timeout * 2);
} }
@ -70,7 +79,9 @@ namespace ICSharpCode.Decompiler.PowerShell
task.Wait(); task.Wait();
WriteProgress(new ProgressRecord(1, "Decompiling " + fileName, "Decompilation finished") { RecordType = ProgressRecordType.Completed }); WriteProgress(new ProgressRecord(1, "Decompiling " + fileName, "Decompilation finished") { RecordType = ProgressRecordType.Completed });
} catch (Exception e) { }
catch (Exception e)
{
WriteVerbose(e.ToString()); WriteVerbose(e.ToString());
WriteError(new ErrorRecord(e, ErrorIds.DecompilationFailed, ErrorCategory.OperationStopped, null)); WriteError(new ErrorRecord(e, ErrorIds.DecompilationFailed, ErrorCategory.OperationStopped, null));
} }

15
ICSharpCode.Decompiler.PowerShell/GetDecompiledSourceCmdlet.cs

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Management.Automation; using System.Management.Automation;
using System.Text; using System.Text;
using ICSharpCode.Decompiler.CSharp; using ICSharpCode.Decompiler.CSharp;
using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.TypeSystem;
@ -20,17 +21,23 @@ namespace ICSharpCode.Decompiler.PowerShell
protected override void ProcessRecord() protected override void ProcessRecord()
{ {
try { try
{
StringWriter output = new StringWriter(); StringWriter output = new StringWriter();
if (TypeName == null) { if (TypeName == null)
{
output.Write(Decompiler.DecompileWholeModuleAsString()); output.Write(Decompiler.DecompileWholeModuleAsString());
} else { }
else
{
var name = new FullTypeName(TypeName); var name = new FullTypeName(TypeName);
output.Write(Decompiler.DecompileTypeAsString(name)); output.Write(Decompiler.DecompileTypeAsString(name));
} }
WriteObject(output.ToString()); WriteObject(output.ToString());
} catch (Exception e) { }
catch (Exception e)
{
WriteVerbose(e.ToString()); WriteVerbose(e.ToString());
WriteError(new ErrorRecord(e, ErrorIds.DecompilationFailed, ErrorCategory.OperationStopped, null)); WriteError(new ErrorRecord(e, ErrorIds.DecompilationFailed, ErrorCategory.OperationStopped, null));
} }

11
ICSharpCode.Decompiler.PowerShell/GetDecompiledTypesCmdlet.cs

@ -4,6 +4,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Management.Automation; using System.Management.Automation;
using System.Text; using System.Text;
using ICSharpCode.Decompiler.CSharp; using ICSharpCode.Decompiler.CSharp;
using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.TypeSystem;
@ -23,16 +24,20 @@ namespace ICSharpCode.Decompiler.PowerShell
{ {
HashSet<TypeKind> kinds = TypesParser.ParseSelection(Types); HashSet<TypeKind> kinds = TypesParser.ParseSelection(Types);
try { try
{
List<ITypeDefinition> output = new List<ITypeDefinition>(); List<ITypeDefinition> output = new List<ITypeDefinition>();
foreach (var type in Decompiler.TypeSystem.MainModule.TypeDefinitions) { foreach (var type in Decompiler.TypeSystem.MainModule.TypeDefinitions)
{
if (!kinds.Contains(type.Kind)) if (!kinds.Contains(type.Kind))
continue; continue;
output.Add(type); output.Add(type);
} }
WriteObject(output.ToArray()); WriteObject(output.ToArray());
} catch (Exception e) { }
catch (Exception e)
{
WriteVerbose(e.ToString()); WriteVerbose(e.ToString());
WriteError(new ErrorRecord(e, ErrorIds.DecompilationFailed, ErrorCategory.OperationStopped, null)); WriteError(new ErrorRecord(e, ErrorIds.DecompilationFailed, ErrorCategory.OperationStopped, null));
} }

8
ICSharpCode.Decompiler.PowerShell/GetDecompilerCmdlet.cs

@ -4,6 +4,7 @@ using System.IO;
using System.Management.Automation; using System.Management.Automation;
using System.Reflection.PortableExecutable; using System.Reflection.PortableExecutable;
using System.Text; using System.Text;
using ICSharpCode.Decompiler.CSharp; using ICSharpCode.Decompiler.CSharp;
using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.PdbProvider; using ICSharpCode.Decompiler.PdbProvider;
@ -35,7 +36,8 @@ namespace ICSharpCode.Decompiler.PowerShell
{ {
string path = GetUnresolvedProviderPathFromPSPath(LiteralPath); string path = GetUnresolvedProviderPathFromPSPath(LiteralPath);
try { try
{
var module = new PEFile(LiteralPath, new FileStream(LiteralPath, FileMode.Open, FileAccess.Read), PEStreamOptions.Default); var module = new PEFile(LiteralPath, new FileStream(LiteralPath, FileMode.Open, FileAccess.Read), PEStreamOptions.Default);
var debugInfo = DebugInfoUtils.FromFile(module, PDBFilePath); var debugInfo = DebugInfoUtils.FromFile(module, PDBFilePath);
var decompiler = new CSharpDecompiler(path, new DecompilerSettings(LanguageVersion) { var decompiler = new CSharpDecompiler(path, new DecompilerSettings(LanguageVersion) {
@ -47,7 +49,9 @@ namespace ICSharpCode.Decompiler.PowerShell
}); });
decompiler.DebugInfoProvider = debugInfo; decompiler.DebugInfoProvider = debugInfo;
WriteObject(decompiler); WriteObject(decompiler);
} catch (Exception e) { }
catch (Exception e)
{
WriteVerbose(e.ToString()); WriteVerbose(e.ToString());
WriteError(new ErrorRecord(e, ErrorIds.AssemblyLoadFailed, ErrorCategory.OperationStopped, null)); WriteError(new ErrorRecord(e, ErrorIds.AssemblyLoadFailed, ErrorCategory.OperationStopped, null));
} }

5
ICSharpCode.Decompiler.PowerShell/GetDecompilerVersion.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Management.Automation; using System.Management.Automation;
using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.Decompiler.PowerShell namespace ICSharpCode.Decompiler.PowerShell
@ -8,8 +9,8 @@ namespace ICSharpCode.Decompiler.PowerShell
[OutputType(typeof(string))] [OutputType(typeof(string))]
public class GetDecompilerVersion : PSCmdlet public class GetDecompilerVersion : PSCmdlet
{ {
protected override void ProcessRecord() protected override void ProcessRecord()
{ {
WriteObject(typeof(FullTypeName).Assembly.GetName().Version.ToString()); WriteObject(typeof(FullTypeName).Assembly.GetName().Version.ToString());
} }
} }

17
ICSharpCode.Decompiler.PowerShell/TypesParser.cs

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.Decompiler.PowerShell namespace ICSharpCode.Decompiler.PowerShell
@ -12,9 +13,12 @@ namespace ICSharpCode.Decompiler.PowerShell
{ {
var possibleValues = new Dictionary<string, TypeKind>(StringComparer.OrdinalIgnoreCase) { ["class"] = TypeKind.Class, ["struct"] = TypeKind.Struct, ["interface"] = TypeKind.Interface, ["enum"] = TypeKind.Enum, ["delegate"] = TypeKind.Delegate }; var possibleValues = new Dictionary<string, TypeKind>(StringComparer.OrdinalIgnoreCase) { ["class"] = TypeKind.Class, ["struct"] = TypeKind.Struct, ["interface"] = TypeKind.Interface, ["enum"] = TypeKind.Enum, ["delegate"] = TypeKind.Delegate };
HashSet<TypeKind> kinds = new HashSet<TypeKind>(); HashSet<TypeKind> kinds = new HashSet<TypeKind>();
if (values.Length == 1 && !possibleValues.Keys.Any(v => values[0].StartsWith(v, StringComparison.OrdinalIgnoreCase))) { if (values.Length == 1 && !possibleValues.Keys.Any(v => values[0].StartsWith(v, StringComparison.OrdinalIgnoreCase)))
foreach (char ch in values[0]) { {
switch (ch) { foreach (char ch in values[0])
{
switch (ch)
{
case 'c': case 'c':
kinds.Add(TypeKind.Class); kinds.Add(TypeKind.Class);
break; break;
@ -32,8 +36,11 @@ namespace ICSharpCode.Decompiler.PowerShell
break; break;
} }
} }
} else { }
foreach (var value in values) { else
{
foreach (var value in values)
{
string v = value; string v = value;
while (v.Length > 0 && !possibleValues.ContainsKey(v)) while (v.Length > 0 && !possibleValues.ContainsKey(v))
v = v.Remove(v.Length - 1); v = v.Remove(v.Length - 1);

18
ILSpy.AddIn.slnf

@ -0,0 +1,18 @@
{
"solution": {
"path": "ILSpy.sln",
"projects": [
"ICSharpCode.Decompiler.PdbProvider.Cecil\\ICSharpCode.Decompiler.PdbProvider.Cecil.csproj",
"ICSharpCode.Decompiler.Tests\\ICSharpCode.Decompiler.Tests.csproj",
"ICSharpCode.Decompiler\\ICSharpCode.Decompiler.csproj",
"ILSpy.AddIn\\ILSpy.AddIn.csproj",
"ILSpy.BamlDecompiler.Tests\\ILSpy.BamlDecompiler.Tests.csproj",
"ILSpy.BamlDecompiler\\ILSpy.BamlDecompiler.csproj",
"ILSpy.ReadyToRun\\ILSpy.ReadyToRun.csproj",
"ILSpy.Tests\\ILSpy.Tests.csproj",
"ILSpy\\ILSpy.csproj",
"SharpTreeView\\ICSharpCode.TreeView.csproj",
"TestPlugin\\TestPlugin.csproj"
]
}
}

17
ILSpy.Wpf.slnf

@ -0,0 +1,17 @@
{
"solution": {
"path": "ILSpy.sln",
"projects": [
"ICSharpCode.Decompiler.PdbProvider.Cecil\\ICSharpCode.Decompiler.PdbProvider.Cecil.csproj",
"ICSharpCode.Decompiler.Tests\\ICSharpCode.Decompiler.Tests.csproj",
"ICSharpCode.Decompiler\\ICSharpCode.Decompiler.csproj",
"ILSpy.BamlDecompiler.Tests\\ILSpy.BamlDecompiler.Tests.csproj",
"ILSpy.BamlDecompiler\\ILSpy.BamlDecompiler.csproj",
"ILSpy.ReadyToRun\\ILSpy.ReadyToRun.csproj",
"ILSpy.Tests\\ILSpy.Tests.csproj",
"ILSpy\\ILSpy.csproj",
"SharpTreeView\\ICSharpCode.TreeView.csproj",
"TestPlugin\\TestPlugin.csproj"
]
}
}

11
ILSpy.XPlat.slnf

@ -0,0 +1,11 @@
{
"solution": {
"path": "ILSpy.sln",
"projects": [
"ICSharpCode.Decompiler.Console\\ICSharpCode.Decompiler.Console.csproj",
"ICSharpCode.Decompiler.PowerShell\\ICSharpCode.Decompiler.PowerShell.csproj",
"ICSharpCode.Decompiler.Tests\\ICSharpCode.Decompiler.Tests.csproj",
"ICSharpCode.Decompiler\\ICSharpCode.Decompiler.csproj"
]
}
}

12
ILSpy.sln

@ -39,6 +39,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ILSpy.Tests", "ILSpy.Tests\
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ILSpy.ReadyToRun", "ILSpy.ReadyToRun\ILSpy.ReadyToRun.csproj", "{0313F581-C63B-43BB-AA9B-07615DABD8A3}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ILSpy.ReadyToRun", "ILSpy.ReadyToRun\ILSpy.ReadyToRun.csproj", "{0313F581-C63B-43BB-AA9B-07615DABD8A3}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ICSharpCode.Decompiler.Console", "ICSharpCode.Decompiler.Console\ICSharpCode.Decompiler.Console.csproj", "{743B439A-E7AD-4A0A-BAB6-222E1EA83C6D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ICSharpCode.Decompiler.PowerShell", "ICSharpCode.Decompiler.PowerShell\ICSharpCode.Decompiler.PowerShell.csproj", "{50060E0C-FA25-41F4-B72F-8490324EC9F0}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -89,6 +93,14 @@ Global
{0313F581-C63B-43BB-AA9B-07615DABD8A3}.Debug|Any CPU.Build.0 = Debug|Any CPU {0313F581-C63B-43BB-AA9B-07615DABD8A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0313F581-C63B-43BB-AA9B-07615DABD8A3}.Release|Any CPU.ActiveCfg = Release|Any CPU {0313F581-C63B-43BB-AA9B-07615DABD8A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0313F581-C63B-43BB-AA9B-07615DABD8A3}.Release|Any CPU.Build.0 = Release|Any CPU {0313F581-C63B-43BB-AA9B-07615DABD8A3}.Release|Any CPU.Build.0 = Release|Any CPU
{743B439A-E7AD-4A0A-BAB6-222E1EA83C6D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{743B439A-E7AD-4A0A-BAB6-222E1EA83C6D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{743B439A-E7AD-4A0A-BAB6-222E1EA83C6D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{743B439A-E7AD-4A0A-BAB6-222E1EA83C6D}.Release|Any CPU.Build.0 = Release|Any CPU
{50060E0C-FA25-41F4-B72F-8490324EC9F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{50060E0C-FA25-41F4-B72F-8490324EC9F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{50060E0C-FA25-41F4-B72F-8490324EC9F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{50060E0C-FA25-41F4-B72F-8490324EC9F0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

Loading…
Cancel
Save