我正在写一个MSN Plus脚本,其实是JavaScript。
对于与Windows的互操作,有一个名为Interop
的类。
使用其静态函数Call
,可以在指定的dll中调用指定的函数,最多有12个参数。
我的目标是编写一个脚本,从PID中获取进程名称。
我做的一切都正确,但它仍然无法正常工作。msn加脚本读取/写入内存
function GetProcNameFromPID(pid) { var hnd = Interop.Call("kernel32", "CreateToolhelp32Snapshot", 2, 0); var handle = Interop.Call("kernel32", "GetCurrentProcess"); var StructP = Interop.Allocate(4+4+4+4+4+4+4+4+4+260);//*Allocate space for the ProcessEntry32 struct* var hnd_ptr = Interop.Allocate(4); var ress = Interop.Call("kernel32", "WriteProcessMemory", handle, StructP, StructP.size.DataPtr, 4, hnd_ptr); Debug.Trace(ReadInt(hnd_ptr, 0)); var res = Interop.Call("kernel32", "Process32FirstW", hnd, StructP.DataPtr); if(!res) { Debug.Trace("FAAAAIIIILLLLL/" + Interop.Call("kernel32", "GetLastError") + "/" + ress); } else { do { var pos = 0; ReadInt(StructP, pos); ReadInt(StructP, pos); var owpid = ReadInt(StructP, pos); ReadInt(StructP, pos); ReadInt(StructP, pos); ReadInt(StructP, pos); var parpid = ReadInt(StructP, pos); ReadInt(StructP, pos); ReadInt(StructP, pos); ReadInt(StructP, pos); var name = ReadString(pos, 50); if(pid == owpid) return name; StructP = Interop.Allocate(4+4+4+4+4+4+4+8+4+50); Interop.Call("kernel32", "WriteProcessMemory", handle, StructP.DataPtr, StructP.size.DataPtr, 4, null); } while(Interop.Call("kernel32", "Process32NextW", hnd, StructP.DataPtr) == true) } } function ReadInt(buffer, pos) { var res = 0; for(var i = 0; i >> 24; var b2 = addr >> 24; var b3 = addr >> 24; var b4 = addr >> 24; return b4 + b3*256 + b2*256*256 + b1*256*256*256; }
的Process32FirstW
函数总是suceeds,但结构是空的。
WriteProcessMemory
功能也成功。但是写入的字节数始终为0
没有人有什么想法吗? – alex 2010-10-24 15:02:17