You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.7 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Management.Automation;
  5. using System.Text;
  6. using ICSharpCode.Decompiler.CSharp;
  7. using Mono.Cecil;
  8. namespace ICSharpCode.Decompiler.PowerShell
  9. {
  10. [Cmdlet(VerbsCommon.Get, "DecompiledProject")]
  11. [OutputType(typeof(string))]
  12. public class GetDecompiledProjectCmdlet : PSCmdlet
  13. {
  14. [Parameter(Position = 0, Mandatory = true)]
  15. public CSharpDecompiler Decompiler { get; set; }
  16. [Parameter(Position = 1, Mandatory = true)]
  17. [Alias("PSPath", "OutputPath")]
  18. [ValidateNotNullOrEmpty]
  19. public string LiteralPath { get; set; }
  20. protected override void ProcessRecord()
  21. {
  22. string path = GetUnresolvedProviderPathFromPSPath(LiteralPath);
  23. if (!Directory.Exists(path))
  24. {
  25. WriteObject("Destination directory must exist prior to decompilation");
  26. return;
  27. }
  28. try
  29. {
  30. string assemblyFileName = Decompiler.TypeSystem.Compilation.MainAssembly.UnresolvedAssembly.Location; // just to keep the API "the same" across all cmdlets
  31. ModuleDefinition module = UniversalAssemblyResolver.LoadMainModule(assemblyFileName);
  32. WholeProjectDecompiler decompiler = new WholeProjectDecompiler();
  33. decompiler.DecompileProject(module, path);
  34. WriteObject("Decompilation finished");
  35. } catch (Exception e) {
  36. WriteVerbose(e.ToString());
  37. WriteError(new ErrorRecord(e, ErrorIds.DecompilationFailed, ErrorCategory.OperationStopped, null));
  38. }
  39. }
  40. }
  41. }