From 2cd674dac75855c35373d3e6b89359f3e89b1178 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Sun, 9 Sep 2018 03:14:20 +0430 Subject: jmp_t_s now uses the new way of registering tables, the 5.3 way. bruiser is supposed to be luarocks-friendly so i wont remove the compatibility build. --- bruiser/asmrewriter.c | 13 +++++++++++++ bruiser/lua-scripts/asmrw.lua | 24 ++++++++++++------------ bruiser/lua-scripts/asmtest.lua | 6 +++--- bruiser/lua-scripts/demo2.lua | 4 ++++ 4 files changed, 32 insertions(+), 15 deletions(-) (limited to 'bruiser') diff --git a/bruiser/asmrewriter.c b/bruiser/asmrewriter.c index d8401c4..12d358a 100644 --- a/bruiser/asmrewriter.c +++ b/bruiser/asmrewriter.c @@ -298,6 +298,18 @@ static const luaL_Reg jmpt_meta[] = { }; int jmpt_register(lua_State* __ls) { + lua_newtable(__ls); + luaL_setfuncs(__ls, jmpt_methods, 0); + luaL_newmetatable(__ls, "jmp_s_t"); + luaL_setfuncs(__ls, jmpt_meta, 0); + lua_pushliteral(__ls, "__index"); + lua_pushvalue(__ls, -3); + lua_rawset(__ls, -3); + lua_pushliteral(__ls, "__metatable"); + lua_pushvalue(__ls, -3); + lua_rawset(__ls, -3); + return 1; +#if 0 luaL_openlib(__ls, "jmp_s_t", jmpt_methods, 0); luaL_newmetatable(__ls, "jmp_s_t"); luaL_openlib(__ls, 0, jmpt_meta, 0); @@ -309,6 +321,7 @@ int jmpt_register(lua_State* __ls) { lua_rawset(__ls, -3); lua_pop(__ls, 1); return 1; +#endif } //@DEVI-after jmpt_register, the methods are still on the stack. remove them by lua_pop(__ls, 1) /**********************************************************************************************************************/ diff --git a/bruiser/lua-scripts/asmrw.lua b/bruiser/lua-scripts/asmrw.lua index b8de4c5..07844ca 100644 --- a/bruiser/lua-scripts/asmrw.lua +++ b/bruiser/lua-scripts/asmrw.lua @@ -22,14 +22,14 @@ xobj = require("xobj") -- this will hold a copy of the original text section local text_buffer = {} -setmetatable(jmp_s_t, {__call = - function(self, arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12) - local t = self.new(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12) - print("created", t) - return t - end - } -) +--setmetatable(jmp_s_t, {__call = + --function(self, arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12) + --local t = self.new(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12) + --print("created", t) + --return t + --end + --} +--) function asmrw.strings(exe) io.write(colors("%{cyan}".."lua:getting text section...\n")) @@ -48,10 +48,10 @@ end function asmrw.strings_deep(exe) end -function jmp_s_t:dump(msg) - print(msg, self:custom()) - return self -end +--function jmp_s_t:dump(msg) + --print(msg, self:custom()) + --return self +--end function asmrw.get_head(elf_exe) local text_section = xobj.getTextSection(elf_exe) diff --git a/bruiser/lua-scripts/asmtest.lua b/bruiser/lua-scripts/asmtest.lua index d7c0583..f5809d8 100644 --- a/bruiser/lua-scripts/asmtest.lua +++ b/bruiser/lua-scripts/asmtest.lua @@ -5,13 +5,13 @@ asmrw = require("asmrw") function test() local elf_exe = "../bfd/test/test" local text_section = xobj.getTextSection(elf_exe) - local head = jmp_s_t() + -- local head = jmp_s_t() -- messes up the stack. I could fix it but not sure why i would want to keep this in --local head2 = jmp_s_t:new() - head = getjmptable(#text_section, text_section) + local head = getjmptable(#text_section, text_section) while head:inext() ~= nil do - head:dump("entry") + --head:dump("entry") io.write("type:", head:type(), "\tlocation:", "0x"..string.format("%x", head:location())) print() head = head:inext() diff --git a/bruiser/lua-scripts/demo2.lua b/bruiser/lua-scripts/demo2.lua index 73a177c..4a1730e 100644 --- a/bruiser/lua-scripts/demo2.lua +++ b/bruiser/lua-scripts/demo2.lua @@ -52,16 +52,20 @@ function test() print(dummy) end +--[[ setmetatable(jmp_s_t, {__call = function(self, arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12) local t = self.new(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12) print("created", t) return t end}) +]]-- +--[[ function jmp_s_t:show(msg) print(msg, self, self:custom()) return self end +]]-- function jmp_t_test() local t = jmp_s_t.new(1,2,3,nil,nil,nil,7,8,9,0,0,1) -- cgit v1.2.3