⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ntstatusexplorerdlg.cpp

📁 查看NT状态
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// NTSTATUSExplorerDlg.cpp : implementation file
//

#include "stdafx.h"
#include <afxtempl.h>
#include "StatusList.h"
#include "NTSTATUSExplorer.h"
#include "NTSTATUSExplorerDlg.h"
#include "regvars.h"
#include "FileOptions.h"

#include "winIoctl.h"
#include "statusRIoctl.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

class WinErrorData {
    public:
	WinErrorData(CString & n, DWORD v) { name = n; value = v; }
	virtual ~WinErrorData() { }
    
	CString name;
	DWORD value;
		   };

class WinErrorTable {
     public:
	WinErrorTable() { }
	virtual ~WinErrorTable();
	void Add(CString & n, DWORD v);
	CString Lookup(DWORD v);
     protected:
	CList<WinErrorData *, WinErrorData *> data;
		    };

WinErrorTable::~WinErrorTable()
    {
     if(data.IsEmpty())
	return;

     while(!data.IsEmpty())
        { /* delete each */
	 WinErrorData * d = data.RemoveHead();
	 delete d;
	} /* delete each */
    }

void WinErrorTable::Add(CString & n, DWORD v)
   {
    WinErrorData * d = new WinErrorData(n, v);
    data.AddHead(d);
   }

CString WinErrorTable::Lookup(DWORD v)
   {
    if(data.IsEmpty())
       return CString(_T(""));
    POSITION p = data.GetHeadPosition();
    while(p != NULL)
       { /* scan */
	WinErrorData * d = data.GetNext(p);
	if(d->value == v)
	   return d->name;
       } /* scan */
    return CString(_T(""));
   }

WinErrorTable WinError;

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNTSTATUSExplorerDlg dialog

CNTSTATUSExplorerDlg::CNTSTATUSExplorerDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CNTSTATUSExplorerDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CNTSTATUSExplorerDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	hTest = INVALID_HANDLE_VALUE;
}

void CNTSTATUSExplorerDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CNTSTATUSExplorerDlg)
	DDX_Control(pDX, IDC_PROGRESS, c_Progress);
	DDX_Control(pDX, IDC_BYRESULT, c_ByResult);
	DDX_Control(pDX, IDC_ERRORNAME, c_ByErrorName);
	DDX_Control(pDX, IDC_UNSORTED, c_Unsorted);
	DDX_Control(pDX, IDC_CLEAR, c_Clear);
	DDX_Control(pDX, IDC_BYVALUE, c_ByValue);
	DDX_Control(pDX, IDC_BYNAME, c_ByName);
	DDX_Control(pDX, IDC_NTSTATUS, c_NTSTATUS);
	DDX_Control(pDX, IDC_SELECTALL, c_SelectAll);
	DDX_Control(pDX, IDC_SAVE, c_Save);
	DDX_Control(pDX, IDC_GO, c_Go);
	DDX_Control(pDX, IDC_FIND, c_Find);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CNTSTATUSExplorerDlg, CDialog)
	//{{AFX_MSG_MAP(CNTSTATUSExplorerDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_DESTROY()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_ADD, OnAdd)
	ON_BN_CLICKED(IDC_BYNAME, OnByname)
	ON_BN_CLICKED(IDC_BYVALUE, OnByvalue)
	ON_BN_CLICKED(IDC_BYRESULT, OnByresult)
	ON_BN_CLICKED(IDC_SAVE, OnSave)
	ON_BN_CLICKED(IDC_SELECTALL, OnSelectall)
	ON_BN_CLICKED(IDC_FIND, OnFind)
	ON_BN_CLICKED(IDC_GO, OnGo)
	ON_BN_CLICKED(IDC_CLEAR, OnClear)
	ON_BN_CLICKED(IDC_UNSORTED, OnUnsorted)
	ON_WM_SIZE()
	ON_BN_CLICKED(IDC_WINERROR, OnWinerror)
	ON_BN_CLICKED(IDC_ERRORNAME, OnByErrorname)
	ON_BN_CLICKED(IDC_OUTPUT, OnOutput)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNTSTATUSExplorerDlg message handlers

BOOL CNTSTATUSExplorerDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	CString strAboutMenu;
	strAboutMenu.LoadString(IDS_ABOUTBOX);
	if (!strAboutMenu.IsEmpty())
	{
		pSysMenu->AppendMenu(MF_SEPARATOR);
		pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	CheckRadioButton(IDC_BYNAME, IDC_UNSORTED, IDC_UNSORTED);
	c_Save.EnableWindow(FALSE);
	c_Clear.EnableWindow(FALSE);
	
	// Locate the test device

	hTest = CreateFile(
                     "\\\\.\\STATUSR",
                     GENERIC_READ | GENERIC_WRITE,
                     0,
                     NULL,
                     OPEN_EXISTING,
                     FILE_ATTRIBUTE_NORMAL,
                     NULL
                     );

        if(hTest == INVALID_HANDLE_VALUE)
	   { /* failed */
	    AfxMessageBox(IDS_DRIVER_NOT_LOADED);
	    // c_Go.EnableWindow(FALSE);
	   } /* failed */

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CNTSTATUSExplorerDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
 	switch(nID & 0xFFF0)
	   { /* nID */
	    case IDM_ABOUTBOX:
		{
		    CAboutDlg dlgAbout;
		    dlgAbout.DoModal();
		}
		    return;
	    case SC_CLOSE:
		    OnOK();
		    return;
	   } /* nID */
	CDialog::OnSysCommand(nID, lParam);
}

void CNTSTATUSExplorerDlg::OnDestroy()
{
	WinHelp(0L, HELP_QUIT);
	CDialog::OnDestroy();
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CNTSTATUSExplorerDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CNTSTATUSExplorerDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

/****************************************************************************
*                       CNTSTATUSExplorerDlg::parseHeader
* Inputs:
*       CStdIoFile & file: INput file
* Result: void
*       
* Effect: 
*       Reads the file as best it can
****************************************************************************/

void CNTSTATUSExplorerDlg::parseHeader(CStdioFile & file)
    {
     CString s;
     CString parenNTSTATUS(_T("((NTSTATUS)"));
     CString hashDefine(_T("#define"));

     while(file.ReadString(s))
        { /* loop */
	 if(s.GetLength() == 0)
	     continue;
	 if(s[0] != '#')
	    continue;
         if(_tcsncmp(s, hashDefine, hashDefine.GetLength()) != 0)
	    continue;
         // #define name value
         // #define name  ((NTSTATUS)value)   
	 s = s.Mid(7);  // throw away first seven characters
	 s.TrimLeft();
         int pos = s.FindOneOf(_T(" \t"));
	 if(pos < 0)
	    continue; // no whitespace after name
	 CString name(s, pos);
	 s = s.Mid(pos);
	 s.TrimLeft();

	 // Is it ((NTSTATUS)?
	 if(_tcsncmp(s, parenNTSTATUS, parenNTSTATUS.GetLength()) != 0)
	    continue;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -