I'm trying to write my own SEH. But I've got a problem to assemble the code with MASM. Following two lines causes trouble:
push dword ptr fs:[0]
mov fs:[0], esp

In TASM it just assembles fine, but MASM do not allow me to use this instructions. Is there are way to assemble it anyway (beside inlining it directly with 'db')?

Thanks in advance.

Marilyn
Posted on 2002-01-26 13:23:21 by Marilyn
But what exactly you want to do?

ESP does not save the value that you pushed.

I think your code is the same as:


sub esp, 2d
mov ebx,esp
Posted on 2002-01-26 13:30:49 by CodeLover
It was not my intention to save the value that I've pushed. My problem is that those both instructions are not allowed with MASM (doesn't matter in which order).
I've read some tutorials about SEH (from Snakebyte and Jeremy Gordon) which also uses this instructions, but the sources are compiled with TASM in these tutorials and I cannot recompile it with MASM.
So, I'm just searching a possibility to get a read/write access to fs:[0] with MASM, if there is any.

Marilyn
Posted on 2002-01-26 13:52:27 by Marilyn
ASSUME FS:NOTHING
put that in your asm file and you can use the segment override thingy
Posted on 2002-01-26 14:12:04 by Noodle
Cool, it works. Thanks a lot Noodle. But can you also explain me, why I have to assume FS to nothing to overrite it?
Posted on 2002-01-27 03:59:21 by Marilyn
I belive by default code (CS selector) is assumed to be code
and accesses to data (DS) is assumed to be data and stack (SS) is assumed to be stack (also data).
In windows theese segments span the entire address space (0 to -1) but they dont have to, so if masm was used to write a program ment to run in an OS that did not have overlapping segments you would have to define when to access data by overriding with the DS prefix byte.
FS is assumed by masm to be something other than data i think, its not afaik a specific selector and can like GS or ES be used to access any special case segment. In windows some OS specific things are kept in the FS segment like the SEH structure, the process and thread handles/ids and tls slots and many other things.
Try ASSUME CS:NOTHING and ASSUME DS:NOTHING and masm should put CS prefix in code and DS prefix in data accesses in the code.
hmm this is probalby not really an answer, maybe you should ask this question in the compiler part of the forum?
Posted on 2002-01-27 04:38:07 by Noodle
Thanks again. I think I get the idea.
Posted on 2002-01-27 14:45:54 by Marilyn