📄 ntstatusexplorerdlg.cpp
字号:
s = s.Mid(parenNTSTATUS.GetLength());
// 0x00000000
DWORD value;
if(_tcsncmp(s, _T("0x"), 2) == 0 || _tcsncmp(s, _T("0X"), 2) == 0)
{ /* hex */
s = s.Mid(2);
value = _tcstoul(s, NULL, 16);
} /* hex */
else
{ /* decimal */
value = _tcstoul(s, NULL, 10);
} /* decimal */
c_NTSTATUS.AddString(name, value);
} /* loop */
c_Save.EnableWindow(TRUE);
c_Clear.EnableWindow(TRUE);
}
/****************************************************************************
* CNTSTATUSExplorerDlg::OnAdd
* Result: void
*
* Effect:
* Adds the definitions from a header file to the list of names
****************************************************************************/
void CNTSTATUSExplorerDlg::OnAdd()
{
RegistryString filename(IDS_FILENAME);
filename.load(_T("NTSTATUS.h"));
CFileDialog dlg(TRUE, _T(".h"), filename.value);
switch(dlg.DoModal())
{ /* CFileDialog */
case 0: return; // bogus
case IDCANCEL: return; // cancelled
case IDOK: break;
} /* CFileDialog */
CString name = dlg.GetPathName();
CStdioFile input(name, CFile::modeRead);
parseHeader(input);
input.Close();
filename.value = name;
filename.store();
}
void CNTSTATUSExplorerDlg::OnByname()
{
c_NTSTATUS.SetSort(CStatusList::ByName);
c_Unsorted.EnableWindow(FALSE);
}
void CNTSTATUSExplorerDlg::OnByvalue()
{
c_NTSTATUS.SetSort(CStatusList::ByValue);
c_Unsorted.EnableWindow(FALSE);
}
void CNTSTATUSExplorerDlg::OnByresult()
{
c_NTSTATUS.SetSort(CStatusList::ByResult);
c_Unsorted.EnableWindow(FALSE);
}
void CNTSTATUSExplorerDlg::OnByErrorname()
{
c_NTSTATUS.SetSort(CStatusList::ByWinError);
c_Unsorted.EnableWindow(FALSE);
}
void CNTSTATUSExplorerDlg::OnUnsorted()
{
c_NTSTATUS.SetSort(CStatusList::Unsorted);
}
void CNTSTATUSExplorerDlg::OnSave()
{
UINT key;
if(c_ByName.GetCheck())
key = IDS_OUTPUT_BY_STATUS_NAME;
else
if(c_ByValue.GetCheck())
key = IDS_OUTPUT_BY_STATUS_VALUE;
else
if(c_ByResult.GetCheck())
key = IDS_OUTPUT_BY_ERROR_VALUE;
else
if(c_ByErrorName.GetCheck())
key = IDS_OUTPUT_BY_ERROR_NAME;
else
key = IDS_OUTPUT;
RegistryString outputName(key);
outputName.load(_T("NTSTATUS.lst"));
CFileDialog dlg(FALSE, _T("lst"), outputName.value);
switch(dlg.DoModal())
{ /* doModal */
case 0:
return;
case IDCANCEL:
return;
} /* doModal */
CString name = dlg.GetPathName();
CWaitCursor cursor;
TRY {
CStdioFile output(name, CFile::modeCreate | CFile::modeWrite);
c_NTSTATUS.Save(output);
output.Close();
outputName.value = name;
outputName.store();
}
CATCH(CFileException, e)
{
// NYI: error
}
END_CATCH
}
void CNTSTATUSExplorerDlg::OnSelectall()
{
c_NTSTATUS.SetRedraw(FALSE);
int count = c_NTSTATUS.GetCount();
for(int i = 0; i < count; i++)
c_NTSTATUS.SetSel(i, TRUE);
c_NTSTATUS.SetRedraw(TRUE);
c_NTSTATUS.InvalidateRect(NULL);
}
void CNTSTATUSExplorerDlg::OnFind()
{
// TODO: Add your control notification handler code here
}
void CNTSTATUSExplorerDlg::OnGo()
{
CWaitCursor cursor;
int sels = c_NTSTATUS.GetSelCount();
int * selections = new int[sels];
if(sels > 10)
{ /* progress */
c_Progress.SetRange(0, sels);
c_Progress.SetStep(1);
c_Progress.ShowWindow(SW_SHOW);
} /* progress */
for(int i = 0; i < sels; i++)
{ /* process it */
c_NTSTATUS.GetSelItems(sels, selections);
DWORD value = c_NTSTATUS.GetValue(selections[i]);
DWORD OutBuffer; // not actually used
DWORD ReturnedLength; // not used, but required
BOOL IoctlResult;
c_Progress.StepIt();
if(value == 0xFFFFFFFF)
continue;
DWORD result = 0;
if(hTest != INVALID_HANDLE_VALUE)
{ /* do test */
IoctlResult = DeviceIoControl(
hTest, // Handle to device
(unsigned long)IOCTL_FAIL_WITH, // IO Control code for Read
&value, // Buffer to driver.
sizeof(value), // Length of buffer in bytes.
&OutBuffer, // Buffer from driver.
sizeof(OutBuffer), // Length of buffer in bytes.
&ReturnedLength, // Bytes placed in DataBuffer.
NULL // NULL means wait till op. completes.
);
if(!IoctlResult)
result = GetLastError();
} /* do test */
else
{ /* debug mode */
result = ERROR_SERVICE_NOT_FOUND; // No service installed
result = ERROR_BAD_LENGTH;
} /* debug mode */
c_NTSTATUS.SetResult(selections[i], result, WinError.Lookup(result));
} /* process it */
c_Progress.ShowWindow(SW_HIDE);
delete [] selections;
}
void CNTSTATUSExplorerDlg::OnOK()
{
if(hTest != INVALID_HANDLE_VALUE)
CloseHandle(hTest);
CDialog::OnOK();
}
void CNTSTATUSExplorerDlg::OnCancel()
{
return; // disable ESC key
}
/****************************************************************************
* CNTSTATUSExplorerDlg::parseWinError
* Inputs:
* CStdioFile & file: Input file
* Result: void
*
* Effect:
* Parses the WinError.h file and creates the WinError symbol table
****************************************************************************/
void CNTSTATUSExplorerDlg::parseWinError(CStdioFile & file)
{
CString s;
CString ERROR_(_T("ERROR_"));
CString hashDefine(_T("#define"));
CString RPC_(_T("RPC_"));
CString EPT_S_(_T("EPT_S_"));
while(file.ReadString(s))
{ /* scan */
if(s.GetLength() == 0)
continue;
if(s[0] != _T('#'))
continue;
if(_tcsncmp(s, hashDefine, hashDefine.GetLength()) != 0)
continue;
s = s.Mid(hashDefine.GetLength());
s.TrimLeft();
if(_tcsncmp(s, ERROR_, ERROR_.GetLength()) != 0 &&
_tcsncmp(s, RPC_, RPC_.GetLength()) != 0 &&
_tcsncmp(s, EPT_S_, EPT_S_.GetLength()) != 0)
continue;
int pos = s.FindOneOf(_T(" \t"));
if(pos < 0)
continue;
CString name(s, pos);
s = s.Mid(pos);
s.TrimLeft();
DWORD value;
value = _tcstoul(s, NULL, 10);
WinError.Add(name, value);
} /* scan */
}
/****************************************************************************
* void CNTSTATUSExplorerDlg::OnClear
* Result: void
*
* Effect:
* Clears the listbox contents
****************************************************************************/
void CNTSTATUSExplorerDlg::OnClear()
{
c_NTSTATUS.ResetContent();
c_Unsorted.EnableWindow(TRUE);
c_Save.EnableWindow(FALSE);
CheckRadioButton(IDC_BYNAME, IDC_UNSORTED, IDC_UNSORTED);
}
void CNTSTATUSExplorerDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
CRect r;
if(c_NTSTATUS.m_hWnd == NULL)
return;
c_NTSTATUS.GetWindowRect(&r);
ScreenToClient(&r);
CRect c;
GetClientRect(&c);
c_NTSTATUS.MoveWindow(r.left, r.top, c.Width(), c.Height() - r.top);
}
void CNTSTATUSExplorerDlg::OnWinerror()
{
RegistryString filename(IDS_WINERROR);
filename.load(_T("WinError.h"));
CFileDialog dlg(TRUE, _T(".h"), filename.value);
switch(dlg.DoModal())
{ /* CFileDialog */
case 0: return; // bogus
case IDCANCEL: return; // cancelled
case IDOK: break;
} /* CFileDialog */
CString name = dlg.GetPathName();
CStdioFile input(name, CFile::modeRead);
parseWinError(input);
input.Close();
filename.value = name;
filename.store();
}
void CNTSTATUSExplorerDlg::OnOutput()
{
CFileOptions dlg;
dlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -