def __init__(oBugReport, oCdbWrapper):
        oProductDetails = (
            mProductDetails.foGetProductDetailsForMainModule()
            or mProductDetails.foGetProductDetailsForModule(cBugId))
        oBugReport.sBugTypeId = "CdbNotTerminated"
        oBugReport.sBugDescription = "Cdb could not be terminated"
        oBugReport.sBugLocation = None
        oBugReport.sSecurityImpact = None
        oBugReport.oException = None
        oBugReport.oStack = None

        asBlocksHTML = []

        if oCdbWrapper.bGenerateReportHTML and dxConfig["bLogInReport"]:
            asBlocksHTML.append(
                sBlockHTMLTemplate % {
                    "sName": "Application run log",
                    "sCollapsed": "Collapsible",  # ...but not Collapsed
                    "sContent": oCdbWrapper.sLogHTML,
                })
        oBugReport.sProcessBinaryName = "cdb.exe"

        oBugReport.sId = oBugReport.sBugTypeId
        oBugReport.sStackId = None
        oBugReport.sBugSourceLocation = None
        oBugReport.asVersionInformation = [
            "%s: %s" %
            (oProductDetails.sProductName, oProductDetails.oProductVersion)
        ]
        if oCdbWrapper.bGenerateReportHTML:
            # Add Cdb IO to HTML report
            asBlocksHTML.append(
                sBlockHTMLTemplate % {
                    "sName": "Application and cdb output log",
                    "sCollapsed": "Collapsed",
                    "sContent": oCdbWrapper.sCdbIOHTML
                })
            # Create HTML details
            (sLicenseHeaderHTML, sLicenseFooterHTML
             ) = ftsReportLicenseHeaderAndFooterHTML(oProductDetails)
            oBugReport.sReportHTML = sReportHTMLTemplate % {
              "sId": oCdbWrapper.fsHTMLEncode(oBugReport.sId),
              "sOptionalUniqueStackId": "",
              "sBugLocation": oCdbWrapper.fsHTMLEncode(oBugReport.sBugLocation or "Unknown"),
              "sOptionalSource": "",
              "sBugDescription": oCdbWrapper.fsHTMLEncode(oBugReport.sBugDescription),
              "sBinaryVersion": "Not available",
              "sSecurityImpact": oBugReport.sSecurityImpact and \
                    '<span class="SecurityImpact">%s</span>' % oCdbWrapper.fsHTMLEncode(oBugReport.sSecurityImpact) or "None",
              "sOptionalIntegrityLevel": "",
              "sOptionalMemoryUsage": "",
              "sOptionalApplicationArguments": "",
              "sBlocks": "\r\n".join(asBlocksHTML),
              "sCdbStdIO": oCdbWrapper.sCdbIOHTML,
              "sProductName": oProductDetails.sProductName,
              "sProductVersion": oProductDetails.oProductVersion,
              "sProductAuthor": oProductDetails.sProductAuthor,
              "sProductURL": oProductDetails.sProductURL,
              "sLicenseHeader": sLicenseHeaderHTML,
              "sLicenseFooter": sLicenseFooterHTML,
            }
        else:
            oBugReport.sReportHTML = None
Exemplo n.º 2
0
 def fReport(oBugReport, oCdbWrapper):
   oProductDetails = (
     mProductDetails.foGetProductDetailsForMainModule()
     or mProductDetails.foGetProductDetailsForModule(cBugId)
   );
   # Remove the internal process object from the bug report; it is no longer needed and should not be exposed to the
   # outside.
   oProcess = oBugReport.__oProcess;
   del oBugReport.__oProcess;
   oThread = oBugReport.__oThread;
   del oBugReport.__oThread;
   oStack = oBugReport.__oStack;
   del oBugReport.__oStack;
   # Calculate sStackId, determine sBugLocation and optionally create and return sStackHTML.
   aoStackFramesPartOfId, sStackHTML = oBugReport.fxProcessStack(oCdbWrapper, oProcess, oStack);
   oBugReport.sId = "%s %s" % (oBugReport.sBugTypeId, oBugReport.sStackId);
   if oBugReport.sSecurityImpact is None:
     oBugReport.sSecurityImpact = "Denial of Service";
   
   # If bug binary and main binary are not the same, gather information for both of them:
   aoRelevantModules = [oProcess.oMainModule];
   # Find the Module in which the bug is reported and add it to the relevant list if it's not there already.
   for oStackFrame in aoStackFramesPartOfId:
     if oStackFrame.oModule:
       if oStackFrame.oModule != oProcess.oMainModule:
         aoRelevantModules.append(oStackFrame.oModule);
       break;
   # Add relevant binaries information to cBugReport and optionally to the HTML report.
   if oCdbWrapper.bGenerateReportHTML:
     # If a HTML report is requested, these will be used later on to construct it.
     asBinaryInformationHTML = [];
     asBinaryVersionHTML = [];
   oBugReport.asVersionInformation = [];
   for oModule in aoRelevantModules:
     # This function populates the version properties of the oModule object and returns HTML if a report is needed.
     oBugReport.asVersionInformation.append(
         "%s %s (%s)" % (oModule.sBinaryName, oModule.sFileVersion or oModule.sTimestamp or "unknown", oModule.sISA));
     if oCdbWrapper.bGenerateReportHTML:
       asBinaryInformationHTML.append(oModule.sInformationHTML);
       asBinaryVersionHTML.append("<b>%s</b>: %s (%s)" % \
           (oModule.sBinaryName, oModule.sFileVersion or oModule.sTimestamp or "unknown", oModule.sISA));
   
   if oCdbWrapper.bGenerateReportHTML:
     # Create HTML details
     asBlocksHTML = [];
     # Create and add important output block if needed
     if oCdbWrapper.bGenerateReportHTML and dxConfig["bLogInReport"]:
       asBlocksHTML.append(sBlockHTMLTemplate % {
         "sName": "Application run log",
         "sCollapsed": "Collapsible", # ...but not Collapsed
         "sContent": oCdbWrapper.sLogHTML,
       });
     
     # Add stack block
     asBlocksHTML.append(sBlockHTMLTemplate % {
       "sName": "Stack",
       "sCollapsed": "Collapsible", # ...but not Collapsed
       "sContent": "<span class=\"Stack\">%s</span>" % sStackHTML
     });
     
     # Add exception specific blocks if needed:
     asBlocksHTML += oBugReport.asExceptionSpecificBlocksHTML;
     
     if oBugReport.bRegistersRelevant:
       # Create and add registers block
       duRegisterValue_by_sName = oThread.fduGetRegisterValueByName();
       uPadding = 3 + 3 + ({"x86":8, "x64": 16}[oProcess.sISA]);
       asRegistersHTML = [];
       for asRegisterNamesAndPadding in gaasRelevantRegisterNamesAndPadding_by_sISA[oProcess.sISA]:
         asLine = [];
         for sRegisterNameAndPadding in asRegisterNamesAndPadding:
           (sRegisterName, sPadding) = sRegisterNameAndPadding.split(":");
           uRegisterValue = duRegisterValue_by_sName[sRegisterName];
           sRegisterValue = "%X" % uRegisterValue;
           sValuePadding = " " * (long(sPadding) - len(sRegisterValue));
           asLine.append("<td>%s = %s<span class=\"HexNumberHeader\">0x</span>%s</td>" % \
               (sRegisterName.ljust(5), sValuePadding, sRegisterValue));
         asRegistersHTML.append("<tr>%s</tr>" % "".join(asLine));
       asBlocksHTML.append(sBlockHTMLTemplate % {
         "sName": "Registers",
         "sCollapsed": "Collapsed",
         "sContent": "<table class=\"Registers\">%s</table>" % "\n".join(asRegistersHTML),
       });
     
     # Add relevant memory blocks in order if needed
     for uStartAddress in sorted(oBugReport.__dtxMemoryDumps.keys()):
       (uEndAddress, sDescription) = oBugReport.__dtxMemoryDumps[uStartAddress];
       sMemoryDumpHTML = oBugReport.fsMemoryDumpHTML(oCdbWrapper, oProcess, sDescription, uStartAddress, uEndAddress);
       if sMemoryDumpHTML:
         asBlocksHTML.append(sBlockHTMLTemplate % {
           "sName": sDescription,
           "sCollapsed": "Collapsed",
           "sContent": "<span class=\"Memory\">%s</span>" % sMemoryDumpHTML,
         });
     
     # Create and add disassembly blocks if needed:
     for oFrame in aoStackFramesPartOfId:
       if oFrame.uInstructionPointer is not None:
         if oFrame.uIndex == 0:
           sFrameDisassemblyHTML = oBugReport.fsGetDisassemblyHTML(
             oCdbWrapper,
             oProcess,
             uAddress = oFrame.uInstructionPointer,
             sDescriptionOfInstructionAtAddress = "current instruction"
           );
         else:
           sFrameDisassemblyHTML = oBugReport.fsGetDisassemblyHTML(
             oCdbWrapper, 
             oProcess,
             uAddress = oFrame.uInstructionPointer,
             sDescriptionOfInstructionBeforeAddress = "call",
             sDescriptionOfInstructionAtAddress = "return address"
           );
         if sFrameDisassemblyHTML:
           asBlocksHTML.append(sBlockHTMLTemplate % {
             "sName": "Disassembly of stack frame %d at %s" % (oFrame.uIndex + 1, oFrame.sAddress),
             "sCollapsed": "Collapsed",
             "sContent": "<span class=\"Disassembly\">%s</span>" % sFrameDisassemblyHTML,
           });
     
     # Add relevant binaries information to cBugReport and HTML report.
     sBinaryInformationHTML = "<br/>\n<br/>\n".join(asBinaryInformationHTML);
     sBinaryVersionHTML = "<br/>\n".join(asBinaryVersionHTML) or "not available";
     if sBinaryInformationHTML:
       asBlocksHTML.append(sBlockHTMLTemplate % {
         "sName": "Binary information",
         "sCollapsed": "Collapsed",
         "sContent": "<span class=\"BinaryInformation\">%s</span>" % sBinaryInformationHTML
       });
     # Get process integrity level.
     if oProcess.uIntegrityLevel is None:
       sOptionalIntegrityLevelHTML = "(unknown)";
     else:
       sIntegrityLevel =  " ".join([s for s in [
         {0: "Untrusted", 1: "Low", 2: "Medium", 3: "High", 4: "System"}.get(oProcess.uIntegrityLevel >> 12, "Unknown"),
         "Integrity",
         oProcess.uIntegrityLevel & 0x100 and "Plus",
       ] if s]);
       if oProcess.uIntegrityLevel >= 0x3000:
         sIntegrityLevel += "; this process appears to run with elevated privileges!";
       elif oProcess.uIntegrityLevel >= 0x2000:
         sIntegrityLevel += "; this process appears to not be sandboxed!";
       else:
         sIntegrityLevel += "; this process appears to be sandboxed.";
       sOptionalIntegrityLevelHTML = "<tr><td>Integrity level: </td><td>0x%X (%s)</td></tr>" % \
           (oProcess.uIntegrityLevel, sIntegrityLevel);
     if oCdbWrapper.oJobObject is None or oBugReport.sBugTypeId != "OOM":
       sOptionalMemoryUsageHTML = None;
     else:
       sOptionalMemoryUsageHTML = "<tr><td>Memory usage: </td><td>%6.1fMb (process)/ %6.1fMb (application)</td></tr>" % (
         oCdbWrapper.oJobObject.fuGetMaxProcessMemoryUse() / 1000000,
         oCdbWrapper.oJobObject.fuGetMaxTotalMemoryUse() / 1000000,
       );
     # Add Cdb IO to HTML report
     asBlocksHTML.append(sBlockHTMLTemplate % {
       "sName": "Application and cdb output log",
       "sCollapsed": "Collapsed",
       "sContent": oCdbWrapper.sCdbIOHTML,
     });
     # Create the report using all available information, or a limit amount of information if there is not enough
     # memory to do that.
     (sLicenseHeaderHTML, sLicenseFooterHTML) = ftsReportLicenseHeaderAndFooterHTML(oProductDetails);
     while asBlocksHTML:
       bReportTruncated = False;
       try:
         oBugReport.sReportHTML = sReportHTMLTemplate % {
           "sId": oCdbWrapper.fsHTMLEncode(oBugReport.sId),
           "sOptionalUniqueStackId": oBugReport.sUniqueStackId != oBugReport.sStackId and
               "<tr><td>Full stack id:</td><td>%s</td></tr>" % oCdbWrapper.fsHTMLEncode(oBugReport.sUniqueStackId) or "",
           "sBugLocation": oCdbWrapper.fsHTMLEncode(oBugReport.sBugLocation),
           "sBugDescription": oCdbWrapper.fsHTMLEncode(oBugReport.sBugDescription),
           "sBinaryVersion": sBinaryVersionHTML,
           "sOptionalSource": oBugReport.sBugSourceLocation and \
               "<tr><td>Source: </td><td>%s</td></tr>" % oBugReport.sBugSourceLocation or "",
           "sSecurityImpact": (oBugReport.sSecurityImpact == "Denial of Service" and
               "%s" or '<span class="SecurityImpact">%s</span>') % oCdbWrapper.fsHTMLEncode(oBugReport.sSecurityImpact),
           "sOptionalIntegrityLevel": sOptionalIntegrityLevelHTML,
           "sOptionalMemoryUsage": sOptionalMemoryUsageHTML or "",
           "sOptionalApplicationArguments": oCdbWrapper.asApplicationArguments and \
               "<tr><td>Arguments: </td><td>%s</td></tr>" % oCdbWrapper.asApplicationArguments or "",
           "sBlocks": "\n".join(asBlocksHTML) + 
               (bReportTruncated and "\n<hr/>\nThe report was truncated because there was not enough memory available to add all information available." or ""),
           "sProductName": oProductDetails.sProductName,
           "sProductVersion": oProductDetails.oProductVersion,
           "sProductAuthor": oProductDetails.sProductAuthor,
           "sProductURL": oProductDetails.sProductURL,
           "sLicenseHeader": sLicenseHeaderHTML,
           "sLicenseFooter": sLicenseFooterHTML,
         };
       except MemoryError:
         # We cannot add everything, so let's remove a block of information to free up some memory and reduce the size
         # of the final report before we try again. It makes sense to remove the last block, as they are ordered
         # (somewhat) by how useful the information is to the user, the last block containing less useful information
         # than the first.
         asBlocksHTML.pop();
         # Add a notice to the report about it being truncated.
         bReportTruncated = True;
       else:
         break;
     else:
       # There is so little memory available that we cannot seem to be able to create a report at all.
       # This is highly unlikely, but let's try to handle every eventuality.
       oBugReport.sReportHTML = "The report was <b>NOT</b> created because there was not enough memory available to add any information.";
   oBugReport.sProcessBinaryName = oProcess.sBinaryName;
   
   # See if a dump should be saved
   if dxConfig["bSaveDump"]:
     # We'd like a dump file name base on the BugId, but the later may contain characters that are not valid in a file name
     sDesiredDumpFileName = "%s @ %s.dmp" % (oBugReport.sId, oBugReport.sBugLocation);
     # Thus, we need to translate these characters to create a valid filename that looks very similar to the BugId. 
     # Unfortunately, we cannot use Unicode as the communication channel with cdb is ASCII.
     sDumpFileName = mFileSystem.fsValidName(sDesiredDumpFileName, bUnicode = False);
     if dxConfig["sDumpFilePath"]:
       sDumpFilePath = os.path.join(dxConfig["sDumpFilePath"], sDumpFileName);
     else:
       sDumpFilePath = sDumpFileName;
     sOverwriteFlag = dxConfig["bOverwriteDump"] and "/o" or "";
     oCdbWrapper.fasExecuteCdbCommand( \
       sCommand = ".dump %s /%s \"%s\";" % (sOverwriteFlag, dxConfig["bFullDump"] and "f" or "ma", sDumpFilePath),
       sComment = "Save dump to file",
     );
   assert oCdbWrapper.fbFireEvent("Bug report", oBugReport), \
       "You really should add an event handler for \"Bug report\" events, as reporting bugs is cBugIds purpose";
Exemplo n.º 3
0
def fPrintVersionInformation(bCheckForUpdates, bCheckAndShowLicenses, bShowInstallationFolders):
  # Read product details for rs and all modules it uses.
  aoProductDetails = mProductDetails.faoGetProductDetailsForAllLoadedModules();
  oMainProductDetails = mProductDetails.foGetProductDetailsForMainModule();
  if bCheckForUpdates:
    uCheckedProductCounter = 0;
    for oProductDetails in aoProductDetails:
      oConsole.fProgressBar(
        uCheckedProductCounter * 1.0 / len(aoProductDetails),
        "Checking %s for updates..." % oProductDetails.sProductName,
      );
      try:
        oProductDetails.oLatestProductDetailsFromRepository;
      except Exception as oException:
        oConsole.fPrint(
          ERROR, u"- Version check for ", ERROR_INFO, oProductDetails.sProductName,
          ERROR, " failed: ", ERROR_INFO, str(oException),
        );
      uCheckedProductCounter += 1;
  oConsole.fLock();
  try:
    if bCheckAndShowLicenses:
      aoLicenses = [];
      asLicensedProductNames = [];
      asProductNamesInTrial = [];
      asUnlicensedProductNames = [];
      for oProductDetails in aoProductDetails:
        if oProductDetails.oLicense:
          if oProductDetails.oLicense not in aoLicenses:
            aoLicenses.append(oProductDetails.oLicense);
          asLicensedProductNames.append(oProductDetails.sProductName);
        elif oProductDetails.bHasTrialPeriod and oProductDetails.bInTrialPeriod:
          asProductNamesInTrial.append(oProductDetails.sProductName);
        else:
          asUnlicensedProductNames.append(oProductDetails.sProductName);

      oLicenseCheckServer = mProductDetails.cLicenseCheckServer(oMainProductDetails.sLicenseServerURL);
      uCheckedLicenseCounter = 0;
      for oLicense in aoLicenses:
        oConsole.fProgressBar(
          uCheckedLicenseCounter * 1.0 / len(aoLicenses),
          "Checking license %s with server..." % oLicense.sLicenseId,
        );
        sLicenseCheckServerError = oLicense.fsCheckWithServerAndGetError(oLicenseCheckServer, bForceCheck = True);
        if sLicenseCheckServerError:
          oConsole.fPrint(
            ERROR, u"- License check for ", ERROR_INFO, oLicense.sLicenseId,
            ERROR, " on server ", ERROR_INFO, oMainProductDetails.sLicenseServerURL,
            ERROR, " failed: ", ERROR_INFO, sLicenseCheckServerError,
          );
        uCheckedLicenseCounter += 1;
    
    oConsole.fPrint(
      u"\u250C\u2500 ", INFO, "Version information", NORMAL, " ", sPadding = u"\u2500"
    );
    # Output the BugId product information first, then its dependencies:
    fPrintProductDetails(oMainProductDetails, bIsMainProduct = True, bShowInstallationFolders = bShowInstallationFolders);
    for oProductDetails in aoProductDetails:
      if oProductDetails != oMainProductDetails:
        fPrintProductDetails(oProductDetails, bIsMainProduct = False, bShowInstallationFolders = bShowInstallationFolders);
    
    oConsole.fPrint(
      u"\u2502 \u2219 ", INFO, "Windows",
      NORMAL, " version: ", INFO, oSystemInfo.sOSName,
      NORMAL, " release ", INFO, oSystemInfo.sOSReleaseId,
      NORMAL, ", build ", INFO, oSystemInfo.sOSBuild,
      NORMAL, " ", INFO, oSystemInfo.sOSISA,
      NORMAL, ".",
    );
    oConsole.fPrint(
      u"\u2502 \u2219 ", INFO, "Python",
      NORMAL, " version: ", INFO, str(platform.python_version()),
      NORMAL, " ", INFO, fsGetPythonISA(),
      NORMAL, ".",
    );
    
    if bCheckAndShowLicenses:
      oConsole.fPrint(
        u"\u251C\u2500 ", INFO, "License information", NORMAL, " ", sPadding = u"\u2500",
      );
      if aoLicenses:
        oConsole.fPrint(
          NORMAL, u"\u2502 \u2219 This system is registered with id ", INFO, mProductDetails.fsGetSystemId(), NORMAL, " on the license server",
        );
      for oLicense in aoLicenses:
        oConsole.fPrint(
          u"\u2502 \u2219 License ", INFO, oLicense.sLicenseId,
          NORMAL, " for ", INFO, oLicense.asProductNames[0], 
          NORMAL, " covers ", INFO, oLicense.sUsageTypeDescription, 
          NORMAL, " by ", INFO, oLicense.sLicenseeName,
          NORMAL, " of the following products:",
        );
        oConsole.fPrint(u"\u2502     ", faxListOutput(oLicense.asProductNames, "and", INFO, NORMAL));
      if asProductNamesInTrial:
        oConsole.fPrint(*(
          [
            u"\u2502 \u2219 "
          ] + faxListOutput(asProductNamesInTrial, "and", WARNING_INFO, WARNING)  + [
            WARNING, " ", len(asProductNamesInTrial) == 1 and "is" or "are", " not covered by a valid, active license but ",
            len(asProductNamesInTrial) == 1 and "it is in its" or "they are in their", " trial period.",
          ]
        ));
      if asUnlicensedProductNames:
        oConsole.fPrint(*(
          [
            u"\u2502 \u2219 "
          ] + faxListOutput(asUnlicensedProductNames, "and", ERROR_INFO, ERROR)  + [
            ERROR, " ", len(asProductNamesInTrial) == 1 and "is" or "are", " not covered by a valid, active license and ",
            len(asProductNamesInTrial) == 1 and "has exceeded its" or "have exceeded their", " trial period.",
          ]
        ));
    oConsole.fPrint(
      u"\u2514", sPadding = u"\u2500",
    );
    oConsole.fPrint();
  finally:
    oConsole.fUnlock();

  (asLicenseErrors, asLicenseWarnings) = mProductDetails.ftasGetLicenseErrorsAndWarnings();
  if asLicenseErrors:
    oConsole.fLock();
    try:
      oConsole.fPrint(ERROR, u"\u250C\u2500", ERROR_INFO, " Software license error ", ERROR, sPadding = u"\u2500");
      for sLicenseError in asLicenseErrors:
        oConsole.fPrint(ERROR, u"\u2502 ", ERROR_INFO, sLicenseError);
      oConsole.fPrint(ERROR, u"\u2514", sPadding = u"\u2500");
    finally:
      oConsole.fUnlock();
  if asLicenseWarnings:
    oConsole.fLock();
    try:
      oConsole.fPrint(WARNING, u"\u250C\u2500", WARNING_INFO, " Software license warning ", WARNING, sPadding = u"\u2500");
      for sLicenseWarning in asLicenseWarnings:
        oConsole.fPrint(WARNING, u"\u2502 ", WARNING_INFO, sLicenseWarning);
      oConsole.fPrint(WARNING, u"\u2514", sPadding = u"\u2500");
    finally:
      oConsole.fUnlock();
Exemplo n.º 4
0
import os, sys

# Augment the search path: pretend we are in the parent folder so we can load mProductDetails as a module:
sMainFolderPath = os.path.abspath(os.path.dirname(__file__))
sParentFolderPath = os.path.normpath(os.path.join(sMainFolderPath, ".."))
sys.path = [sParentFolderPath] + sys.path

import mProductDetails
from fsToOxfordComma import fsToOxfordComma

print "Unique system id: " + mProductDetails.fsGetSystemId()

print "Product version information:"
oMainProductDetails = mProductDetails.foGetProductDetailsForMainModule()
aoProductDetails = mProductDetails.faoGetProductDetailsForAllLoadedModules()
# Change order to put main product at the front:
aoProductDetails.remove(oMainProductDetails)
aoProductDetails.insert(0, oMainProductDetails)
for oProductDetails in aoProductDetails:
    print "+ \"%s\" version \"%s\" by \"%s\" installed in \"%s\"." % \
        (oProductDetails.sProductName, oProductDetails.oProductVersion, oProductDetails.sProductAuthor, oProductDetails.sInstallationFolderPath)
print

print "Checking licenses for loaded software products:"
oLicenseCollection = mProductDetails.foGetLicenseCollectionForAllLoadedProducts(
)
(asErrors, asWarnings) = oLicenseCollection.ftasGetLicenseErrorsAndWarnings()
if asErrors:
    print "Software license error%s:" % (len(asErrors) > 1 and "s" or "")
    for sError in asErrors:
        print "- " + sError