1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| const LUA_PATH = "文件监控路径" function LuaFileWatcher(){ var inotify_init = new NativeFunction(Module.findExportByName(null,"inotify_init"),'int',[]) var inotify_add_watch = new NativeFunction(Module.findExportByName(null,"inotify_add_watch"),'int',['int','pointer','int']) const read = new NativeFunction(Module.findExportByName(null,"read"),'int',['int','pointer','int']); var fd = inotify_init() var wd = inotify_add_watch(fd,Memory.allocUtf8String(LUA_PATH),256) console.log("fd "+fd+",wd "+wd) const inotify_event_len = 0x10 var data = Memory.alloc(inotify_event_len*10); while (1){ let readlen = read(fd,data,inotify_event_len*10-1) if( readlen<0){ console.log('[+] Unable to read [!] '); continue } console.log(readlen,data)
for (let i = 0; i < (readlen/0x10) ; i++) { let readData = data.add(i*0x10) let envent = [] envent.wd = readData.readS32(); envent.mask = readData.add(4).readU32(); envent.cookie = readData.add(8).readU32(); envent.len = readData.add(12).readU32(); envent.name = readData.add(16).readCString(); console.log('open file : ',envent.name,envent.mask) if(envent.mask!=256) continue; try{ console.log('----------------------') let luaname = envent.name.replaceAll("_",".") console.log("luaname"+luaname) var scr ='if string.find(package.path,\"'+ LUA_PATH+'\") == nil then\n' + ' package.path = package.path .. \";'+LUA_PATH+'/?\"\n' + 'end\n'+ 'require(\"HotFixOOOK\")\n'+ 'hotfix(\"'+luaname+'\")' var luaL_loadstring_ret = luaL_loadstring(lua_State,Memory.allocUtf8String(scr)) console.log("luaL_loadstring_ret : "+luaL_loadstring_ret) send("load lua init ret "+ lua_pcall(lua_State,0,0,0) + " str:"+lua_tolstring(lua_State, -1).readCString())
}catch (e) { send("err:"+e.toString()) } }
}
}
var pthread_create = new NativeFunction(Module.findExportByName(null,"pthread_create"),'int',['pointer','pointer','pointer','pointer']) var LuaFileWatcherNative = new NativeCallback(LuaFileWatcher,'void',['void'])
pthread_create(Memory.alloc(16),new NativePointer(0),LuaFileWatcherNative,new NativePointer(0))
|