Example #1
1
gpii.windows.getProcessPath = function (pid) {
    var processPath = null;
    var hProcess = windows.kernel32.OpenProcess(c.PROCESS_QUERY_INFORMATION, 0, pid);
    if (hProcess) {
        try {
            var maxLength = 0x400;
            var pathBuffer = Buffer.alloc(maxLength);
            var length = ref.alloc(windows.types.DWORD, maxLength);
            var ret = windows.kernel32.QueryFullProcessImageNameW(hProcess, 0, pathBuffer, length);
            if (ret) {
                processPath = gpii.windows.stringFromWideChar(pathBuffer);
            } else {
                fluid.log(windows.win32errorText("QueryFullProcessImageName", ret));
            }
        } finally {
            windows.kernel32.CloseHandle(hProcess);
        }
    }

    if (!processPath) {
        processPath = gpii.windows.getProcessExe(pid);
    }

    return processPath;
};
Example #2
0
var getAppDirectoryKey = function(lib, request) {
  if (!registeredClientHandle) {
    return util.sendError(request.id, 999, 'Client Handle not available');
  }
  var appName = request.params.appName;
  var appId = request.params.appId;
  var vendor = request.params.vendor;

  var sizePtr = ref.alloc(int);
  var capacityPtr = ref.alloc(int);
  var resultPtr = ref.alloc(int);
  util.sendLog('DEBUG', 'FFI/mod/auth.js - Getting App Root Dir Key');
  /*jscs:disable requireCamelCaseOrUpperCaseIdentifiers*/
  lib.get_app_dir_key.async(appName, appId, vendor, sizePtr, capacityPtr, resultPtr,
      registeredClientHandle, function(err, pointer) {
        /*jscs:enable requireCamelCaseOrUpperCaseIdentifiers*/
        if (err) {
          util.sendException(request.id, err);
        }
        var result = resultPtr.deref();
        if (result !== 0) {
          util.sendLog('ERROR', 'FFI/mod/auth.js - Getting App Root Dir Key failed with code ' + result);
          return util.sendError(request.id, result, 'Failed with error code ' + result);
        }
        var size = sizePtr.deref();
        var capacity = capacityPtr.deref();
        var appDirKey = ref.reinterpret(pointer, size).toString('base64');
        /*jscs:disable requireCamelCaseOrUpperCaseIdentifiers*/
        lib.drop_vector.async(pointer, size, capacity, function() {});
        /*jscs:enable requireCamelCaseOrUpperCaseIdentifiers*/
        util.send(request.id, appDirKey);
      });
};
Example #3
0
	get maximumSize() {
		let w = ref.alloc('int')
		let h = ref.alloc('int')
		SDL_video.SDL_GetWindowMaximumSize(this._window, w, h)
		return utils.arraylike({
			w: w.deref(), 
			h: h.deref()
		})
	}
Example #4
0
	get position() {
		let x = ref.alloc('int')
		let y = ref.alloc('int')
		SDL_video.SDL_GetWindowPosition(this._window, x, y)
		return utils.arraylike({
			x: x.deref(), 
			y: y.deref()
		})
	}
Example #5
0
	get size() {
		let w = ref.alloc('double')
		let h = ref.alloc('double')
		ui.uiDrawTextLayoutExtents(this.layout, w, h)
		return common.arraylike({
			w: w.deref(),
			h: h.deref(),
		})

	}
Example #6
0
	getSize(text = '') {
		text = text.toString()
		let w = ref.alloc('int')
		let h = ref.alloc('int')
		!this.isNull() && SDL_ttf.TTF_SizeUTF8(this._font, text, w, h)
		return utils.arraylike({
			w: w.deref(),
			h: h.deref()
		})
	}
Example #7
0
	get bordersSize() {
		let top = ref.alloc('int')
		let left = ref.alloc('int')
		let bottom = ref.alloc('int')
		let right = ref.alloc('int')
		SDL_video.SDL_GetWindowBordersSize(this._window, top, left, bottom, right)
		return utils.arraylike({
			top: top.deref(), 
			left: left.deref(), 
			bottom: bottom.deref(), 
			right: right.deref()
		})
	}
Example #8
0
    get: function () {
      var self = this;
      var file = ref.alloc(lib.CXString);
      var line = ref.alloc(ref.types.uint32);
      var column = ref.alloc(ref.types.uint32);
      lib.libclang.clang_getPresumedLocation(self._instance,
        file, line, column);

      return {
        filename: util.toString(file.deref()),
        line: line.deref(),
        column: column.deref(),
      };
    },
    elevate: function (filepath, parameters, callback) {
        if(!filepath) {
            debug('Missing filepath');
            callback('Missing filepath');
            return;
        }
        var shellexecuteinfoval = new windef.SHELLEXECUTEINFO({
            cbSize: windef.SHELLEXECUTEINFO.size,
            fMask: 0x00000000,
            hwnd: null,
            lpVerb: lpVerb,
            lpFile: filepath,
            lpParameters: parameters,
            lpDirectory: null,
            nShow: SW_SHOWNORMAL,
            hInstApp: hInstApp,
            lpIDList: null,
            lpCLass: null,
            hkeyClass: null,
            dwHotKey: null,
            DUMMYUNIONNAME: {
                hIcon: null,
                hMonitor: null
            },
            hProcess: ref.alloc(types.HANDLE)
        });

        shell32.ShellExecuteExA.async(shellexecuteinfoval.ref(), callback);
    },
Example #10
0
// Constructor
function clSVM(context, flags, size, alignment) {
	var cl = context.cl;
	var err = ref.alloc(cl.types.ErrorCode);
	this.handle = cl.imports.clSVMAlloc(clUtils.toHandle(context), flags, size, alignment);
	this.context = context;
	cl.checkError(err);
};
Example #11
0
exports.Cs.prototype.disasm = function (buffer, addr, max) {
    var insn = ref.alloc(new ArrayType(InsnType));

    var count = capstone.cs_disasm(
        this.csh.deref(),
        buffer,
        buffer.length,
        addr,
        max || 0,
        insn
    );
    if (!count) {
        var errno = this.errno();
        throw "cs_disasm returned " + errno + ": " + exports.strerror(errno);
    }

    // Get instruction array, and fix length
    var insns = insn.deref();
    insns.length = count;

    // Create a JavaScript view of the instruction array
    var instructions = [];
    for (var i = 0; i < count; i++) {
        instructions.push(new CsInsn(insns[i], this.arch));
    }

    // Free the native instruction array
    capstone.cs_free(insns.buffer, count);

    return instructions;
};
function getWindowList(windowTitle) {

    function strOfLength(size) {
        var str = "";
        var i;
        for (i = 0; i < size; i++) {
            str += " ";
        }
        return str;
    }

    var windows = [];
    var titleBuffer = ref.alloc('String', strOfLength(MAX_TITLE_SIZE * 2));
    var lpEnumFunc = ffi.Callback('bool', ['int', 'int'],
        function (hwnd, lParam) {
            var titleLength = user32.GetWindowTextW(hwnd,
                titleBuffer, MAX_TITLE_SIZE);
            var title =
                titleBuffer.reinterpret(titleLength * 2).toString('ucs2');
            if (title === windowTitle) {
                windows.push(hwnd);
            }
            return true;
        });

    user32.EnumWindows(lpEnumFunc, 0);

    return windows;
}
Example #13
0
  var proxy = function () {
    debug('invoking proxy function')

    if (arguments.length !== numArgs) {
      throw new TypeError('Expected ' + numArgs +
          ' arguments, got ' + arguments.length)
    }

    // storage buffers for input arguments and the return value
    var result = new Buffer(resultSize)
      , argsList = new Buffer(argsArraySize)

    // write arguments to storage areas
    var i, argType, val, valPtr
    try {
      for (i = 0; i < numArgs; i++) {
        argType = argTypes[i]
        val = arguments[i]
        valPtr = ref.alloc(argType, val)
        argsList.writePointer(valPtr, i * POINTER_SIZE)
      }
    } catch (e) {
      e.message = 'error setting argument ' + i + ' - ' + e.message
      throw e
    }

    // invoke the `ffi_call()` function
    bindings.ffi_call(cif, funcPtr, result, argsList)

    result.type = returnType
    return result.deref()
  }
gpii.windows.spi.createPvParam = function (payload) {
    var pvParam;

    switch (payload.options.pvParam.type) {
    case "struct":
        pvParam = gpii.windows.createEmptyStructure(payload.options.pvParam.name).ref();
        break;

    case "array":
        var length = payload.options.pvParam.length;
        var size = ref.types[gpii.windows.types[payload.options.pvParam.valueType]].size;
        pvParam = new Buffer(length * size);
        break;

    case "NULL":
        pvParam = ref.NULL;
        break;

    default:
        if (payload.options.pvParam.type in gpii.windows.types) {
            pvParam = ref.alloc(gpii.windows.types[payload.options.pvParam.type]);
        } else {
            fluid.fail("SpiSettingsHandler.js: spi.createPvParam() failed: got unknown pvParam type " + payload.options.pvParam.type);
        }
    }

    return pvParam;
};
Example #15
0
 getMemRefCount: function (host, handle) {
     var info = ref.alloc(ref.types.uint);
     ref.types.uint.set(info, 0, 0);
     var err = host.cl.imports.clGetMemObjectInfo(handle, host.cl.defs.CL_MEM_REFERENCE_COUNT, ref.types.uint.size, info, null);
     host.cl.checkError(err);
     return info.deref();
 }
Example #16
0
function CLBuffer1(context, flags, dataSize, hostPtr) {
    hostPtr = hostPtr || null;
    var cl = context.cl;
    var err = ref.alloc(cl.types.ErrorCode);
    var handle = cl.imports.clCreateBuffer(clUtils.toHandle(context), flags, dataSize, clUtils.toPtr(hostPtr, "hostPtr"), err);
    cl.checkError(err);
    CLMemory.call(this, context, handle);
}
Example #17
0
Ks.prototype.asm = function(code, addr) {
  var encoding = ref.alloc('uchar *'),
      size = ref.alloc('size_t'),
      count = ref.alloc('size_t'),
      err, msg 

  if (Keystone.ks_asm(this._ks, code, addr || 0, encoding, size, count) !== consts.ERR_OK) {
    err = this.errno
    msg = Keystone.ks_strerror(err)
    throw new KsError(msg, err, count.deref())
  }

  return {
    encoding: ref.reinterpret(encoding.deref(), size.deref(), 0),
    count: count.deref()
  }
}
Example #18
0
function CLKernel1(program, name) {
    var cl = program.cl;
    var err = ref.alloc(cl.types.ErrorCode);
    var handle = cl.imports.clCreateKernel(clUtils.toHandle(program), name, err);
    cl.checkError(err);
    CLWrapper.call(this, cl, handle);
    this.propgram = program;
    this._name = name;
}
Example #19
0
        get: function () {
            var num = ref.alloc("uint");

            // _OpenCL API:_ [clGetPlatformIDs](https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetPlatformIDs.html)
            var err = this.cl.imports.clGetPlatformIDs(0, null, num);

            this.cl.checkError(err);
            return num;
        }
Example #20
0
 get(file) {
   if (this.handle) {
     const fileHandlePtr = ref.alloc(HANDLEPtr);
     if (StormLib.SFileOpenFileEx(this.handle, file, this.constructor.FROM_MPQ, fileHandlePtr)) {
       return new File(fileHandlePtr.deref());
     }
   }
   return null;
 }
			getPosition: function() {

				if (window !== null) {

					let x = _ref.alloc('int');
					let y = _ref.alloc('int');

					SDL.SDL_GetWindowPosition(window, x, y);

					return {
						x:  x.deref(),
						y: y.deref()
					};

				}

				return null;

			},
Example #22
0
const devInitContext = async szDevName => {
    let ppPAEWContext = ref.alloc(voidPP);
    let res = 0;

    try {
        if (!szDevName) {
            res = RETVALUE.ret_err_argument;
            throw res;
        }

        res = await new Promise((resolve, reject) => {
            PAEW_InitContextWithDevName.async(
                ppPAEWContext,
                szDevName,
                DLLDEVTYPE.PAEW_DEV_TYPE_HID,
                callbackFunc,
                callbackParam.ref(),
                (err, res) => {
                    if (res == DLLRET.PAEW_RET_SUCCESS) {
                        resolve(RETVALUE.convertFromDevRet(res));
                    } else {
                        reject(RETVALUE.convertFromDevRet(res));
                    }
                }
            );
        });

        /*
        res = await new Promise((resolve, reject) => {
            PAEW_FreeContext.async(devContext, (err, res) => {
                if (res == DLLRET.PAEW_RET_SUCCESS) {
                    resolve(RETVALUE.convertFromDevRet(res));
                } else {
                    reject(RETVALUE.convertFromDevRet(res));
                }
            });
        });
        */
    } catch (err) {
        return { res: err, payload: RETVALUE.convertToMsg(err) };
    }

    const devIndex = szDevName;
    deviceList = deviceList.filter(elem => {
        return elem.devIndex != devIndex;
    });
    const devElement = {
        devIndex,
        devContext: ppPAEWContext.deref(),
        devBusy: false
    };
    deviceList.push(devElement);

    return { res, payload: devIndex };
};
Example #23
0
module.exports = function (req, res, next) {
  function freeTree () {
    debug('free()ing `git_tree` instance');
    git.git_tree_free(tree);
  }

  var commit, tree, sha, oid, err;
  sha = req.sha;
  res.set('X-Commit-SHA', sha);
  debug('getting "git_tree" instance for the root dir of commit', sha);

  // get the `git_oid` instance if necessary
  oid = req.oid;
  if (!oid) {
    debug('`req.oid` not set - retrieving %j `git_oid` instance', sha);
    oid = ref.alloc(git.git_oid);
    err = git.git_oid_fromstr(oid, sha);
    if (err !== 0) return next(new GitError('git_oid_fromstr', err));
    req.oid = oid;
  }

  // now we must get the `git_commit *` instance for the SHA
  commit = ref.alloc(ref.refType(git.git_commit));
  err = git.git_commit_lookup(commit, req.app.settings.repo, oid);
  if (err !== 0) return next(new GitError('git_commit_lookup', err));
  commit = commit.deref();

  // now we must get the root `git_tree *` instance from the git_commit
  tree = ref.alloc(ref.refType(git.git_tree));
  err = git.git_commit_tree(tree, commit);
  if (err !== 0) return next(new GitError('git_commit_tree', err));
  debug('created "git_tree" instance successfully');
  req.root_tree = tree = tree.deref();

  // don't forget to clean up the `git_tree` instance once the request finishes
  res.on('finish', freeTree);

  next();

  // free() the `git_commit *` instance
  git.git_commit_free(commit);
};
Example #24
0
ToxDns.prototype.generateSync = function(name) {
  var namebuf = new Buffer(name),
      outbuf = new Buffer(TOXDNS3_RECORD_SIZE_MAX),
      requestId = ref.alloc('uint32'),
      length = this.getLibrary().tox_generate_dns3_string(
      this.getHandle(), outbuf, outbuf.length, requestId, namebuf, namebuf.length);
  if(length < 0) throw new Error('tox_generate_dns3_string returned ' + length);
  var str = outbuf.slice(0, length).toString(),
      id = Number(requestId.deref());
  return { record: str, id: id };
};
			getSize: function() {

				if (window !== null) {

					let width  = _ref.alloc('int');
					let height = _ref.alloc('int');

					SDL.SDL_GetWindowSize(window, width, height);

					return {
						width:  width.deref(),
						height: height.deref()
					};

				}


				return null;

			}
Example #26
0
	metrics(ch = '') {
		ch = ch.toString()[0]
		let minx = ref.alloc('int')
		let maxx = ref.alloc('int')
		let miny = ref.alloc('int')
		let maxy = ref.alloc('int')
		let advance = ref.alloc('int')
		!this.isNull() && SDL_ttf.TTF_GlyphMetrics(this._font, ch, minx, maxx, miny, maxy, advance)
		return ({
			x: {
				min: minx.deref(),
				max: maxx.deref()
			},
			y: {
				min: miny.deref(),
				max: maxy.deref()
			},
			advance: advance.deref()
		})
	}
Example #27
0
CLBuffer.prototype.createSubBuffer = function (flags, origin, size) {
    this._throwIfReleased();
    var reg = new (this.cl.types.BufferRegion)();
    reg.origin = origin;
    reg.size = size;
    var pReg = reg.ref();
    var err = ref.alloc(this.cl.types.ErrorCode);
    var subHandle = this.cl.imports.clCreateSubBuffer(this.handle, flags, this.cl.defs.CL_BUFFER_CREATE_TYPE_REGION, pReg, err);
    this.cl.checkError(err);
    return new CLBuffer(this.context, subHandle);
};
Example #28
0
  /**
   * Copies and returns an Array of the instance variables defined by a given
   * Class pointer. To get class variables, call this function on a metaclass.
   */
  function copyIvarList (classPtr) {
    var rtn = []
      , ivars = objc.class_copyIvarList(classPtr, ref.alloc('uint'))
      , count = numIvars.deref();

    for (var i=0; i<count; i++) 
      rtn.push(objc.ivar_getName(ivars.readPointer(i * ref.sizeof.pointer)));

    free(ivars);
    return rtn;
  }
Example #29
0
    gpii.windows.enumerateWindows(function (hwnd) {
        // Get the process ID that owns the Window.
        var ptr = ref.alloc(windows.types.DWORD);
        gpii.windows.user32.GetWindowThreadProcessId(hwnd, ptr);
        var windowPid = ptr.deref();

        if (pids.indexOf(windowPid) !== -1) {
            // Send WM_QUIT, which tells the thread to terminate.
            gpii.windows.user32.PostMessageW(hwnd, windows.API_constants.WM_QUIT, options.exitCode, 0);
            foundWindow = true;
        }
    });
Example #30
0
exports.recv_event = function(options) {
	options || (options = {});
	var non_block = options.block ? 0 : 1;

	var lenref = ref.alloc('size_t');
	var recv = TurtlCore.turtlc_recv_event(non_block, lenref);
	if(recv.isNull()) return false;
	var len = lenref.deref();
	var data = ref.reinterpret(recv, len);
	var msg = new Buffer(data.buffer).toString('utf8');
	return msg;
};