Ejemplo n.º 1
0
gpii.windows.getProcessExe = function (pid) {
    var processExe = null;

    // Take the process snapshot.
    var snapShot = windows.kernel32.CreateToolhelp32Snapshot(windows.API_constants.TH32CS_SNAPPROCESS, null);
    if (snapShot === windows.API_constants.INVALID_HANDLE_VALUE) {
        fluid.log(windows.win32errorText("CreateToolhelp32Snapshot", snapShot));
    } else {
        try {
            var processEntry = new windows.PROCESSENTRY32();
            processEntry.dwSize = windows.PROCESSENTRY32.size;

            // Enumerate the processes
            var gotProcess = windows.kernel32.Process32First(snapShot, processEntry.ref());
            while (gotProcess) {
                if (processEntry.th32ProcessID === pid) {
                    // The matching process.
                    processExe = ref.readCString(processEntry.szExeFile.buffer);
                    break;
                }
                // Get the next one
                gotProcess = windows.kernel32.Process32Next(snapShot, processEntry.ref());
            }
        } finally {
            windows.kernel32.CloseHandle(snapShot);
        }
    }

    return processExe;
};
Ejemplo n.º 2
0
 it('should read a point', function(done) {
     var ptWKT = ref.allocCString("POINT(0 0)");
     var point = geos.GEOSWKTReader_read(geos.wkt_reader,ptWKT);
     var cstring = geos.GEOSWKTWriter_write(geos.wkt_writer,point);
     var wkt = ref.readCString(cstring);
     assert.equal(wkt,'POINT (0.0000000000000000 0.0000000000000000)');
     geos.GEOSFree(cstring);
     geos.GEOSGeom_destroy(point);
     done();
 });
Ejemplo n.º 3
0
 it('should read a line', function(done) {
     var lineWKT = ref.allocCString("LINESTRING(0 0,1 1,2 2)");
     var line = geos.GEOSWKTReader_read(geos.wkt_reader,lineWKT);
     var cstring = geos.GEOSWKTWriter_write(geos.wkt_writer,line);
     var wkt = ref.readCString(cstring);
     assert.equal(wkt,'LINESTRING (0.0000000000000000 0.0000000000000000, 1.0000000000000000 1.0000000000000000, 2.0000000000000000 2.0000000000000000)');
     geos.GEOSFree(cstring);
     geos.GEOSGeom_destroy(line);
     done();
 });
Ejemplo n.º 4
0
gpii.windows.findProcessByName = function (filename, all, fullInfo) {

    // Get a snapshot of the processes.
    var hSnapShot = windows.kernel32.CreateToolhelp32Snapshot(windows.API_constants.TH32CS_SNAPPROCESS, null);
    if (hSnapShot === windows.API_constants.INVALID_HANDLE_VALUE) {
        console.error("CreateToolhelp32Snapshot failed. Win32 error: " + windows.GetLastError());
        return null;
    }

    var matches = [];
    var filenameLower = filename && filename.toLowerCase();

    try {
        // Create the structure for the return parameter of Process32First/Next.
        var pEntry = new windows.PROCESSENTRY32();
        pEntry.dwSize = windows.PROCESSENTRY32.size;

        // Enumerate the processes.
        var hRes = windows.kernel32.Process32First(hSnapShot, pEntry.ref());
        while (hRes) {
            var buf = new Buffer(pEntry.szExeFile);
            var processName = ref.readCString(buf, 0);

            if (!filename || processName.toLowerCase() === filenameLower) {
                var proc;
                if (fullInfo) {
                    proc = {
                        pid: pEntry.th32ProcessID,
                        ppid: pEntry.th32ParentProcessID,
                        exeFile: processName
                    };
                } else {
                    proc = pEntry.th32ProcessID;
                }
                if (all) {
                    // Add it to the array of matches.
                    matches.push(proc);
                } else {
                    // Only want the first one - return it.
                    return proc;
                }
            }

            hRes = windows.kernel32.Process32Next(hSnapShot, pEntry.ref());
        }
    } finally {
        // Make sure the snapshot is closed.
        if (hSnapShot) {
            windows.kernel32.CloseHandle(hSnapShot);
        }
    }

    return all ? matches : null;
};
Ejemplo n.º 5
0
    function completer(text, start, end) {
      var result = null;
      rl_attempted_completion_over.writeUInt8(1);
      //opts.completer(text, (results) => fs.writeFileSync(pipe[1], JSON.stringify(results) + "\n"));
      //var rl_line_buffer = libreadline_so.get('rl_line_buffer');
      text = rl_line_buffer.readPointer().readCString();
      opts.completer(text, function(err, results) {
        var j = new Buffer(JSON.stringify(results) + "\n");
        libc.write(pipe[1], j, Buffer.byteLength(j));
      });
      var bytes = libc.read(pipe[0], buffer, buffer.length - 1);
      if (bytes >= 0)
        buffer.writeUInt8(0, bytes);
      else
        console.log("read() failed!");

      try {
        result = JSON.parse(ref.readCString(buffer, 0));
        result = result[0].map((s) => s.substring(start).trimRight()).filter((s) => s.trim().length);
      } catch(e) {
        console.log("Cannot read JSON at " + ref.readCString(buffer, 0) + " / " + util.inspect(ref.readCString(buffer,0)));
        console.log(e);
        return ref.NULL_POINTER.deref();
      }
      if (result === null) result = [];
      if (result.length > 1)
        result.unshift(text.substring(start));
      else if (result.length === 0)
        return ref.NULL_POINTER.deref();
      var out = ref.alloc(ArrayType('string', result.length + 1));
      var cstr = result.map((s) => ref.allocCString(s));
      cstr = cstr.map((s) => libc.strdup(s));
      for(var i = 0; i < result.length; i++)
        ref._writePointer(out, i * ref.sizeof.pointer, cstr[i]);
      ref.writePointer(out, result.length * ref.sizeof.pointer, ref.NULL_POINTER.deref());
      var mem = libc.malloc(out.length);
      libc.memcpy(mem, out, out.length);
      //libc.abort(mem);
      return mem;
    }
function cPointerEqualsArray(test, expected, actual) {
	for(var i = 0; i < expected.length; i++) {
		var namePtr = ref.readPointer(actual, i*8, 50);
		test.equal(ref.readCString(namePtr,0),expected[i]);
	}
}