| 經過了多次測試寫出了歷史上第一個有點意義的MFC程序。效果差強人意。^_^ ? CODE: // CrackWinmineDlg.cpp : implementation file // #include "stdafx.h" #include "CrackWinmine.h" #include "CrackWinmineDlg.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() / // CCrackWinmineDlg dialog CCrackWinmineDlg::CCrackWinmineDlg(CWnd* pParent /*=NULL*/) : CDialog(CCrackWinmineDlg::IDD, pParent) { //{{AFX_DATA_INIT(CCrackWinmineDlg) m_searchstats = _T(""); //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CCrackWinmineDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CCrackWinmineDlg) DDX_Control(pDX, IDC_btnOpen, m_btnOpen); DDX_Control(pDX, IDC_btnCrack, m_btnCrack); DDX_Text(pDX, IDC_txtSearchWnd, m_searchstats); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CCrackWinmineDlg, CDialog) //{{AFX_MSG_MAP(CCrackWinmineDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_WM_TIMER() ON_BN_CLICKED(IDC_butAbout, OnbutAbout) ON_BN_CLICKED(IDC_btnOpen, OnbtnOpen) ON_BN_CLICKED(IDC_btnCrack, OnbtnCrack) //}}AFX_MSG_MAP END_MESSAGE_MAP() / // CCrackWinmineDlg message handlers BOOL CCrackWinmineDlg::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 int iInstallTimer=SetTimer(1,100,NULL); if(iInstallTimer==0) MessageBox("無法啟動定時器"); return TRUE; // return TRUE unless you set the focus to a control } void CCrackWinmineDlg::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 CCrackWinmineDlg::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 CCrackWinmineDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CCrackWinmineDlg::OnTimer(UINT nIDEvent) {
UpdateData(); if(SearchProcess()==NULL) { ?? m_searchstats="游戲未啟動"; ?? m_btnOpen.EnableWindow(true); ?? m_btnCrack.EnableWindow(false); } else { ?? m_searchstats.Format("啟動中,PID:%d",proid); ?? m_btnOpen.EnableWindow(false); ?? m_btnCrack.EnableWindow(true); } UpdateData(false); CDialog::OnTimer(nIDEvent); } void CCrackWinmineDlg::OnCancel() {
CDialog::OnCancel(); } void CCrackWinmineDlg::OnbutAbout() { CAboutDlg dlg; dlg.DoModal();
} bool CCrackWinmineDlg::SearchProcess() { hwnd=::FindWindow(NULL,"掃雷"); if(hwnd==NULL) return false; GetWindowThreadProcessId(hwnd,&proid); handleProc=OpenProcess(PROCESS_ALL_ACCESS,false,proid); return true; } void CCrackWinmineDlg::OnbtnOpen() { if(WinExec("c:\\windows\\system32\\winmine.exe",SW_SHOW)<32) ?? MessageBox("你系統沒有掃雷游戲!");
} void CCrackWinmineDlg::OnbtnCrack() { CPoint clientp; GetCursorPos(&clientp); DWORD ads_minenum=0x1005330; DWORD ads_minew=0x1005334; DWORD ads_mineh=0x1005338; DWORD ads_start=0x1005361; byte hight,weight,num; ReadProcessMemory(handleProc,(void *)ads_minenum,&num,1,NULL); ReadProcessMemory(handleProc,(void *)ads_minew,&weight,1,NULL); ReadProcessMemory(handleProc,(void *)ads_mineh,&hight,1,NULL); ::ShowWindow(hwnd,SW_RESTORE); ::SetForegroundWindow(hwnd); // return; CRect rect; CPoint point; ::GetClientRect(hwnd,&rect); point.x=rect.left+20; point.y=rect.top+60; ::ClientToScreen(hwnd,&point); INPUT lbutton[2],rbutton[2]; ZeroMemory(&lbutton,sizeof(INPUT)*2); ZeroMemory(&rbutton,sizeof(INPUT)*2); lbutton[0].type=INPUT_MOUSE; rbutton[0].type=INPUT_MOUSE; lbutton[1].type=INPUT_MOUSE; rbutton[1].type=INPUT_MOUSE; lbutton[0].mi.dwFlags=MOUSEEVENTF_LEFTDOWN; lbutton[1].mi.dwFlags=MOUSEEVENTF_LEFTUP; rbutton[0].mi.dwFlags=MOUSEEVENTF_RIGHTDOWN; rbutton[1].mi.dwFlags=MOUSEEVENTF_RIGHTUP; int line,row; for(row=0;row<hight;row++) ?? for (line=0;line<weight;line++) ?? { ??? byte value; ??? ReadProcessMemory(handleProc,(void *)(ads_start+row*32+line),&value,1,NULL); ??? SetCursorPos(point.x+line*16,point.y+row*16); ??? if(value==0x8f) ??? { ???? SendInput(2,rbutton,sizeof(INPUT)); ??? } ??? if(value!=0x40) ??? { ???? SendInput(2,lbutton,sizeof(INPUT)); ??? } ?? } SetCursorPos(clientp.x,clientp.y); CloseHandle(handleProc);
} |