Foro de elhacker.net

Programación => ASM => Mensaje iniciado por: JonaLamper en 26 Marzo 2014, 23:11 pm



Título: Duda con Stack Pointer (Registro 13)
Publicado por: JonaLamper en 26 Marzo 2014, 23:11 pm
Como bien es sabido, al utilizar subrutinas, se debe preservar el valor del SP. Me preguntaba que pasaría si no se preservara dicho valor... supongo que llegaría un momento en la memoria que la pila seguiría subiendo hasta mezclarse con el propio código ASM y entonces, ¿qué ocurriría? quiero decir, ¿qué efectos produce eso en un ordenador?

Me pica la curiosidad.


Título: Re: Duda con Stack Pointer (Registro 13)
Publicado por: ivancea96 en 27 Marzo 2014, 00:15 am
Prácticamente, si cambias la pila y la dejas mal cuando estás dentro de una subrutina, el ret no retornará a la dirección correcta, generalmente,


Título: Re: Duda con Stack Pointer (Registro 13)
Publicado por: Eternal Idol en 27 Marzo 2014, 01:12 am
Eso mismo hubiera dicho pero esto es para ARM (y no para PC como practicamente todo en este subforo).

SP, the Stack Pointer

Register R13 is used as a pointer to the active stack.

In Thumb code, most instructions cannot access SP. The only instructions that can access SP are those designed to use SP as a stack pointer. The use of SP for any purpose other than as a stack pointer is deprecated. Note Using SP for any purpose other than as a stack pointer is likely to break the requirements of operating systems, debuggers, and other software systems, causing them to malfunction.

LR, the Link Register

Register R14 is used to store the return address from a subroutine. At other times, LR can be used for other purposes.

When a BL or BLX instruction performs a subroutine call, LR is set to the subroutine return address. To perform a subroutine return, copy LR back to the program counter. This is typically done in one of two ways, after entering the subroutine with a BL or BLX instruction:

• Return with a BX LR instruction.

• On subroutine entry, store LR to the stack with an instruction of the form: PUSH {,LR} and use a matching instruction to return: POP {,PC} ...

http://stackoverflow.com/questions/8236959/what-are-sp-stack-and-lr-in-arm


Título: Re: Duda con Stack Pointer (Registro 13)
Publicado por: xv0 en 27 Marzo 2014, 23:50 pm
Tambien intentarias escribir en una direccion sin permisos de escritura y lectura y tu binario "crashearia". Supongo que en ARM seria igual.

Un saludo.