0

I'm extremely new to asm, I've been following some guides and codes from other people to do some things my own, but it's just very hard for me.

So I found this code:

_asm
    {
        push Fn3Var2;
        mov ecx, 0x7AAD828;
        mov esi, 0x00402F50;
        call esi;
        push eax;
        mov eax, dword ptr ds : [0x7C13C7C];
        lea eax, dword ptr ds : [eax + eax * 0x4];
        lea edx, dword ptr ds : [eax + eax * 0x4];
        lea eax, dword ptr ds : [edx * 0x4 + 0x7BE1238];
        push eax;
        mov esi, 0x00851348;
        call esi;
        mov eax, dword ptr ds : [0x7C13C7C];
        add esp, 0x8;
        mov dword ptr ds : [eax * 0x4 + 0x7BE239C], 0x08; // ebx
        mov dword ptr ds : [eax * 0x4 + 0x7C114A0], 0x1; // ebx
        inc eax;
        mov dword ptr ds : [0x7C13C7C], eax;

        mov eax, 0x00594CFD;
        jmp eax;
    }

So the Fn3Var2 is a DWORD. This code is working fine for me on what it is supposed to do (add text to an item on a game). But I wanted to add another line of text, and this is what the person that shared the code said:

"Just register another variable (DWORD Fn3Var3), set it in each item case then mov it to stack in asm code."

So obviously creating a new DWORD Fn3Var3 I understand, but then I have no idea how to add it or mov it to stack. Could someone that actually understand this better than me explain it to me please? :)

Edit: That "set it in each item case" was meant for adding that Fn3Var3 on some if conditions, don't worry about that.

Edit2: Sorry I forgot to add this, maybe it's important. This code:

    _asm
{
    mov ax, word ptr ds : [edi];
    mov Fn3Var1, eax;
}

Runs before the other one.

Edit3: So I searched for those 3 locations on IDA (0x00402F50, 0x00851348, 0x00594CFD) and this is what it looks like: https://i.stack.imgur.com/2LwEz.jpg Not sure if it helps or not, but any ways :)

Last Edit: I managed to do it by looking at someone else's similar code, you can close this question. :)

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
user1913644
  • 157
  • 1
  • 11
  • I think that he's saying to `push` it as well, but without the whole context of what the called function do it's difficult to tell - especially because generally if the function is variadic you have to tell it in some way the number of arguments it has to pop from the stack. – Matteo Italia Aug 04 '17 at 06:56
  • How you push it as well assuming the simplest possible case? Sorry if this is a stupid question :) Edit: This is where I found the code: http://forum.ragezone.com/f508/jewels-1-03k-main-1-a-815717/ – user1913644 Aug 04 '17 at 07:08
  • 2
    On StackOverflow if you manage to solve your own question you should not change the title, but post your solution as an answer and mark it as "accepted" (click on the "tick" below the votes counter). – Matteo Italia Aug 04 '17 at 09:31
  • You're certainly not making things easy for yourself by using inline-asm this way when you're still just learning asm. `mov esi, 0x00402F50;` / `call esi;` is pretty horrible. You should put labels on your functions so you can `call _foobar` and have the linker fill in the right address for `foobar`. (Actually a relative displacement from the `call` instruction to the function.) Using a register-indirect `call` instruction with a magic constant is almost certainly not the best solution for whatever problem you had. – Peter Cordes Aug 06 '17 at 05:49

0 Answers0