.686
.model flat, stdcall
option casemap:none
include windows.inc
include kernel32.inc
include user32.inc
includelib user32.lib
includelib kernel32.lib
.data
stack dword NULL
.code
start:
invoke VirtualAlloc, NULL, 16380d, MEM_COMMIT, PAGE_EXECUTE_READWRITE ; allocating 16kb of memory
assume fs:nothing ; assume FS:nothing so masm doesnt err
mov dword ptr fs:[8],0 ; set TIB's stack base to 0
mov dword ptr fs:[4],7fff0000h ; set TIB's stack limit to the end of user land memory minus 64kb ; store esp in evx
xchg esp, eax ; swap the stacks ( EAX holds the address to allocated memory )
add esp, 16384 ; set esp to point to the end of allocated memory
mov ebp, esp ; mov the stack pointer into the base pointer
sub ebp, 4 ; and sub the base pointer by 4 ( EBP is usually ESP-4 )
push eax ; push our old stack address onto the new stack
invoke MessageBox,NULL, NULL, NULL, NULL ; call some stuff on the new stack
pop esp ; yep ;) you can pop esp, in this example, its the best way
mov ebp, esp ; to the original stack, now me mov esp into ebp
sub ebp, 4 ; and sub the base pointer by 4 to get it back to its correct value
invoke ExitProcess, NULL ; and we push data onto our old stack, then exit.
end start