Everybody walk into the next video.
So we're going to be talking about logic conditions and logic control in this particular video.
Now when I talk about logic control it's going to be different than how we talked about it for Python
so there isn't an if statement per say in assembly.
What you have are conditions.
So just how the if statement has a condition we can make.
We just have a single condition to perform some sort of interaction which is normally a jump.
Now to do this we're gonna set up a few things.
So the first thing I want to do is only you start to allow us to jump to setup method.
So we're assuming something we're gonna use.
Now jump.
What it does is it takes either a label or a memory address and then jumps ESB or EIB to that particular
memory location.
So that way it can start executing code at the at that memory location or the label representing that
memory location.
So we're going to do something called setup
and we're gonna set that up up here right.
We'll do a setup function for what I want to do and setup function is I wanna setup something I want
to set up our X registered to be 0 x 5.
So I want to have a counter which will make which will make sense and a little bit.
Now following that because we don't want to start printing something right away we want to jump to our
final methods so we'll just call this final
final method.
Perfect.
So this code is going to do is it's going to start at start jumped to set up function it's going to
go ahead and set up our easy X register that we're gonna jump to final which will name this final method
instead.
So now we've got a print statement.
What's interesting here is our print statement will never be executed until we get to our final method
which is important to note because we're jumping between a memory dresses not letting it execute directly
through.
So what we want to do before we start this we want to keep track of X because we're not going to be
using loop we're going to loop through this based on an if statement or a jump statement.
So what we're gonna do is we need to push you see X on the stack because we need to keep track of that
before we do our push push RFD and actually call our print method.
So right now we've stored AC X which is our counter.
We go ahead and go through our epilogue and Prolog we call her we call our function we restore everything
we're gonna want to do is do a pop you see X so now we've got our C X back.
So now we've got our counter back of what it was before we issued the call and then we're gonna do a
deck X
now this is going to do right now if we ran this we would jump to setup function we would go ahead and
move E C X and the 0 0 0 x 5 and the U.S. X and the we jumped to our final method which comes down here
again skipping the print we would push X on the stack pushed the registers push the push the the flags
and we're gonna call print which pushes ESB into EDP then we go ahead and issue our print now and then
we leave which is the opposite of the epilogue then we return restore the stack and the flags and then
we pop X off the stack and go ahead and decrement it.
Now you mustn't you might have noticed that we are pushing we're saving isa X but we're also restoring
it in the first place.
I'm doing that on purpose.
Realistically you don't need this number you don't need this instruction and you don't need this instruction.
Easy X will be restored with this but I want you to get familiar with pushing things onto the stack
and restoring them.
When that when in order you need to get familiar with that because if you push something onto the stack
and forget what order and what's like you have five other things pushed onto it but those never got
popped off.
You're not gonna get the correct value.
So I'm stressing that importance.
So now we've decrement ID are you see X register.
So now our counter would been from five to four.
Now what I want to do is introduce you to a conditional jump.
So jump not zero J Enzi and then we're going to do our final method.
So this looks very similar to loop and underneath Nazism is what it's actually doing is basically can
joining these two statements just under something on ASM called Loop however that's important to understand
that because everything is a condition when it comes to logic and assembly.
So there are quite a few different jump conditions.
So I want you to go ahead and use the link above the video to kind of get a better idea on some of the
other different conditions on jumps that you can work with.
Understanding those are gonna be pretty important when you start working with Shell code and building
your own exploits and working in memory.
So now that we've got this done we should be able to run this and get our the same outcome that we did
before.
Perfect we've got our five.
We've gone through we've set up our functions we've set up our values we've gone ahead and returned
everything just for shits and giggles we'll go ahead and do GDP make we'll go ahead and break start
said
US assembly flavor Intel then we're going to go ahead and disassemble.
Oh I'll get it out first and then disassemble so we can see here we've hit our first job which is our
jump which is nice enough tell us that the logic call or the symbol call or label is set up function.
So we're right here so if we go ahead and step I go ahead and disassemble now.
Now we see we've moved to this function up here.
So now we see X and then we've got our final jump which goes to this memory address which happens to
be final method.
So if we do step and then do info registers you can see that you see X is now set to five go ahead and
step I again disassemble.
So now you can see we've skipped our print method and we're now at push easy X and we've got our push
80 and push FTE.
In this case it's just called push a and push up so go ahead and do it step by we push X onto the stack
we set up our registers then we've set up our flags so if we do just assemble perfect.
Then we're going to go ahead and step I again which is going to jump us over to the print method.
Perfect disassemble.
So now we've got our our epilogue in our prologue or epilogue in this case or do step by step eyes that
pushed us into pushing BP and we'll step again and we're moving ESPN to BP and then we will step one
more time and then we'll go ahead and disassemble.
And now we can see we've moved our string over into it into our buffer and now we're going to move or
our buffer in DC.
Now we're going to move our our length into ADX.
So we'll do it step by when we do info registers.
We can see that this has been set.
So we can see that X is for E C X is set to our string and then E D X is set to 15 which is the length
of the string that we're using but we can see ETP VIP everything looks good.
So we see IP is our print method on the eighteen point.
So we'll go ahead and disassemble once more.
Now we're under interrupt.
So if we go ahead and do a step I will go and get our first print to the screen.
We can see that right there and then we'll do step I again to do our leave.
And then step I forget.
So if we disassemble we can see now we've returned back from our function.
So step I again we'll pop everything back off the stack
and now we can see looks like we're good.
So before we pop easy X we're gonna go ahead and info registers so you can see you see X is still set
to 5 and that's completely fine.
The reason being is because we did the push 80 and push 50.
Again I want you to just understand that.
So step I.
So now we've technically pushed it back or popped it off the stack and reset easy but since it was 5
originally it's going to stay that way.
So again info registers would show us that you see X is 5.
So if we decrement it we'll go ahead and do Step II and then we'll do it for registers.
Now I can see easy easy access for and it will just continue to repeat that process all the way until
it's finished.
So if we do info let's do this simple
perfect so we can see our jump not equal.
So if we do info registers flags flag
so we can see the zero flags not set.
So if we do step I then do disassemble we'll be back up on the final method up here.
So this will repeat until the Zero flag is actually set.
So go ahead and play around with this make a few more functions have things jump around a little bit
more play around with the conditions so maybe you want this to jump to a different method if it's not
been set.
So it prints something else and then as soon as it is set it prints the original text that you want
to play around with it get familiar with moving things around with jumps.