// MineSweeping.cpp: initialization routine defined DLL.
//
#include "stdafx.h"
#include "MineSweeping.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
//
// TODO: If this DLL with respect to the MFC DLL is dynamically linked,
any transferred from the DLL exported //
// MFC function must be added to the macro AFX_MANAGE_STATE
// This function first.
//
// example:
//
// extern "C" BOOL the PASCAL the EXPORT ExportedFunction ()
// {
// the AFX_MANAGE_STATE (AfxGetStaticModuleState ());
// // normal function body here
//}
//
// This macro call before any MFC
// appear very important in each function. This means that
// it must be the first entry in the following statement:
// appear, even to declare all object variables,
// because their constructors may generate MFC
// DLL calls.
//
// Other details,
// please see MFC Technical Note 33 and 58.
//
// CMineSweepingApp
BEGIN_MESSAGE_MAP(CMineSweepingApp, CWinApp)
END_MESSAGE_MAP()
// CMineSweepingApp construction
:: CMineSweepingApp CMineSweepingApp ()
{
// the TODO: code configured to add here,
// all significant initialization in InitInstance
}
// only CMineSweepingApp objects
CMineSweepingApp theApp;
HWND g_Wnd;
WNDPROC g_OldProc;
PDWORD g_pWidth = (PDWORD)0x01005334;
PDWORD g_pHeight = (PDWORD)0x01005338;
PDWORD g_pMineCount = (PDWORD)0x01005330;
PBYTE g_pBase = (PBYTE)0x1005340;
#define MINE 0x8F
// CMineSweepingApp 初始化
// MOV ECX, DWORD PTR DS: [0x1005334]
// MOV EDX, DWORD PTR DS: [0x1005338]
// LEA EAX, DWORD PTR DS: [ECX + 0x2]
// TEST EAX, EAX
// PUSH ESI
// MOV ESI, EDX
// SHL ESI, 0x5
// LEA ESI, DWORD PTR DS: [ESI + 0x1005360]
// EAX DEC;
// BYTE MOV PTR DS: [EAX + 0x1005340], 0x10
// BYTE MOV PTR DS: [EAX + ESI], 0x10
// jnz SHORT winmine.01002F03
LRESULT
CALLBACK
WindowProc(
_In_ HWND hWnd,
_In_ UINT Msg,
_In_ WPARAM wParam,
_In_ LPARAM lParam)
{
if (Msg == WM_KEYDOWN && wParam == VK_F5)
{
OutputDebugString(L"F5");
int * = nWidth g_pWidth;
int * = nHeight g_pHeight;
int * = nMineCount g_pMineCount;
CString strString;
strString.Format(L"宽度: %d, 高度: %d ,雷数: %d", nWidth,
nHeight,nMineCount);
OutputDebugString(strString.GetBuffer());
int nFindCount = 0;
for (size_t y = 1; y < nHeight+1; y++)
{
CString strLine;
for (size_t x = 1; x < nWidth + 1; x++)
{
BYTE byCode = *(PBYTE)((DWORD)g_pBase + x + y * 32);
if (byCode == MINE)
{
nFindCount++;
//byCode = 0x8E;
}
else
{
int xPos, yPos;
xPos = (x << 4) - 4;
yPos = (y << 4) + 0x27;
//模拟键盘输入
SendMessage(hWnd, WM_LBUTTONDOWN, 0, MAKELPARAM(xPos, yPos));
SendMessage(hWnd, WM_LBUTTONUP, 0, MAKELPARAM(xPos, yPos));
}
CString strCode;
strCode.Format(L"%02x", byCode);
strLine += strCode;
}
OutputDebugString(strLine.GetBuffer());
}
CString strCode;
strCode.Format(L"雷的个数%d ", nFindCount);
OutputDebugString(strCode.GetBuffer());
}
else if(Msg == WM_MOUSEMOVE)
{
int x, y;
x = LOWORD(lParam);
y = HIWORD(lParam);
= X (X +. 4) >>. 4;
Y = (Y - 0x27) >>. 4;
BYTE * = byCode (PBYTE) ((DWORD) g_pBase + X + Y * 32);
IF (byCode == MINE)
{
SetWindowText (hWnd, L "where there is thunder");
// the MessageBox (NULL, L "be careful here Ray", NULL, NULL);
}
the else
{
SetWindowText (hWnd, L "demining");
}
}
return the CallWindowProc ( g_OldProc, the hWnd, Msg, the wParam, the lParam);
}
BOOL CMineSweepingApp::InitInstance()
{
CWinApp::InitInstance();
// Find window by 1, obtaining the window handle
g_Wnd = FindWindow (L "demining", L "demining");
IF (g_Wnd == NULL)
{
the OutputDebugString (L "window handle acquisition failure");
return FALSE;
}
/ . / 2 window provided callback
g_OldProc = (WNDPROC) the SetWindowLong (g_Wnd,
the GWL_WNDPROC, (a LONG) the WindowProc);
IF (g_OldProc == NULL)
{
the OutputDebugString (L "settings window failed callbacks");
return FALSE;
}
return TRUE;
}