Click to See Complete Forum and Search --> : Game trainer??


access1011
April 2nd, 2009, 05:05 PM
i have my button set up on a windows for a game trainer. i need to know how to give it the funtion to write to memory. I know how to invoke WriteProcessMemory.....i just cant get the button to function..im lost because i can do this in c++ but this is way different.


heres my code


; #########################################################################

.386
.model flat, stdcall ; 32 bit memory model
option casemap :none ; case sensitive

include showbmp.inc ; local includes for this file

; #########################################################################
DlgProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
.data
Gaddress1 dd 0040cd46h
Gval1 db 090h,090h,090h,090h,090h,090h
Gnum1 dd 6
bytes_written dw 0
FileName db "game.exe",0
flag_loaded db 0
Flag_@error db 0
Hwnd dd 0

.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 :DWORD,
hPrevInst :DWORD,
CmdLine :DWORD,
CmdShow :DWORD

;====================
; Put LOCALs on stack
;====================

LOCAL wc :WNDCLASSEX
LOCAL msg :MSG
LOCAL Wwd :DWORD
LOCAL Wht :DWORD
LOCAL Wtx :DWORD
LOCAL Wty :DWORD

;==================================================
; Fill WNDCLASSEX structure with required variables
;==================================================

invoke LoadIcon,hInst,500 ; icon ID
mov hIcon, eax


szText szClassName,"Project_Class"

mov wc.cbSize, sizeof WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW \
or CS_BYTEALIGNWINDOW
mov wc.lpfnWndProc, offset WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
m2m wc.hInstance, hInst
mov wc.hbrBackground, COLOR_BTNFACE+1
mov wc.lpszMenuName, NULL
mov wc.lpszClassName, offset szClassName
m2m wc.hIcon, hIcon
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor, eax
m2m wc.hIconSm, hIcon

invoke RegisterClassEx, ADDR wc

;================================
; Centre window at following size
;================================

mov Wwd, 264
mov Wht, 380

invoke GetSystemMetrics,SM_CXSCREEN
invoke TopXY,Wwd,eax
mov Wtx, eax

invoke GetSystemMetrics,SM_CYSCREEN
invoke TopXY,Wht,eax
mov Wty, eax

invoke CreateWindowEx,WS_EX_LEFT,
ADDR szClassName,
ADDR szDisplayName,
WS_OVERLAPPED or WS_SYSMENU,
Wtx,Wty,Wwd,Wht,
NULL,NULL,
hInst,NULL
mov hWnd,eax

invoke LoadMenu,hInst,600 ; menu ID
invoke SetMenu,hWnd,eax

invoke ShowWindow,hWnd,SW_SHOWNORMAL
invoke UpdateWindow,hWnd

;===================================
; Loop until PostQuitMessage is sent
;===================================

StartLoop:
invoke GetMessage,ADDR msg,NULL,0,0
cmp eax, 0
je ExitLoop
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
jmp StartLoop
ExitLoop:

return msg.wParam

WinMain endp

; #########################################################################

WndProc proc hWin :DWORD,
uMsg :DWORD,
wParam :DWORD,
lParam :DWORD

LOCAL var :DWORD
LOCAL caW :DWORD
LOCAL caH :DWORD
LOCAL hStatImage :DWORD
LOCAL hStatIcon :DWORD
LOCAL hIcon1 :DWORD
LOCAL hBmp :DWORD
LOCAL Rct :RECT
LOCAL hDC :DWORD
LOCAL Ps :PAINTSTRUCT
LOCAL buffer1[128]:BYTE ; these are two spare buffers
LOCAL buffer2[128]:BYTE ; for text manipulation etc..

.if uMsg == WM_COMMAND


.elseif uMsg == WM_CREATE

.data
butn1 db "Terminate ME",0

.code

invoke PushButton,ADDR butn1,hWin,0,305,264,50,500



; ---------------------------------------
; Setting the top X and Y co-ordinate are
; the only ones that matter. Loading the
; bitmap into the control auto-sizes the
; control to the size of the bitmap.
; ---------------------------------------
invoke StaticImage,NULL,hWin,0,0,10,10,65535
mov hStatImage, eax

; --------------------------------------
; load the bitmap from the resource file
; --------------------------------------
invoke LoadBitmap,hInstance,750
mov hBmp, eax ; put the return value into a DWORD variable

; -------------------------------------
; Set the image into the static control
; -------------------------------------
invoke SendMessage,hStatImage,STM_SETIMAGE,IMAGE_BITMAP,hBmp



mov hStatIcon, eax
invoke LoadIcon,hInstance,500
mov hIcon1, eax
invoke SendMessage,hStatIcon,STM_SETIMAGE,IMAGE_ICON,hIcon1


.elseif uMsg == WM_SIZE

.elseif uMsg == WM_PAINT
invoke BeginPaint,hWin,ADDR Ps
mov hDC, eax
invoke Paint_Proc,hWin,hDC
invoke EndPaint,hWin,ADDR Ps
return 0

.elseif uMsg == WM_CLOSE

.elseif uMsg == WM_DESTROY
invoke PostQuitMessage,NULL
return 0
.endif

invoke DefWindowProc,hWin,uMsg,wParam,lParam

ret

WndProc endp

; ########################################################################

TopXY proc wDim:DWORD, sDim:DWORD

shr sDim, 1 ; divide screen dimension by 2
shr wDim, 1 ; divide window dimension by 2
mov eax, wDim ; copy window dimension into eax
sub sDim, eax ; sub half win dimension from half screen dimension

return sDim

TopXY endp

; #########################################################################

Paint_Proc proc hWin:DWORD, hDC:DWORD

LOCAL btn_hi :DWORD
LOCAL btn_lo :DWORD
LOCAL Rct :RECT

invoke GetSysColor,COLOR_BTNHIGHLIGHT
mov btn_hi, eax

invoke GetSysColor,COLOR_BTNSHADOW
mov btn_lo, eax

return 0

Paint_Proc endp

; ########################################################################

end start

rxbagain
April 2nd, 2009, 08:47 PM
To get the click event from the button we process the WM_COMMAND message. But before we can check what button generated the message, we should assign a control id when we create the button

.if uMsg == WM_COMMAND
.if wParam == 100 ; is it MAKELONG(BN_CLICKED, 100) ?
szText msg, "Button was clicked"
invoke MessageBox, hWin, ADDR msg, NULL, MB_ICONINFORMATION
.endif
.elseif uMsg == WM_CREATE

...

szText szButtonClass, "Button"
invoke CreateWindowEx, 0, ADDR szButtonClass, ADDR butn1, WS_CHILD OR WS_BORDER OR WS_VISIBLE,
0, 0, 100, 100, hWin, 100, hInstance, NULL

...

I don't know what your function PushButton does but I have a feeling parameter 3 is used to set the control id :D.

Hope it will help you :)

Edit: You can also save the Button HWND and compare it with the lParam of WM_COMMAND. I prefer to use the control ID though.