getdns_list* GNUtil::convertToList(Local<Array> array) { uint32_t len = array->Length(); getdns_list* result = getdns_list_create(); for (uint32_t i = 0; i < len; ++i) { size_t idx = getdns_list_get_length(result, &idx); Local<Value> val = array->Get(i); GetdnsType type = getGetdnsType(val); switch (type) { case IntType: getdns_list_set_int(result, idx, val->ToUint32()->Value()); break; case BoolType: if (val->IsTrue()) { getdns_list_set_int(result, idx, GETDNS_EXTENSION_TRUE); } else { getdns_list_set_int(result, idx, GETDNS_EXTENSION_FALSE); } break; case StringType: { struct getdns_bindata strdata; String::Utf8Value utf8Str(val->ToString()); int len = utf8Str.length(); strdata.data = (uint8_t*) *utf8Str; strdata.size = len; getdns_list_set_bindata(result, idx, &strdata); } break; case BinDataType: { struct getdns_bindata bdata; bdata.data = (uint8_t*) node::Buffer::Data(val); bdata.size = node::Buffer::Length(val); getdns_list_set_bindata(result, idx, &bdata); } break; case ListType: { Local<Array> subArray = Local<Array>::Cast(val); struct getdns_list* sublist = GNUtil::convertToList(subArray); getdns_list_set_list(result, idx, sublist); getdns_list_destroy(sublist); } break; case DictType: { Local<Object> subObj = val->ToObject(); struct getdns_dict* subdict = GNUtil::convertToDict(subObj); if (subdict) { getdns_list_set_dict(result, idx, subdict); getdns_dict_destroy(subdict); } } break; default: break; } } return result; }
/* * Prototype: * Stalker.removeCallProbe(id) * * Docs: * TBW * * Example: * TBW */ static void gum_v8_stalker_on_remove_call_probe ( const FunctionCallbackInfo<Value> & info) { GumV8Stalker * self = static_cast<GumV8Stalker *> ( info.Data ().As<External> ()->Value ()); Isolate * isolate = info.GetIsolate (); Local<Value> id = info[0]; if (!id->IsUint32 ()) { isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 (isolate, "Stalker.removeCallProbe: argument must be a probe id"))); return; } gum_stalker_remove_call_probe (_gum_v8_stalker_get (self), id->ToUint32 ()->Value ()); return; }
getdns_dict* GNUtil::convertToDict(Local<Object> obj) { if (obj->IsRegExp() || obj->IsDate() || obj->IsFunction() || obj->IsUndefined() || obj->IsNull() || obj->IsArray()) { return NULL; } Local<Array> names = obj->GetOwnPropertyNames(); getdns_dict* result = getdns_dict_create(); for(unsigned int i = 0; i < names->Length(); i++) { Local<Value> nameVal = names->Get(i); Nan::Utf8String name(nameVal); Local<Value> val = obj->Get(nameVal); GetdnsType type = getGetdnsType(val); switch (type) { case IntType: getdns_dict_set_int(result, *name, val->ToUint32()->Value()); break; case BoolType: if (val->IsTrue()) { getdns_dict_set_int(result, *name, GETDNS_EXTENSION_TRUE); } else { getdns_dict_set_int(result, *name, GETDNS_EXTENSION_FALSE); } break; case StringType: { struct getdns_bindata strdata; String::Utf8Value utf8Str(val->ToString()); int len = utf8Str.length(); strdata.data = (uint8_t*) *utf8Str; strdata.size = len; getdns_dict_set_bindata(result, *name, &strdata); } break; case BinDataType: { struct getdns_bindata bdata; bdata.data = (uint8_t*) node::Buffer::Data(val); bdata.size = node::Buffer::Length(val); getdns_dict_set_bindata(result, *name, &bdata); } break; case ListType: { Local<Array> subArray = Local<Array>::Cast(val); struct getdns_list* sublist = GNUtil::convertToList(subArray); getdns_dict_set_list(result, *name, sublist); getdns_list_destroy(sublist); } break; case DictType: { Local<Object> subObj = val->ToObject(); struct getdns_dict* subdict = GNUtil::convertToDict(subObj); if (subdict) { getdns_dict_set_dict(result, *name, subdict); getdns_dict_destroy(subdict); } } break; default: break; } } return result; }