Advertise

Monday, 16 September 2013

Assembly Language Primer For Hackers (Part 11) Functions Stack


Description: This is Part 11 of the "Assembly Language Primer for Hackers" video series. Please start this series by watching Part 1, if you have not already done so. In this video, we will look at how to use the Stack to pass arguments to functions. In course of this video we will look into exactly how the Stack works, how to store arguments on the stack, how the "call" instruction stores the return address on the stack, the logic behind storing the EBP register on the stack, how and why EBP is used to reference function arguments and local variables in a function and how to adjust the ESP to accommodate all this. This video is very important as a lot of learning from this will be used in the Buffer overflow video series I plan to make next.

Please download 
Function3.s before you view this video. 

Code:
.data

    HelloWorld:
        .asciz "Hello World!\n"

.text

    .globl _start
    .type PrintFunction, @function

    PrintFunction:
      
        pushl %ebp  # store the current value of EBP on the stack
        movl %esp, %ebp # Make EBP point to top of stack
      
        # The write function

        movl $4, %eax
        movl $1, %ebx
        movl 8(%ebp), %ecx
        movl 12(%ebp), %edx
        int $0x80

        movl %ebp, %esp # Restore the old value of ESP
        popl %ebp # Restore the old value of EBP
        ret  # change EIP to start the next instruction

    _start:

        nop
      
        # push the strlen on the stack
        pushl $13

        # push the string pointer on the stack

        pushl $HelloWorld

        # Call the function
        call PrintFunction

        # adjust the stack pointer

        addl $8, %esp


        # Exit Routine

        ExitCall:

            movl $1, %eax
            int $0x80

Disclaimer: We are a infosec video aggregator and this video is linked from an external website. The original author may be different from the user re-posting/linking it here. Please do not assume the authors to be same without verifying. 

Security tube is also providing linux Assembly course for 99$ here -> http://securitytube-training.com/online-...ly-expert/
 
World of Hacker © 2011 Creative Commons License
World of Hacker by KroKite is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Based on a work at http://www.worldofhacker.com.
Permissions beyond the scope of this license may be available at https://groups.google.com/forum/#!newtopic/hackerforum.