tdennist
November 18th, 2004, 20:16
The task: make a trainer for the included Minesweeper game with Windows to stop the timer from advancing. I found the code address, and I made this program. However, it doesn't work
.
Am I allowed to ask someone to look over my code and tell me what's wrong? In case I am (:-D):
Using Hutch's Masm32 8.2. The problem is that when I press the 'u' key, the program crashes. And SoftIce doesn't pop up, which is rather annoying. Keep in mind when you're reading this that I am really new at this, and this is my first attempt at a serious one of these type things. Don't make too much fun of me
.
Thanks.

Am I allowed to ask someone to look over my code and tell me what's wrong? In case I am (:-D):
Using Hutch's Masm32 8.2. The problem is that when I press the 'u' key, the program crashes. And SoftIce doesn't pop up, which is rather annoying. Keep in mind when you're reading this that I am really new at this, and this is my first attempt at a serious one of these type things. Don't make too much fun of me

Code:
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\gdi32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\kernel32.lib
WinMain protoWORD,
WORD,
WORD,
WORD
.DATA
ClassName db "SimpleWinClass",0
AppName db "Window Name",0
char WPARAM 20h
winName db "Minesweeper",0 ; the name of the window
toWrite QWORD 909090909090h ; the bytes to write; 6 NOPs
.DATA?
hInstance HINSTANCE ?
CommandLine LPSTR ?
IDProcess DWORD ? ; the ID of the process
tempHWnd HWND ? ; the window handle of the process
hProcess HANDLE ? ; eventually, the process to write to
.CODE
start:
invoke GetModuleHandle, NULL
mov hInstance, eax
invoke GetCommandLine
mov CommandLine, eax
invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT
invoke ExitProcess, eax
WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShowWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND
mov wc.cbSize, SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
push hInstance
pop wc.hInstance
mov wc.hbrBackground, COLOR_WINDOW+1
mov wc.lpszMenuName, NULL
mov wc.lpszClassName, OFFSET ClassName
invoke LoadIcon, NULL, IDI_APPLICATION
mov wc.hIcon, eax
mov wc.hIconSm, eax
invoke LoadCursor, NULL, IDC_ARROW
mov wc.hCursor, eax
invoke RegisterClassEx, addr wc
invoke CreateWindowEx, NULL,\
ADDR ClassName,\
ADDR AppName,\
WS_OVERLAPPEDWINDOW,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
200,\
200,\
NULL,\
NULL,\
hInst,\
NULL
mov hwnd, eax
invoke ShowWindow, hwnd, CmdShow
invoke UpdateWindow, hwnd
.WHILE TRUE
invoke GetMessage, ADDR msg, NULL, 0, 0
.BREAK .IF (!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDW
mov eax, msg.wParam
ret
WinMain endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL hdc:HDC
LOCAL ps:PAINTSTRUCT
.IF uMsg == WM_DESTROY
invoke PostQuitMessage, NULL
.ELSEIF uMsg == WM_CHAR
push wParam
pop char
.IF char == 75h ;u
mov char,25h ;%
invoke InvalidateRect, hWnd, NULL, TRUE
call StopTime
.ELSE
invoke InvalidateRect, hWnd, NULL, TRUE
.ENDIF
.ELSEIF uMsg==WM_PAINT
invoke BeginPaint, hWnd, ADDR ps
mov hdc,eax
invoke TextOut, hdc, 90,70, ADDR char, 1
invoke EndPaint, hWnd, ADDR ps
.ELSE
invoke DefWindowProc,hWnd, uMsg, wParam, lParam
ret
.ENDIF
xor eax,eax
ret
WndProc endp
StopTime proc
invoke FindWindowA, NULL, ADDR winName ;get hWnd for Minesweeper
mov tempHWnd, eax ;put it into tempHWnd
invoke GetWindowThreadProcessId, tempHWnd, IDProcess ;get the process ID
invoke OpenProcess, PROCESS_ALL_ACCESS, FALSE, IDProcess ;open the process
mov hProcess, eax ;load the process handle into hProcess
invoke WriteProcessMemory, hProcess, 01002FF5h, ADDR toWrite, 6, NULL ;write the stuff
invoke CloseHandle, hProcess
StopTime endp
end start
Thanks.