ASM function call? menu

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    akh's Avatar Member
    Reputation
    4
    Join Date
    Mar 2008
    Posts
    39
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ASM function call?

    Hi.

    I have been playing with some dll injection and stuff the last couple of days. I got the dll injected and I have set up a named pipe connection to commuicate with the injected dll. Now I would like to call certain functions in WoW by using ASM. One of the functions I have in mind is CastSpellById. I got the address from WoWX to be 0x006FC520. The functions that call this address seems to push 4 arguments to the stack whereas the first one is the spellId and then call the CastSpellById function.

    This is an example on how the function is called (from OllyDbg):
    Code:
    00495810   A1 F8FAC600      MOV EAX,DWORD PTR DS:[C6FAF8]
    00495815   6A 00                  PUSH 0
    00495817   6A 00                  PUSH 0
    00495819   6A 00                  PUSH 0
    0049581B   50                       PUSH EAX
    0049581C   E8 FF6C2600      CALL Wow.006FC520
    00495821   83C4 10              ADD ESP,10
    Now I have some ASM code that should do the same thing:
    Code:
    void CastSpellByID( int spellid )
    {
    	unsigned long dwCastSpellById = gpWoWX->GetFindPattern()->GetAddress( "CastSpellById" );
    	__asm
    	{
    		MOV EAX, spellid
    		PUSH 0
    		PUSH 0
    		PUSH 0
    		PUSH EAX
    		CALL dwCastSpellById
    		ADD ESP,10
    	}
    }
    The problem is that nothing happens in WoW when I try to execute the call, but when I set a breakpoint at the address in OllyDbg I can see that ASM code is being executed.
    It might be a obvious error or something that I have missed, but as I said I just started a couple of days ago, and don't have much experience in this field.
    Last edited by akh; 08-27-2008 at 07:28 AM.

    ASM function call?
  2. #2
    Xarg0's Avatar Member
    Reputation
    61
    Join Date
    Jan 2008
    Posts
    389
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I didn't take a look at the function but I'd say you need to copy WoWs Mainthreads TLS thingy, cause it handles the ObjectManagerClass and lot's of functions need it to work properly
    I'm not shure but I think WoWX provides a function to do this, UpdateCurMngr it's named or something like this ^^
    I hacked 127.0.0.1

  3. #3
    akh's Avatar Member
    Reputation
    4
    Join Date
    Mar 2008
    Posts
    39
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your reply Xarg0.

    I tried hooking CurMgr, but still no luck.

  4. #4
    kynox's Avatar Account not activated by Email
    Reputation
    830
    Join Date
    Dec 2006
    Posts
    888
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here:

    Code:
    void __forceinline UpdateCurMgr()
    {
        DWORD    s_curMgr = *(DWORD*)(*(DWORD*)__ClientConnection + 0x2218);
        DWORD*    pTmp = NULL;
        _asm mov eax, DWORD PTR FS:[0x2C]
        _asm mov eax, DWORD PTR DS:[eax]
        _asm mov pTmp, eax
        *(DWORD*)((DWORD)pTmp + 0x10) = s_curMgr;
    }
    
        DWORD GetSpellByName( char* szName )
        {
            UpdateCurMgr();
            DWORD dwUnknown = 0;
            __asm
            {
                LEA EAX, dwUnknown
                PUSH EAX
                PUSH szName
                MOV  EAX, __GetSpellIDByName
                CALL EAX
                ADD  ESP, 8
            }
        }
    
        void CastSpellById( DWORD dwSpellID)
        {
            UpdateCurMgr();
            __asm
            {
                PUSH 0
                PUSH 0
                PUSH 0
                PUSH dwSpellID
                MOV  EAX, __CastSpellByID
                CALL EAX
                ADD  ESP, 0x10
            }
        }
    ClientConnection can be found in the WoW 2.4.3 offset dump, i posted it there.

  5. #5
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1356
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your function is also returning void. It should be returning a DWORD like in kynox's code otherwise how are you going to get the result of the function call.

  6. #6
    akh's Avatar Member
    Reputation
    4
    Join Date
    Mar 2008
    Posts
    39
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry for the late reply. I have tried to run the code Kynox posted but still nothing happens. Here is what I did:
    Made a new dll32 project in Visual Studio.
    Pasted the code from Kynox.
    Injected the dll in WoW with an injector found on GameDeception.

    The method is being called like it was before, but it does not cast any spell:

    Here is the code:

    SpellCastDLL.cpp:
    Code:
    #include "stdafx.h"
    
    	void main() 
    	{
    		CastSpellById( 168 ); //Frost Armor (Rank 1)
    	}
    
    	void __forceinline UpdateCurMgr()
    	{
    		DWORD dwClientCon = 0x00D43318;
    		DWORD s_curMgr = *(DWORD*)(*(DWORD*)dwClientCon + 0x2218);
    		DWORD* pTmp = NULL;
    		_asm mov eax, DWORD PTR FS:[0x2C]
    		_asm mov eax, DWORD PTR DS:[eax]
    		_asm mov pTmp, eax
    		*(DWORD*)((DWORD)pTmp + 0x10) = s_curMgr;
    	}
    
    	void CastSpellById( DWORD dwSpellID )
    	{
    		DWORD dwCastSpellById = 0x006FC520;
    		UpdateCurMgr();
    		__asm
    		{
    			PUSH 0
    			PUSH 0
    			PUSH 0
    			PUSH dwSpellID
    			MOV  EAX, dwCastSpellById
    			CALL EAX
    			ADD  ESP, 0x10
    		}
    	}
    dllmain.cpp:
    Code:
    #include "stdafx.h"
    
    BOOL APIENTRY DllMain( HMODULE hModule,
                           DWORD  ul_reason_for_call,
                           LPVOID lpReserved
    					 )
    {
    	switch (ul_reason_for_call)
    	{
    	case DLL_PROCESS_ATTACH:
    		{
    			main();
    			break;
    		}
    	case DLL_THREAD_ATTACH:
    	case DLL_THREAD_DETACH:
    	case DLL_PROCESS_DETACH:
    		break;
    	}
    	return TRUE;
    }
    stdafx.h:
    Code:
    #pragma once
    
    #include "targetver.h"
    
    #define WIN32_LEAN_AND_MEAN
    #include <windows.h>
    
    void main();
    void CastSpellById( DWORD dwSpellID );

  7. #7
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1356
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    On an aside you should make sure you don't do too much in DllMain on DLL_PROCESS_ATTACH because if your code doesn't return fast enough (or at all) then you'll cause a deadlock and no other modules can load. I had that problem a while back.

    The easiest solution is to just create a new new thread if you need to do any actual real work in DllMain other than just some basic initialization.

    eg This is the DLLMain from my DLL.
    Code:
    BOOL WINAPI DllMain(HINSTANCE hinstDLL, unsigned int fdwReason, LPVOID)
    {
        switch (fdwReason)
        {
        case DLL_PROCESS_ATTACH:
            {
                _beginthreadex(NULL,NULL,MyThread,hinstDLL,NULL,NULL);
                break;
            }
        case DLL_PROCESS_DETACH:
            {
                DeletePointers();
                break;
            }
        }
        return TRUE;
    }
    You'll notice I'm using _beginthreadex, make sure you always use that rather than CreateThread or you may run into some bugs that are very difficult to diagnose unless you already know you're not supposed to be calling it directly in most circumstances.

  8. #8
    kynox's Avatar Account not activated by Email
    Reputation
    830
    Join Date
    Dec 2006
    Posts
    888
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My best guess is the ID is wrong. Use CastSpellByID( GetSpellByName( "Frost Armor" ) )

  9. #9
    akh's Avatar Member
    Reputation
    4
    Join Date
    Mar 2008
    Posts
    39
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi again.. I tried creating a new thread in my dll like Cypher suggested, and I checked the spellId, but still nothing happens. I have uploaded my project here, maybe you will have a look at it. I made a test, first it finds the spellId using GetSpellIdByName and after 5 sec it tries to cast the spell. Wow has to be running and logged in before you press inject.

    I really appreciate that you are trying to help me

  10. #10
    kynox's Avatar Account not activated by Email
    Reputation
    830
    Join Date
    Dec 2006
    Posts
    888
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by akh View Post
    hi again.. I tried creating a new thread in my dll like Cypher suggested, and I checked the spellId, but still nothing happens. I have uploaded my project here, maybe you will have a look at it. I made a test, first it finds the spellId using GetSpellIdByName and after 5 sec it tries to cast the spell. Wow has to be running and logged in before you press inject.

    I really appreciate that you are trying to help me
    That's got me stumped :S. You are a Mage and you have that spell, yes?

  11. #11
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1356
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll write up some working code for you tomorrow or something, really tired atm.

  12. #12
    akh's Avatar Member
    Reputation
    4
    Join Date
    Mar 2008
    Posts
    39
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by kynox View Post
    That's got me stumped :S. You are a Mage and you have that spell, yes?
    I have tried it on a trial acc with a lvl 3 mage with rank 1 frost armor, and on my private server with a lvl 70 mage with rank 3.

    The getSpellByName function works and returns the spellId of the spell with the highest rank.
    Last edited by akh; 08-31-2008 at 06:21 AM.

  13. #13
    akh's Avatar Member
    Reputation
    4
    Join Date
    Mar 2008
    Posts
    39
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just got it working.. It was the UpdateCurMgr() method that was the problem.
    *(DWORD*)((DWORD)pTmp + 0x10) = s_curMgr; had to be changed to *(DWORD*)((DWORD)pTmp + 0x = s_curMgr;

    Thanks for your help

  14. #14
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1356
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah **** the TLS slot was swapped. Hahaha, epic win, can't believe I missed that.

  15. #15
    kynox's Avatar Account not activated by Email
    Reputation
    830
    Join Date
    Dec 2006
    Posts
    888
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Haha, oh wow. Sorry; I pasted it from an older source!

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 11
    Last Post: 11-21-2011, 12:25 AM
  2. "pure virtual function call" c++ error
    By Kzuly in forum Diablo 3 Emulator Servers
    Replies: 2
    Last Post: 10-21-2011, 12:37 AM
  3. Remote function call, calling convention?
    By lweid in forum WoW Memory Editing
    Replies: 11
    Last Post: 03-24-2011, 03:39 PM
  4. CEGUI - EndScene Hook - DLL Function Call
    By Orix in forum WoW Memory Editing
    Replies: 5
    Last Post: 02-12-2011, 03:51 PM
  5. detection of engine function calls
    By mnbvc in forum WoW Memory Editing
    Replies: 10
    Last Post: 03-28-2010, 03:06 PM
All times are GMT -5. The time now is 01:20 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search