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. <br><br>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. <br><br>Please download Function3.s before you view this video. <br><br><br><style type="text/css"> body { background: #FFF; } </style> </div>
Tags: programming ,
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.
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!
Great Video!
Awesome ! thank you Sir !
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.
Thank you for all the work you have put into these videos.
They provide a solid introduction to assembly programming.
Thank you very much for your good work.
It was really helpful.
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
Fantastic! Thank you - been really helpful.
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.
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
Hi Vivek, excellent series thank you so much! I reckon its time for a coffee and then onto Buffer Overflow Series.
Thanks
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. =)
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!!
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.
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.
Great videoseries. Looking forward to seeing more interesting videos from you. Thanks!
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.
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.
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
As always! Another great movie! Thank you Vivek!
My mind is blown.
awesome work.more concept in this video.little confusion.
any how great video vivek.thanks a lot.
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
Great Series!!! Thank you so much!
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
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!
@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.
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 !!
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.
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!
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!
Today ,I realize Assembly programming is not so tuff
Followed the entire series. Awesome job. Very informative and I learned a lot. No real suggestions for improvement are needed.
Thanks Vivek. Simple and very effective tutorials (part1-part11).
If you can improve the screen clarity , esp, when you are running the code...it would be better.
A great video series. Thank u so much Vivek! :)
I studied this tutorial using a 64bit machine. I solved the problem of the instructions like pushl etc assembling and linking with 32bit directives.
Eg: "as --32 -o my_prog.o my_prog.s" and for the linker "ld -m elf_i386 -o my_prog my_prog.o"
I did that in order to reproduce correctly the examples on my machine.
So thx again Vivek!
A wonderful series :-)
This is a great series and it's very helpful to me. I am studying buffer overflows and this series was a good starting point for me.
Vivek,
Great series of videos!!! As always!!!
Its very hard to find people like you with an open heart and mind, that is open to share knowledge.
If I can help on anything just let me know.
Thanks a lot
Love the videos! They've been great. Could you please make some cheat sheets for your future videos. It's quite hard and frustrating having to look through all the videos to find one command/solution to your problem. Thanks.
This was a greate Linux Assembly Megaprimer. Thank you very much vivek for your time and dedication.
Cheers
thank you vivek sir,,, i have learned alot of intersting things,,,,and your tutorials are amazing.
mostly i like the linux assembly and buffer overflow.
great learning in great way...thank you very much....!!!
Great teaching style! I've enjoyed all of your videos, and they've gotten me interested in Assembly --- which is no small feat! The only thing I've run into as a beginner that caused a bit of trouble was: it seems that most of the code that I see is in Intel notation; though, because the differences are somewhat minor, it wasn't a huge deal. I'm going onto buffer overflow and windows asm now --- thank you for these!
makes me feel as if I understand the garbage collection and how variables are handles in high level languages
Another superb video. The Function3 program would not compile for me. I got the following errors when I ran "as -ggstabs -o Function3.o Function3.s"
Function3.s:13:Error: invalid instruction suffix for 'push'
Function3.s:25:Error: invalid instruction suffix for 'pop'
Function3.s:33:Error: invalid instruction suffix for 'push'
Function3.s:37:Error: invalid instruction suffix for 'push'
It must be because I have a 64 bit CPU. I will investigate this and try to see if I can figure out the appropriate fixes.
Okay. I did the following and the program worked for me
as --32 -ggstabs -o Function3.o Function3.s
ld -m elf_i386 -o Function3 Function3.o
./Function3
Thanks for the great video.