flat assembler
Message board for the users of flat assembler.
Index
> Main > xor sp,sp |
Author |
|
f0dder 01 Jan 2006, 22:03
"xor esp, esp" will cause windows to terminate the application, yes, but it's kind of a "panic" way to do it... ExitProcess is documented, works, will continue working without popping up exceptions, etc. Not much reason to use a hack like "xor esp, esp" unless you're coding for extreme conditions... but then you might as well use a "ret".
|
|||
01 Jan 2006, 22:03 |
|
shism2 02 Jan 2006, 00:01
Where did you get this information from asmrus...?? OH ESP OOPS I thought you meant sp. Using xor sp,sp instead of xor esp,esp.
It seems to only xor party of the esp register... fodder What is the sp register??? When you do xor esp,esp , you can do a push later on and it will terminate Last edited by shism2 on 02 Jan 2006, 16:47; edited 1 time in total |
|||
02 Jan 2006, 00:01 |
|
Madis731 02 Jan 2006, 12:30
I think when you push to [0000h] you get some exception. You have to pop like f0dder said.
xor sp,sp was maybe used in DOS ages, but I don't think this would be much more of a use because you have interrupts there. In Windows (32-bit) you must use xor esp,esp if you want to clear the whole 32 bits. I haven't tryed - maybe xor esp,esp | pop esp causes exception too. It just sounds too fishy |
|||
02 Jan 2006, 12:30 |
|
revolution 02 Jan 2006, 13:12
Quote: "xor esp, esp" will cause windows to terminate the application Code: a_function: mov [global_var_for_this_thread],esp mov esp,eax xor esp,ebx xor esp,ecx xor esp,edx xor esp,esi xor esp,edi xor esp,ebp mov [result],esp mov esp,[global_var_for_this_thread] ret This can sometimes give you an extra general purpose register to use if you need it. But the code as above is not re-entrant because the global variable will be overwritten each time it is called. For a single thread application this is not a problem, but for multi-threaded app's you need to take extra care with global variables. In DOS and other real mode OS's the code above can be fatal if interrupts are enabled because the interrupts use the same esp for all code. Thus, you will need a 'cli'/'sti' pair in the code to pretect it from interrupts. If you deliberately want to cause an exception in WIN32, one of the easiest methods is simply 'UD2'. Even 'CLI' can be used if the 2 byte opcode for ud2 is a problem. |
|||
02 Jan 2006, 13:12 |
|
Borsuc 02 Jan 2006, 13:13
I think what you're trying to do is:
1) set the stack pointer to an invalid address (aka null) 2) do an operation there This will generate a page fault exception since you're operating to an invalid address (at least invalid from Windows' point of view ) It's not recommended, simply because it will not clean after your application's mess, like destroying all windows in memory, and this will (probably) generate memory leaks, etc.. It's like using TerminateProcess. ExitProcess is the recommended function to exit from a process. |
|||
02 Jan 2006, 13:13 |
|
revolution 02 Jan 2006, 13:18
Quote: It's not recommended, simply because it will not clean after your application's mess |
|||
02 Jan 2006, 13:18 |
|
Borsuc 02 Jan 2006, 13:24
Ah yes.. I mean, it's recommended if your app does not handle exceptions properly.
|
|||
02 Jan 2006, 13:24 |
|
shism2 02 Jan 2006, 16:48
Like fodder said this is for extreme condition programming ( Software protection)
|
|||
02 Jan 2006, 16:48 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.