Hi all ;)

This is my first post here :) and I am glad to be here.

I'm trying to make a code for a Global Hotkey using masm , can you please take a look and tell me what is wrong with the code ?

.386

.model flat,stdcall
.data
Iczelion23421433 db 0
.code
IczelionStart:
include c:\masm32\include\windows.inc
include c:\masm32\include\user32.inc
include c:\masm32\include\kernel32.inc
includelib c:\masm32\lib\user32.lib
includelib c:\masm32\lib\kernel32.lib



.data?
hInstance HINSTANCE ?
waHwnd dd ?
hWnd dd ?
msg MSG <?>


.data
wc WNDCLASSEX <size WNDCLASSEX, 0, WndProc, 0, 0, hInstance, 0, 0, COLOR_WINDOW, 0, windowClass, 0>

windowClass db "Hotkey",0
waClass db "Winamp v1.x",0

hmsg db "HotKey CTRL + ALT + A Works good!",0
hcap db "Hotkey Example",0



.code
start:

invoke GetModuleHandle, NULL
mov hInstance,eax

call WinMain

push 0
call ExitProcess


WinMain proc

push offset wc
call RegisterClassExA

push 0
push offset hInstance
push 0
push 0
push 0
push 0
push 0
push 0
push 0
push 0
push offset windowClass
push 0
call CreateWindowExA

mov hWnd, eax

msg_loop:

push 0
push 0
push 0
push offset msg
call GetMessageA

or eax,eax
jz end_loop

push offset msg
call DispatchMessageA
jmp msg_loop

end_loop:

WinMain endp



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

.if uMsg == WM_CREATE
invoke RegisterHotKey,hWnd,065h,MOD_CONTROL or MOD_ALT, 041h

.elseif uMsg == WM_HOTKEY
invoke MessageBox,hWin,addr hmsg,addr hcap, MB_OK or MB_ICONINFORMATION

.elseif uMsg == WM_DESTROY
invoke UnregisterHotKey,hWin,065h
invoke PostQuitMessage,NULL
ret 0
.endif

WndProc endp
end start
db 'IczelionMarker'
end IczelionStart


Thanks a lot for taking a look ... now answer me :D
I want the hotkey to be F7 ... i will look it out later.

HACKERGY.
Posted on 2004-10-07 07:12:29 by HACKERGY
hi hackergy
i dont know wat u are trying to do coz u want the hotkey to be f7 and u are registering one for ctrl+alt+a.
anyway, i have fixed it, i guess.
instead of ur this code


.elseif uMsg == WM_HOTKEY
invoke MessageBox,hWin,addr hmsg,addr hcap, MB_OK or MB_ICONINFORMATION

use this code. it will work.


.ELSEIF uMsg == WM_HOTKEY
mov eax,wParam
.if eax==065h
invoke MessageBox,hWin,addr hmsg,addr hcap, MB_OK
.endif
Posted on 2004-10-07 14:03:14 by nickdigital
Thank you very much man.

What does mov eax,wParam means :oops: ?


I'm trying to add this code to another EXE .... you know like code injection .... and I think there something wrong because it is not working :(

You know Snippet Creator ? ... i'm trying to add my code using it .... but when I click on "Patch Target" ... Snippet Creator crashes !!! Why is that ?
Posted on 2004-10-08 06:04:56 by HACKERGY
hi hackergy
i can only tell why snippet creator crashes when u show me ur code or else its dificult to get to know actually wat u want to do.
be specific and may be i ll help u if nothing fishy is goin in ur mind

anyway i feel u can create ur own loader instead of using snippet creator.
it would be completely under ur control.

nickdigital
Posted on 2004-10-08 10:02:47 by nickdigital
Thanks a lot man.

But I don't know how to make Loader !
Posted on 2004-10-08 11:43:55 by HACKERGY
hi hackergy
if u wanna chat with me then u can do it in yahoo messenger.
my id is mastercode_digger
most of the time u can find me in programming rooms
Posted on 2004-10-08 13:07:53 by nickdigital
Thanks man I apreciate it :)

After the correction u made to my code ..... I assemble the code with no errors .... but when I try to run it it just crashes up ! ... what is the reason ?
Posted on 2004-10-08 13:12:48 by HACKERGY
:)
Maybe you could use this instead of code injection (easier, less "hacky"):
http://www.asmcommunity.net/board/viewtopic.php?t=14463
Posted on 2004-10-08 13:19:44 by QvasiModo
hi hackergy
i guess u are new to masm...
anyway ur code is full of errors like
u have defined .data and .code 2 times.
correct it first and then next time post ur
code
nickdigital
Posted on 2004-10-08 13:22:33 by nickdigital
Hi guys ;)

Thanks for you.

Now this is the code corrected from errors as I think :
.386

.model flat,stdcall
.data
Iczelion23421433 db 0
.code
IczelionStart:
include c:\masm32\include\windows.inc
include c:\masm32\include\user32.inc
include c:\masm32\include\kernel32.inc
includelib c:\masm32\lib\user32.lib
includelib c:\masm32\lib\kernel32.lib

jmp @F

hInstance HINSTANCE ?
waHwnd dd ?
hWnd dd ?
msg MSG <?>
wc WNDCLASSEX <size WNDCLASSEX, 0, WndProc, 0, 0, hInstance, 0, 0, COLOR_WINDOW, 0, windowClass, 0>
windowClass db "Hotkey",0
waClass db "Winamp v1.x",0
hmsg db "HotKey CTRL + ALT + A Works good!",0
hcap db "Hotkey Example",0

@@:
invoke GetModuleHandleA, NULL
mov hInstance,eax

call WinMain

push 0
call ExitProcess


WinMain proc

push offset wc
call RegisterClassExA

push 0
push offset hInstance
push 0
push 0
push 0
push 0
push 0
push 0
push 0
push 0
push offset windowClass
push 0
call CreateWindowExA

mov hWnd, eax

msg_loop:

push 0
push 0
push 0
push offset msg
call GetMessageA

or eax,eax
jz end_loop

push offset msg
call DispatchMessageA
jmp msg_loop

end_loop:

WinMain endp



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

.if uMsg == WM_CREATE
invoke RegisterHotKey,hWnd,065h,MOD_CONTROL or MOD_ALT, 041h

.ELSEIF uMsg == WM_HOTKEY
mov eax,wParam
.if eax==065h
invoke MessageBoxA,hWin,addr hmsg,addr hcap, MB_OK
.endif

.elseif uMsg == WM_DESTROY
invoke UnregisterHotKey,hWin,065h
invoke PostQuitMessage,NULL
ret 0
.endif

WndProc endp

db 'IczelionMarker'
end IczelionStart


Now what I am doing is using Snippet Creator is patching the target file with this code with the option of making a new section and "Redirected EntryPoint RVA" so as I think my code will be executed as soon as the program is loaded. The file is patched succesfully but when I run the EXE file the program crashes :( why is that ? Am I patching my code in the wrong place ?

What I want is just the program to work and when I click on my Hotkey the message comes out.


Thanks.
Posted on 2004-10-08 14:35:19 by HACKERGY
hi hackergy
i feel ur program still has a lot of bugs.
i am just giving you a small example of how a
hotkey is created.i guess it will help u .

compile it, execute it and press ctrl+alt+a to activate the hotkey.


.386
.model flat,stdcall
option casemap:none
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib


.data

ClassName db "DLGCLASS",0
DlgName db "MyDialog",0
AppName db "Hotkey example by Nickdigital",0
loaded db "You pressed the hotkey Ctrl+Alt+A",0
Voila db "Voila",0

.data?
hInstance HINSTANCE ?
CommandLine LPSTR ?

.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,CmdShow:DWORD
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 hInst
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,0
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,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\
hInst,NULL
mov hWnd,eax
INVOKE ShowWindow, hWnd,SW_SHOWNORMAL
INVOKE UpdateWindow, hWnd

.WHILE TRUE
INVOKE GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke IsDialogMessage, hWnd, ADDR msg
.if eax==FALSE
INVOKE TranslateMessage, ADDR msg
INVOKE DispatchMessage, ADDR msg
.endif
.ENDW
mov eax,msg.wParam
ret
WinMain endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

.if uMsg==WM_CREATE
invoke RegisterHotKey,hWnd,065h,MOD_CONTROL or MOD_ALT, 041h ; CTRL + ALT + A
.ELSEIF uMsg==WM_DESTROY
invoke UnregisterHotKey,hWnd,065h
invoke PostQuitMessage,NULL
.ELSEIF uMsg == WM_HOTKEY
mov eax,wParam
.if eax==065h
invoke MessageBox,NULL, ADDR loaded,ADDR Voila, MB_ICONEXCLAMATION

.endif

.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret
WndProc endp
end start

Posted on 2004-10-08 15:45:45 by nickdigital
Afternoon, HACKERGY.

Talking about Hot Keys is fine, however please refrain from talking about code injection.

Cheers,
Scronty
Posted on 2004-10-09 06:28:09 by Scronty