Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
]);
var pcap_handlerPtr = exports.pcap_handlerPtr = ref.refType(pcap_handler);
// PCAP Header
var pcap_pkthdr = exports.pcap_pkthdr = Struct({
'ts_sec': 'long',
'ts_usec': 'long',
'incl_len': 'int',
'orig_len': 'int'
});
var pktHdr = exports.pktHdr = new pcap_pkthdr;
pktHdr = ref.refType(ref.types.void);
/* NDPI Hook */
var ndpi = exports.ndpi = new ffi.Library('../ndpiexlib.so', {
init: [ref.types.void, [
]],
getResults: [ref.types.void, [
]],
setDatalinkType: [ref.types.void, [
pcap_tPtr,
]],
processPacket: [ref.types.void, [
voidPtr,
uint8_t,
]],
finish: [ref.types.void, [
]],
addProtocolHandler: [ref.types.void, [
callback
]],
// Create the struct required to save the window bounds
const Rect = struct({
left: 'long',
top: 'long',
right: 'long',
bottom: 'long',
});
const RectPointer = refType(Rect);
// Required by QueryFullProcessImageName
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms684880(v=vs.85).aspx
const PROCESS_QUERY_LIMITED_INFORMATION = 0x1000;
// Create FFI declarations for the C++ library and functions needed (User32.dll), using their "Unicode" (UTF-16) version
const user32 = new Library('User32.dll', {
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms633505(v=vs.85).aspx
GetForegroundWindow: ['pointer', []],
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms633522(v=vs.85).aspx
GetWindowThreadProcessId: ['uint32', ['pointer', 'uint32 *']],
// Get window bounds function
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getwindowrect
GetWindowRect: ['bool', ['pointer', RectPointer]],
});
function windows() {
// Windows C++ APIs' functions are declared with capitals, so this rule has to be turned off
// Get a "handle" of the active window
const activeWindowHandle = user32.GetForegroundWindow();
if (isNull(activeWindowHandle)) {
public constructor ({ command }: { command?: string }) {
// @formatter:off
this.client = ffi.Library(
resolvePath(command || PATH_TO_LIBRARY_FILE),
{
td_json_client_create: ['pointer', []],
td_json_client_send: ['void', ['pointer', 'string']],
td_json_client_receive: ['string', ['pointer', 'double']],
td_json_client_execute: ['string', ['pointer', 'string']],
td_json_client_destroy: ['void', ['pointer']]
})
// @formatter:on
}
// Create the struct required to save the window bounds
const Rect = struct({
left: 'long',
top: 'long',
right: 'long',
bottom: 'long'
});
const RectPointer = ref.refType(Rect);
// Required by QueryFullProcessImageName
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms684880(v=vs.85).aspx
const PROCESS_QUERY_LIMITED_INFORMATION = 0x1000;
// Create FFI declarations for the C++ library and functions needed (User32.dll), using their "Unicode" (UTF-16) version
const user32 = new ffi.Library('User32.dll', {
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms633505(v=vs.85).aspx
GetForegroundWindow: ['pointer', []],
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms633520(v=vs.85).aspx
GetWindowTextW: ['int', ['pointer', 'pointer', 'int']],
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms633521(v=vs.85).aspx
GetWindowTextLengthW: ['int', ['pointer']],
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms633522(v=vs.85).aspx
GetWindowThreadProcessId: ['uint32', ['pointer', 'uint32 *']],
// Get window bounds function
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getwindowrect
GetWindowRect: ['bool', ['pointer', RectPointer]]
});
const SIZE_T = 'uint64';
// https://docs.microsoft.com/en-us/windows/desktop/api/psapi/ns-psapi-_process_memory_counters
settings?: FModel.LoadSettings,
): T {
const st = parse_settings(settings)
if (st && st.singleton) {
let inst = get_inst_by_name(dllName)
if (! inst) {
inst = ffi.Library(dllName, gen_api_opts(dllFuncs, fns)) as T
set_inst_by_name(dllName, inst)
}
return inst
}
else {
return ffi.Library(dllName, gen_api_opts(dllFuncs, fns))
}
}
export function load(
dllName: string,
dllFuncs: FModel.DllFuncs,
fns?: FModel.FnName[],
settings?: FModel.LoadSettings,
): T {
const st = parse_settings(settings)
if (st && st.singleton) {
let inst = get_inst_by_name(dllName)
if (! inst) {
inst = ffi.Library(dllName, gen_api_opts(dllFuncs, fns)) as T
set_inst_by_name(dllName, inst)
}
return inst
}
else {
return ffi.Library(dllName, gen_api_opts(dllFuncs, fns))
}
}
function loadLib(dir,name) {
var libname;
if (dir) {
libname = path.join(dir,name);
} else {
libname = name;
}
try {
libmqm = ffi.Library(libname, {
'MQCONNX': ['void', ['pointer', MQT.PHCONN, MQT.PCNO, MQT.PLONG, MQT.PLONG]],
'MQDISC' : ['void', [MQT.PHCONN, MQT.PLONG, MQT.PLONG]],
'MQOPEN' : ['void', [MQT.HCONN, MQT.POD,MQT.LONG,MQT.PHOBJ,MQT.PLONG,MQT.PLONG]],
'MQCLOSE': ['void', [MQT.HCONN, MQT.PHOBJ,MQT.LONG,MQT.PLONG,MQT.PLONG]],
'MQSTAT' : ['void', [MQT.HCONN, MQT.LONG, MQT.PSTS, MQT.PLONG,MQT.PLONG]],
'MQBEGIN': ['void', [MQT.HCONN, 'pointer', MQT.PLONG, MQT.PLONG]],
'MQCMIT' : ['void', [MQT.HCONN, MQT.PLONG, MQT.PLONG]],
'MQBACK' : ['void', [MQT.HCONN, MQT.PLONG, MQT.PLONG]],
'MQPUT' : ['void', [MQT.HCONN, MQT.HOBJ,MQT.PMD,MQT.PPMO,MQT.LONG, 'pointer',MQT.PLONG, MQT.PLONG]],
'MQPUT1' : ['void', [MQT.HCONN, MQT.POD, MQT.PMD, MQT.PPMO, MQT.LONG, 'pointer',MQT.PLONG, MQT.PLONG]],
'MQGET' : ['void', [MQT.HCONN, MQT.HOBJ,MQT.PMD, MQT.PGMO,MQT.LONG, 'pointer',MQT.PLONG, MQT.PLONG, MQT.PLONG]],
'MQSUB' : ['void', [MQT.HCONN, MQT.PSD, MQT.PHOBJ,MQT.PHOBJ,MQT.PLONG,MQT.PLONG]],
'MQSUBRQ': ['void', [MQT.HCONN, MQT.HOBJ, MQT.LONG,MQT.PSRO,MQT.PLONG,MQT.PLONG]],
//'MQCTL' : ['void', [MQT.HCONN, MQT.LONG, MQT.PCTLO,MQT.PLONG,MQT.PLONG]],
//'MQCB' : ['void', [MQT.HCONN, MQT.LONG, MQT.PCBD,MQT.HOBJ,MQT.PMD,MQT.PGMO,MQT.PLONG,MQT.PLONG]],
'MQINQ' : ['void', [MQT.HCONN, MQT.HOBJ, MQT.LONG, mqLongArray, MQT.LONG, mqLongArray, MQT.LONG, 'pointer', MQT.PLONG,MQT.PLONG]],
'use strict'
const Ref = require('ref-napi')
, FFI = require('ffi-napi')
, Commons = require('./commons')
const cInt = Ref.types.int
, cVoid = Ref.types.void
const ffi = FFI.Library(null, {
//name ret 1 2 3 4 5
setsockopt: [cInt, [cInt, cInt, cInt, Ref.refType(cVoid), cInt]],
getsockopt: [cInt, [cInt, cInt, cInt, Ref.refType(cVoid), Ref.refType(cInt)]]
})
const setsockopt = (fd, level, name, value, valueLength) => {
const err = ffi.setsockopt(fd, level, name, value, valueLength)
if (err !== 0) {
let errno = FFI.errno()
throw Commons.errnoException(errno, 'setsockopt')
}
return true
}
constructor (libraryFile: string = defaultLibraryName) {
debug('constructor', libraryFile)
this._tdlib = ffi.Library(
resolvePath(libraryFile),
{
'td_json_client_create' : ['pointer', []],
'td_json_client_send' : ['void' , ['pointer', 'string']],
'td_json_client_receive' : ['string' , ['pointer', 'double']],
'td_json_client_execute' : ['string' , ['pointer', 'string']],
'td_json_client_destroy' : ['void' , ['pointer']],
'td_set_log_file_path' : ['int' , ['string']],
'td_set_log_max_file_size' : ['void' , ['int64']],
'td_set_log_verbosity_level' : ['void' , ['int']],
'td_set_log_fatal_error_callback': ['void' , ['pointer']]
})
}