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

📄 crackaccessdlg.cpp

📁 加密与解码——密码技术剖析与实战应用中的一个例子
💻 CPP
字号:
// CrackAccessDlg.cpp : implementation file
//

#include "stdafx.h"
#include "CrackAccess.h"
#include "CrackAccessDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CCrackAccessDlg dialog

CCrackAccessDlg::CCrackAccessDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCrackAccessDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCrackAccessDlg)
	m_strFileName = _T("");
	m_strPassword = _T("");
	
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CCrackAccessDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCrackAccessDlg)
	DDX_Control(pDX, IDC_COMBO1, m_ctrlType);
	DDX_Control(pDX, IDC_EDIT_PASSWORD, m_ctrlPassword);
	DDX_Control(pDX, IDC_EDIT_FILENAME, m_ctrlFileName);	
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CCrackAccessDlg, CDialog)
//{{AFX_MSG_MAP(CCrackAccessDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDFILEOPEN, OnFileOpen)
ON_BN_CLICKED(IDDECODE, OnDecode)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCrackAccessDlg message handlers

BOOL CCrackAccessDlg::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);
	if (pSysMenu != NULL)
	{
		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
	
	// TODO: Add extra initialization here
	file = new CFile;	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CCrackAccessDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// 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 CCrackAccessDlg::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 CCrackAccessDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CCrackAccessDlg::OnFileOpen() 
{	
	CFileDialog dlg(TRUE);
	if (dlg.DoModal()==IDOK){	
		m_strFileName = dlg.GetPathName();
		m_ctrlFileName.SetWindowText(m_strFileName);
		file->Open(dlg.GetPathName(),CFile::modeRead|CFile::shareDenyNone);				
	}	
}

void CCrackAccessDlg::OnDecode() 
{
	GetAccessPassword(file);
}

void CCrackAccessDlg::GetAccessPassword(CFile *f)
{	
	char *pBuffer; 	/*数据缓冲区*/
	DWORD dwReadBytes,i,j;
	
	char CodeXP[0x27]={0x93,0xEC,0x48,0x9C,0xD3,0x28,0x06,0x8A,0x41,0x7B, 		/*XP 译码表*/
		0xE0,0xDF,0x62,0x13,0xDA,0xB1,0x21,0x79,0x87,0x7C}; 
    char Code2k[0x27]={0x96,0xEC,0x4D,0x9C,0xD6,0x28,0x03,0x8A,0x44,0x7B,		/*2000 译码表*/
		0xE5,0xDF,0x67,0x13,0xDF,0xB1,0x24,0x79,0x82,0x7C}; 
	char Code97[0x27]={0x86,0xFB,0xEC,0x37,0x5D,0x44,0x9C,0xFA,0xC6,0x5E,0x28,	/*97 译码表*/
		0xE6,0x13,0xB6,0x8A,0x60,0x54,0x94,0x7B,0x36};
	char Code[0x27];	
	
	UpdateData();
	int nType = m_ctrlType.GetCurSel(); //类型选择
	switch (nType){	
	case 0:
		for (i=0;i<0x27;i++)
			Code[i]=Code97[i];		
		break;
	case 1:
		for (i=0;i<0x27;i++)
			Code[i]=Code2k[i];		
		break;
	case 2:
		for (i=0;i<0x27;i++)
			Code[i]=CodeXP[i];		
		break;
	}				 
	
	if (f){
		f->Seek(0x42,CFile::begin); 				/*文件定位*/
		pBuffer=new char[0x27]; 
		dwReadBytes = f->Read(pBuffer,0x27); 		/*读取数据,返回字节个数*/        
		i=dwReadBytes/2; 
		for(j=0;j<=i;j++) 		
		{ 
			if (nType>0)							/* nType =1,2为Access2000,XP*/		
				Code[j]=Code[j]^pBuffer[2*j];		/*与译码表作异或,译出密码*/ 
			else									/* nType =0   Access 97 */
				Code[j]=Code[j]^pBuffer[j];			/*与译码表作异或,译出密码*/ 
		}		
		delete [] pBuffer; 

		m_strPassword = Code;						/*结果存入Password Edit*/
		if(strlen(m_strPassword) == 0) 
			m_ctrlPassword.SetWindowText("此数据库未设置密码!");
		else
			m_ctrlPassword.SetWindowText(m_strPassword);
		
	} 
	else 
	{ 
        MessageBox("没有输入有效的文件名","注意!",MB_OK); 
	}	
}

⌨️ 快捷键说明

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