Пример #1
0
        static void DecompileAsProject(string assemblyFileName, string outputDirectory)
        {
            ModuleDefinition       module     = UniversalAssemblyResolver.LoadMainModule(assemblyFileName);
            WholeProjectDecompiler decompiler = new WholeProjectDecompiler();

            decompiler.DecompileProject(module, outputDirectory);
        }
Пример #2
0
        private static string DecompileTarget(string assemblyFileName)
        {
            string decompileDirectory = string.Empty;

            if (File.Exists(assemblyFileName))
            {
                decompileDirectory = FileUtilities.GetDecompileDirectory(assemblyFileName, false);
                ModuleDefinition       module     = null;
                WholeProjectDecompiler decompiler = null;

                if (Directory.Exists(decompileDirectory) && Directory.GetFiles(decompileDirectory).Count() > 0)
                {
                    module     = UniversalAssemblyResolver.LoadMainModule(assemblyFileName, false);
                    decompiler = new WholeProjectDecompiler();
                    decompiler.Settings.ThrowOnAssemblyResolveErrors = false;
                    decompileDirectory = FileUtilities.GetDecompileDirectory(assemblyFileName, false);

                    if (Directory.Exists(decompileDirectory) && Directory.GetFiles(decompileDirectory).Count() > 0)
                    {
                        ConsoleOutput.SystemMessage($"Already decompiled located here {decompileDirectory}");
                        return(decompileDirectory);
                    }
                    else
                    {
                        Directory.CreateDirectory(decompileDirectory);
                    }

                    try
                    {
                        ConsoleOutput.SystemMessage($"Decompiling {assemblyFileName} to {decompileDirectory}");
                        decompiler.DecompileProject(module, decompileDirectory);
                    }
                    catch (Exception ex)
                    {
                        var message = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                        ConsoleOutput.ErrorMessage($"Decompiling {assemblyFileName} threw an exception with the message {message}");
                    }
                }
                else
                {
                    ConsoleOutput.ErrorMessage($"The assembly '{assemblyFileName}' does not exist");
                }
            }

            return(decompileDirectory);
        }
Пример #3
0
        public bool AddAssembly(string path)
        {
            try
            {
                var mainModule = UniversalAssemblyResolver.LoadMainModule(path);
                if (mainModule != null)
                {
                    _mainModules.Add(path, mainModule);
                    PopulateTokenToProviderMap(path);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                _logger?.LogError("An exception occurred when reading assembly {assembly}: {exception}", path, ex);
            }

            return(false);
        }
        protected override void ProcessRecord()
        {
            string path = GetUnresolvedProviderPathFromPSPath(LiteralPath);

            if (!Directory.Exists(path))
            {
                WriteObject("Destination directory must exist prior to decompilation");
                return;
            }

            try
            {
                string                 assemblyFileName = Decompiler.TypeSystem.Compilation.MainAssembly.UnresolvedAssembly.Location; // just to keep the API "the same" across all cmdlets
                ModuleDefinition       module           = UniversalAssemblyResolver.LoadMainModule(assemblyFileName);
                WholeProjectDecompiler decompiler       = new WholeProjectDecompiler();
                decompiler.DecompileProject(module, path);

                WriteObject("Decompilation finished");
            } catch (Exception e) {
                WriteVerbose(e.ToString());
                WriteError(new ErrorRecord(e, ErrorIds.DecompilationFailed, ErrorCategory.OperationStopped, null));
            }
        }