/***************************************************Project Mutator****************************************************/
/*first line intentionally left blank.*/
/*bruiser's lua asmrewriter implementation for jump tables*/
/*Copyright (C) 2018 Farzad Sadeghi
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*/
/**********************************************************************************************************************/
#include "./lua-5.3.4/src/lua.hpp"
#include "./bruisercapstone.h"
#include "./asmrewriter.h"
#include <inttypes.h>
/**********************************************************************************************************************/
static JMP_S_T* convert_jmpt(lua_State* __ls, int index) {
JMP_S_T* dummy = (JMP_S_T*)lua_touserdata(__ls, index);
if (dummy == NULL) luaL_typerror(__ls, index, dummy);
return dummy;
}
static JMP_S_T* check_jmpt(lua_State* __ls, int index) {
JMP_S_T* dummy;
luaL_checktype(__ls, index, LUA_TUSERDATA);
dummy = (JMP_S_T*)luaL_checkudata(__ls, index, JMP_S_T);
if (dummy == NULL) luaL_typerror(__ls, index, dummy);
return dummy;
}
static JMP_S_T* push_jmpt(lua_State* __ls) {
JMP_S_T* dummy = (JMP_S_T*)lua_newuserdata(__ls, sizeof(JMP_S_T));
luaL_getmetatable(__ls, JMP_S_T);
lua_setmetatable(__ls, -2);
return dummy;
}
static int new_jmpt(lua_State* __ls) {
JMP_T jmp_t = luaL_optint(__ls, 1, 0);
uint64_t location = luaL_optint(__ls, 2, 0);
uint8_t size = luaL_optint(__ls, 3, 0);
//
//
//
uint64_t address = luaL_optint(__ls, 7, 0);
uint64_t address_y = luaL_optint(__ls, 8, 0);
uint64_t address_n = luaL_optint(__ls, 9, 0);
unsigned char y = luaL_optint(__ls, 10, 0);
unsigned char n = luaL_optint(__ls, 11, 0);
unsigned char z = luaL_optint(__ls, 12, 0);
JMP_S_T* dummy = push_jmpt(__ls);
dummy->type = jmp_t;
dummy->location = location;
dummy->size = size;
//dummy->next =;
//dummy->next_y =;
//dummy->next_n =;
dummy->address = address;
dummy->address_y = address_y;
dummy->address_n = address_n;
dummy->y = y;
dummy->n = n;
dummy->z = z;
return 1;
}
static int jmpt_custom(lua_State* __ls) {
JMP_S_T* dummy = check_jmpt(__ls, 1);
printf("this is the jump table custom function.\n");
lua_pushnumber(__ls, dummy->type);
lua_pushnumber(__ls, dummy->location);
lua_pushnumber(__ls, dummy->size);
lua_pushlightuserdata(__ls, dummy->next);
lua_pushlightuserdata(__ls, dummy->next_y);
lua_pushlightuserdata(__ls, dummy->next_n);
lua_pushnumber(__ls, dummy->address);
lua_pushnumber(__ls, dummy->address_y);
lua_pushnumber(__ls, dummy->address_n);
lua_pushnumber(__ls, dummy->y);
lua_pushnumber(__ls, dummy->n);
lua_pushnumber(__ls, dummy->z);
return 12;
}
#define SET_GENERATOR(X) \
static int jmpt_set_##X(lua_State* __ls) {\
JMP_S_T* dummy = check_jmpt(__ls,1);\
dummy->type = luaL_checkint(__ls, 2);\
lua_settop(__ls, 1);\
return 1;\
}
#define X_LIST_GEN \
X(type, "setter method for type")\
X(location, "setter method for location")\
X(size, "setter method for size")\
X(address, "setter method for address")\
X(address_y, "setter method for address_y")\
X(address_n, "setter method for address_n")\
X(y, "setter method for y")\
X(n, "setter method for n")\
X(z, "setter method for z")
#define X(X1,X2) SET_GENERATOR(X1)
X_LIST_GEN
#undef X
#undef X_LIST_GEN
#undef SET_GENERATOR
static int jmpt_set_next(lua_State* __ls) {}
static int jmpt_set_next_y(lua_State* __ls) {}
static int jmpt_set_next_n(lua_State* __ls) {}
static int jmpt_gc(lua_State* __ls) {}
int jmpt_register(lua_State* __ls) {
luaL_openlib(__ls, JMP_S_T, jmpt_methods, 0);
luaL_newmetatable(__ls, JMP_S_T);
luaL_openlib(__ls, 0, 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);
lua_pop(__ls, 1);
return 1;
}
//@DEVI-after jmpt_register, the methods are still on the stack. remove them by lua_pop(__ls, 1)
/**********************************************************************************************************************/
//@DEVI-the main is only meant for testing
#pragma weak main
int main(int argc, char** argv) {
return 0;
}
/**********************************************************************************************************************/
/*last line intentionally left blank.*/