Injected DLL, C# function delegates menu

User Tag List

Results 1 to 2 of 2
  1. #1
    mexicaan's Avatar Member
    Reputation
    3
    Join Date
    Jan 2007
    Posts
    8
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Injected DLL, C# function delegates

    Hello,

    I recently got interested in WoW hacking. Thanks to various resources on this board I managed to inject a assembly into WoW using EasyHook. Next I was interested in calling WoW functions by converting an unmanaged function pointer to a delegate. I started with CGObject's GetObjectName.

    First I tried it using the WhiteMagic library available on this forum
    Code:
    // WoW VMT index
    public const uint Wow_VMT_GetName = 52;
    
    ...
    
    // Delegate declaration
    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
    private delegate string VMT_GetNameDelegate();    
    
    ...
    
    // Function
    private static VMT_GetNameDelegate VMT_FuncGetName;
    
    ...
    
    // Returns the WoW name for the specified object address by marshalling the WoW GetObjectName() function
    public static string Wow_GetName(uint objectAddr)
    {
        Logger.Debug("Wow_GetName("+objectAddr.ToString()+")");
    
        IntPtr getNameFuncPtr = Magic.GetObjectVtableFunction((IntPtr)objectAddr, Wow_VMT_GetName);
        Logger.Debug("Object's VMT_FuncGetName found at: " + getNameFuncPtr.ToString());
        VMT_FuncGetName = Marshal.GetDelegateForFunctionPointer(getNameFuncPtr, typeof(VMT_GetNameDelegate)
    
        Logger.Debug("Calling VMT_FuncGetName()");
        string result = VMT_FuncGetName((IntPtr)objectAddr);
        Logger.Debug("Result: " + result);
    
        return result;
    }
    But trying the function on different kind of WoW objects all made the WoW process crash. After reading some more on this forum, Instead of using Cdecl I'd try using ThisCall.

    Code:
    // WoW function addresses
    public const uint Wow_GetName = 0x006A2150;
    
    ...
    
    // Delegate declaration
    [UnmanagedFunctionPointer(CallingConvention.ThisCall)]
    private delegate string VMT_GetNameDelegate(IntPtr objectBase);    
    
    ...
    
    // Function
    private static VMT_GetNameDelegate VMT_FuncGetName;
    
    ...
    
    // Register WoW function
    public void RegisterWowDelegate()
    {
        Logger.Debug("RegisterWowDelegate:  Wow_FuncGetName");
        VMT_FuncGetName = Tools.GetRegisterDelegate<VMT_GetNameDelegate>(Wow_GetName);
    }
    
    ...
    
    // Returns the WoW name for the specified object address by marshalling the WoW GetObjectName() function
    public static string Wow_GetName(uint objectAddr)
    {
        Logger.Debug("Wow_GetName("+objectAddr.ToString()+")");
    
        Logger.Debug("Calling VMT_FuncGetName()");
        string result = VMT_FuncGetName((IntPtr)objectAddr);
        Logger.Debug("Result: " + result);
    
        return result;
    }
    This aswell made the process crash. So next I (even though I have no clue how use it ), opened IDA and looked up the address and it's function.
    I found the class method, and the function declaration showed this
    Code:
    char *__thiscall sub_6A2150(int this, int a2, unsigned int a3)
    {
    ...
    }
    The whole code contained sutff like "UNKNOWNOBJECT" and "Unknown Being", so I'm pretty sure I have the correct method.
    But I'm at a loss now, the function is a class method of the CGObject class. I see my function delegate doesn't have the 2nd and 3rd parameter, and I don't know what they do, or what I'm suppose to feed the arguments.

    I'm stuck at this point, so if looking for some help.

    thanks in advance

    Injected DLL, C# function delegates
  2. #2
    Apoc's Avatar Angry Penguin
    Reputation
    1387
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/12
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
            [UnmanagedFunctionPointer(CallingConvention.ThisCall, CharSet = CharSet.Ansi)]
            private delegate IntPtr GetNameDelegate(IntPtr instance);
    
            public string Name
            {
                get
                {
                    if (_getName == null)
                    {
                        _getName = Utilities.RegisterDelegate<GetNameDelegate>(GetVFunc(VFTableIndex.GetName));
                    }
                    return Marshal.PtrToStringAnsi(_getName(this));
                }
            }
    Only reason I'm helping you, is because that gave me trouble too. (The code is actually kynox's!)

Similar Threads

  1. Cant access any wow function from injected dll
    By Kwapuzzi in forum WoW Memory Editing
    Replies: 8
    Last Post: 11-01-2012, 01:58 PM
  2. Replies: 4
    Last Post: 07-20-2011, 09:50 PM
  3. Inject DLLs into D2
    By Canbus in forum Diablo 2
    Replies: 1
    Last Post: 09-05-2010, 02:44 PM
  4. [Injection] Selecting/customizing functionality to inject
    By Bananenbrot in forum WoW Memory Editing
    Replies: 9
    Last Post: 06-05-2010, 07:37 AM
  5. [CODE] Dumping Python Modules (from an injected DLL)
    By GliderPro in forum Programming
    Replies: 0
    Last Post: 04-08-2009, 02:20 PM
All times are GMT -5. The time now is 06:21 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