[NEED HELP]lua_getfield is puzzling me menu

User Tag List

Results 1 to 6 of 6
  1. #1
    zys924's Avatar Active Member
    Reputation
    20
    Join Date
    Nov 2009
    Posts
    113
    Thanks G/R
    0/7
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [NEED HELP]lua_getfield is puzzling me

    Im trying to find out a _G lua var value by calling 'lua_getfield'

    First take a look at the standard lua_getfield signature:
    void lua_getfield (lua_State *L, int index, const char *k);

    But with IDA+HexRays, Ive located lua_getfield as:
    int __cdecl lua_getfield(int a1, int a2, int Str, signed int a4);

    As you can see, the lua_getfield in WOW has one more param "a4" of type "int" which quite puzzles me...

    Furthormore, using C# Injection, Ive tried in-process call to it. Each time got failed as a result of illegal memory operations.

    Here's my declaration and call in C#:
    Code:
    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
    private delegate int Lua_GetFieldDelegate(uint luaState, int tableindex, string varname, int unknown);
    private static Lua_GetFieldDelegate Lua_GetField;
    private static const LUA_GLOBALSINDEX = -10001;
    
    private static void TryGetField()
    {
        Lua_GetField(Lua_GetState(), LUA_GLOBALSINDEX, "someluavarname", 0);
    }
    This code doesnt work and cause memory operation exception...
    Would anybody plz give me a way out?
    Last edited by zys924; 03-28-2010 at 08:10 AM.

    [NEED HELP]lua_getfield is puzzling me
  2. #2
    flo8464's Avatar Active Member
    Reputation
    30
    Join Date
    Apr 2009
    Posts
    434
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you assigning an address to your delegate?
    Hey, it compiles! Ship it!

  3. #3
    abdula123's Avatar Sergeant
    Reputation
    14
    Join Date
    Feb 2010
    Posts
    46
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    L = Lua_GetState()
    lua_gettable(L, LUA_GLOBALSINDEX)
    lua_getfield(L, -1, "somename")
    this works for me.
    getting table LUA_GLOBALINDEX on top of stack
    and then getting field from table at top of stack

  4. #4
    zys924's Avatar Active Member
    Reputation
    20
    Join Date
    Nov 2009
    Posts
    113
    Thanks G/R
    0/7
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by abdula123 View Post
    Code:
    L = Lua_GetState()
    lua_gettable(L, LUA_GLOBALSINDEX)
    lua_getfield(L, -1, "somename")
    this works for me.
    getting table LUA_GLOBALINDEX on top of stack
    and then getting field from table at top of stack
    ehh...as you said, then how come the "somename" is retrieved? (By calling lua_gettop(L))?
    One more confusionoes the return val of lua_getfield make some sense?

    By the way: 3.3.3a lua_getfield @ 0x00974A50, of course i've set the delegate value of Lua_GetField to this address by:
    Code:
    Lua_GetField = Marshal.GetDelegateForFunctionPointer((IntPtr)0x00974A50, typeof(Lua_GetFieldDelegate)) as Lua_GetFieldDelegate;

  5. #5
    abdula123's Avatar Sergeant
    Reputation
    14
    Join Date
    Feb 2010
    Posts
    46
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    lua_gettop_addr         = 0x00488A80
    lua_gettable_addr       = 0x00488D00
    lua_getfield_addr       = 0x00489440
    lua_pcall_addr          = 0x00489B00
    lua_remove_addr         = 0x00488B00
    Code:
            L = Lua_GetState()
            reset_security()
            stack_begin = lua_gettop(L)
    
            lua_gettable(L, LUA_GLOBALSINDEX)
            lua_getfield(L, -1, name)
    
            if lua_typename(L, lua_type(L, -1)) != "function":
                print "function %s not found (%s)" % (name, lua_typename(L, lua_type(L, -1)))
                return
            lua_remove(L, -2) # remove table from stack
    
            .....
            push fn args on stack (if any)
            .....
    
            lua_pcall(L, len(args), LUA_MULTRET, 0)
    
            stack_end = lua_gettop(L)
            .....
            get fn results from stack (if any) and remove it from stack
            .....
    this code is from my Python -> Lua bridge. its works in 3.3.3a (except reset_security - still not fixed after changes in 3.3.2 -> 3.3.3)

  6. #6
    zys924's Avatar Active Member
    Reputation
    20
    Join Date
    Nov 2009
    Posts
    113
    Thanks G/R
    0/7
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by abdula123 View Post
    Code:
    lua_gettop_addr         = 0x00488A80
    lua_gettable_addr       = 0x00488D00
    lua_getfield_addr       = 0x00489440
    lua_pcall_addr          = 0x00489B00
    lua_remove_addr         = 0x00488B00
    Code:
            L = Lua_GetState()
            reset_security()
            stack_begin = lua_gettop(L)
    
            lua_gettable(L, LUA_GLOBALSINDEX)
            lua_getfield(L, -1, name)
    
            if lua_typename(L, lua_type(L, -1)) != "function":
                print "function %s not found (%s)" % (name, lua_typename(L, lua_type(L, -1)))
                return
            lua_remove(L, -2) # remove table from stack
    
            .....
            push fn args on stack (if any)
            .....
    
            lua_pcall(L, len(args), LUA_MULTRET, 0)
    
            stack_end = lua_gettop(L)
            .....
            get fn results from stack (if any) and remove it from stack
            .....
    this code is from my Python -> Lua bridge. its works in 3.3.3a (except reset_security - still not fixed after changes in 3.3.2 -> 3.3.3)
    GODD.. Find pattern out a wrong addr... thx a lot!

Similar Threads

  1. need help with shammy talents
    By jason in forum World of Warcraft General
    Replies: 5
    Last Post: 07-19-2006, 02:02 AM
  2. Need Help with WoW Glider
    By paypal in forum World of Warcraft General
    Replies: 2
    Last Post: 07-07-2006, 02:08 AM
  3. I need help
    By ff9pro in forum World of Warcraft General
    Replies: 4
    Last Post: 07-05-2006, 08:43 PM
  4. Need help
    By zamp in forum World of Warcraft General
    Replies: 1
    Last Post: 06-24-2006, 10:54 PM
  5. Need Help
    By Slumlorde in forum World of Warcraft General
    Replies: 4
    Last Post: 06-23-2006, 08:20 AM
All times are GMT -5. The time now is 01:36 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