Changeset 65478 in vbox for trunk/src/VBox/Frontends/VBoxBugReport
- Timestamp:
- Jan 27, 2017 10:00:44 AM (8 years ago)
- Location:
- trunk/src/VBox/Frontends/VBoxBugReport
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxBugReport/VBoxBugReport.cpp
r65456 r65478 146 146 }; 147 147 148 149 BugReportFilter::BugReportFilter() : m_pvBuffer(0), m_cbBuffer(0) 150 { 151 } 152 153 BugReportFilter::~BugReportFilter() 154 { 155 if (m_pvBuffer) 156 RTMemFree(m_pvBuffer); 157 } 158 159 void *BugReportFilter::allocateBuffer(size_t cbNeeded) 160 { 161 if (m_pvBuffer) 162 { 163 if (cbNeeded > m_cbBuffer) 164 RTMemFree(m_pvBuffer); 165 else 166 return m_pvBuffer; 167 } 168 m_pvBuffer = RTMemAlloc(cbNeeded); 169 if (!m_pvBuffer) 170 throw RTCError(com::Utf8StrFmt("Failed to allocate %ld bytes\n", cbNeeded)); 171 m_cbBuffer = cbNeeded; 172 return m_pvBuffer; 173 } 174 175 148 176 /* 149 177 * An abstract class serving as the root of the bug report item tree. … … 152 180 { 153 181 m_pszTitle = RTStrDup(pszTitle); 182 m_filter = 0; 154 183 } 155 184 156 185 BugReportItem::~BugReportItem() 157 186 { 187 if (m_filter) 188 delete m_filter; 158 189 RTStrFree(m_pszTitle); 159 190 } 160 191 192 void BugReportItem::addFilter(BugReportFilter *filter) 193 { 194 m_filter = filter; 195 } 196 197 void *BugReportItem::applyFilter(void *pvSource, size_t *pcbInOut) 198 { 199 if (m_filter) 200 return m_filter->apply(pvSource, pcbInOut); 201 return pvSource; 202 } 203 161 204 const char * BugReportItem::getTitle(void) 162 205 { … … 184 227 } 185 228 186 void BugReport::addItem(BugReportItem* item) 187 { 229 void BugReport::addItem(BugReportItem* item, BugReportFilter *filter) 230 { 231 if (filter) 232 item->addFilter(filter); 188 233 if (item) 189 234 m_Items.append(item); … … 199 244 } 200 245 RTPrintf("100%% - compressing...\n\n"); 246 } 247 248 void *BugReport::applyFilters(BugReportItem* item, void *pvSource, size_t *pcbInOut) 249 { 250 return item->applyFilter(pvSource, pcbInOut); 201 251 } 202 252 … … 447 497 while (RT_SUCCESS(rc = RTStrmReadEx(strmIn, buf, sizeof(buf), &cbRead)) && cbRead) 448 498 { 449 rc = RTStrmWriteEx(m_StrmTxt, buf, cbRead, &cbWritten);499 rc = RTStrmWriteEx(m_StrmTxt, applyFilters(item, buf, &cbRead), cbRead, &cbWritten); 450 500 if (RT_FAILURE(rc) || cbRead != cbWritten) 451 501 throw RTCError(com::Utf8StrFmt("Write failure (rc=%d, cbRead=%lu, cbWritten=%lu)\n", … … 522 572 offset += cbRead) 523 573 { 524 handleRtError(RTTarFileWriteAt(m_hTarFile, offset, buf, cbRead, NULL),574 handleRtError(RTTarFileWriteAt(m_hTarFile, offset, applyFilters(item, buf, &cbRead), cbRead, NULL), 525 575 "Failed to write %u bytes to TAR", cbRead); 526 576 } -
trunk/src/VBox/Frontends/VBoxBugReport/VBoxBugReport.h
r65456 r65478 86 86 87 87 /* 88 * An abstract class serving as the root of the bug report filter tree. 89 * A child provides an implementation of the 'apply' method. A child 90 * should modify the input buffer (provided via pvSource) in place, or 91 * allocate a new buffer via 'allocateBuffer'. Allocated buffers are 92 * released automatically when another buffer is allocated, which means 93 * that NEXT CALL TO 'APPLY' INVALIDATES BUFFERS RETURNED IN PREVIOUS 94 * CALLS! 95 */ 96 class BugReportFilter 97 { 98 public: 99 BugReportFilter(); 100 virtual ~BugReportFilter(); 101 virtual void *apply(void *pvSource, size_t *pcbInOut) = 0; 102 protected: 103 void *allocateBuffer(size_t cbNeeded); 104 private: 105 void *m_pvBuffer; 106 size_t m_cbBuffer; 107 }; 108 109 110 /* 88 111 * An abstract class serving as the root of the bug report item tree. 89 112 */ … … 95 118 virtual const char *getTitle(void); 96 119 virtual PRTSTREAM getStream(void) = 0; 120 void addFilter(BugReportFilter *filter); 121 void *applyFilter(void *pvSource, size_t *pcbInOut); 97 122 private: 98 123 char *m_pszTitle; 124 BugReportFilter *m_filter; 99 125 }; 100 126 … … 108 134 virtual ~BugReport(); 109 135 110 void addItem(BugReportItem* item );136 void addItem(BugReportItem* item, BugReportFilter *filter = 0); 111 137 int getItemCount(void); 112 138 void process(); 139 void *applyFilters(BugReportItem* item, void *pvSource, size_t *pcbInOut); 113 140 114 141 virtual void processItem(BugReportItem* item) = 0; -
trunk/src/VBox/Frontends/VBoxBugReport/VBoxBugReportWin.cpp
r65456 r65478 534 534 for (int i = 0; SetupDiEnumDeviceInfo(m_hDevInfo, i, &deviceInfoData); ++i) 535 535 { 536 if (m_hHostCtrlDev != INVALID_HANDLE_VALUE) 537 CloseHandle(m_hHostCtrlDev); 538 if (m_pDetailData) 539 RTMemFree(m_pDetailData); 540 536 541 SP_DEVICE_INTERFACE_DATA deviceInterfaceData; 537 542 deviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); … … 694 699 695 700 701 class BugReportFilterRegistryWin : public BugReportFilter 702 { 703 public: 704 BugReportFilterRegistryWin() {}; 705 virtual ~BugReportFilterRegistryWin() {}; 706 virtual void *apply(void *pvSource, size_t *pcbInOut); 707 }; 708 709 void *BugReportFilterRegistryWin::apply(void *pvSource, size_t *pcbInOut) 710 { 711 /* 712 * The following implementation is not optimal by any means. It serves to 713 * illustrate and test the case when filter's output is longer than its 714 * input. 715 */ 716 RT_NOREF(pcbInOut); 717 /* Registry export files are encoded in UTF-16 (little endian on Intel x86). */ 718 void *pvDest = pvSource; 719 uint16_t *pwsSource = (uint16_t *)pvSource; 720 if (*pwsSource++ == 0xFEFF && *pcbInOut > 48) 721 { 722 if (!memcmp(pwsSource, L"Windows Registry Editor", 46)) 723 { 724 *pcbInOut += 2; 725 pvDest = allocateBuffer(*pcbInOut); 726 uint16_t *pwsDest = (uint16_t *)pvDest; 727 *pwsDest++ = 0xFEFF; 728 *pwsDest++ = '#'; 729 /* Leave space for 0xFEFF and '#' */ 730 memcpy(pwsDest, pwsSource, *pcbInOut - 4); 731 } 732 } 733 return pvDest; 734 } 735 696 736 697 737 void createBugReportOsSpecific(BugReport* report, const char *pszHome) … … 721 761 report->addItem(new BugReportCommand("DriverStore", PathJoin(WinSysDir.c_str(), "pnputil.exe"), "-e", NULL)); 722 762 report->addItem(new BugReportCommandTemp("RegDevKeys", PathJoin(WinSysDir.c_str(), "reg.exe"), "export", 723 "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Enum\\Root\\NET", NULL)); 763 "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Enum\\Root\\NET", NULL), 764 new BugReportFilterRegistryWin()); 724 765 report->addItem(new BugReportCommandTemp("RegDrvKeys", PathJoin(WinSysDir.c_str(), "reg.exe"), "export", 725 "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}", NULL)); 766 "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}", NULL), 767 new BugReportFilterRegistryWin()); 726 768 report->addItem(new BugReportCommandTemp("RegNetwork", PathJoin(WinSysDir.c_str(), "reg.exe"), "export", 727 "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}", NULL)); 769 "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}", NULL), 770 new BugReportFilterRegistryWin()); 728 771 report->addItem(new BugReportUsbTreeWin); 729 772 report->addItem(new BugReportDriversWin);
Note:
See TracChangeset
for help on using the changeset viewer.