Since I often see a thread where someone asks about using esp, removing the leave instruction, no stack-frames, no-locals etc. I present the no stack-frame, no locals, no proc MsgProc!!



MsgProc:

mov eax, [esp+8] ;uMsg

.IF eax==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSE

mov edi, [esp] ;save esp top contents from being trashed.They will be trashed
add esp,4 ; mov esp, esi ;advance esp to address of hWnd
call DefWindowProc
sub esp,20 ;fix esp, 16 for parms, 4 for advance
mov [esp],edi ;restore trashed esp top contents
ret ;jumps somewhere, probably kernerl32, but hey, it works...
.ENDIF

xor eax,eax ;dont think we ever get here
ret


Since the parameters where already on the stack, I just set esp to the right place before the call. Reused stack space.

I don't advocate programming this way. I did it just to see if I could.

Discuss amongst yourselves...
Posted on 2002-07-15 08:35:46 by ThoughtCriminal


ret ;jumps somewhere, probably kernerl32, but hey, it works...


I like this line :)
Posted on 2002-07-15 08:45:06 by bazik
If you want a shorter one:

For Frame-Based Procedure:

pop ebp
jmp DefWindowProc

For Non-Frame-Based Procedure:

jmp DefWindowProc

:grin:
Posted on 2002-07-15 13:41:28 by stryker
MsgProc:

cmp [esp+8], WM_DESTROY ; uMsg
je @F
jmp DefWindowProc
@@: invoke PostQuitMessage, NULL
ret 4*4 ; be nice :)
Posted on 2002-07-15 13:58:55 by bitRAKE
bAZiK,

The only lib I had included was kernel32. The ret whent to an address like 77de****, so I'd say kernel32.

I have been spending alot of time lately trying to figure out a coding style that fits how I think. I think it is PROCless.

No more prototypes, no more inc file of prototypes. Easy use of public and extern. Now I set up my proc like this:


...all the lib includes, .686 etc.

public (procname)
public (procdata)

.data
(procdata) label dword

data1 dword 0
data2 dword 0

.code
(procname) dd offset @(procname);pointer for indirect call to proc
@(procname):
pop esi

....do stuff here

jmp esi
end

Prototype to make calls work:
LCALL TYPEDEF proto;label call
PLCALL TYPEDEF PTR LCALL

extern (procname):proc
extern (procdata):dword ;public and extern are now easy!!

call PLCALL (procname)


I spent alot of effort to find a way that would give me informative diassembly when debugging.

My PLCALL will dissassemble to:

call [_procname(0000000)]

not call ($$$0001)

Declaring (procdata) pubilc, makes all data below public with just one extern. In an alternate file, I will still get real names.

mov eax, data1

will stay the same not

mov eax, procname+4

THe above was just a quick(first draft) test with something I didn't write.
Posted on 2002-07-15 22:15:53 by ThoughtCriminal
You really thing your code is still readable for human beeing? :rolleyes:



:grin:
Posted on 2002-07-16 01:03:01 by bazik
Sorry, dont have time to type nicely right now:


------------------------------------------------------------------------
...all the lib includes, .686 etc.

public fooproc
public foodata

.data
foodata label dword
data1 dword 0
data2 dword 0

.code
fooproc dd offset @fooproc ;pointer for indirect call to proc
@fooproc:
pop esi

....do stuff here

jmp esi
end
-----------------------------------------------------------------------------
In another file:

extern fooproc:proc
extern foodata:dword ;public and extern are now easy!!

.code
call PLCALL fooproc
-----------------------------------------------------------------------------
Prototype to make calls work:
LCALL TYPEDEF proto ;label call
PLCALL TYPEDEF PTR LCALL

Hope this is a little easier to read.
Posted on 2002-07-16 01:59:41 by ThoughtCriminal