function GetString(Address)
local buf = ffi.new("char[256]",0)
local txt
Od.Readmemory(buf, Address, 256, bit.bor(0x01,0x02));
if buf then
if buf[1] == 0 then
--做unicode 处理
local ulen = ffi.C.WideCharToMultiByte(0,0,ffi.cast("void *",buf),-1,nil,0,nil,nil)
txt = ffi.new("char[?]",ulen)
ffi.C.WideCharToMultiByte(0,0,ffi.cast("void *",buf),-1,txt,ulen,nil,nil)
return tostring(ffi.string(txt))
else
--做ANSI处理
txt = ffi.cast("char *",buf)
return tostring(ffi.string(txt))
end
end
return ""
end
function FindString()
local cBase = ffi.new("ulong[1]",0)
local cSize = ffi.new("ulong[1]",0)
local MAXCMDSIZE = 16
local cmdsize
local cmd = ffi.new("char[?]",MAXCMDSIZE)
local da = ffi.new("t_disasm")
local mem
local Text
Od.Getdisassemblerrange(cBase,cSize)
local dwBase,dwSize = cBase[0],cSize[0]
local index = dwBase
while index <= dwBase + dwSize do
Od.Readcommand(index,cmd);
cmdsize = Od.Disasm(cmd,MAXCMDSIZE,index,nil,da,4,0)
local asmcode = ffi.string(da.result)
local immconst = 0
if asmcode:find("move") or asmcode:find("lea") or asmcode:find("push") then
if da.immconst ~= 0 then
immconst = da.immconst
elseif da.adrconst ~= 0 then
immconst = da.immconst
end
mem = ffi.cast("t_memory *",Od.Findmemory(immconst))
if mem then
Text = GetString(immconst)
if Text ~= "" then
Od.Addtolist(index,0,"%s",string.format("%s------->%s",asmcode,Text))
end
end
end
index = index + cmdsize
end
end
FindString()