Nemo's Rev1 reme

Tut by Crudd




Tools:
SoftIce (for testing and learning)
MASM
WIN32 API guide

OK, now whut is it we have to do: Display a splash screen (it's in resource of Rev1.exe), when You click on the Bitmap menu. Seems easy enough...until we read the rules:
NO PATCHING & PROCESSPATCHING ALLOWED!!!
Step 1: Gaining Control...
Ok so first we have to find a way to do this..I decided on a hook on WH_CALLWNDPROC. This will send control to our dll whenever a windows message is processed. So we use: invoke SetWindowsHookEx,WH_CALLWNDPROC,addr WindProc,hInstance,NULL
This sets a hook to send messages to WindProc in our loader dll. Now we need to check to see if the right menu button is pushed. I had a bit of trouble with this part. I first checked if the windows message was WM_MENUSELECT. Lets take a look at WM_MENUSELECT in our API guide.
WM_MENUSELECT 
uItem = (UINT) LOWORD(wParam);   // menu item or submenu index 
fuFlags = (UINT) HIWORD(wParam); // menu flags 
hmenu = (HMENU) lParam;          // handle of menu clicked 
 
Ok, so we need to check the lParam for the menu handle and the loword of wParam for the submenu index. So we'll get the menu handle and the submenu index of our required menu upon entering the dll. But to do this well have to have the rev1.exe already loaded when the dll is loaded. So that means we gotta code a loader also. NOTE: There are other ways to do this, but i chose a loader. Loaders are pretty basic so im not gonna go over it. The source is commented if you need help understanding. So when we enter the dll we'll store the hwnd of the submenu and its ID. Then we'll check these when WM_MENUSELECT is processed. Heres the code for that:
WindProc proc nCode:DWORD,wParam2:DWORD,lParam2:DWORD
	invoke CallNextHookEx,hHook,nCode,wParam2,lParam2 
	mov edx,lParam2
	assume edx:PTR CWPSTRUCT		;see notes on CWPSTRUCT
	.if [edx].message == WM_MENUSELECT	;is the WM MenuSelect?
		mov eax,dword ptr [edx]		;mov lParam to eax
		.if eax == hwnd_menu		;is it our Menu?
			mov eax,edx		;point eax to CWPSTRUCT
			add eax,4		;point to wParam of CWPSTRUCT
			mov eax,dword ptr [eax] ;move wParam to eax
			.if ax == id_menu	;check ax against our menu ID
		 	    invoke MessageBoxA,NULL,addr ok,addr ok,NULL  ;for debugging
			.endif
		.endif
	.endif
First heres CWPSTRUCT:
typedef struct tagCWPSTRUCT { // cwps 
    LPARAM  lParam; 	[edx]
    WPARAM  wParam; 	[edx+4]   
    UINT    message; 	
    HWND    hwnd; 	
} CWPSTRUCT; 
Thats just to let you know how edx is set up after the assume edx:PTR CWPSTRUCT line. The messagebox is there for testing if its triggered when we select our menu item (it is :). So now all we have to do is put the rest of out code in place of the messagebox, right? Wrong. This is where the problem starts. This is only triggered when the menu item is selected, not pushed. Well after watching a few times in SI and reading over our API guide i found out If the fuFlags parameter contains 0xFFFF and the hmenu parameter contains NULL, Windows has closed the menu. Well this means the menu was selected. So that means we first need to find if our menu was selected, and if it was was it also pushed. To do this i set a flag. Instead of the messagebox in the above code i put:
.if ax == id_menu
	mov flag_menu,1
.else
	mov flag_menu,0
.endif
this sets a flag if our menu was selected. Next i added this if our menu wasnt selected (ie. if another menu is chosen or is a menu is clicked):
.else
	.if [edx].wParam == 0FFFF0000h		;these two lines check if
		.if [edx].lParam == 0		;a menu item was clicked
			.if flag_menu == 1	;is it our menu?
				call ShowBitMap ;call our splash code
			.endif
		.endif
	.endif
	mov flag_menu,0				;clear flag (our menu not selected)
.endif
Ok, now onto our ShowBitMap procedure. This was mainly taken from Iczelion's asm tut 26. I just adjusted the sizes in CreateWindow WM_CREATE and the StretchBlt WM_PAINT. I also got rid of the timer because the bitmap is chosen by the so i think the user should chose when to close it. I think that is about it.
All in all this was a pretty cool reme and i had fun beating SantMat with a solution :). Full source is included. Any questions, comments, or threats mail me at:
Crudd@DrunkenBastards.com. I also got a new REGame on my site, so check it out: Crudd.cjb.net

Greets: Muad'Dib, SantMat, Sheep140 and all of [CrEaM], noptical, extasy, all of the Immortal Descendants for thier great work, anyone who has helped me along the way, L!m!t and all of [TeX], anyone i forgot (sorry) and anyone who reads this.

Thanks to: Nemo for his great reme, beer for helping me with this reme, sluts, and of course you.

Mail me at: Crudd@DrunkenBastards.com Or check out: Crudd.cjb.net