flat assembler
Message board for the users of flat assembler.

Index > Windows > How to access the stack below 4k?

Author
Thread Post new topic Reply to topic
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 21 Aug 2012, 10:59
Hi, is there any way to increase stack size ?
For example, AFAIK stack is MAX 4KB for current process. How can I increase it like I could have more than 4KB (1MB for example.)
If you don't understand what I mean, here's code and sorry for English.
Code:
push ebp
mov ebp,esp
sub esp,10000h
mov dword[esp],1 <-- crash.
    

Thanks.
Post 21 Aug 2012, 10:59
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20340
Location: In your JS exploiting you and your system
revolution 21 Aug 2012, 11:41
Can we asusme you are coding for Windows? It looks as though you are. So based upon that assumption, you will have to play nicely with the stack guard mechanism used in Windows. You have to "touch" the stack somewhere in each page boundary to trigger the guard bit and allocate a new page from the reserved pool. And depending upon your assembly setting your reserved stack size can be as large as the memory system allows:
Code:
format pe ...
stack ??? ;put you stack size here if you want more or less than the default size

;...

;now touch the stack

mov al,byte[esp-4096*1] ;or rsp for 64-bit
mov al,byte[esp-4096*2]
mov al,byte[esp-4096*3]
mov al,byte[esp-4096*4]
mov al,byte[esp-4096*5]
mov al,byte[esp-4096*6]
;etc.    
I'll leave it up to you to code whatever loops and things that suit your actual code
Post 21 Aug 2012, 11:41
View user's profile Send private message Visit poster's website Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 21 Aug 2012, 12:05
Hi, thanks for reply but I tried it and program still crashes.. used really huge value for stack, look example:
Code:
stack 1000000h
...
push ebp,
mov ebp,esp
sub esp,10000h
mov dword[esp],1 ;<-- still crashes..
    

and yes, I'm working in Windows environment.
Post 21 Aug 2012, 12:05
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20340
Location: In your JS exploiting you and your system
revolution 21 Aug 2012, 12:07
You have to touch the stack as in my example code above. You can't simply go straight to the lowest stack address, it will always crash as you found out.
Post 21 Aug 2012, 12:07
View user's profile Send private message Visit poster's website Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 21 Aug 2012, 12:13
hmm, thanks revolution! still, one last question.
I'm using file directive in local variables and that's the reason of crashing program. Isn't there other way to define it there ? I'm just playing with stack and trying to understand it more deeper.
Post 21 Aug 2012, 12:13
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20340
Location: In your JS exploiting you and your system
revolution 21 Aug 2012, 12:20
Overflowz wrote:
I'm using file directive in local variables ...
Sorry, I only support sane uses of the assembler.
Post 21 Aug 2012, 12:20
View user's profile Send private message Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1625
Location: Toronto, Canada
AsmGuru62 21 Aug 2012, 13:37
stack directive has TWO parameters:
Code:
stack 100000h,100000h
    

The above will produce 1Mb stack without guard pages.
Post 21 Aug 2012, 13:37
View user's profile Send private message Send e-mail Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 22 Aug 2012, 13:17
Thanks AsmGuru62! That's what I was looking for.
Post 22 Aug 2012, 13:17
View user's profile Send private message Reply with quote
bzdashek



Joined: 15 Feb 2012
Posts: 147
Location: Tolstokvashino, Russia
bzdashek 23 Aug 2012, 15:07
revolution wrote:
Overflowz wrote:
I'm using file directive in local variables ...
Sorry, I only support sane uses of the assembler.

Your profile's location states otherwise. Very Happy
Post 23 Aug 2012, 15:07
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.