flat assembler
Message board for the users of flat assembler.

Index > Windows > segmentation

Author
Thread Post new topic Reply to topic
asmrox



Joined: 19 Jan 2008
Posts: 160
asmrox
cs - segment pointer of .code
ds - segment pointer of .data

Code:
format pe console
section '.code' code readable executable writeable
push dword [ds:0]
push f
call [printf]
add esp,8
ret
section '.data' data readable writeable executable
db 'test',0 ;this is under offset 0
f db '%s',0 ;this is ds:5
section '.idata' import data readable
dd 0,0,0,RVA msvcrt_name,RVA msvcrt_table
dd 5 dup 0
msvcrt_table:
printf dd RVA _pritnf
dd 0
msvcrt_name db 'msvcrt.dll',0
_pritnf db 0,0,'printf',0    


Access violation, why?
Post 14 Feb 2008, 01:54
View user's profile Send private message Reply with quote
System86



Joined: 15 Aug 2007
Posts: 77
System86
Windows does not use segmentation (except for the fs segment register, but that's a different story). It uses flat addressing, and in your code you attempted to access address 0, which your application can't do, so it crashed. Forget about cs/ds/es/ss under Win32, the segment registers always have 0 base, 4 GB limit, so you can ignore them.
Post 14 Feb 2008, 03:00
View user's profile Send private message Reply with quote
asmrox



Joined: 19 Jan 2008
Posts: 160
asmrox
so why sections was made?
Post 14 Feb 2008, 19:13
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
asmrox wrote:
so why sections was made?
Just 'cause there are effectively no segments doesn't mean it can't use paging. This is how the OS allocates memory to your proggy, by paging it in a section at a time.
Post 14 Feb 2008, 19:20
View user's profile Send private message Visit poster's website Reply with quote
asmrox



Joined: 19 Jan 2008
Posts: 160
asmrox
so even simply hello world will load 4096 bytes memory of?
is that same as heap? can i use rest of memory? Where is the pointer to it?
Post 14 Feb 2008, 20:31
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-2020, Tomasz Grysztar.

Powered by rwasa.