The debug code right after WM_TIMER is not working.
I could not find the nops either in Ollydbg.
Did the compiler substitute something else ?
include \masm32\include\debug.inc
includelib \masm32\lib\debug.lib
; ----------------------------
; memory to memory assignment
; ----------------------------
m2m MACRO M1, M2
push M2
pop M1
ENDM
WM_SHELLNOTIFY equ WM_USER+5
IDI_TRAY equ 0
IDM_EXIT equ 100
IDM_Dial equ 200
IDM_Hangup equ 250
WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
ID_TIMER equ 1
IDI_TASKBARICON equ 0
WM_CALLBACK equ WM_USER + 100
RASENTRYNAME5A STRUCT
dwSize dd ?
szEntryName db 260 dup(?)
dwFlags dd ?
szPhonebookPath db 264 dup(?)
RASENTRYNAME5A ENDS
RASENTRYNAME5 EQU <RASENTRYNAME5A>
RASDIALPARAMS4A STRUCT
dwSize dd ?
szEntryName db 101h dup(?)
szPhoneNumber db 81h dup(?)
szCallbackNumber db 81h dup(?)
szUserName db 101h dup(?)
szPassword db 101h dup(?)
szDomain db 13h dup(?)
dwSubEntry dd ?
dwCallbackId dd ?
RASDIALPARAMS4A ENDS
RASDIALPARAMS4 EQU <RASDIALPARAMS4A>
.data
hInstance dd 0
hWnd dd 0
hIcon dd 0
hPopupMenu dd 0
hSwitchIcon db 0
szClassName db "AutoDial",0
szDisplayName db "Dialing Out",0
szExitString db "Exit program",0
szDial_Out db "Dial in to Internet.",0
szHangup db "Disconnect from the internet.",0
szApp db "AutoDial",0
Sound db "C:\WINDOWS\Media\tada.wav",0
pt POINT <>
note NOTIFYICONDATA <>
.data?
l_RASCONN RASCONN 0FFh dup ({})
l_Buffer_Size dd ?
l_Conn_Count dd ?
hIconGreen DWORD ? ; Green icon
hIconRed DWORD ? ; Red icon
.code
WaterMark db "SiegeWorks"
%Date db " &@Date " ; Compile date
start:
invoke GetModuleHandle,0
mov hInstance,eax
invoke WinMain,hInstance,0,0,0
invoke ExitProcess,eax
WinMain proc hInst:DWORD,hPrevInst:DWORD,CmdLine:DWORD,CmdShow:DWORD
; Standard window creation stuff
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
mov wc.cbSize,SIZEOF WNDCLASSEX
mov wc.style,CS_HREDRAW or CS_VREDRAW or CS_BYTEALIGNWINDOW
mov wc.lpfnWndProc,OFFSET WndProc
mov wc.cbClsExtra,0
mov wc.cbWndExtra,0
mov eax,hInst
mov wc.hInstance,eax
mov wc.hbrBackground,COLOR_WINDOW+1
mov wc.lpszMenuName,0
mov wc.lpszClassName,OFFSET szClassName
invoke LoadImage,hInstance,2000,IMAGE_ICON,0,0,LR_DEFAULTSIZE ; Green icon
mov hIcon,eax
mov wc.hIcon,eax
invoke LoadCursor,0,IDC_ARROW
mov wc.hCursor,eax
mov wc.hIconSm,0
invoke RegisterClassEx,ADDR wc
invoke CreateWindowEx,WS_EX_LEFT,
ADDR szClassName,
ADDR szDisplayName,
WS_OVERLAPPEDWINDOW,
0,0,0,0,
0,0,
hInstance,0
mov hWnd,eax
StartLoop:
invoke GetMessage,ADDR msg,0,0,0
cmp eax,0
je ExitLoop
invoke TranslateMessage,ADDR msg
invoke DispatchMessage,ADDR msg
jmp StartLoop
ExitLoop:
invoke KillTimer, hWnd, ID_TIMER
mov eax,msg.wParam
ret
WinMain endp
WndProc proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
LOCAL lpRasEntryName :DWORD
LOCAL dwCb :DWORD
LOCAL dwEntries :DWORD
LOCAL rp :RASDIALPARAMS4
LOCAL fPass :BOOL
LOCAL hConn :DWORD
.if uMsg == WM_CREATE
; We will need a pop up menu
invoke LoadImage,hInstance,2000,IMAGE_ICON,0,0,NULL ; The green icon
mov hIconGreen, eax
invoke LoadImage,hInstance,3000,IMAGE_ICON,0,0,NULL ; Red icon
mov hIconRed,eax
invoke CreatePopupMenu
mov hPopupMenu,eax
invoke AppendMenu,hPopupMenu,MF_STRING,IDM_Dial,ADDR szDial_Out
invoke AppendMenu,hPopupMenu,MF_STRING,IDM_Hangup,ADDR szHangup
invoke AppendMenu,hPopupMenu,MF_STRING,IDM_EXIT,ADDR szExitString
mov note.cbSize,sizeof NOTIFYICONDATA
push hWin
pop note.hwnd
mov note.uID,IDI_TASKBARICON
mov note.uFlags,NIF_ICON+NIF_MESSAGE+NIF_TIP
mov note.uCallbackMessage,WM_SHELLNOTIFY
m2m note.hIcon, hIconGreen
invoke lstrcpy,addr note.szTip,addr szApp
invoke Shell_NotifyIcon,NIM_ADD,addr note
.elseif uMsg == WM_COMMAND
; Handle pop up menu options to Dial In,Disconnect,or Exit the program.
.if lParam == 0
mov eax,wParam
.if eax == IDM_EXIT
invoke Shell_NotifyIcon,NIM_DELETE,ADDR note
invoke SendMessage,hWin,WM_DESTROY,0,0
.elseif eax == IDM_Dial
; Let's dial in for dollars :-)
;invoke SetTimer, hWnd, ID_TIMER, 100, NULL ; Doesn't work here either
mov dwCb, sizeof RASENTRYNAME5
mov lpRasEntryName, 0
AllocateRasEntryNameLoop1:
cmp lpRasEntryName, 0
je AllocateRasEntryName1
invoke GetProcessHeap
invoke HeapFree, eax, 0, lpRasEntryName
AllocateRasEntryName1:
invoke GetProcessHeap
invoke HeapAlloc, eax, 0, dwCb
cmp eax, 0
je RetFail1
mov lpRasEntryName, eax
invoke RtlZeroMemory, lpRasEntryName, dwCb
mov ebx, sizeof RASENTRYNAME5
mov eax, lpRasEntryName
mov (RASENTRYNAME5 PTR [eax]).dwSize, ebx
invoke RasEnumEntries, NULL, NULL, lpRasEntryName, ADDR dwCb, ADDR dwEntries
cmp eax, 278h
je AllocateRasEntryNameLoop1
cmp eax, 0
jne RetFail1
mov dwCb, sizeof RASDIALPARAMS4
invoke RtlZeroMemory, ADDR rp, dwCb
mov eax, dwCb
mov rp.dwSize, eax
mov eax, lpRasEntryName
invoke lstrcpy, ADDR rp.szEntryName, ADDR (RASENTRYNAME5 PTR [eax]).szEntryName
invoke RasGetEntryDialParams, NULL, ADDR rp, ADDR fPass
cmp eax, 0
jne RetFail1
mov hConn, 0
invoke RasDial, NULL, NULL, ADDR rp, 0, NULL, ADDR hConn
cmp eax, 0
jne RetFail1
invoke PlaySound,ADDR Sound,NULL,SND_SYNC
; Blinks when connected, but continues to blink when disconnected ?
invoke SetTimer, hWnd, ID_TIMER, 100, NULL ; Doesn't work here
RetFail1:
cmp lpRasEntryName, 0
je AllocateRasEntryName1
invoke GetProcessHeap
invoke HeapFree, eax, 0, lpRasEntryName
;invoke SetTimer, hWnd, ID_TIMER, 100, NULL ; Doesn't work here
.elseif eax == IDM_Hangup
mov l_RASCONN.dwSize, sizeof RASCONN + 1
mov l_Buffer_Size, sizeof l_RASCONN
; list all active RAS connections
invoke RasEnumConnections, addr l_RASCONN, addr l_Buffer_Size, addr l_Conn_Count
; terminate the Remote Access Connection
invoke RasHangUp, l_RASCONN.hrasconn
invoke Sleep,1500 ; give the system enuf time to end the connection
; Don't want to leave the port in an inconsistent state.
; Orig. position of SetTimer
;invoke SetTimer, hWnd, ID_TIMER, 100, NULL ; Orig. position of SetTimer
.endif
.endif
.elseif uMsg == WM_SHELLNOTIFY
; Pop up apps menu if the user right clicks on sys tray icon.
.if wParam == IDI_TRAY
.if lParam == WM_RBUTTONDOWN or WM_RBUTTONUP
invoke GetCursorPos,ADDR pt
invoke SetForegroundWindow,hWin
invoke TrackPopupMenuEx,hPopupMenu,
TPM_RIGHTALIGN or TPM_LEFTBUTTON,
pt.x,pt.y,hWin,0
invoke PostMessage,hWin,WM_NULL,0,0
.endif
.endif
.elseif uMsg == WM_DESTROY
; Destroy popup menu and shut down our app.
invoke DestroyMenu,hPopupMenu
invoke PostQuitMessage,0
.ELSEIF uMsg == WM_TIMER
nop ; could not find these on Ollydbg
PrintText "TIMER"
PrintDec hSwitchIcon
nop
.if hSwitchIcon==0
m2m note.hIcon, hIconGreen ; Green icon
mov hSwitchIcon,1
.else
m2m note.hIcon, hIconRed ; Red icon
mov hSwitchIcon,0
.endif
invoke Shell_NotifyIcon, NIM_MODIFY, ADDR note
.endif
invoke DefWindowProc,hWin,uMsg,wParam,lParam
ret
WndProc endp
end start
try using DB...
db 90h ;NOP
If you are using a compiler, who knows what it is doing :-)
Are you sure your eyes aren't missing the NOP's? PrintText and PrintDec add ALOT of code to your exe, so it will be kinda hard to find the NOPS.. put an INT 3 right before your NOP and run your program, when WM_TIMER fires your program will crash and if Olly is your JIT debugger it will open to the INT 3 line.
The code works after I added this PrintDec, why I have no idea.
The blinking icon code still isn't working.
I am not ready to give up. :thumbu
mov hWnd,eax
PrintDec eax ; print value of EAX
I have verified that the SetTimer and KillTimer are working.
So if the timer is killed, why is this code still executing after a
connection has been made ?
I don't understand what "time out value" means in regards to SetTimer.
.ELSEIF uMsg == WM_TIMER
.if hSwitchIcon==0
m2m note.hIcon, hIconGreen ; Green icon
mov hSwitchIcon,1
.else
m2m note.hIcon, hIconRed ; Red icon
mov hSwitchIcon,0
.endif
invoke Shell_NotifyIcon, NIM_MODIFY, ADDR note
.endif
invoke DefWindowProc,hWin,uMsg,wParam,lParam
windows timer event mechanism is good for some things
sometimes, it's easier to simply create a thread and use Sleep :P
Do I use CreateProcess for that ?
I am reading up on it.
CreateThread
xor eax,eax
INVOKE CreateThread,eax,eax,TimeThrd,eax,eax,eax
;
;
;
TimeThrd PROC
INVOKE Sleep,TimeoutPeriodInMs
;
;when the time expires, do stuff here
;
INVOKE ExitThread,0
TimeThrd ENDP
there are numerous ways to make variations
you can pass the function a parameter (grab it with [esp+4])
and you can test to see if the thread has terminated with GetExitCodeThread
forgot to mention...
another variation - i sometimes create a semaphore and use it in conjunction with the thread