0

so I've been debugging this and made a function to send a packet to the server

here is the function

Naked void CB::Send_To_Server(CHARARRAY Buffer, int Length)
{
    __asm
    {    
            PUSH ESI
            LEA EAX, Length
            MOVZX ECX, DWORD PTR DS : [Buffer]
            PUSH ECX
            PUSH EAX
            MOV ECX, NetworkClass
            CALL Send_Packet_Original_Address
            POP ESI
            RET

    }
}

the problem here is first when I debug my application it shows that the function has 3 arguments instead of 2 (Buffer,Length,Length) and when I use it it actually pushes the length twice the first time is the correct length the second time it's some weird negative long number like -29470056 <---- Not rly a value that showed to me just an example

so as you might see I am rly bad with both c++ and asm so if anyone has an idea on how to fix this or maybe it's normal I'd rly appreciate your help :)

Jester
  • 56,577
  • 4
  • 81
  • 125
Diab
  • 124
  • 1
  • 10
  • You didn't provide enough information but I would at least do the following things 1) use `mov eax, [length]` not `lea` 2) use `push [Buffer]` not `movzx`+`push` 3) delete the `ret`. Also no idea why you need inline asm for this, it looks like you are just chaining to a different method. `push esi`/`pop esi` seems unnecessary too since that doesn't get modified. – Jester Mar 13 '16 at 16:13
  • @Jester I tried it it still pushed the length twice and esi is a pointer which I enter and I need it to return (I think) also I made it that way so I mirrored the same function as the game so it doesn't crash (as I said I don't know much about asm) and what more information do you need? – Diab Mar 13 '16 at 16:36
  • 2
    I suggest writing a similar function in C++ and have the compiler print out the assembly language. Next compare to your implementation of the function. – Thomas Matthews Mar 13 '16 at 18:48
  • Why are you doing this in asm in the first place? [MSVC inline asm is not very good](http://stackoverflow.com/questions/3323445/what-is-the-difference-between-asm-and-asm/35959859#35959859), and you don't appear to be doing anything that a compiler couldn't easily generate. (and do a better job than that: e.g. you have a useless(?) save/restore of a register you never touch (`esi`).) – Peter Cordes Mar 13 '16 at 19:59

1 Answers1

3

In order to refer to arguments by name EBP must be set to the value of ESP on entry to the function, if the function is not declared as naked this is done automatically.

Timothy Baldwin
  • 3,551
  • 1
  • 14
  • 23