Assembly Primer For Hackers (Part 11) Functions Stack

Posted By: SecurityTube_Bot
Posted On: Mon 21 Feb 2011
Views: 16135
Share this video:
Share it on Facebook Share it on Twitter Share it on Reddit Share it on Digg Share it on Stumbleupon
Support SecurityTube:


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.


Tags: programming ,

This video is part of the following groups:

1. Assembly Language Megaprimer for Linux ( 11 videos)


Comments (31)

cr1tt3r on Sun 27 Feb 2011

Great Series Vivek! I think I'm gonna check out the Buffer Overflow series next.

General comments about this series are all positive, I liked how we went through and used gdb to set breakpoints and examine the memory, it really helped me to understand what was going on. Please make more!

rowslim on Fri 04 Mar 2011

Great Video!

_32_maheffa on Sun 13 Mar 2011

Awesome ! thank you Sir !

Alasjo on Tue 22 Mar 2011

Thank you for a comprehensive introduction to the assembly language and what goes on in the memory. I hope to find more in-depth videos from you further on.

slingshot on Sat 26 Mar 2011

Thank you for all the work you have put into these videos.
They provide a solid introduction to assembly programming.

zhic on Mon 28 Mar 2011

Thank you very much for your good work.
It was really helpful.

jdaanial on Mon 11 Apr 2011

Like everyone, I like your work, I think we need more people like you who are willing to share their knowledge, I have followed the series since the first video and I've tried all the examples, all they have worked, however, I you need to clarify something I've encountered and I'm sure many have found too, it is the execution platform, I mean:
If you run an assembly code on a 32 bit, works perfectly using functions like popl, movl, leal, pushl, etc.
but if you use a 64-bit platform, you can still use some registers and ecx, ebx, etc. and functions as movl, leal, etc. with some success, but functions like popl %eXX, pushl %eXX doesn't work at all...
and worse, operations such as those shown in this video, obtaining a value as a function of the memory location of the EBX register, to run this example I changed the shape functions by popq, pushq, movq, addq, etc, and the registers by %rsp, %rsb, %rax, %rbx, etc. Also, get a value from the memory location of the EBX/RBX the values must be multiplied by two (64 bits platform after all),
for this reason the instructions in the function have changed to the following:
movq $4, %rax
movq $1, %rbx
movq 16(%rbp), %rcx
movq 24(%rbp), %rdx
int $0x80
I hope that if someone is in a similar situation trying the exercises, this review will be helpful.

Again, thank you for your wonderful work Vivek, I hope to see many more videos made ​​by you on Hacking.

Greetings

Jorje on Tue 12 Apr 2011

Fantastic! Thank you - been really helpful.

atoi on Mon 18 Apr 2011

Vivek, Thank you so much. I am very much enjoying these videos! Please continue to post great quality content on assembly / hacking :)

One question: Do you plan on covering calls to libc functions (like printf) from asm? I think you mentioned that in one of the earlier videos but I do not recall seeing that in this primer series.

mezo_36 on Wed 27 Apr 2011

hi vivek realy very good tutorial but i dont understand the indirect addressing using registers
please can u describe in more detail about indirect addressing

Col_Loki on Sat 30 Apr 2011

Hi Vivek, excellent series thank you so much! I reckon its time for a coffee and then onto Buffer Overflow Series.

Thanks

sekstiseks on Sat 30 Apr 2011

Excellent video series Vivek! Really appreciate you taken your time to assemble this primer for us! Thank you alot.

Now on with the Buffer Overflow. =)

Squidly1 on Sat 14 May 2011

Thank you so much Vivek for the time and effort it took you to create this series of very useful videos! For those who are new to assembly and really need to get the basics down for proper reverse engineering efforts, this series should help quite a bit. I plan to pass on the "group" URL for this series to all of my junior co-workers. Thanks again!!

ambient on Mon 16 May 2011

I have been walked through this series. It is a good introduction to the world of assembly language. Thank you for your hardworking and contribution to the world of computer security.

miltonG on Tue 17 May 2011

Thanks a lot for making this video series! You have a very good teaching style and you move along in the material at the right pace. I will definitely be staying tuned.

d-scream on Mon 23 May 2011

Great videoseries. Looking forward to seeing more interesting videos from you. Thanks!

JohnM on Mon 13 Jun 2011

This whole series has been a good refresher, and this video in particular was very interesting to me, in that it has helped me better understand the C to asm connection. Thanks much for making these.

Alteminor on Sun 19 Jun 2011

I really, really, appreciate this series. However, you've asked for constructive feedback and commentary, so I'll pose what comes to mind. Why are you using AT&T syntax when the standard seems to be Intel syntax (and GAS supports Intel syntax just fine)? Also, why did you choose to use GAS versus something like NASM, since GAS been been designed specifically for the GCC back-end, and not really as a standard for normal products. I can see that, having been exposed to GAS (and AT&T syntax), learning another flavor of assembly would be relatively easy, but I think NASM is a better start for most people. Or at least Intel syntax, since that's what most others use.

Sandstone on Wed 06 Jul 2011

Thank you for this! I finally understand these underlying concepts because of this series!

Keep up the fantastic work, I really love what your doing

xplt on Fri 08 Jul 2011

As always! Another great movie! Thank you Vivek!

lardycake on Sat 09 Jul 2011

My mind is blown.

neo on Sat 16 Jul 2011

awesome work.more concept in this video.little confusion.
any how great video vivek.thanks a lot.

in0cula on Tue 19 Jul 2011

fiuuuuuu this last one was intense :) i have to digest it, i watched all videos in two days, need to review. Thank you Vivek, great job

ian on Fri 28 Oct 2011

Great Series!!! Thank you so much!

maximus on Wed 30 Nov 2011

Vivek,
Excellent video series. Your clear and easy to follow approach is very effective in learning.

One minor item I would like to clarify/point out. There seems to be an error in the slides showing the stack contents, corresponding to the example function.

Shouldnt the sequence be:

10
20
Ret
Old-EBP
...

instead of:

20
10
Ret
Old-EBP
...

Thanks & Regards

RobinB on Mon 12 Dec 2011

These tutorials have been great Vivek! The hands on experience works really good. Is there any exercises one can do get all the information to stay :)? Hope to see more soon!

maddog on Sun 25 Dec 2011

@maximus

Actually, the slides are correct. When you pass arguments to a function in assembly, you push them in the reverse order. Because of that, when you want to do:

function(a, b); //in C, for example

You are doing:

push b
push a

in assembly. I hope I made you understand.

Prd_schumy on Tue 27 Dec 2011

One of the best tutorial series I've ever seen...(not just for asm)...was probably a little too slow (in the middle of the series) for crash course learners - but was abs. great overall !!

Crimson on Tue 27 Dec 2011

I just went through all of these videos and wanted to leave my comment until the end: You rock. I've heard of people complain about how assembly is so hard to learn that it deterred me from even trying. But going through your tutorials, I don't know what they are complaining about because I feel like I know so much about assembly right now. I'm going to share this link with all of my old CS friends at the University of Chicago.

Erix on Tue 17 Jan 2012

Mr Vivek, Assembly owes you too much beyond imaginations!
thanks a lot for your tutorials, i really enjoyed and hope u keep up this good works and makes more videos!
peace!

J0hnny_b14z3 on Sat 11 Feb 2012

Thanks again Vivek! Another awesome series with a ton of easy to understand information! I am officially addicted to securitytube lol! I was wondering if you had any plans on adding to this series at all and delving any deeper into assembly? I'd like to learn more about working with firmware and writing assembly code to hack LED displays, mechanical outputs, or other simple electronics. Would this be something you would be interested in elaborating on? One way or another thank you very much for taking the time to create all the videos, primers, and guides on this site. It is indispensable for anyone getting into IT security or hacking for fun! I look forward to many more videos from you in the future!

Login to post a comment