2011-12-31 04:48:42 -07:00
|
|
|
#include "Core.h"
|
|
|
|
#include "Export.h"
|
|
|
|
#include "PluginManager.h"
|
|
|
|
#include "MemAccess.h"
|
|
|
|
#include "MiscUtils.h"
|
2011-07-16 08:22:45 -06:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2011-07-16 11:43:57 -06:00
|
|
|
|
2011-07-16 13:08:58 -06:00
|
|
|
#include "luamain.h"
|
2011-07-27 18:11:33 -06:00
|
|
|
#include "lua_Process.h"
|
2011-08-03 07:07:57 -06:00
|
|
|
#include "lua_Hexsearch.h"
|
2011-08-13 06:42:09 -06:00
|
|
|
#include "lua_Misc.h"
|
2013-01-02 09:26:30 -07:00
|
|
|
|
2012-03-24 06:47:51 -06:00
|
|
|
#include "DataDefs.h"
|
2012-03-31 05:40:54 -06:00
|
|
|
#include "LuaTools.h"
|
2011-07-16 10:29:46 -06:00
|
|
|
|
2011-07-16 08:22:45 -06:00
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
using namespace DFHack;
|
|
|
|
|
|
|
|
|
2011-08-08 17:46:32 -06:00
|
|
|
|
2013-01-02 09:26:30 -07:00
|
|
|
DFHACK_PLUGIN("dfusion")
|
2011-07-16 08:22:45 -06:00
|
|
|
|
2013-01-02 09:26:30 -07:00
|
|
|
static int loadObjectFile(lua_State* L)
|
2011-08-08 17:46:32 -06:00
|
|
|
{
|
2013-01-02 09:26:30 -07:00
|
|
|
std::string path;
|
|
|
|
|
|
|
|
path=luaL_checkstring(L,1);
|
|
|
|
|
|
|
|
OutFile::File f(path);
|
|
|
|
lua_newtable(L);
|
|
|
|
int table_pos=lua_gettop(L);
|
|
|
|
size_t size=f.GetTextSize();
|
|
|
|
Lua::Push(L,size);
|
|
|
|
lua_setfield(L,table_pos,"data_size");
|
|
|
|
char* buf=new char[size];
|
|
|
|
f.GetText(buf);
|
|
|
|
|
|
|
|
//Lua::PushDFObject(L,DFHack::,buf);
|
|
|
|
//Lua::Push(L,buf);
|
|
|
|
lua_pushlightuserdata(L,buf);
|
|
|
|
lua_setfield(L,table_pos,"data");
|
|
|
|
const OutFile::vSymbol &symbols=f.GetSymbols();
|
|
|
|
lua_newtable(L);
|
|
|
|
for(size_t i=0;i<symbols.size();i++)
|
|
|
|
{
|
|
|
|
Lua::Push(L,i);
|
|
|
|
lua_newtable(L);
|
|
|
|
Lua::Push(L,symbols[i].name);
|
|
|
|
lua_setfield(L,-2,"name");
|
|
|
|
Lua::Push(L,symbols[i].pos);
|
|
|
|
lua_setfield(L,-2,"pos");
|
|
|
|
|
|
|
|
|
|
|
|
lua_settable(L,-3);
|
|
|
|
}
|
|
|
|
lua_setfield(L,table_pos,"symbols");
|
|
|
|
return 1;
|
2012-03-11 06:33:08 -06:00
|
|
|
}
|
2013-01-02 09:26:30 -07:00
|
|
|
static int markAsExecutable(lua_State* L)
|
2011-07-16 15:11:21 -06:00
|
|
|
{
|
2013-01-02 09:26:30 -07:00
|
|
|
unsigned addr=luaL_checkunsigned(L,1);
|
|
|
|
std::vector<DFHack::t_memrange> ranges;
|
|
|
|
DFHack::Core::getInstance().p->getMemRanges(ranges);
|
|
|
|
for(size_t i=0;i<ranges.size();i++)
|
2012-04-15 09:09:25 -06:00
|
|
|
{
|
2013-01-02 09:26:30 -07:00
|
|
|
if(ranges[i].isInRange((void*)addr))
|
2012-04-21 06:53:17 -06:00
|
|
|
{
|
2013-01-02 09:26:30 -07:00
|
|
|
DFHack::t_memrange newperm=ranges[i];
|
|
|
|
newperm.execute=true;
|
|
|
|
DFHack::Core::getInstance().p->setPermisions(ranges[i],newperm);
|
|
|
|
return 0;
|
2012-04-21 06:53:17 -06:00
|
|
|
}
|
2012-04-15 09:09:25 -06:00
|
|
|
}
|
2013-01-02 09:26:30 -07:00
|
|
|
lua_pushlstring(L,"Memory range not found",23);
|
|
|
|
lua_error(L);
|
|
|
|
return 0;
|
2011-08-19 09:09:00 -06:00
|
|
|
}
|
2013-01-02 09:26:30 -07:00
|
|
|
DFHACK_PLUGIN_LUA_COMMANDS {
|
|
|
|
DFHACK_LUA_COMMAND(loadObjectFile),
|
|
|
|
DFHACK_LUA_COMMAND(markAsExecutable),
|
|
|
|
DFHACK_LUA_END
|
|
|
|
};
|
|
|
|
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
|
2011-08-19 09:09:00 -06:00
|
|
|
{
|
2013-01-02 09:26:30 -07:00
|
|
|
return CR_OK;
|
|
|
|
}
|