Problems using whitemagic. Trying to delegate a function. menu

User Tag List

Results 1 to 7 of 7
  1. #1
    FenixTX2's Avatar Active Member
    Reputation
    23
    Join Date
    Mar 2009
    Posts
    125
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problems using whitemagic. Trying to delegate a function.


    Hi,

    I'm attempting to delegate a function with the help of whitemagic.
    Problem is, it keeps throwing exceptions.

    The first happens almost randomly.
    This code below will occasionally throw "InvalidFunctionPointerInDelegate was detected" with reference to "function pointer 0x65ec30"
    Code:
    _getName = m.RegisterDelegate<GetNameDelegate>(GetVFunc(VFTableIndex.GetName);

    But the real killer comes from the code below.
    Code:
    return Marshal.PtrToStringAnsi(_getName((IntPtr)BaseAddress));

    The delegate function throws "AccesViolationException was unhandled 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'"

    Has anyone any ideas how to solve this?

    Problems using whitemagic. Trying to delegate a function.
  2. #2
    MaiN's Avatar Elite User
    Reputation
    335
    Join Date
    Sep 2006
    Posts
    1,047
    Thanks G/R
    0/10
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    [UnmanagedFunctionPointer(CallingConvention.ThisCall)]
    private delegate IntPtr GetObjectNameDelegate(IntPtr baseAddress);
    private static GetObjectNameDelegate GetObjectNameHandler;
    
    public string Name
    {
        get
        {
            if (GetObjectNameHandler == null)
            {
                GetObjectNameHandler = GetVirtualFunction<GetObjectNameDelegate>(Offsets.VirtualFunctions.GetName);
            }
    
            IntPtr objNamePtr = GetObjectNameHandler(BaseAddress);
            if (objNamePtr != IntPtr.Zero)
            {
                return Marshal.PtrToStringAnsi(objNamePtr);
            }
    
            return string.Empty;
        }
    }
    
    public T GetVirtualFunction<T>(Offsets.VirtualFunctions function) where T : class
    {
        return Magic.Instance.RegisterDelegate<T>(Magic.Instance.GetObjectVtableFunction(BaseAddress, (uint)function));
    }
    [16:15:41] Cypher: caus the CPU is a dick
    [16:16:07] kynox: CPU is mad
    [16:16:15] Cypher: CPU is all like
    [16:16:16] Cypher: whatever, i do what i want

  3. #3
    FenixTX2's Avatar Active Member
    Reputation
    23
    Join Date
    Mar 2009
    Posts
    125
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanks for that MaiN,

    I had a go at implemeting the template class, although I had to switch a few things to make it fit.

    (BaseAddress and function are both uints,
    In my tests BaseAddress is the base address of the local player
    and function is 51)

    Code:
            public T GetVirtualFunction<T>(uint function) where T : class
            {
                return Magic.RegisterDelegate<T>(Magic.GetObjectVtableFunction((IntPtr)BaseAddress, function));
            }
    This throws an exception of "ArgumentNullException was unhandled 'Value cannot be null.
    Parameter name: value'"

    Within the code, it is actually
    Code:
            (Magic.GetObjectVtableFunction((IntPtr)BaseAddress, function)
    that is throwing the above exception.

    *note, if i force to program to move passed that exception I still get the 'AccesViolationException' exception from 'IntPtr objNamePtr = GetObjectNameHandler(BaseAddress);'

    Last edited by FenixTX2; 11-13-2009 at 05:19 PM.

  4. #4
    MaiN's Avatar Elite User
    Reputation
    335
    Join Date
    Sep 2006
    Posts
    1,047
    Thanks G/R
    0/10
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by FenixTX2 View Post

    Thanks for that MaiN,

    I had a go at implemeting the template class, although I had to switch a few things to make it fit.

    (BaseAddress and function are both uints,
    In my tests BaseAddress is the base address of the local player
    and function is 51)

    Code:
            public T GetVirtualFunction<T>(uint function) where T : class
            {
                return Magic.RegisterDelegate<T>(Magic.GetObjectVtableFunction((IntPtr)BaseAddress, function));
            }
    This throws an exception of "ArgumentNullException was unhandled 'Value cannot be null.
    Parameter name: value'"

    Within the code, it is actually
    Code:
            (Magic.GetObjectVtableFunction((IntPtr)BaseAddress, function)
    that is throwing the above exception.

    *note, if i force to program to move passed that exception I still get the 'AccesViolationException' exception from 'IntPtr objNamePtr = GetObjectNameHandler(BaseAddress);'

    Code:
    return Magic.RegisterDelegate<T>(Magic.Read<IntPtr>(BaseAddress, function * 4));
    [16:15:41] Cypher: caus the CPU is a dick
    [16:16:07] kynox: CPU is mad
    [16:16:15] Cypher: CPU is all like
    [16:16:16] Cypher: whatever, i do what i want

  5. #5
    FenixTX2's Avatar Active Member
    Reputation
    23
    Join Date
    Mar 2009
    Posts
    125
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanks again MaiN,

    Sad to say that it's still not functioning.
    I've done some digging and the error seems to stem from
    ReadInternals within the Magic class.

    Within that function there is a Byte[] called ba.
    This is initialised wtih as

    Code:
            Byte[] ba = _win32.ReadBytes(address, size);
    However ba always turns out to be null.

    The actual error comes from further into the ReadInternal function @

    Code:
            case TypeCode.UInt32:
                        ret = BitConverter.ToUInt32(ba, 0);
                        break;
    where ba is the null value in question.

    Any ideas as to why this may be happening?

  6. #6
    Apoc's Avatar Angry Penguin
    Reputation
    1388
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/13
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by FenixTX2 View Post

    Thanks again MaiN,

    Sad to say that it's still not functioning.
    I've done some digging and the error seems to stem from
    ReadInternals within the Magic class.

    Within that function there is a Byte[] called ba.
    This is initialised wtih as

    Code:
            Byte[] ba = _win32.ReadBytes(address, size);
    However ba always turns out to be null.

    The actual error comes from further into the ReadInternal function @

    Code:
            case TypeCode.UInt32:
                        ret = BitConverter.ToUInt32(ba, 0);
                        break;
    where ba is the null value in question.

    Any ideas as to why this may be happening?
    ba will only be null when Win32.ReadBytes fails. I suggest you do some actual debugging and figure out why ReadProcessMemory fails for you.

  7. #7
    Nesox's Avatar ★ Elder ★
    Reputation
    1280
    Join Date
    Mar 2007
    Posts
    1,238
    Thanks G/R
    0/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @FenixTX2: do you have a CLR bootstrapper? and are injecting and running your managed assembly in / from wow? WhiteMagic is not mean't to work 'out of process'

Similar Threads

  1. [LazyBot] Problem using Devouring plague
    By Iusethis in forum WoW Bots Questions & Requests
    Replies: 3
    Last Post: 10-30-2012, 10:56 PM
  2. MySQL Problems (Using Hamachi)
    By iso in forum WoW EMU Questions & Requests
    Replies: 5
    Last Post: 10-31-2009, 09:38 AM
  3. Problems using Nogit and other map editing tools
    By Heartripperz in forum WoW EMU Questions & Requests
    Replies: 2
    Last Post: 05-13-2009, 04:27 PM
  4. NPC spawning problems using SQL to code
    By ddftrick in forum World of Warcraft Emulator Servers
    Replies: 11
    Last Post: 04-26-2008, 08:37 PM
  5. Problem using Mafiaboy's repack
    By Bodom in forum World of Warcraft Emulator Servers
    Replies: 4
    Last Post: 02-17-2008, 02:29 AM
All times are GMT -5. The time now is 04:37 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search