[gameprogrammer] Re: Pushing on stack in assembly

  • From: Kevin Jenkins <gameprogrammer@xxxxxxxxxx>
  • To: gameprogrammer@xxxxxxxxxxxxx
  • Date: Sat, 22 Mar 2008 10:23:02 -0700

At the fundamental level, it is to call native C or C++ functions on a remote system, given a straight function call, and nothing other than the function name and function pointer. For example,


// System A
void MyFunc(int a, char b);
Register("MyFunc", MyFunc);

// System B
CALL("MyFunc", 5,'a');

I actually have it done right now. I'm just trying to figure out how to push an array of bytes onto the stack for a function call. It's something like this (I think). But I'm not sure on cross-platform, or 64 bit.

// Bytes to pass, rounded up to 4
        0041371F  sub         esp,200h

        // Loop counter
        00413725  mov         ecx,80h

        // Load esi with address of variable
        0041372A  lea         esi,[ebp-208h]

        // Copy esp to edi
        00413730  mov         edi,esp

// * Moves a byte, word or doubleword (8 bytes) from data segment and offset esi to extra segment and offset edi .
//      * Increments/decrements both edi and esi :
//      ecx stores count, not sure how it is calculated yet
        00413732  rep movs    dword ptr es:[edi],dword ptr [esi]

        // Copy out odd bytes
        // 0041372B  movs        word ptr es:[edi],word ptr [esi]

        // Call function
        00413734  call        func2 (4111EFh)

        // Take bytes off stack
        00413739  add         esp,200h

Chris Nystrom wrote:
On Sat, Mar 22, 2008 at 9:56 AM, Kevin Jenkins
<gameprogrammer@xxxxxxxxxx> wrote:
Because it is otherwise impossible.

I wrote a simple RPC protocol in C that had variable amounts of
parameters. Bascially the first thing I passed was an INT to identify
the procedure and then since I knew the procedue I knew the number and
types of parameters to pull out of the stream. It worked great, but I
ended up using messages instead of RPC because messageas were faster.

You might also be able to use a token to describe the end of the
parameter list, or a value right at the start that descripe what is to
follow. I am a little fuzzy about what you are trying to do that is
impossible. Maybe you could describe in more detail the problem you
are trying to solve?

Chris


---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: