Page 1 of 1

is it possible to inject ingame not allowed lua code ?

Posted: Sun Aug 15, 2010 11:42 am
by Micke
Hi,

i hope i've read it correct - it's not possible/allowed to use the "require" function inside the lua VM in runes of magic.
But i need this, cause i want include a luapackage into my addon which give me access to non-lua-written-libraries.

Most likely i cant inject forbidden code, but who knows ....

thanx in advance
Micke

Re: is it possible to inject ingame not allowed lua code ?

Posted: Sun Aug 15, 2010 7:42 pm
by Administrator
You could hook the luaL_openlibs() and luaL_register() Lua functions. Your openlibs would be something like this:

Code: Select all

static int myLuaFunction(lua_State *lstate)
{
  return 0;
}

LUAL_OPENLIBS hook_luaL_openlibs(lua_State *lstate)
{
  int success = real_luaL_openlibs(lstate); -- Install standard libraries

  static const lua_reg regMap[] = {
    {"myLuaFunction", myLuaFunction},
    {NULL, NULL}
  };

  real_luaL_register(lstate, "myLibraryName", regMap); -- Install custom library

  -- You can now call myLuaFunction() from within the Lua VM

  return success;
}

Re: is it possible to inject ingame not allowed lua code ?

Posted: Tue Aug 17, 2010 4:41 pm
by Micke
puuh, wow, big thnx .... didn't knew that i can catch a foreign VM and use her as if i have initiated her, can't i ?

understand, but if it is so easy, i wonder why so many guys writing their addons in LUA, instead of reduce the lua code to a minimum and handle the logic in a less primitive language.
ok ok ....

thanx a lot admin
( even if i know i will spent some hours with your example, finishing with 2 new questions ;-) )

Re: is it possible to inject ingame not allowed lua code ?

Posted: Tue Aug 17, 2010 9:54 pm
by Administrator
understand, but if it is so easy, i wonder why so many guys writing their addons in LUA, instead of reduce the lua code to a minimum and handle the logic in a less primitive language.
You've got it backwards. Lua is a high-level scripting language while C is a (relatively) low-level programming language. It's almost like comparing apples and oranges.

One (Lua) is quick and simple, while the other (C) is dirty, hackish, and requires a lot of knowledge and experience because it works by exploiting how a portable executable works.

Re: is it possible to inject ingame not allowed lua code ?

Posted: Wed Aug 18, 2010 1:11 am
by Micke
using the attribute primitive i won't affront someone,
i miss the advantages of the object oriented aspect.
anyway ...


do u have pls some keywords to find posts how to catch the Lua VM hosted in ROM ?

I would complete your example with
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
lua_State *lstate = luaL_newstate();

But how do i know what class/type/lib ROM is using for that ?

thnx in advance
Micke

Re: is it possible to inject ingame not allowed lua code ?

Posted: Wed Aug 18, 2010 2:22 am
by Administrator
You don't need to worry about that. You're looking at function hooking.

Include the attached files in your project. Read the readme. You'll use DetourFunc() to hook the two functions I stated earlier (and those are the only ones you need for now).


Here's an example of it:
http://forum.gamedeception.net/threads/ ... bix-detour.

Re: is it possible to inject ingame not allowed lua code ?

Posted: Sun Aug 22, 2010 2:58 pm
by Micke
oha, thnx admin, very helpful, really.

pls excuse when i dont answered immidiately, but its a very new topic for me and i first have to spent some time with your references - that as a small feedback that i've read all.

Re: is it possible to inject ingame not allowed lua code ?

Posted: Sun Oct 24, 2010 4:00 pm
by Micke