J'écris sur un script MSN Plus, qui est en fait javascript. Pour une interopérabilité avec Windows, il existe une classe appelée Interop
.
Avec sa fonction statique Call
, on peut appeler la fonction spécifiée dans une DLL spécifiée avec jusqu'à 12 arguments.
Mon but est d'écrire un script qui obtient un nom de processus hors du PID.
J'ai tout fait correctement, mais ça ne marche toujours pas.msn plus script lecture/écriture mémoire
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; }
La fonction Process32FirstW
toujours proprement déroulée, mais le struct est vide. La fonction WriteProcessMemory
réussit également. Mais le nombre d'octets écrits est toujours 0.
Personne n'a d'idées? – alex