mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-11 05:43:33 +00:00
1. Fixed uncaught exception in websocket that could happen if peer disconnects
2. Updated debugger to work with updated promise 3. Fixed bug in event emitter where 'explicit' event type wasn't honored 4. Updated _GenericMarshal to support interface and function marshaling 5. Added COM/WMI support to windows
This commit is contained in:
@@ -502,7 +502,7 @@ void* ILibDuktape_Debugger_StartEngine(duk_context *ctx, int transport, int webp
|
||||
duk_ret_t ILibDuktape_Debugger_JSAttach_promise_wait(duk_context *ctx)
|
||||
{
|
||||
char *eventName = (char*)duk_require_string(ctx, 0);
|
||||
if (strcmp(eventName, "resolved") != 0) { return(0); }
|
||||
if (strcmp(eventName, "settled") != 0) { return(0); }
|
||||
|
||||
duk_push_heap_stash(ctx);
|
||||
duk_get_prop_string(ctx, -1, ILibDuktape_Debugger_DebugObject);
|
||||
|
||||
@@ -54,6 +54,7 @@ typedef uintptr_t PTRSIZE;
|
||||
#define ILibDuktape_GenericMarshal_Variable_Parms "\xFF_GenericMarshal_Variable_Parms"
|
||||
#define ILibDuktape_GenericMarshal_StashTable "\xFF_GenericMarshal_StashTable"
|
||||
#define ILibDuktape_GenericMarshal_GlobalCallback_ThreadID "\xFF_GenericMarshal_ThreadID"
|
||||
#define ILibDutkape_GenericMarshal_INTERNAL "\xFF_INTERNAL"
|
||||
#define ILibDuktape_GenericMarshal_Variable_EnableAutoFree(ctx, idx) duk_dup(ctx, idx);duk_push_true(ctx);duk_put_prop_string(ctx, -2, ILibDuktape_GenericMarshal_Variable_AutoFree);duk_pop(ctx)
|
||||
#define ILibDuktape_GenericMarshal_Variable_DisableAutoFree(ctx, idx) duk_dup(ctx, idx);duk_push_false(ctx);duk_put_prop_string(ctx, -2, ILibDuktape_GenericMarshal_Variable_AutoFree);duk_pop(ctx)
|
||||
#define WAITING_FOR_RESULT__DISPATCHER 2
|
||||
@@ -436,6 +437,25 @@ duk_ret_t ILibDuktape_GenericMarshal_Variable_bignum_SET(duk_context *ctx)
|
||||
return(0);
|
||||
}
|
||||
#endif
|
||||
duk_ret_t ILibDuktape_GenericMarshal_Variable_Increment(duk_context *ctx)
|
||||
{
|
||||
duk_push_this(ctx); // [var]
|
||||
ILibDuktape_GenericMarshal_Variable_DisableAutoFree(ctx, -1);
|
||||
void *_ptr = Duktape_GetPointerProperty(ctx, -1, "_ptr");
|
||||
int offset = duk_require_int(ctx, 0);
|
||||
if (duk_is_boolean(ctx, 1) && duk_require_boolean(ctx, 1))
|
||||
{
|
||||
_ptr = (void*)(uintptr_t)duk_require_uint(ctx, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
_ptr = (char*)_ptr + offset;
|
||||
}
|
||||
duk_push_this(ctx);
|
||||
duk_push_pointer(ctx, _ptr);
|
||||
duk_put_prop_string(ctx, -2, "_ptr");
|
||||
return(1);
|
||||
}
|
||||
void ILibDuktape_GenericMarshal_Variable_PUSH(duk_context *ctx, void *ptr, int size)
|
||||
{
|
||||
duk_push_object(ctx); // [var]
|
||||
@@ -463,6 +483,8 @@ void ILibDuktape_GenericMarshal_Variable_PUSH(duk_context *ctx, void *ptr, int s
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "autoFree", ILibDuktape_GenericMarshal_Variable_autoFree, DUK_VARARGS);
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "pointerBuffer", ILibDuktape_GenericMarshal_Variable_pointerBuffer, 0);
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "getPointerPointer", ILibDuktape_GenericMarshal_Variable_pointerpointer, 0);
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "increment", ILibDuktape_GenericMarshal_Variable_Increment, DUK_VARARGS);
|
||||
|
||||
|
||||
ILibDuktape_CreateFinalizer(ctx, ILibDuktape_GenericMarshal_Variable_Finalizer);
|
||||
}
|
||||
@@ -1948,6 +1970,470 @@ duk_ret_t ILibDuktape_GenericMarshal_GlobalCallback_close(duk_context *ctx)
|
||||
return(0);
|
||||
}
|
||||
|
||||
int ILibDuktape_GlobalGenericCallbackEx_n[22] = { 0 };
|
||||
ILibDuktape_EventEmitter *ILibDuktape_GlobalGenericCallbackEx_nctx[22] = { 0 };
|
||||
extern void* gILibChain;
|
||||
|
||||
duk_ret_t ILibDuktape_GlobalGenericCallbackEx_Process_ChainEx_2(ILibDuktape_EventEmitter *emitter)
|
||||
{
|
||||
duk_push_heapptr(emitter->ctx, emitter->object); // [array][var]
|
||||
char *id = Duktape_GetStringPropertyValue(emitter->ctx, -1, ILibDuktape_OBJID, "");
|
||||
duk_get_prop_string(emitter->ctx, -1, "emit"); // [array][var][emit]
|
||||
duk_get_prop_string(emitter->ctx, -1, "apply"); // [array][var][emit][apply]
|
||||
|
||||
duk_dup(emitter->ctx, -2); // [array][var][emit][apply][emit]
|
||||
duk_dup(emitter->ctx, -4); // [array][var][emit][apply][emit][this]
|
||||
duk_dup(emitter->ctx, -6); // [array][var][emit][apply][emit][this][array]
|
||||
duk_push_string(emitter->ctx, "GlobalCallback"); // [array][var][emit][apply][emit][this][array][GlobalCallback]
|
||||
duk_array_unshift(emitter->ctx, -2); // [array][var][emit][apply][emit][this][array]
|
||||
duk_remove(emitter->ctx, -5); // [array][var][apply][emit][this][array]
|
||||
duk_remove(emitter->ctx, -5); // [array][apply][emit][this][array]
|
||||
duk_remove(emitter->ctx, -5); // [apply][emit][this][array]
|
||||
return(duk_pcall_method(emitter->ctx, 2)); // [retVal]
|
||||
|
||||
//duk_dup(emitter->ctx, -3); // [array][var][emit][apply][this]
|
||||
//duk_dup(emitter->ctx, -5); // [array][var][emit][apply][this][array]
|
||||
//duk_remove(emitter->ctx, -5); // [array][emit][apply][this][array]
|
||||
//duk_remove(emitter->ctx, -5); // [emit][apply][this][array]
|
||||
//duk_remove(emitter->ctx, -4); // [apply][this][array]
|
||||
//duk_push_string(emitter->ctx, "GlobalCallback"); // [apply][this][array][GlobalCallback]
|
||||
//duk_array_unshift(emitter->ctx, -2); // [apply][this][array]
|
||||
//return(duk_pcall(emitter->ctx, 2)); // [retVal]
|
||||
}
|
||||
void ILibDuktape_GlobalGenericCallbackEx_Process_ChainEx(void * chain, void *user)
|
||||
{
|
||||
Duktape_GlobalGeneric_Data *data = (Duktape_GlobalGeneric_Data*)user;
|
||||
duk_context *ctx = data->emitter->ctx;
|
||||
int i;
|
||||
|
||||
duk_idx_t top = duk_get_top(ctx);
|
||||
duk_push_array(ctx); // [array]
|
||||
for (i = 0; i < data->numArgs; ++i)
|
||||
{
|
||||
ILibDuktape_GenericMarshal_Variable_PUSH(ctx, (void*)data->args[i], sizeof(PTRSIZE));// [array][var]
|
||||
duk_array_push(ctx, -2); // [array]
|
||||
}
|
||||
if (ILibDuktape_GlobalGenericCallbackEx_Process_ChainEx_2(data->emitter) != 0)
|
||||
{
|
||||
// Exception was thrown
|
||||
ILibDuktape_Process_UncaughtExceptionEx(data->emitter->ctx, "Exception occured in GlobalCallback: %s", duk_safe_to_string(data->emitter->ctx, -1));
|
||||
data->retVal = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ILibMemory_CanaryOK(data->emitter))
|
||||
{
|
||||
duk_push_heapptr(ctx, data->emitter->object); // [obj]
|
||||
duk_prepare_method_call(ctx, -1, "emit_returnValue"); // [obj][emitRV][this]
|
||||
if (duk_pcall_method(ctx, 0) == 0)
|
||||
{
|
||||
data->retVal = Duktape_GetPointerProperty(ctx, -1, "_ptr");
|
||||
}
|
||||
}
|
||||
}
|
||||
duk_set_top(ctx, top);
|
||||
sem_post(&(data->contextWaiter));
|
||||
}
|
||||
PTRSIZE ILibDuktape_GlobalGenericCallbackEx_Process(PTRSIZE arg1, int count, ILibDuktape_EventEmitter *emitter, va_list args)
|
||||
{
|
||||
int i;
|
||||
if (gILibChain != NULL && ILibIsRunningOnChainThread(gILibChain) == 0)
|
||||
{
|
||||
// Need to Context Switch to different thread, but before we do, we need to export all the parameters from va_list
|
||||
void *ret = NULL;
|
||||
Duktape_GlobalGeneric_Data *user = ILibMemory_SmartAllocate(sizeof(Duktape_GlobalGeneric_Data) + ((count + 1) * sizeof(PTRSIZE)));
|
||||
user->chain = gILibChain;
|
||||
user->numArgs = count + 1;
|
||||
user->emitter = emitter;
|
||||
for (i = 0; i < user->numArgs; ++i)
|
||||
{
|
||||
user->args[i] = i == 0 ? arg1 : va_arg(args, PTRSIZE);
|
||||
}
|
||||
sem_init(&(user->contextWaiter), 0, 0);
|
||||
ILibChain_RunOnMicrostackThread(user->chain, ILibDuktape_GlobalGenericCallbackEx_Process_ChainEx, user);
|
||||
|
||||
sem_wait(&(user->contextWaiter));
|
||||
if (user->retVal != NULL) { ret = user->retVal; }
|
||||
sem_destroy(&(user->contextWaiter));
|
||||
ILibMemory_Free(user);
|
||||
return((PTRSIZE)ret);
|
||||
}
|
||||
|
||||
// No Context Switch is necessary
|
||||
duk_push_array(emitter->ctx); // [array]
|
||||
for (i = 0; i < (count + 1); ++i)
|
||||
{
|
||||
ILibDuktape_GenericMarshal_Variable_PUSH(emitter->ctx, (void*)( i == 0 ? arg1 : va_arg(args, PTRSIZE)), sizeof(PTRSIZE)); // [array][var]
|
||||
duk_array_push(emitter->ctx, -2); // [array]
|
||||
}
|
||||
if (ILibDuktape_GlobalGenericCallbackEx_Process_ChainEx_2(emitter) != 0)
|
||||
{
|
||||
// Exception was thrown
|
||||
ILibDuktape_Process_UncaughtExceptionEx(emitter->ctx, "Exception occured in GlobalCallback: ");
|
||||
duk_pop(emitter->ctx);
|
||||
return(0);
|
||||
}
|
||||
uintptr_t ret = 0;
|
||||
duk_pop(emitter->ctx);
|
||||
if (emitter->lastReturnValue != NULL)
|
||||
{
|
||||
duk_push_heapptr(emitter->ctx, emitter->lastReturnValue);
|
||||
ret = (uintptr_t)Duktape_GetPointerProperty(emitter->ctx, -1, "_ptr");
|
||||
duk_pop(emitter->ctx);
|
||||
}
|
||||
return((PTRSIZE)ret);
|
||||
}
|
||||
PTRSIZE ILibDuktape_GlobalGenericCallbackEx_0(PTRSIZE arg1, ...)
|
||||
{
|
||||
PTRSIZE ret;
|
||||
va_list args;
|
||||
va_start(args, arg1);
|
||||
ret = ILibDuktape_GlobalGenericCallbackEx_Process(arg1, ILibDuktape_GlobalGenericCallbackEx_n[0], ILibDuktape_GlobalGenericCallbackEx_nctx[0], args);
|
||||
va_end(args);
|
||||
return(ret);
|
||||
}
|
||||
PTRSIZE ILibDuktape_GlobalGenericCallbackEx_1(PTRSIZE arg1, ...)
|
||||
{
|
||||
PTRSIZE ret;
|
||||
va_list args;
|
||||
va_start(args, arg1);
|
||||
ret = ILibDuktape_GlobalGenericCallbackEx_Process(arg1, ILibDuktape_GlobalGenericCallbackEx_n[1], ILibDuktape_GlobalGenericCallbackEx_nctx[1], args);
|
||||
va_end(args);
|
||||
return(ret);
|
||||
}
|
||||
PTRSIZE ILibDuktape_GlobalGenericCallbackEx_2(PTRSIZE arg1, ...)
|
||||
{
|
||||
PTRSIZE ret;
|
||||
va_list args;
|
||||
va_start(args, arg1);
|
||||
ret = ILibDuktape_GlobalGenericCallbackEx_Process(arg1, ILibDuktape_GlobalGenericCallbackEx_n[2], ILibDuktape_GlobalGenericCallbackEx_nctx[2], args);
|
||||
va_end(args);
|
||||
return(ret);
|
||||
}
|
||||
PTRSIZE ILibDuktape_GlobalGenericCallbackEx_3(PTRSIZE arg1, ...)
|
||||
{
|
||||
PTRSIZE ret;
|
||||
va_list args;
|
||||
va_start(args, arg1);
|
||||
ret = ILibDuktape_GlobalGenericCallbackEx_Process(arg1, ILibDuktape_GlobalGenericCallbackEx_n[3], ILibDuktape_GlobalGenericCallbackEx_nctx[3], args);
|
||||
va_end(args);
|
||||
return(ret);
|
||||
}
|
||||
PTRSIZE ILibDuktape_GlobalGenericCallbackEx_4(PTRSIZE arg1, ...)
|
||||
{
|
||||
PTRSIZE ret;
|
||||
va_list args;
|
||||
va_start(args, arg1);
|
||||
ret = ILibDuktape_GlobalGenericCallbackEx_Process(arg1, ILibDuktape_GlobalGenericCallbackEx_n[4], ILibDuktape_GlobalGenericCallbackEx_nctx[4], args);
|
||||
va_end(args);
|
||||
return(ret);
|
||||
}
|
||||
PTRSIZE ILibDuktape_GlobalGenericCallbackEx_5(PTRSIZE arg1, ...)
|
||||
{
|
||||
PTRSIZE ret;
|
||||
va_list args;
|
||||
va_start(args, arg1);
|
||||
ret = ILibDuktape_GlobalGenericCallbackEx_Process(arg1, ILibDuktape_GlobalGenericCallbackEx_n[5], ILibDuktape_GlobalGenericCallbackEx_nctx[5], args);
|
||||
va_end(args);
|
||||
return(ret);
|
||||
}
|
||||
PTRSIZE ILibDuktape_GlobalGenericCallbackEx_6(PTRSIZE arg1, ...)
|
||||
{
|
||||
PTRSIZE ret;
|
||||
va_list args;
|
||||
va_start(args, arg1);
|
||||
ret = ILibDuktape_GlobalGenericCallbackEx_Process(arg1, ILibDuktape_GlobalGenericCallbackEx_n[6], ILibDuktape_GlobalGenericCallbackEx_nctx[6], args);
|
||||
va_end(args);
|
||||
return(ret);
|
||||
}
|
||||
PTRSIZE ILibDuktape_GlobalGenericCallbackEx_7(PTRSIZE arg1, ...)
|
||||
{
|
||||
PTRSIZE ret;
|
||||
va_list args;
|
||||
va_start(args, arg1);
|
||||
ret = ILibDuktape_GlobalGenericCallbackEx_Process(arg1, ILibDuktape_GlobalGenericCallbackEx_n[7], ILibDuktape_GlobalGenericCallbackEx_nctx[7], args);
|
||||
va_end(args);
|
||||
return(ret);
|
||||
}
|
||||
PTRSIZE ILibDuktape_GlobalGenericCallbackEx_8(PTRSIZE arg1, ...)
|
||||
{
|
||||
PTRSIZE ret;
|
||||
va_list args;
|
||||
va_start(args, arg1);
|
||||
ret = ILibDuktape_GlobalGenericCallbackEx_Process(arg1, ILibDuktape_GlobalGenericCallbackEx_n[8], ILibDuktape_GlobalGenericCallbackEx_nctx[8], args);
|
||||
va_end(args);
|
||||
return(ret);
|
||||
}
|
||||
PTRSIZE ILibDuktape_GlobalGenericCallbackEx_9(PTRSIZE arg1, ...)
|
||||
{
|
||||
PTRSIZE ret;
|
||||
va_list args;
|
||||
va_start(args, arg1);
|
||||
ret = ILibDuktape_GlobalGenericCallbackEx_Process(arg1, ILibDuktape_GlobalGenericCallbackEx_n[9], ILibDuktape_GlobalGenericCallbackEx_nctx[9], args);
|
||||
va_end(args);
|
||||
return(ret);
|
||||
}
|
||||
PTRSIZE ILibDuktape_GlobalGenericCallbackEx_10(PTRSIZE arg1, ...)
|
||||
{
|
||||
PTRSIZE ret;
|
||||
va_list args;
|
||||
va_start(args, arg1);
|
||||
ret = ILibDuktape_GlobalGenericCallbackEx_Process(arg1, ILibDuktape_GlobalGenericCallbackEx_n[10], ILibDuktape_GlobalGenericCallbackEx_nctx[10], args);
|
||||
va_end(args);
|
||||
return(ret);
|
||||
}
|
||||
PTRSIZE ILibDuktape_GlobalGenericCallbackEx_11(PTRSIZE arg1, ...)
|
||||
{
|
||||
PTRSIZE ret;
|
||||
va_list args;
|
||||
va_start(args, arg1);
|
||||
ret = ILibDuktape_GlobalGenericCallbackEx_Process(arg1, ILibDuktape_GlobalGenericCallbackEx_n[11], ILibDuktape_GlobalGenericCallbackEx_nctx[11], args);
|
||||
va_end(args);
|
||||
return(ret);
|
||||
}
|
||||
PTRSIZE ILibDuktape_GlobalGenericCallbackEx_12(PTRSIZE arg1, ...)
|
||||
{
|
||||
PTRSIZE ret;
|
||||
va_list args;
|
||||
va_start(args, arg1);
|
||||
ret = ILibDuktape_GlobalGenericCallbackEx_Process(arg1, ILibDuktape_GlobalGenericCallbackEx_n[12], ILibDuktape_GlobalGenericCallbackEx_nctx[12], args);
|
||||
va_end(args);
|
||||
return(ret);
|
||||
}
|
||||
PTRSIZE ILibDuktape_GlobalGenericCallbackEx_13(PTRSIZE arg1, ...)
|
||||
{
|
||||
PTRSIZE ret;
|
||||
va_list args;
|
||||
va_start(args, arg1);
|
||||
ret = ILibDuktape_GlobalGenericCallbackEx_Process(arg1, ILibDuktape_GlobalGenericCallbackEx_n[13], ILibDuktape_GlobalGenericCallbackEx_nctx[13], args);
|
||||
va_end(args);
|
||||
return(ret);
|
||||
}
|
||||
PTRSIZE ILibDuktape_GlobalGenericCallbackEx_14(PTRSIZE arg1, ...)
|
||||
{
|
||||
PTRSIZE ret;
|
||||
va_list args;
|
||||
va_start(args, arg1);
|
||||
ret = ILibDuktape_GlobalGenericCallbackEx_Process(arg1, ILibDuktape_GlobalGenericCallbackEx_n[14], ILibDuktape_GlobalGenericCallbackEx_nctx[14], args);
|
||||
va_end(args);
|
||||
return(ret);
|
||||
}
|
||||
PTRSIZE ILibDuktape_GlobalGenericCallbackEx_15(PTRSIZE arg1, ...)
|
||||
{
|
||||
PTRSIZE ret;
|
||||
va_list args;
|
||||
va_start(args, arg1);
|
||||
ret = ILibDuktape_GlobalGenericCallbackEx_Process(arg1, ILibDuktape_GlobalGenericCallbackEx_n[15], ILibDuktape_GlobalGenericCallbackEx_nctx[15], args);
|
||||
va_end(args);
|
||||
return(ret);
|
||||
}
|
||||
PTRSIZE ILibDuktape_GlobalGenericCallbackEx_16(PTRSIZE arg1, ...)
|
||||
{
|
||||
PTRSIZE ret;
|
||||
va_list args;
|
||||
va_start(args, arg1);
|
||||
ret = ILibDuktape_GlobalGenericCallbackEx_Process(arg1, ILibDuktape_GlobalGenericCallbackEx_n[16], ILibDuktape_GlobalGenericCallbackEx_nctx[16], args);
|
||||
va_end(args);
|
||||
return(ret);
|
||||
}
|
||||
PTRSIZE ILibDuktape_GlobalGenericCallbackEx_17(PTRSIZE arg1, ...)
|
||||
{
|
||||
PTRSIZE ret;
|
||||
va_list args;
|
||||
va_start(args, arg1);
|
||||
ret = ILibDuktape_GlobalGenericCallbackEx_Process(arg1, ILibDuktape_GlobalGenericCallbackEx_n[17], ILibDuktape_GlobalGenericCallbackEx_nctx[17], args);
|
||||
va_end(args);
|
||||
return(ret);
|
||||
}
|
||||
PTRSIZE ILibDuktape_GlobalGenericCallbackEx_18(PTRSIZE arg1, ...)
|
||||
{
|
||||
PTRSIZE ret;
|
||||
va_list args;
|
||||
va_start(args, arg1);
|
||||
ret = ILibDuktape_GlobalGenericCallbackEx_Process(arg1, ILibDuktape_GlobalGenericCallbackEx_n[18], ILibDuktape_GlobalGenericCallbackEx_nctx[18], args);
|
||||
va_end(args);
|
||||
return(ret);
|
||||
}
|
||||
PTRSIZE ILibDuktape_GlobalGenericCallbackEx_19(PTRSIZE arg1, ...)
|
||||
{
|
||||
PTRSIZE ret;
|
||||
va_list args;
|
||||
va_start(args, arg1);
|
||||
ret = ILibDuktape_GlobalGenericCallbackEx_Process(arg1, ILibDuktape_GlobalGenericCallbackEx_n[19], ILibDuktape_GlobalGenericCallbackEx_nctx[19], args);
|
||||
va_end(args);
|
||||
return(ret);
|
||||
}
|
||||
PTRSIZE ILibDuktape_GlobalGenericCallbackEx_20(PTRSIZE arg1, ...)
|
||||
{
|
||||
PTRSIZE ret;
|
||||
va_list args;
|
||||
va_start(args, arg1);
|
||||
ret = ILibDuktape_GlobalGenericCallbackEx_Process(arg1, ILibDuktape_GlobalGenericCallbackEx_n[20], ILibDuktape_GlobalGenericCallbackEx_nctx[20], args);
|
||||
va_end(args);
|
||||
return(ret);
|
||||
}
|
||||
PTRSIZE ILibDuktape_GlobalGenericCallbackEx_21(PTRSIZE arg1, ...)
|
||||
{
|
||||
PTRSIZE ret;
|
||||
va_list args;
|
||||
va_start(args, arg1);
|
||||
ret = ILibDuktape_GlobalGenericCallbackEx_Process(arg1, ILibDuktape_GlobalGenericCallbackEx_n[21], ILibDuktape_GlobalGenericCallbackEx_nctx[21], args);
|
||||
va_end(args);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
duk_ret_t ILibDuktape_GenericMarshal_PutGlobalGenericCallbackEx(duk_context *ctx)
|
||||
{
|
||||
duk_push_global_stash(ctx); // [stash]
|
||||
duk_get_prop_string(ctx, -1, "GlobalCallBacksEx"); // [stash][array]
|
||||
if (!duk_has_prop_string(ctx, 0, ILibDutkape_GenericMarshal_INTERNAL))
|
||||
{
|
||||
return(ILibDuktape_Error(ctx, "Invalid Parameter"));
|
||||
}
|
||||
duk_get_prop_string(ctx, 0, ILibDutkape_GenericMarshal_INTERNAL); // [stash][array][obj]
|
||||
duk_array_push(ctx, -2); // [stash][array]
|
||||
return(0);
|
||||
}
|
||||
|
||||
duk_ret_t ILibDuktape_GenericMarshal_GetGlobalGenericCallbackEx(duk_context *ctx)
|
||||
{
|
||||
int numParms = duk_require_int(ctx, 0);
|
||||
Duktape_GlobalGeneric_Data *data = NULL;
|
||||
|
||||
duk_push_global_stash(ctx); // [stash]
|
||||
if (!duk_has_prop_string(ctx, -1, "GlobalCallBacksEx"))
|
||||
{
|
||||
duk_push_array(ctx); // [stash][array]
|
||||
|
||||
duk_push_object(ctx);
|
||||
duk_push_pointer(ctx, (void*)ILibDuktape_GlobalGenericCallbackEx_0); duk_put_prop_string(ctx, -2, "PTR");
|
||||
duk_push_int(ctx, 0); duk_put_prop_string(ctx, -2, "INDEX");
|
||||
duk_array_push(ctx, -2);
|
||||
|
||||
duk_push_object(ctx);
|
||||
duk_push_pointer(ctx, (void*)ILibDuktape_GlobalGenericCallbackEx_1); duk_put_prop_string(ctx, -2, "PTR");
|
||||
duk_push_int(ctx, 1); duk_put_prop_string(ctx, -2, "INDEX");
|
||||
duk_array_push(ctx, -2);
|
||||
|
||||
duk_push_object(ctx);
|
||||
duk_push_pointer(ctx, (void*)ILibDuktape_GlobalGenericCallbackEx_2); duk_put_prop_string(ctx, -2, "PTR");
|
||||
duk_push_int(ctx, 2); duk_put_prop_string(ctx, -2, "INDEX");
|
||||
duk_array_push(ctx, -2);
|
||||
|
||||
duk_push_object(ctx);
|
||||
duk_push_pointer(ctx, (void*)ILibDuktape_GlobalGenericCallbackEx_3); duk_put_prop_string(ctx, -2, "PTR");
|
||||
duk_push_int(ctx, 3); duk_put_prop_string(ctx, -2, "INDEX");
|
||||
duk_array_push(ctx, -2);
|
||||
|
||||
duk_push_object(ctx);
|
||||
duk_push_pointer(ctx, (void*)ILibDuktape_GlobalGenericCallbackEx_4); duk_put_prop_string(ctx, -2, "PTR");
|
||||
duk_push_int(ctx, 4); duk_put_prop_string(ctx, -2, "INDEX");
|
||||
duk_array_push(ctx, -2);
|
||||
|
||||
duk_push_object(ctx);
|
||||
duk_push_pointer(ctx, (void*)ILibDuktape_GlobalGenericCallbackEx_5); duk_put_prop_string(ctx, -2, "PTR");
|
||||
duk_push_int(ctx, 5); duk_put_prop_string(ctx, -2, "INDEX");
|
||||
duk_array_push(ctx, -2);
|
||||
|
||||
duk_push_object(ctx);
|
||||
duk_push_pointer(ctx, (void*)ILibDuktape_GlobalGenericCallbackEx_6); duk_put_prop_string(ctx, -2, "PTR");
|
||||
duk_push_int(ctx, 6); duk_put_prop_string(ctx, -2, "INDEX");
|
||||
duk_array_push(ctx, -2);
|
||||
|
||||
duk_push_object(ctx);
|
||||
duk_push_pointer(ctx, (void*)ILibDuktape_GlobalGenericCallbackEx_7); duk_put_prop_string(ctx, -2, "PTR");
|
||||
duk_push_int(ctx, 7); duk_put_prop_string(ctx, -2, "INDEX");
|
||||
duk_array_push(ctx, -2);
|
||||
|
||||
duk_push_object(ctx);
|
||||
duk_push_pointer(ctx, (void*)ILibDuktape_GlobalGenericCallbackEx_8); duk_put_prop_string(ctx, -2, "PTR");
|
||||
duk_push_int(ctx, 8); duk_put_prop_string(ctx, -2, "INDEX");
|
||||
duk_array_push(ctx, -2);
|
||||
|
||||
duk_push_object(ctx);
|
||||
duk_push_pointer(ctx, (void*)ILibDuktape_GlobalGenericCallbackEx_9); duk_put_prop_string(ctx, -2, "PTR");
|
||||
duk_push_int(ctx, 9); duk_put_prop_string(ctx, -2, "INDEX");
|
||||
duk_array_push(ctx, -2);
|
||||
|
||||
duk_push_object(ctx);
|
||||
duk_push_pointer(ctx, (void*)ILibDuktape_GlobalGenericCallbackEx_10); duk_put_prop_string(ctx, -2, "PTR");
|
||||
duk_push_int(ctx, 10); duk_put_prop_string(ctx, -2, "INDEX");
|
||||
duk_array_push(ctx, -2);
|
||||
|
||||
duk_push_object(ctx);
|
||||
duk_push_pointer(ctx, (void*)ILibDuktape_GlobalGenericCallbackEx_11); duk_put_prop_string(ctx, -2, "PTR");
|
||||
duk_push_int(ctx, 11); duk_put_prop_string(ctx, -2, "INDEX");
|
||||
duk_array_push(ctx, -2);
|
||||
|
||||
duk_push_object(ctx);
|
||||
duk_push_pointer(ctx, (void*)ILibDuktape_GlobalGenericCallbackEx_12); duk_put_prop_string(ctx, -2, "PTR");
|
||||
duk_push_int(ctx, 12); duk_put_prop_string(ctx, -2, "INDEX");
|
||||
duk_array_push(ctx, -2);
|
||||
|
||||
duk_push_object(ctx);
|
||||
duk_push_pointer(ctx, (void*)ILibDuktape_GlobalGenericCallbackEx_13); duk_put_prop_string(ctx, -2, "PTR");
|
||||
duk_push_int(ctx, 13); duk_put_prop_string(ctx, -2, "INDEX");
|
||||
duk_array_push(ctx, -2);
|
||||
|
||||
duk_push_object(ctx);
|
||||
duk_push_pointer(ctx, (void*)ILibDuktape_GlobalGenericCallbackEx_14); duk_put_prop_string(ctx, -2, "PTR");
|
||||
duk_push_int(ctx, 14); duk_put_prop_string(ctx, -2, "INDEX");
|
||||
duk_array_push(ctx, -2);
|
||||
|
||||
duk_push_object(ctx);
|
||||
duk_push_pointer(ctx, (void*)ILibDuktape_GlobalGenericCallbackEx_15); duk_put_prop_string(ctx, -2, "PTR");
|
||||
duk_push_int(ctx, 15); duk_put_prop_string(ctx, -2, "INDEX");
|
||||
duk_array_push(ctx, -2);
|
||||
|
||||
duk_push_object(ctx);
|
||||
duk_push_pointer(ctx, (void*)ILibDuktape_GlobalGenericCallbackEx_16); duk_put_prop_string(ctx, -2, "PTR");
|
||||
duk_push_int(ctx, 16); duk_put_prop_string(ctx, -2, "INDEX");
|
||||
duk_array_push(ctx, -2);
|
||||
|
||||
duk_push_object(ctx);
|
||||
duk_push_pointer(ctx, (void*)ILibDuktape_GlobalGenericCallbackEx_17); duk_put_prop_string(ctx, -2, "PTR");
|
||||
duk_push_int(ctx, 17); duk_put_prop_string(ctx, -2, "INDEX");
|
||||
duk_array_push(ctx, -2);
|
||||
|
||||
duk_push_object(ctx);
|
||||
duk_push_pointer(ctx, (void*)ILibDuktape_GlobalGenericCallbackEx_18); duk_put_prop_string(ctx, -2, "PTR");
|
||||
duk_push_int(ctx, 18); duk_put_prop_string(ctx, -2, "INDEX");
|
||||
duk_array_push(ctx, -2);
|
||||
|
||||
duk_push_object(ctx);
|
||||
duk_push_pointer(ctx, (void*)ILibDuktape_GlobalGenericCallbackEx_19); duk_put_prop_string(ctx, -2, "PTR");
|
||||
duk_push_int(ctx, 19); duk_put_prop_string(ctx, -2, "INDEX");
|
||||
duk_array_push(ctx, -2);
|
||||
|
||||
duk_push_object(ctx);
|
||||
duk_push_pointer(ctx, (void*)ILibDuktape_GlobalGenericCallbackEx_20); duk_put_prop_string(ctx, -2, "PTR");
|
||||
duk_push_int(ctx, 20); duk_put_prop_string(ctx, -2, "INDEX");
|
||||
duk_array_push(ctx, -2);
|
||||
|
||||
duk_push_object(ctx);
|
||||
duk_push_pointer(ctx, (void*)ILibDuktape_GlobalGenericCallbackEx_21); duk_put_prop_string(ctx, -2, "PTR");
|
||||
duk_push_int(ctx, 21); duk_put_prop_string(ctx, -2, "INDEX");
|
||||
duk_array_push(ctx, -2);
|
||||
|
||||
|
||||
duk_put_prop_string(ctx, -2, "GlobalCallBacksEx"); // [stash]
|
||||
}
|
||||
duk_get_prop_string(ctx, -1, "GlobalCallBacksEx"); // [stash][array]
|
||||
|
||||
if (numParms < 1) { return(ILibDuktape_Error(ctx, "Must have 1 or more arguments")); }
|
||||
duk_array_pop(ctx, -1); // [stash][array][obj]
|
||||
int index = Duktape_GetIntPropertyValue(ctx, -1, "INDEX", -1);
|
||||
void *PTR = Duktape_GetPointerProperty(ctx, -1, "PTR");
|
||||
ILibDuktape_GenericMarshal_Variable_PUSH(ctx, PTR, sizeof(PTRSIZE));// [stash][array][obj][var]
|
||||
ILibDuktape_GenericMarshal_Variable_DisableAutoFree(ctx, -1);
|
||||
ILibDuktape_EventEmitter_CreateEventEx(ILibDuktape_EventEmitter_Create(ctx), "GlobalCallback");
|
||||
|
||||
duk_dup(ctx, -2); // [stash][array][obj][var][obj]
|
||||
duk_put_prop_string(ctx, -2, ILibDutkape_GenericMarshal_INTERNAL); // [stash][array][obj][var]
|
||||
ILibDuktape_GlobalGenericCallbackEx_n[index] = numParms;
|
||||
ILibDuktape_GlobalGenericCallbackEx_nctx[index] = ILibDuktape_EventEmitter_GetEmitter(ctx, -1);
|
||||
return(1);
|
||||
}
|
||||
duk_ret_t ILibDuktape_GenericMarshal_GetGlobalGenericCallback(duk_context *ctx)
|
||||
{
|
||||
int numParms = duk_require_int(ctx, 0);
|
||||
@@ -2151,6 +2637,49 @@ duk_ret_t ILibDuktape_GenericMarshal_GetCurrentThread(duk_context *ctx)
|
||||
return(1);
|
||||
}
|
||||
|
||||
duk_ret_t ILibDuktape_GenericMarshal_MarshalFunction(duk_context *ctx)
|
||||
{
|
||||
if (duk_is_object(ctx, 0) && strcmp("_GenericMarshal.Variable", Duktape_GetStringPropertyValue(ctx, 0, ILibDuktape_OBJID, "")) == 0)
|
||||
{
|
||||
duk_push_c_function(ctx, ILibDuktape_GenericMarshal_MethodInvoke, DUK_VARARGS); // [func]
|
||||
duk_get_prop_string(ctx, 0, "_ptr"); // [func][addr]
|
||||
if (duk_is_number(ctx, 1))
|
||||
{
|
||||
void **p = (void**)duk_get_pointer(ctx, -1);
|
||||
int i = (int)duk_require_int(ctx, 1);
|
||||
duk_push_pointer(ctx, p[i]); // [func][addr][ptr]
|
||||
duk_remove(ctx, -2); // [func][ptr]
|
||||
}
|
||||
duk_put_prop_string(ctx, -2, "_address"); // [func]
|
||||
duk_push_string(ctx, "_MarshalledFunction"); duk_put_prop_string(ctx, -2, "_exposedName");
|
||||
return(1);
|
||||
}
|
||||
return(ILibDuktape_Error(ctx, "Invalid Parameter"));
|
||||
}
|
||||
duk_ret_t ILibDuktape_GenericMarshal_MarshalFunctions(duk_context *ctx)
|
||||
{
|
||||
if (duk_is_object(ctx, 0) && strcmp("_GenericMarshal.Variable", Duktape_GetStringPropertyValue(ctx, 0, ILibDuktape_OBJID, "")) == 0 && duk_is_array(ctx, 1))
|
||||
{
|
||||
int i = 0;
|
||||
duk_array_clone(ctx, 1); // [array]
|
||||
duk_push_object(ctx); // [array][ret]
|
||||
while (duk_get_length(ctx, -2) > 0)
|
||||
{
|
||||
duk_array_shift(ctx, -2); // [array][ret][str]
|
||||
duk_push_this(ctx); // [array][ret][str][this]
|
||||
duk_prepare_method_call(ctx, -1, "MarshalFunction"); // [array][ret][str][this][func][this]
|
||||
duk_dup(ctx, 0); // [array][ret][str][this][func][this][parm]
|
||||
duk_push_int(ctx, i++); // [array][ret][str][this][func][this][parm][val]
|
||||
duk_call_method(ctx, 2); // [array][ret][str][this][marshalled]
|
||||
duk_remove(ctx, -2); // [array][ret][str][marshalled]
|
||||
duk_put_prop(ctx, -3); // [array][ret]
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
return(ILibDuktape_Error(ctx, "Invalid Parameters"));
|
||||
}
|
||||
|
||||
|
||||
void ILibDuktape_GenericMarshal_Push(duk_context *ctx, void *chain)
|
||||
{
|
||||
duk_push_object(ctx); // [obj]
|
||||
@@ -2162,12 +2691,17 @@ void ILibDuktape_GenericMarshal_Push(duk_context *ctx, void *chain)
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "CreateCallbackProxy", ILibDuktape_GenericMarshal_CreateCallbackProxy, 2);
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "CreateNativeProxy", ILibDuktape_GenericMarshal_CreateNativeProxy, DUK_VARARGS);
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "GetGenericGlobalCallback", ILibDuktape_GenericMarshal_GetGlobalGenericCallback, DUK_VARARGS);
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "GetGenericGlobalCallbackEx", ILibDuktape_GenericMarshal_GetGlobalGenericCallbackEx, DUK_VARARGS);
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "PutGenericGlobalCallbackEx", ILibDuktape_GenericMarshal_PutGlobalGenericCallbackEx, 1);
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "WrapObject", ILibDuktape_GenericMarshal_WrapObject, 1);
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "UnWrapObject", ILibDuktape_GenericMarshal_UnWrapObject, 1);
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "StashObject", ILibDuktape_GenericMarshal_StashObject, 1);
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "UnstashObject", ILibDuktape_GenericMarshal_UnstashObject, DUK_VARARGS);
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "ObjectToPtr", ILibDuktape_GenericMarshal_ObjectToPtr, 1);
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "GetCurrentThread", ILibDuktape_GenericMarshal_GetCurrentThread, 0);
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "MarshalFunction", ILibDuktape_GenericMarshal_MarshalFunction, DUK_VARARGS);
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "MarshalFunctions", ILibDuktape_GenericMarshal_MarshalFunctions, 2);
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
duk_push_object(ctx);
|
||||
|
||||
@@ -4799,6 +4799,11 @@ duk_ret_t ILibDuktape_WebSocket_bytesSent_uncompressed(duk_context *ctx)
|
||||
|
||||
ILibDuktape_WebSocket_State *ws = NULL;
|
||||
duk_push_this(ctx); // [WebSocket_Decoded]
|
||||
if (!duk_has_prop_string(ctx, -1, ILibDuktape_WSDEC2WS))
|
||||
{
|
||||
duk_push_null(ctx);
|
||||
return(1);
|
||||
}
|
||||
duk_get_prop_string(ctx, -1, ILibDuktape_WSDEC2WS); // [WebSocket_Decoded][WebSocket]
|
||||
ws = (ILibDuktape_WebSocket_State*)Duktape_GetBufferProperty(ctx, -1, ILibDuktape_WebSocket_StatePtr);
|
||||
|
||||
|
||||
@@ -2369,6 +2369,13 @@ void ILibDuktape_Polyfills_JS_Init(duk_context *ctx)
|
||||
|
||||
// win-systray is a helper to add a system tray icon with context menu. Refer to modules/win-systray.js
|
||||
duk_peval_string_noresult(ctx, "addCompressedModule('win-systray', Buffer.from('eJzdGV1v27b2PUD+A2cUk7zZSpreJ2fr4CXpatzGyY2dBUMSGIxE22xlUpei4hiF//s9h5JsUZI/mt2+zA+JSB2e70/q6KfDgzMZLRSfTDU5OT45Jj2hWUjOpIqkoppLcXhwePCJ+0zELCCJCJgiespIN6I+/MvetMifTMUATU68Y+IiQCN71WieHh4sZEJmdEGE1CSJGWDgMRnzkBH24rNIEy6IL2dRyKnwGZlzPTVUMhze4cFfGQb5pCkAUwCPYDUughGqkVsCv6nWUefoaD6fe9Rw6kk1OQpTuPjoU+/soj+4aAO3eOJWhCyOiWL/TbgCMZ8WhEbAjE+fgMWQzolUhE4Ug3daIrNzxTUXkxaJ5VjPqWKHBwGPteJPibb0lLMG8hYBQFNUkEZ3QHqDBvm9O+gNWocHd73hx6vbIbnr3tx0+8PexYBc3ZCzq/55b9i76sPqA+n2/yL/7vXPW4SBloAKe4kUcg8sctQgC0BdA8Ys8mOZshNHzOdj7oNQYpLQCSMT+cyUAFlIxNSMx2jFGJgLDg9CPuPaOEFclQiI/HSEynumikRKwlFGfs116DrZloPmR5Dhx3cnZ4PRoN+9Hn68ueieA/Dxy3H6+1cGdHc5+s9tb5i9enuy3j77dDW4yPePT5HwOBE+MkciGetLUAGI42oeNA8PvqZegGcnsyJXoz+YYIr7l1TFUxoa7nJIcEwFsJOZd6YY1awPoj+zayVfFq5zCy/fnXhBuD6D8BnoJdNTGbjONXAynMJWkPHTtaGr75HhVi43wi4t0ULp0zBexJrNRr4hNVR00fOlcDU8XEXGOrbEiuk/aQiSCDbPLeOuMLrgLC2A+dwkX00ceiPYMTqKT1cbn83G51OyzPnnY1Ik6aXaAiJJGDZTkIwH/FUh1zbAdRui0Hia0/QmTKN2BZ0xdyMQSBzLkN3ywG3mLC3Tf0VaMQSABmJaJSyDStXhFaDM+9XKBhtBlEZU+1Ob5zkX7fUb4CdfuF+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te31+nXynB9nhdml4n29fenZUYUUg1JOkZYsAh/92JAwbb/OUa7Fi+VVByvva3FT6stubCJ4mQCxY4zezKGmRO/ef/xe334DBl7X/NhtA6', 'base64'));");
|
||||
|
||||
// win-com is a helper to add COM support. Refer to modules/win-com.js
|
||||
duk_peval_string_noresult(ctx, "addCompressedModule('win-com', Buffer.from('eJylV9tu2zgQfTfgfxjkxXKjKk5a9MHZLODKSiqsL4HtpFsUgUDLtM1WFlWKiuPN+t93qIutW4IUKwSRyDmcy+HMkD5712yYPNgJtlpLuOhcnIPtS+qByUXABZGM+81GszFgLvVDuoDIX1ABck2hFxAXX6lEh3sqQkTDhdEBTQFOUtFJ+7LZ2PEINmQHPpcQhRQ1sBCWzKNAn1waSGA+uHwTeIz4LoUtk+vYSqrDaDa+pRr4XBIEE4QHOFrmYUCk8hbwWUsZdM/OttutQWJPDS5WZ16CC88GtmmNptZ79FatuPM9GoYg6K+ICQxzvgMSoDMumaOLHtkCF0BWgqJMcuXsVjDJ/JUOIV/KLRG02ViwUAo2j2SBp8w1jDcPQKaIDye9KdjTE/jcm9pTvdn4as++jO9m8LU3mfRGM9uawngC5njUt2f2eISja+iNvsFf9qivA0WW0Ap9CoTyHl1kikG6QLqmlBbML3niThhQly2Zi0H5q4isKKz4IxU+xgIBFRsWql0M0blFs+GxDZNxEoTViAxF3Lsz9d9FgARzMDVnfzv26HYyNp2pNbm3JnAF55clwGBs9gZH+ceD3Br3TGc0Hlk42znMTm5Nx3R6d7MvI2dg3VsDp29d9+4GsxqUPbxNMfhlTabjUW+mtH04+jC2R/bMGeJ65Hpi9fpWP1XUbDwSATdDHKaJoLWcG+pTwdwhEeGaeC2VywrFPfrhAoE3Q8MUlEg6Qpoe6a3gTzutFUuNhZfgk1ECG1K55guthVTY/WvBN1PMCH/1Mo4nYxt9V5XxCtD2MSOJx/6hU+pGmJ67N4HfBLKeXoTZb4ojEStgHPkbcHaKajaWke+qHAS3QIU2uY516TC5ttWLB3GmtpuN56QHpAYKcWgdvTYHlKn6NRmbauX7cx068d+LWam/lorx0kOa4yiJUBlWWRUEj/mcuuUMm7HQMt8UZJ1+syVo2hrRmcPmC+SoeOsK89+6cjxwiZ6028Y98eAKi6Od2ExpVY+gMhI+aIgz+lTQpdbOvNwnL7kWfAtayxICW49LPE+1mIqfLTiFdWzoFFrteMf3hU0vVYoWj5Pv404rZgrU3RPBVO/Ow3V4xoNlQbsgRURhn6dVLF0vZItaFeefjrvEllpKeMmtRz3T8RbaMmiRMuqFtLKkyKPJfezWMqbyGFkrp2if465Qm5r9O7zZb2ON/Q5ndpUxlvJ1dfUqW+x/cmW/wFSOq03S4a/Tcajx+Q8diBBHtjJ/MNxhDTorhGRV+xKNOvad/9PnW7+4L6ktddUSS4JVUDATb4qce7XEItLwqL/C+9E7JU57xBQbVX5n0J1XOwmqN4Jk8nO0XCqRoS5UcRySZ3OHroizzkoV8Zy4P0NU/f3hsL9K6HqU+FGAgkOQWnVD48guj+PtWt0ANXUZzKvPAvzzUEIlPbEutFVZGPDgEOMBaAi6wTtOz/MGeAFT53motW48Pieema5slRcpZiOZHv5FLJ4hj3l4mpD7Ax/qqqWpUFl8scDXH3Dctks4PWVVapw11pjKrBv6ollU8p09GAERm7CddyFZ3Dac8fwHdaWtbjSlCB3VaFMFPtnQ3OrS5hpBFK61VGWdlSS3El014tq0ihMuqQ9WSVy9nMg1GXi0oNoQOuFX9lCv5l5N3qiDk4hVtKG+DL93HgwnkEK165gG/G4X8aXlcUbh3qKKQxmU5bkEUL9UMmPtKrJGuXqU8mQbjp6yh3KOqmdfncq6VFwcKijFiqF+zuyynrYqpk9J0T7XI4uND5enB/SGLyKPGvjTgwupiHgu3c66pbFeabDdyoxeaYzdyoxevhB0yxN68djrFoex9NCWS0Kt9dxJn/fHf2b2lTwfP+1b7bjc/wPprn9O', 'base64'), '2021-10-28T20:02:56.000-07:00');");
|
||||
|
||||
// win-wmi is a helper to add wmi support using win-com. Refer to modules/win-wmi.js
|
||||
duk_peval_string_noresult(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ayLKnns+9spGaLO3eFzJMGvJL7US7PSaXRHHf5ePuK2qjiGwVS2HFYRqmjtuq9ncjyMYIiy5uE/bAYWZrPaE6UzMRUVj6L/YtyUYjz/zTHvCfDrM0vVOFtM0xxfimVXXaWW96VWcrnFaruqnCXsNkozuMeYfkgj8OcNak30Thek2mreVL/YHkET7rRGZ0PwXY+0Ir6XWn39vuPJPSWc/qerSJoo9L3NfJghTcYa/SnLDdqRAtQc90arsvCFrzDZoWdSLEHxctIOo8UD+2y0M2Na17LnikV76fp0P/p3sKEb5IAn/MFa9RLLTJsYlyWvSTic1qU6H4miXHbLmiiRWE3lD7v64gmZbe0KxrPyjqj9CnZHc04Ulgj7KJLSp+3DB4G53Pj3Pw93ycthLRBu5S5a85bc56yvneaHr3lOqcS3PQRwmLLiyDrxm7WjF0BK4S2SVNWXFCuMcv2buPmLH3Wvn9TuklbBGLbRm15pOsatgJ1uabtlooVNonKK1augbsTrEVN3PKASzdzS7Ms1dTd0gKre6flYZZq8G6Ds7jJWx5oqWbvtkB3E9jrG78iebnm77a67Sa217aBN+O2thW8EbuSDWH67LwpXAQy81KC2KPlS3aflVdph1agybzIEI4v7EkAlQR+cWw3vPv/Yjexs/hClnZ1z7jPiFaG/wONV9kH', 'base64'), '2021-10-28T19:59:05.000-07:00');");
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _FREEBSD
|
||||
|
||||
@@ -396,7 +396,12 @@ duk_ret_t ILibDuktape_EventEmitter_on(duk_context *ctx)
|
||||
duk_push_this(ctx); // [object]
|
||||
data = (ILibDuktape_EventEmitter*)Duktape_GetBufferProperty(ctx, -1, ILibDuktape_EventEmitter_Data);
|
||||
duk_push_heapptr(ctx, data->table); // [object][table]
|
||||
if (!duk_has_prop_string(ctx, -1, propName)) { duk_push_array(ctx); duk_put_prop_string(ctx, -2, propName); }
|
||||
if (!duk_has_prop_string(ctx, -1, propName))
|
||||
{
|
||||
if (data->eventType == ILibDuktape_EventEmitter_Type_EXPLICIT) { return(ILibDuktape_Error(ctx, "Cannot register for non-existing event: %s", propName)); }
|
||||
duk_push_array(ctx);
|
||||
duk_put_prop_string(ctx, -2, propName);
|
||||
}
|
||||
duk_get_prop_string(ctx, -1, propName); // [object][table][array]
|
||||
|
||||
duk_push_object(ctx); // [object][table][array][handler]
|
||||
|
||||
124
modules/win-com.js
Normal file
124
modules/win-com.js
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
Copyright 2021 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
const CLSCTX_INPROC_SERVER = 1;
|
||||
const CLSCTX_LOCAL_SERVER = 4;
|
||||
const EOAC_NONE = 0;
|
||||
const RPC_C_AUTHN_LEVEL_DEFAULT = 0;
|
||||
const RPC_C_IMP_LEVEL_IMPERSONATE = 3;
|
||||
const COINIT_MULTITHREADED = 0;
|
||||
|
||||
var GM = require('_GenericMarshal');
|
||||
var ole32 = GM.CreateNativeProxy('ole32.dll');
|
||||
ole32.CreateMethod('CLSIDFromString');
|
||||
ole32.CreateMethod('CoCreateInstance');
|
||||
ole32.CreateMethod('CoInitializeSecurity');
|
||||
ole32.CreateMethod('CoInitialize');
|
||||
ole32.CreateMethod('CoInitializeEx');
|
||||
ole32.CreateMethod('IIDFromString');
|
||||
ole32.CreateMethod('StringFromCLSID');
|
||||
ole32.CreateMethod('StringFromIID');
|
||||
|
||||
function createInstance(RFCLSID, RFIID, options)
|
||||
{
|
||||
ole32.CoInitializeEx(0, COINIT_MULTITHREADED);
|
||||
ole32.CoInitializeSecurity(0, -1, 0, 0, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, 0, EOAC_NONE, 0);
|
||||
|
||||
var ppv = GM.CreatePointer();
|
||||
var h;
|
||||
if ((h = ole32.CoCreateInstance(RFCLSID, 0, CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, RFIID, ppv)).Val == 0)
|
||||
{
|
||||
return (ppv.Deref());
|
||||
}
|
||||
throw ('Error calling CoCreateInstance(' + h.Val + ')');
|
||||
}
|
||||
|
||||
function CLSIDFromString(CLSIDString)
|
||||
{
|
||||
var v = GM.CreateVariable(CLSIDString, { wide: true });
|
||||
var rfclsid = GM.CreateVariable(16);
|
||||
|
||||
if(ole32.CLSIDFromString(v, rfclsid).Val == 0)
|
||||
{
|
||||
return (rfclsid);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw ('Error Converting CLSIDString');
|
||||
}
|
||||
}
|
||||
function IIDFromString(IIDString)
|
||||
{
|
||||
var v = GM.CreateVariable(IIDString, { wide: true });
|
||||
var rfiid = GM.CreateVariable(16);
|
||||
|
||||
if(ole32.IIDFromString(v, rfiid).Val==0)
|
||||
{
|
||||
return (rfiid);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw ('Error Converting IIDString');
|
||||
}
|
||||
}
|
||||
|
||||
function marshalFunctions(obj, arr)
|
||||
{
|
||||
return (GM.MarshalFunctions(obj.Deref(), arr));IID_IUnknown
|
||||
}
|
||||
function marshalInterface(arr)
|
||||
{
|
||||
var vtbl = GM.CreateVariable(arr.length * GM.PointerSize);
|
||||
var obj = GM.CreatePointer();
|
||||
vtbl.pointerBuffer().copy(obj.toBuffer());
|
||||
obj._gcallbacks = [];
|
||||
|
||||
obj.cleanup = function ()
|
||||
{
|
||||
var v;
|
||||
while (this._gcallbacks.length > 0)
|
||||
{
|
||||
v = this._gcallbacks.pop();
|
||||
v.removeAllListeners('GlobalCallback');
|
||||
GM.PutGenericGlobalCallbackEx(v);
|
||||
}
|
||||
};
|
||||
|
||||
for (var i = 0; i < arr.length; ++i)
|
||||
{
|
||||
_hide(GM.GetGenericGlobalCallbackEx(arr[i].parms));
|
||||
_hide()._ObjectID = 'GlobalCallback_' + arr[i].name;
|
||||
obj._gcallbacks.push(_hide());
|
||||
_hide().obj = arr[i];
|
||||
_hide().pointerBuffer().copy(vtbl.Deref(i * GM.PointerSize, GM.PointerSize).toBuffer());
|
||||
_hide(true).on('GlobalCallback', function ()
|
||||
{
|
||||
if (arguments[0]._ptr == obj._ptr)
|
||||
{
|
||||
var args = [];
|
||||
for (var i in arguments)
|
||||
{
|
||||
args.push(arguments[i]);
|
||||
}
|
||||
return (this.obj.func.apply(obj, args));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return (obj);
|
||||
}
|
||||
module.exports = { createInstance: createInstance, marshalFunctions: marshalFunctions, marshalInterface: marshalInterface, CLSIDFromString: CLSIDFromString, IIDFromString: IIDFromString, IID_IUnknown: IIDFromString('{00000000-0000-0000-C000-000000000046}') };
|
||||
377
modules/win-wmi.js
Normal file
377
modules/win-wmi.js
Normal file
@@ -0,0 +1,377 @@
|
||||
/*
|
||||
Copyright 2021 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
var promise = require('promise');
|
||||
var GM = require('_GenericMarshal');
|
||||
const CLSID_WbemAdministrativeLocator = '{CB8555CC-9128-11D1-AD9B-00C04FD8FDFF}';
|
||||
const IID_WbemLocator = '{dc12a687-737f-11cf-884d-00aa004b2e24}';
|
||||
const WBEM_FLAG_BIDIRECTIONAL = 0;
|
||||
const WBEM_INFINITE = -1;
|
||||
const WBEM_FLAG_ALWAYS = 0;
|
||||
const E_NOINTERFACE = 0x80004002;
|
||||
var OleAut32 = GM.CreateNativeProxy('OleAut32.dll');
|
||||
OleAut32.CreateMethod('SafeArrayAccessData');
|
||||
|
||||
const LocatorFunctions = ['QueryInterface', 'AddRef', 'Release', 'ConnectToServer'];
|
||||
const ServiceFunctions = [
|
||||
'QueryInterface',
|
||||
'AddRef',
|
||||
'Release',
|
||||
'OpenNamespace',
|
||||
'CancelAsyncCall',
|
||||
'QueryObjectSink',
|
||||
'GetObject',
|
||||
'GetObjectAsync',
|
||||
'PutClass',
|
||||
'PutClassAsync',
|
||||
'DeleteClass',
|
||||
'DeleteClassAsync',
|
||||
'CreateClassEnum',
|
||||
'CreateClassEnumAsync',
|
||||
'PutInstance',
|
||||
'PutInstanceAsync',
|
||||
'DeleteInstance',
|
||||
'DeleteInstanceAsync',
|
||||
'CreateInstanceEnum',
|
||||
'CreateInstanceEnumAsync',
|
||||
'ExecQuery',
|
||||
'ExecQueryAsync',
|
||||
'ExecNotificationQuery',
|
||||
'ExecNotificationQueryAsync',
|
||||
'ExecMethod',
|
||||
'ExecMethodAsync'
|
||||
];
|
||||
const ResultsFunctions = [
|
||||
'QueryInterface',
|
||||
'AddRef',
|
||||
'Release',
|
||||
'Reset',
|
||||
'Next',
|
||||
'NextAsync',
|
||||
'Clone',
|
||||
'Skip'
|
||||
];
|
||||
const ResultFunctions = [
|
||||
'QueryInterface',
|
||||
'AddRef',
|
||||
'Release',
|
||||
'GetQualifierSet',
|
||||
'Get',
|
||||
'Put',
|
||||
'Delete',
|
||||
'GetNames',
|
||||
'BeginEnumeration',
|
||||
'Next',
|
||||
'EndEnumeration',
|
||||
'GetPropertyQualifierSet',
|
||||
'Clone',
|
||||
'GetObjectText',
|
||||
'SpawnDerivedClass',
|
||||
'SpawnInstance',
|
||||
'CompareTo',
|
||||
'GetPropertyOrigin',
|
||||
'InheritsFrom',
|
||||
'GetMethod',
|
||||
'PutMethod',
|
||||
'DeleteMethod',
|
||||
'BeginMethodEnumeration',
|
||||
'NextMethod',
|
||||
'EndMethodEnumeration',
|
||||
'GetMethodQualifierSet',
|
||||
'GetMethodOrigin'
|
||||
];
|
||||
|
||||
const QueryAsyncHandler =
|
||||
[
|
||||
{
|
||||
parms: 3, name: 'QueryInterface', func: function (j, riid, ppv)
|
||||
{
|
||||
var ret = GM.CreateVariable(4);
|
||||
console.info1('QueryInterface', riid.Deref(0, 16).toBuffer().toString('hex'));
|
||||
switch (riid.Deref(0, 16).toBuffer().toString('hex'))
|
||||
{
|
||||
case '0000000000000000C000000000000046': // IID_IUnknown
|
||||
j.pointerBuffer().copy(ppv.Deref(0, 8).toBuffer());
|
||||
ret.increment(0, true);
|
||||
++this.p.refcount;
|
||||
console.info1('QueryInterface (IID_IUnknown)', this.p.refcount);
|
||||
break;
|
||||
case '0178857C8173CF11884D00AA004B2E24': // IID_IWmiObjectSink
|
||||
j.pointerBuffer().copy(ppv.Deref(0, 8).toBuffer());
|
||||
ret.increment(0, true);
|
||||
++this.p.refcount;
|
||||
console.info1('QueryInterface (IID_IWmiObjectSink)', this.p.refcount);
|
||||
break;
|
||||
default:
|
||||
ret.increment(E_NOINTERFACE, true);
|
||||
console.info1('returning E_NOINTERFACE');
|
||||
break;
|
||||
}
|
||||
|
||||
return (ret);
|
||||
}
|
||||
},
|
||||
{
|
||||
parms: 1, name: 'AddRef', func: function ()
|
||||
{
|
||||
++this.p.refcount;
|
||||
console.info1('AddRef', this.p.refcount);
|
||||
return (GM.CreateVariable(4));
|
||||
}
|
||||
},
|
||||
{
|
||||
parms: 1, name: 'Release', func: function ()
|
||||
{
|
||||
--this.p.refcount;
|
||||
console.info1('Release', this.p.refcount);
|
||||
if (this.p.refcount == 0)
|
||||
{
|
||||
this.p.handlers.cleanup();
|
||||
delete this.p.handlers;
|
||||
delete this.p;
|
||||
}
|
||||
return (GM.CreateVariable(4));
|
||||
}
|
||||
},
|
||||
{
|
||||
parms: 3, name: 'Indicate', func: function (j, count, arr)
|
||||
{
|
||||
console.info1('Indicate', count.Val);
|
||||
var j, nme, len, nn;
|
||||
|
||||
for (var i = 0; i < count.Val; ++i)
|
||||
{
|
||||
j = arr.Deref((i * GM.PointerSize) + 0, GM.PointerSize);
|
||||
this.p.results.push(enumerateProperties(j));
|
||||
}
|
||||
|
||||
var ret = GM.CreateVariable(4);
|
||||
ret.increment(0, true);
|
||||
return (ret);
|
||||
}
|
||||
},
|
||||
{
|
||||
parms: 5, name: 'SetStatus', func: function (j, lFlags, hResult, strParam, pObjParam)
|
||||
{
|
||||
console.info1('SetStatus', hResult.Val);
|
||||
|
||||
var ret = GM.CreateVariable(4);
|
||||
ret.increment(0, true);
|
||||
|
||||
if (hResult.Val == 0)
|
||||
{
|
||||
this.p.resolve(this.p.results);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.p.reject(hResult.Val);
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
function enumerateProperties(j)
|
||||
{
|
||||
var nme, len, nn;
|
||||
|
||||
j.funcs = require('win-com').marshalFunctions(j.Deref(), ResultFunctions);
|
||||
nme = GM.CreatePointer();
|
||||
j.funcs.GetNames(j.Deref(), 0, WBEM_FLAG_ALWAYS, 0, nme);
|
||||
len = nme.Deref().Deref(24, 4).toBuffer().readUInt32LE();
|
||||
|
||||
nn = GM.CreatePointer();
|
||||
OleAut32.SafeArrayAccessData(nme.Deref(), nn);
|
||||
|
||||
var properties = [];
|
||||
var values = {};
|
||||
|
||||
for (var i = 0; i < len - 1; ++i)
|
||||
{
|
||||
properties.push(nn.Deref().increment(i * 8).Deref().Wide2UTF8);
|
||||
}
|
||||
|
||||
for (var i = 0; i < properties.length; ++i)
|
||||
{
|
||||
var tmp1 = GM.CreateVariable(24);
|
||||
if (j.funcs.Get(j.Deref(), GM.CreateVariable(properties[i], { wide: true }), 0, tmp1, 0, 0).Val == 0)
|
||||
{
|
||||
switch (tmp1.toBuffer().readUInt16LE())
|
||||
{
|
||||
case 0x0000: // VT_EMPTY
|
||||
case 0x0001: // VT_NULL
|
||||
values[properties[i]] = null;
|
||||
break;
|
||||
case 0x0002: // VT_I2
|
||||
values[properties[i]] = tmp1.Deref(8, 8).toBuffer().readInt16LE();
|
||||
break;
|
||||
case 0x0003: // VT_I4
|
||||
case 0x0016: // VT_INT
|
||||
values[properties[i]] = tmp1.Deref(8, 8).toBuffer().readInt32LE();
|
||||
break;
|
||||
case 0x000B: // VT_BOOL
|
||||
values[properties[i]] = tmp1.Deref(8, 8).toBuffer().readInt32LE() != 0;
|
||||
break;
|
||||
case 0x000E: // VT_DECIMAL
|
||||
break;
|
||||
case 0x0010: // VT_I1
|
||||
values[properties[i]] = tmp1.Deref(8, 8).toBuffer().readInt8();
|
||||
break;
|
||||
case 0x0011: // VT_UI1
|
||||
values[properties[i]] = tmp1.Deref(8, 8).toBuffer().readUInt8();
|
||||
break;
|
||||
case 0x0012: // VT_UI2
|
||||
values[properties[i]] = tmp1.Deref(8, 8).toBuffer().readUInt16LE();
|
||||
break;
|
||||
case 0x0013: // VT_UI4
|
||||
case 0x0017: // VT_UINT
|
||||
values[properties[i]] = tmp1.Deref(8, 8).toBuffer().readUInt32LE();
|
||||
break;
|
||||
//case 0x0014: // VT_I8
|
||||
// break;
|
||||
//case 0x0015: // VT_UI8
|
||||
// break;
|
||||
case 0x0008: // VT_BSTR
|
||||
values[properties[i]] = tmp1.Deref(8, 8).Deref().Wide2UTF8;
|
||||
break;
|
||||
default:
|
||||
console.info1('VARTYPE: ' + tmp1.toBuffer().readUInt16LE());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (values);
|
||||
}
|
||||
|
||||
function queryAsync(resourceString, queryString)
|
||||
{
|
||||
var p = new promise(require('promise').defaultInit);
|
||||
var resource = GM.CreateVariable(resourceString, { wide: true });
|
||||
var language = GM.CreateVariable("WQL", { wide: true });
|
||||
var query = GM.CreateVariable(queryString, { wide: true });
|
||||
var results = GM.CreatePointer();
|
||||
|
||||
p.refcount = 0;
|
||||
p.results = [];
|
||||
p.locator = require('win-com').createInstance(require('win-com').CLSIDFromString(CLSID_WbemAdministrativeLocator), require('win-com').IID_IUnknown);
|
||||
p.locator.funcs = require('win-com').marshalFunctions(p.locator, LocatorFunctions);
|
||||
p.services = require('_GenericMarshal').CreatePointer();
|
||||
if (p.locator.funcs.ConnectToServer(p.locator, resource, 0, 0, 0, 0, 0, 0, p.services).Val != 0) { throw ('Error calling ConnectToService'); }
|
||||
|
||||
p.services.funcs = require('win-com').marshalFunctions(p.services.Deref(), ServiceFunctions);
|
||||
p.handlers = require('win-com').marshalInterface(QueryAsyncHandler);
|
||||
p.handlers.p = p;
|
||||
|
||||
if (p.services.funcs.ExecQueryAsync(p.services.Deref(), language, query, WBEM_FLAG_BIDIRECTIONAL, 0, p.handlers).Val != 0) { throw ('Error in Query'); }
|
||||
return (p);
|
||||
}
|
||||
function query(resourceString, queryString)
|
||||
{
|
||||
var resource = GM.CreateVariable(resourceString, { wide: true });
|
||||
var language = GM.CreateVariable("WQL", { wide: true });
|
||||
var query = GM.CreateVariable(queryString, { wide: true });
|
||||
var results = GM.CreatePointer();
|
||||
|
||||
var locator = require('win-com').createInstance(require('win-com').CLSIDFromString(CLSID_WbemAdministrativeLocator), require('win-com').IID_IUnknown);
|
||||
locator.funcs = require('win-com').marshalFunctions(locator, LocatorFunctions);
|
||||
var services = require('_GenericMarshal').CreatePointer();
|
||||
if (locator.funcs.ConnectToServer(locator, resource, 0, 0, 0, 0, 0, 0, services).Val != 0) { throw ('Error calling ConnectToService'); }
|
||||
|
||||
services.funcs = require('win-com').marshalFunctions(services.Deref(), ServiceFunctions);
|
||||
if (services.funcs.ExecQuery(services.Deref(), language, query, WBEM_FLAG_BIDIRECTIONAL, 0, results).Val != 0) { throw ('Error in Query'); }
|
||||
|
||||
results.funcs = require('win-com').marshalFunctions(results.Deref(), ResultsFunctions);
|
||||
var returnedCount = GM.CreateVariable(8);
|
||||
var result = GM.CreatePointer();
|
||||
var ret = [];
|
||||
|
||||
while (results.funcs.Next(results.Deref(), WBEM_INFINITE, 1, result, returnedCount).Val == 0)
|
||||
{
|
||||
result.funcs = require('win-com').marshalFunctions(result.Deref(), ResultFunctions);
|
||||
|
||||
if (result.funcs.GetNames == null) { console.log('skipskip'); continue; }
|
||||
var nme = GM.CreatePointer();
|
||||
var rr = result.funcs.GetNames(result.Deref(), 0, WBEM_FLAG_ALWAYS, 0, nme);
|
||||
var len = nme.Deref().Deref(24, 4).toBuffer().readUInt32LE();
|
||||
|
||||
var nn = GM.CreatePointer();
|
||||
OleAut32.SafeArrayAccessData(nme.Deref(), nn);
|
||||
|
||||
var properties = [];
|
||||
var values = {};
|
||||
|
||||
for (var i = 0; i < len - 1; ++i)
|
||||
{
|
||||
properties.push(nn.Deref().increment(i * 8).Deref().Wide2UTF8);
|
||||
}
|
||||
|
||||
for(var i=0;i<properties.length;++i)
|
||||
{
|
||||
var tmp1 = GM.CreateVariable(24);
|
||||
if(result.funcs.Get(result.Deref(), GM.CreateVariable(properties[i], {wide: true}), 0, tmp1, 0, 0).Val == 0)
|
||||
{
|
||||
console.log('VARTYPE: ' + tmp1.toBuffer().readUInt16LE());
|
||||
switch(tmp1.toBuffer().readUInt16LE())
|
||||
{
|
||||
case 0x0000: // VT_EMPTY
|
||||
case 0x0001: // VT_NULL
|
||||
values[properties[i]] = null;
|
||||
break;
|
||||
case 0x0002: // VT_I2
|
||||
values[properties[i]] = tmp1.Deref(8, 8).toBuffer().readInt16LE();
|
||||
break;
|
||||
case 0x0003: // VT_I4
|
||||
case 0x0016: // VT_INT
|
||||
values[properties[i]] = tmp1.Deref(8, 8).toBuffer().readInt32LE();
|
||||
break;
|
||||
case 0x000B: // VT_BOOL
|
||||
values[properties[i]] = tmp1.Deref(8, 8).toBuffer().readInt32LE() != 0;
|
||||
break;
|
||||
case 0x000E: // VT_DECIMAL
|
||||
break;
|
||||
case 0x0010: // VT_I1
|
||||
values[properties[i]] = tmp1.Deref(8, 8).toBuffer().readInt8();
|
||||
break;
|
||||
case 0x0011: // VT_UI1
|
||||
values[properties[i]] = tmp1.Deref(8, 8).toBuffer().readUInt8();
|
||||
break;
|
||||
case 0x0012: // VT_UI2
|
||||
values[properties[i]] = tmp1.Deref(8, 8).toBuffer().readUInt16LE();
|
||||
break;
|
||||
case 0x0013: // VT_UI4
|
||||
case 0x0017: // VT_UINT
|
||||
values[properties[i]] = tmp1.Deref(8, 8).toBuffer().readUInt32LE();
|
||||
break;
|
||||
case 0x0014: // VT_I8
|
||||
break;
|
||||
case 0x0015: // VT_UI8
|
||||
break;
|
||||
case 0x0008: // VT_BSTR
|
||||
values[properties[i]] = tmp1.Deref(8, 8).Deref().Wide2UTF8;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ret.push(values);
|
||||
}
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
module.exports = { query: query, queryAsync: queryAsync };
|
||||
Reference in New Issue
Block a user