PDA

View Full Version : if Simba was the chicken, what is the egg?



theholyone
02-14-2016, 12:46 PM
I've always been wondering, if Simba was the hatched egg with all the includes, what is the egg?

what makes up the function for Mouse(x,y)?


how does simba recognize the mouse function?

I know there are many includes for simba, but where do those includes come from?
and if they are from within Simba, what created those?

where does it all start?

are there hard-coded things for programming like X,Y are X,Y because they are X,Y?

( have absolutely no background in this field, just pure curiosity )

the bank
02-14-2016, 01:04 PM
I've always been wondering, if Simba was the hatched egg with all the includes, what is the egg?

what makes up the function for Mouse(x,y)?


how does simba recognize the mouse function?

I know there are many includes for simba, but where do those includes come from?
and if they are from within Simba, what created those?

where does it all start?

are there hard-coded things for programming like X,Y are X,Y because they are X,Y?

( have absolutely no background in this field, just pure curiosity )

First of all, you're basically asking for someone to tell you how an interpreter works. Not cool. Google is your friend too ya'know!

But now I'm already here so let's try -_-

Simba is based off of SCAR which was created by Katneiks, originally just as a pet-project until his main project AutoRune was detected and banned, at which point SCAR became a viable tool. SCAR was closed-source, and is still being developed today by a guy named Freddy1990. Simba spawned to create an open-source version of this platform.

Simba has functions built into it. Since Simba is written in Delphi, so are the internal functions. These include all the functions that make up your standard Simba library. Such as (straight from Simba source code):

//procedure MoveMouse(X, Y: Integer);
procedure TIOManager_Abstract_MoveMouse(const Params: PParamArray); lape_extdecl
PIOManager_Abstract(Params^[0])^.MoveMouse(PInteger(Params^[1])^, PInteger(Params^[2])^);
end;

We can access all of the functions that were built into Simba by default. To add aditional functionality, either write a script, or write an include. A script has localized functions whereas an include has a scope of anywhere you want to include it.

Many people used to write includes, now-aday's theres like 4-5 that are actually used.



are there hard-coded things for programming like X,Y are X,Y because they are X,Y?

Of course not. X and Y are variables, they can represent anything. But the way you wrote that sentence was too damn price-less for me not to point out.


EDIT:
Just realized I didn't even cover interpretation. Yay - Go Me! :D

Brandon
02-14-2016, 02:09 PM
Where does it all start?



You have a function called SendInput in the Windows API (https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310(v=vs.85).aspx). This function is a UserMode function and when invoked, it sends the parameters to your mouse driver telling it where to move. The mouse driver tells the kernel where the mouse should be and everything else is irrelevant from there on.


How is SendInput invoked from MoveMouse? Well things are invoked by instructions (Assembly/Machine Language). SendInput has the following signature:


UINT __stdcall SendInput(UINT nInputs, LPINPUT pInputs, int cbSize);


So what you have to do is (push each parameter onto the stack in reverse order first via assembly instructions/machine instructions and invoke the call instruction):


mov rax, inputs ;Inputs is the address of a structure (LPINPUT aka Long-Pointer to Input Structure). It moves into a register which is pushed later on.
push cbSize
push rax
push nInputs
call SendInput



This is how a function is called at the lowest possible level. This is "Machine instructions". Your CPU sees this and executes each one. No explanation of how is needed because that's irrelevant (but just incase, it's interpreted in voltages).

Samba developers know this so what they do is they parse the MoveMouse function. Store each parameter in a stack (the structure, not the memory). For each parameter on the stack they pop it off and write a push instruction for it. When the stack gets empty (no more parameters), they write a call instruction and make the memory executable with VirtualProtect (Windows) or MMap (OSX/Linux). This will execute the actual SendInput function and voila. Your mouse has moved.


Nowadays no one likes to write assembly/machine language, so a library called LibFFI (https://en.wikipedia.org/wiki/Libffi) does it all for you and does most of it in C (A higher-level human readable language). This library handles the calling conventions like STDCALL, FASTCALL, THISCALL, CDECL, PASCAL, etc.. This means that the library knows what order to push the instructions (STDCALL for reverse order) or whether or not the function belongs to a class (THISCALL), etc.. It also handles x86 and ARM instructions (different CPU architectures).

With this library it's simple. Samba does: Invoke(&SendInput, ....) where ... are the parameters to SendInput and may or may not be a variadic parameter pack (a function accepting any amount parameters).

With this, the developer does not have to know anything about the CPU or Assembly. The developer only needs to know the calling convention, the name of the function to be called (or address of it) and the parameters.

From there on, everything is trivial.

Olly
02-14-2016, 04:57 PM
...

Today you learned Simba uses SetCursorPos to move the mouse!

Nice explanation though. :)