Ejemplo n.º 1
0
        private bool runAutoScripts(StackHashProduct product, StackHashFile file, StackHashEvent theEvent, StackHashCab cab, StackHashScriptDumpType dumpType)
        {
            Collection <AutoScriptBase> autoScripts  = m_TaskParameters.TheScriptManager.AutoScripts;
            ScriptResultsManager        scriptRunner = m_TaskParameters.TheScriptResultsManager;

            bool dumpAnalysisProduced = false;

            // Analyse the Unmanaged mode autoscripts first - as these determine if the dump is managed or not and hence whether
            // the managed scripts will be run. The AutoScripts property above returns the autoscripts in the correct order.
            foreach (AutoScriptBase autoScript in autoScripts)
            {
                bool dumpIsManaged = ((cab.DumpAnalysis != null) && (!String.IsNullOrEmpty(cab.DumpAnalysis.DotNetVersion)));

                if (autoScript.ScriptSettings.DumpType != dumpType)
                {
                    continue;
                }

                if ((autoScript.ScriptSettings.DumpType == StackHashScriptDumpType.ManagedOnly) && (!dumpIsManaged))
                {
                    continue;
                }

                bool forceAutoScript = false;
                if ((cab.DumpAnalysis == null) || (cab.DumpAnalysis.MachineArchitecture == null) || (cab.DumpAnalysis.OSVersion == null))
                {
                    forceAutoScript = true;
                }

                // Run the auto script on the cab if it hasn't already been run.
                StackHashScriptResult scriptResult =
                    scriptRunner.RunScript(product, file, theEvent, cab, null, autoScript.ScriptName, false, null, forceAutoScript);

                // Analyze the results.
                if (scriptResult != null)
                {
                    cab.DumpAnalysis     = autoScript.AnalyzeScriptResults(cab.DumpAnalysis, scriptResult);
                    dumpAnalysisProduced = true;
                    m_ConsecutiveErrors  = 0;
                }
            }

            return(dumpAnalysisProduced);
        }
Ejemplo n.º 2
0
        private StackHashDumpAnalysis processCab(StackHashProduct product, StackHashFile file, StackHashEvent theEvent, StackHashCab cab)
        {
            try
            {
                ScriptResultsManager scriptRunner = m_TaskParameters.TheScriptResultsManager;
                String cabFileName = m_TaskParameters.ErrorIndex.GetCabFileName(product, file, theEvent, cab);

                // It is legitimate for a cab entry to exist in the database but no cab file to exist.
                if (!File.Exists(cabFileName))
                {
                    // Make sure the cab is marked as not downloaded.
                    // Set the downloaded flag appropriately if different.
                    StackHashCab loadedCab = m_TaskParameters.ErrorIndex.GetCab(product, file, theEvent, cab.Id);

                    if (loadedCab != null)
                    {
                        if (loadedCab.CabDownloaded)
                        {
                            loadedCab.CabDownloaded = false;
                            m_TaskParameters.ErrorIndex.AddCab(product, file, theEvent, loadedCab, false);
                        }
                    }

                    return(null);
                }

                // Unwrap the cab if it hasn't been unwrapped already.
                unpackCab(product, file, theEvent, cab, m_TaskParameters.ForceUnpack);

                if (cab.DumpAnalysis == null)
                {
                    cab.DumpAnalysis = new StackHashDumpAnalysis();
                }


                // Process the auto scripts first.
                Collection <AutoScriptBase> autoScripts = m_TaskParameters.TheScriptManager.AutoScripts;

                bool dumpAnalysisProduced = false;

                if (runAutoScripts(product, file, theEvent, cab, StackHashScriptDumpType.UnmanagedOnly))
                {
                    dumpAnalysisProduced = true;
                }
                if (runAutoScripts(product, file, theEvent, cab, StackHashScriptDumpType.UnmanagedAndManaged))
                {
                    dumpAnalysisProduced = true;
                }
                if (runAutoScripts(product, file, theEvent, cab, StackHashScriptDumpType.ManagedOnly))
                {
                    dumpAnalysisProduced = true;
                }

                // Should know by now if the dump is managed or not.
                bool dumpIsManaged = ((cab.DumpAnalysis != null) && (!String.IsNullOrEmpty(cab.DumpAnalysis.DotNetVersion)));

                if (dumpAnalysisProduced)
                {
                    m_TaskParameters.ErrorIndex.AddCab(product, file, theEvent, cab, true);
                }

                // Run all user based scripts marked as automatic.
                foreach (StackHashScriptSettings script in m_AutomaticUserScriptNames)
                {
                    if ((script.DumpType == StackHashScriptDumpType.ManagedOnly) && (!dumpIsManaged))
                    {
                        continue;
                    }
                    if ((script.DumpType == StackHashScriptDumpType.UnmanagedOnly) && (dumpIsManaged))
                    {
                        continue;
                    }

                    // Run the script.
                    scriptRunner.RunScript(product, file, theEvent, cab, null, script.Name, false, null, false);
                }

                return(cab.DumpAnalysis);
            }
            catch (System.Exception ex)
            {
                DiagnosticsHelper.LogException(DiagSeverity.Warning, "Failed to process CAB file", ex);
                m_ConsecutiveErrors++;

                if (m_ConsecutiveErrors >= m_MaxConsecutiveErrors)
                {
                    throw;
                }

                return(null);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Unpacks and runs the specified script + any automatic scripts on the file.
        /// </summary>
        /// <returns>Full dump analysis.</returns>
        private void processCab()
        {
            ScriptResultsManager scriptRunner = m_TaskParameters.TheScriptResultsManager;
            StackHashProduct     product      = m_TaskParameters.Product;
            StackHashFile        file         = m_TaskParameters.File;
            StackHashEvent       theEvent     = m_TaskParameters.TheEvent;
            StackHashCab         cab          = m_TaskParameters.Cab;

            // Unwrap the cab if it hasn't been unwrapped already.
            unpackCab(product, file, theEvent, cab, false);

            if (cab.DumpAnalysis == null)
            {
                cab.DumpAnalysis = new StackHashDumpAnalysis();
            }


            // Run the autoscripts on the cab.
            Collection <AutoScriptBase> autoScripts = m_TaskParameters.TheScriptManager.AutoScripts;

            bool dataFound = false;

            foreach (AutoScriptBase autoScript in autoScripts)
            {
                bool forceAutoScript = false;
                if ((cab.DumpAnalysis == null) || (cab.DumpAnalysis.MachineArchitecture == null) || (cab.DumpAnalysis.OSVersion == null))
                {
                    forceAutoScript = true;
                }

                // Run the auto script on the cab if it has not already been run.
                StackHashScriptResult scriptResult =
                    scriptRunner.RunScript(m_TaskParameters.Product, m_TaskParameters.File, m_TaskParameters.TheEvent,
                                           m_TaskParameters.Cab, null, autoScript.ScriptName, false, null, forceAutoScript);

                // Analyze the results.
                if (scriptResult != null)
                {
                    cab.DumpAnalysis = autoScript.AnalyzeScriptResults(cab.DumpAnalysis, scriptResult);
                    dataFound        = true;
                }
            }

            if (dataFound)
            {
                m_TaskParameters.ErrorIndex.AddCab(product, file, theEvent, cab, true);
            }

            // Now run all the specified scripts.
            foreach (String scriptName in m_TaskParameters.ScriptsToRun)
            {
                if (m_TaskParameters.TheScriptManager.IsAutoScript(scriptName))
                {
                    continue; // Will have already been run above.
                }
                if (CurrentTaskState.AbortRequested)
                {
                    throw new OperationCanceledException("Abort requested");
                }

                scriptRunner.RunScript(m_TaskParameters.Product, m_TaskParameters.File, m_TaskParameters.TheEvent,
                                       m_TaskParameters.Cab, m_TaskParameters.DumpFileName, scriptName, false,
                                       m_TaskParameters.ClientData, true);
            }
        }