2011-08-03 07:07:57 -06:00
|
|
|
#include "lua_Hexsearch.h"
|
|
|
|
int lua::Hexsearch::find(lua_State *L)
|
|
|
|
{
|
|
|
|
lua::state st(L);
|
2012-01-03 17:45:11 -07:00
|
|
|
void * pos=p->FindNext();
|
2011-08-03 07:07:57 -06:00
|
|
|
st.push(pos);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
int lua::Hexsearch::findall(lua_State *L)
|
|
|
|
{
|
|
|
|
lua::state st(L);
|
2012-01-03 17:45:11 -07:00
|
|
|
std::vector<void *> pos=p->FindAll();
|
2011-08-03 07:07:57 -06:00
|
|
|
st.newtable();
|
2011-08-03 08:59:06 -06:00
|
|
|
for(unsigned i=0;i<pos.size();i++)
|
2011-08-03 07:07:57 -06:00
|
|
|
{
|
|
|
|
st.push(i+1);
|
|
|
|
st.push(pos[i]);
|
|
|
|
st.settable();
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
lua::Hexsearch::Hexsearch(lua_State *L,int id):tblid(id)
|
|
|
|
{
|
|
|
|
lua::state st(L);
|
2012-01-05 15:39:14 -07:00
|
|
|
char * start,* end;
|
2011-08-03 07:07:57 -06:00
|
|
|
::Hexsearch::SearchArgType args;
|
2012-01-05 15:39:14 -07:00
|
|
|
start= (char *)st.as<uint32_t>(1);
|
|
|
|
end=(char *)st.as<uint32_t>(2);
|
2011-08-03 07:27:04 -06:00
|
|
|
for(int i=3;i<=st.gettop();i++)
|
2011-08-03 07:07:57 -06:00
|
|
|
{
|
|
|
|
args.push_back(st.as<int>(i));
|
|
|
|
}
|
|
|
|
p=new ::Hexsearch(args,start,end);
|
|
|
|
}
|
|
|
|
lua::Hexsearch::~Hexsearch()
|
|
|
|
{
|
|
|
|
delete p;
|
|
|
|
}
|
|
|
|
int lua::Hexsearch::reset(lua_State *L)
|
|
|
|
{
|
|
|
|
lua::state st(L);
|
|
|
|
p->Reset();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
IMP_LUNE(lua::Hexsearch,hexsearch);
|
|
|
|
LUNE_METHODS_START(lua::Hexsearch)
|
|
|
|
method(lua::Hexsearch,find),
|
|
|
|
method(lua::Hexsearch,findall),
|
|
|
|
method(lua::Hexsearch,reset),
|
|
|
|
LUNE_METHODS_END();
|
2011-08-08 13:17:11 -06:00
|
|
|
#define __ADDCONST(name) st.push(::Hexsearch:: name); st.setglobal(#name)
|
2011-08-03 07:07:57 -06:00
|
|
|
void lua::RegisterHexsearch(lua::state &st)
|
|
|
|
{
|
|
|
|
|
|
|
|
Lune<lua::Hexsearch>::Register(st);
|
2011-08-03 08:59:06 -06:00
|
|
|
__ADDCONST(ANYBYTE);
|
|
|
|
__ADDCONST(ANYDWORD);
|
|
|
|
__ADDCONST(DWORD_);
|
|
|
|
}
|
2011-08-08 13:17:11 -06:00
|
|
|
#undef __ADDCONST
|