flat assembler
Message board for the users of flat assembler.

Index > Main > how to check if i have access to memory

Author
Thread Post new topic Reply to topic
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 10 Sep 2006, 07:39
is there some way (instruction) how to find out if i can access to some portion of memory, without utilizing SEH / other such techniques???
Post 10 Sep 2006, 07:39
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
halyavin



Joined: 21 Aug 2004
Posts: 42
halyavin 10 Sep 2006, 07:49
See VirtualQuery function is kernel32.dll. There is no such instruction in assembler.
Post 10 Sep 2006, 07:49
View user's profile Send private message Visit poster's website Reply with quote
velox



Joined: 06 Jan 2006
Posts: 14
velox 10 Sep 2006, 07:56
Post 10 Sep 2006, 07:56
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 10 Sep 2006, 08:01
Quote:
There is no such instruction in assembler.

Sad

hmm, i have to look at those... and check if own SEH isn't faster (i mean - faster in case when pointer IS valid, when it isn't it's once-per-program fatal error and speed doesn't matter anymore )
Post 10 Sep 2006, 08:01
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 977
Location: Czechoslovakia
MazeGen 10 Sep 2006, 08:51
Well, there are two user-mode instructions, LSL and LAR, but not much of use in flat memory model.
Post 10 Sep 2006, 08:51
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 10 Sep 2006, 09:50
that means i can check if [eax] is accessible with:
Code:
lsl  (anything), [eax]
jnz .not_accessible    


Question
Post 10 Sep 2006, 09:50
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost 10 Sep 2006, 11:49
vid you haven't moved this to Windows, you're slipping Razz
Post 10 Sep 2006, 11:49
View user's profile Send private message AIM Address MSN Messenger Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 977
Location: Czechoslovakia
MazeGen 10 Sep 2006, 14:25
vid wrote:
that means i can check if [eax] is accessible with:
Code:
lsl  (anything), [eax]
jnz .not_accessible    


Question

No, under Windows flat memory model it should work this way (not tested):
Code:
mov eax, ds
lsl eax, eax
jz .really_weird_error ; "ZF is set if the segment limit is loaded successfully"
    

EAX holds the segment limit now. From my experience, the limit is 0xFFFF (or a little less) and the segment is growing down (you get it using LSL instruction), what means the segment is accessible from 0xFFFF to 0xFFFFFFFF.

[EDIT] It seems it was true only in my Win98, now under Win XP SP2 it seems much different (limit is 0xFFFFFFFF, growing up, what means the segment is accessible anywhere - from 0x0 to 0xFFFFFFFF). [/EDIT]

Note that paging is another layer of the protection scheme and there is probably no user-mode instructions how to get if any address is paged and therefore accessible Sad

Long time ago, I wrote simple tool to show limits and attributes of all segment descriptors in Windows. It doesn't call any OS functions, it uses just LAR and LSL instructions. Let me know if anyone is interested, I can prepare it and upload it here with its MASM source code.

Quote:
vid you haven't moved this to Windows, you're slipping

I bet vid ask this question in general, not only for Windows Razz
Post 10 Sep 2006, 14:25
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 10 Sep 2006, 15:30
mazegen is right bout slippiness Razz

seems i will have to utilize my own SEH Sad((
Post 10 Sep 2006, 15:30
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number 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.