Hooked notepad... What to do now to know if the user presses my Menu item?

Started by David, January 17, 2010, 06:24:42 PM

Previous topic - Next topic

David

I have created a menu on NotePad, now all I need to do is somehow hook it so that I know if somebody presses that menu.  How will I do this?  Is it possible without a DLL? Can anybody link me any good reads about hooking using mAssembly?

Here is what I have so far:

hook.asm

.386
.model flat, stdcall
option casemap:none

include hook.inc

.code
start:
main proc
pushz "Untitled - Notepad"
push 0
call FindWindow
cmp eax, 0
jnz _found
push 16
push 0
pushz "Unable to find a running instance of Notepad. Aborting..."
push 0
call MessageBox
Ret
_found:
mov hHookedWindow, eax
push hHookedWindow
call GetMenu
cmp eax, 0
jnz _hooked
push 16 ;Magic number for MB_OK + MB_ICONERROR
push 0 ;magic number for "Error"
pushz "Unable to hook menu. Aborting..."
push 0
call MessageBox
Ret
_hooked:
mov hAppMenu, eax
call CreateMenu
cmp eax, 0
jnz _newmenu
push 16
push 0
pushz "CreateMenu() - Failed. Aborting..."
push 0
call MessageBox
Ret
_newmenu:
mov hAppendMenu, eax
pushz "Hooked"
push hAppendMenu
push MF_STRING or MF_POPUP
push hAppMenu
call AppendMenu
pushz "Open Calculator"
push 125
push MF_STRING
push hAppendMenu
call AppendMenu
Ret
main EndP
end start


hook.inc

include 2macro.inc
include structs.inc

uselib kernel32
uselib user32
uselib shell32
uselib comdlg32
uselib winmm

main PROTO

.CONST

.DATA

.DATA?
hAppMenu DWORD  ?
hAppendMenu DWORD  ?
hMenuWnd DWORD  ?
hHookedWindow DWORD  ?



2macro.inc

include windows.inc

uselib MACRO libname
include libname.inc
includelib libname.lib
EndM

pushz MACRO szText:VARARG
local nexti
call nexti
db szText, 00h
nexti:
EndM


structs.inc

;Empty for now


PS:  I read one article on CodeProject, and they used #pragma data_seg("Shared") in their DLL.  I have no idea how to do that in Assembly.  Hopefully I won't have to use a fat DLL to accomplish this.

askm

Does anyone know a good hooker ?

Good subclassing and hooking book(s) can be sourced.

A good hooker likes to do it in the higher level languages for more immediate pleasure.

Use this low level stuff for tweaking the most executed routines and especially if you are just a minor.

Wear protection always.

Slugsnack

You're probably looking for SetWindowsHookEx() since you did not hook anything in your code.

hutch--

 :bg

> Does anyone know a good hooker ?

Depends on the quality of hookers in your area.  :P
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

dedndave

if i did know one, i would keep it to myself   :P
but, i suspect a "good hooker" is as elusive as "extra money" or "military intelligence"