bool GetCallMemoryCopy(PEdgeCall *edge, Exp **target, Exp **source, Exp **length) { Variable *name = edge->GetDirectFunction(); if (!name) return false; MemcpyFunctionInfo *cur_memcpy = g_memcpy_functions; while (cur_memcpy->name) { if (TextNameMatch(name, cur_memcpy->name)) { *target = GetArgumentValue(cur_memcpy->target_arg); *source = GetArgumentValue(cur_memcpy->source_arg); *length = GetArgumentValue(cur_memcpy->length_arg); return true; } cur_memcpy++; } ReallocFunctionInfo *cur_realloc = g_realloc_functions; while (cur_realloc->name) { if (TextNameMatch(name, cur_realloc->name)) { *target = GetReturnedValue(); *source = GetArgumentValue(cur_realloc->base_arg); (*source)->IncRef(); *length = GetByteUpperBound(*source); return true; } cur_realloc++; } return false; }
result_t querystring_base::stringify(v8::Local<v8::Object> obj, exlib::string sep, exlib::string eq, v8::Local<v8::Object> opt, exlib::string& retVal) { StringBuffer bufs; v8::Local<v8::Array> ks = obj->GetPropertyNames(); int32_t len = ks->Length(); int32_t i; result_t hr; for (i = 0; i < len; i++) { exlib::string strKey, strValue, str; v8::Local<v8::Array> vs; v8::Local<v8::Value> k = ks->Get(i); v8::Local<v8::Value> v = obj->Get(k); GetArgumentValue(k, strKey); encoding_base::encodeURIComponent(strKey, strKey); hr = GetArgumentValue(v, vs, true); if (hr >= 0) { int32_t len1 = vs->Length(); int32_t i1; for (i1 = 0; i1 < len1; i1++) { hr = GetArgumentValue(vs->Get(i1), strValue); if (hr < 0) return hr; encoding_base::encodeURIComponent(strValue, strValue); if (bufs.size() > 0) bufs.append(sep); bufs.append(strKey); bufs.append(eq); bufs.append(strValue); } } else { hr = GetArgumentValue(v, strValue); if (hr < 0) return hr; encoding_base::encodeURIComponent(strValue, strValue); if (bufs.size() > 0) bufs.append(sep); bufs.append(strKey); bufs.append(eq); bufs.append(strValue); } } retVal = bufs.str(); return 0; }
result_t CustomExtLoader::compile(SandBox::Context* ctx, Buffer_base* src, exlib::string name, exlib::string arg_names, v8::Local<v8::Script>& script) { Isolate* isolate = ctx->m_sb->holder(); v8::Local<v8::Value> require_fn = ctx->m_sb->GetPrivate(SandBox::_get_extloader_pname(m_ext)); exlib::string strScript; // read filecontent and compile to strScript :start v8::Local<v8::Value> transpileArgs[2]; src->valueOf(transpileArgs[0]); v8::Local<v8::Object> requireInfo = v8::Object::New(isolate->m_isolate); transpileArgs[1] = requireInfo; requireInfo->Set(isolate->NewString("filename"), isolate->NewString(name)); v8::Local<v8::Value> fileContent = v8::Local<v8::Function>::Cast(require_fn)->Call(v8::Undefined(isolate->m_isolate), 2, transpileArgs); if (fileContent.IsEmpty()) return CALL_E_JAVASCRIPT; result_t hr = GetArgumentValue(fileContent, strScript, true); if (hr < 0) return CHECK_ERROR(hr); // read filecontent and compile to strScript :end obj_ptr<Buffer_base> buf = new Buffer(strScript); return JsLoader::compile(ctx, buf, name, arg_names, script); }
result_t HeapGraphEdgeProxy::get_name(std::string& retVal) { if (m_snapshot == 0) return CHECK_ERROR(CALL_E_INVALIDARG); return GetArgumentValue(m_edge->GetName(), retVal); }
result_t Buffer::write(v8::Local<v8::Array> datas) { int32_t sz = datas->Length(); if (sz) { int32_t i; result_t hr; std::string str; str.resize(sz); for (i = 0; i < sz; i ++) { v8::Local<v8::Value> v = datas->Get(i); int32_t num; hr = GetArgumentValue(v, num); if (hr < 0) return hr; if (num < 0 || num > 256) return CHECK_ERROR(CALL_E_OUTRANGE); str[i] = num; } extMemory((int) sz); m_data.append(str); } return 0; }
void AMXStackFramePrinter::PrintArgumentValue(const AMXStackFrame &frame, int index) { cell value = GetArgumentValue(frame.amx(), frame.address(), index); char old_fill = stream_->fill('0'); *stream_ << std::hex << "0x" << std::setw(kCellWidthChars) << value << std::dec; stream_->fill(old_fill); }
vector<Value*> AssertionSiteInstrumenter::CollectArgs( Instruction *Before, const Automaton& A, Module& Mod, IRBuilder<>& Builder) { // Find named values to be passed to instrumentation. std::map<string,Value*> ValuesInScope; for (auto G = Mod.global_begin(); G != Mod.global_end(); G++) ValuesInScope[G->getName()] = G; auto *Fn = Before->getParent()->getParent(); for (auto& Arg : Fn->getArgumentList()) ValuesInScope[Arg.getName()] = &Arg; auto& EntryBlock(*Fn->begin()); for (auto& I : EntryBlock) { auto *Inst = dyn_cast<AllocaInst>(&I); if (!Inst) break; ValuesInScope[Inst->getName()] = Builder.CreateLoad(Inst); } int ArgSize = 0; for (auto& Arg : A.getAssertion().argument()) if (!Arg.free()) ArgSize = std::max(ArgSize + 1, Arg.index()); vector<Value*> Args(ArgSize, NULL); for (auto& Arg : A.getAssertion().argument()) { if (Arg.free()) continue; string Name(BaseName(Arg)); if (ValuesInScope.find(Name) == ValuesInScope.end()) { string s; raw_string_ostream Out(s); for (auto v : ValuesInScope) { Out << " \"" << v.first << "\": "; v.second->getType()->print(Out); Out << "\n"; } panic("assertion references non-existent variable '" + BaseName(Arg) + "'; was it defined under '#ifdef TESLA'?\n\n" "Variables in scope are:\n" + Out.str()); } Args[Arg.index()] = GetArgumentValue(ValuesInScope[Name], Arg, Builder, true); } return Args; }
bool GetCallMemoryZero(PEdgeCall *edge, Exp **target, Exp **length) { Variable *name = edge->GetDirectFunction(); if (!name) return false; MemsetFunctionInfo *cur_memset = g_memset_functions; while (cur_memset->name) { if (TextNameMatch(name, cur_memset->name)) { // only handling the case where the value argument passed in is zero. if (cur_memset->value_arg < edge->GetArgumentCount()) { Exp *value = edge->GetArgument(cur_memset->value_arg); if (ExpInt *nvalue = value->IfInt()) { long value_int; if (nvalue->GetInt(&value_int) && value_int == 0) { *target = GetArgumentValue(cur_memset->target_arg); *length = GetArgumentValue(cur_memset->length_arg); return true; } } } } cur_memset++; } const char **cur_zero_allocator = g_zero_allocator_functions; while (*cur_zero_allocator) { if (TextNameMatch(name, *cur_zero_allocator)) { Try(GetAllocationFunction(name, target, length)); return true; } cur_zero_allocator++; } return false; }
bool GetAllocationFunction(Variable *name, Exp **object, Exp **size) { MallocFunctionInfo *cur_malloc = g_malloc_functions; while (cur_malloc->name) { if (TextNameMatch(name, cur_malloc->name)) { *object = GetReturnedValue(); *size = GetArgumentValue(cur_malloc->size_arg); return true; } cur_malloc++; } FixedMallocFunctionInfo *cur_fixed = g_fixed_malloc_functions; while (cur_fixed->name) { if (TextNameMatch(name, cur_fixed->name)) { *object = GetReturnedValue(); *size = Exp::MakeInt(cur_fixed->size); return true; } cur_fixed++; } CallocFunctionInfo *cur_calloc = g_calloc_functions; while (cur_calloc->name) { if (TextNameMatch(name, cur_calloc->name)) { Exp *size_one = GetArgumentValue(cur_calloc->size_arg_one); Exp *size_two = GetArgumentValue(cur_calloc->size_arg_two); *object = GetReturnedValue(); *size = Exp::MakeBinop(cur_calloc->binop, size_one, size_two); return true; } cur_calloc++; } return false; }
void FillBakedModset(BlockModset *mod) { Variable *name = mod->GetId()->BaseVar(); TerminateFunctionInfo *cur_term = g_terminate_functions; while (cur_term->name) { if (TextNameMatch(name, cur_term->name)) { Exp *arg_exp = GetArgumentValue(cur_term->terminate_arg); Exp *kind = GetNullTerminate(NULL); mod->AddModset(arg_exp, kind); } cur_term++; } }
result_t Buffer_base::concat(v8::Local<v8::Array> buflist, int32_t cutLength, obj_ptr<Buffer_base>& retVal) { result_t hr = 0; int32_t buf_length; int32_t offset = 0; int32_t total_length = cutLength; int32_t sz = buflist->Length(); if (!sz) return 0; if (cutLength < -1) return CHECK_ERROR(CALL_E_INVALIDARG); std::string str; Isolate* isolate = Isolate::current(); for (int32_t i = 0; i < sz; i ++) { v8::Local<v8::Value> v = buflist->Get(i); obj_ptr<Buffer_base> vdata; hr = GetArgumentValue(isolate->m_isolate, v, vdata); if (hr < 0) return CHECK_ERROR(hr); std::string vstr; vdata -> toString(vstr); buf_length = (int32_t) vstr.length(); if (-1 == cutLength) total_length = offset + buf_length; if (offset + buf_length <= total_length) { str.append(vstr.c_str(), buf_length); offset += buf_length; } else { str.append(vstr.c_str(), total_length - offset); offset = total_length; break; } } obj_ptr<Buffer> bNew = new Buffer(str); bNew->extMemory(offset); retVal = bNew; return hr; }
void AMXStackFramePrinter::PrintArgumentValue(const AMXStackFrame &frame, const AMXDebugSymbol &arg, int index) { std::string tag_name = debug_info_.GetTagName(arg.GetTag()); cell value = GetArgumentValue(frame, index); if (arg.IsVariable()) { PrintValue(tag_name, value); return; } stream_ << "@"; PrintAddress(value); if (arg.IsReference()) { if (cell *ptr = GetDataPtr(frame.amx(), value)) { stream_ << " "; PrintValue(tag_name, *ptr); } return; } if (arg.IsArray() || arg.IsArrayRef()) { std::vector<AMXDebugSymbolDim> dims = arg.GetDims(); // Try to filter out non-printable arrays (e.g. non-strings). // This doesn't work 100% of the time, but it's better than nothing. if (dims.size() == 1 && tag_name == "_" && debug_info_.GetTagName(dims[0].GetTag()) == "_") { std::string string; bool packed; GetStringContents(frame.amx(), value, dims[0].GetSize(), string, packed); stream_ << (packed ? " !" : " "); static const std::size_t kMaxString = 80; if (string.length() > kMaxString) { string.replace(kMaxString, string.length() - kMaxString, "..."); } stream_ << "\"" << string << "\""; } } }
result_t util_base::isPrimitive(v8::Local<v8::Value> v, bool& retVal) { retVal = false; if (v->IsNullOrUndefined()) { retVal = true; } else { result_t hr; Isolate* isolate = Isolate::current(); exlib::string type; hr = GetArgumentValue(v->TypeOf(isolate->m_isolate), type); if (hr < 0) return CHECK_ERROR(hr); if (type != "object" && type != "function") { retVal = true; } } return 0; }
result_t base64vlq_base::encode(v8::Local<v8::Array> data, exlib::string& retVal) { int32_t len = data->Length(); result_t hr; for (int32_t i = 0; i < len; i++) { int32_t num; hr = GetArgumentValue(data->Get(i), num); if (hr < 0) return CHECK_ERROR(hr); hr = encode(num, retVal); if (hr < 0) return hr; } return 0; }
result_t GetArgumentValue(v8::Local<v8::Value> v, obj_ptr<Buffer_base> &vr, bool bStrict) { vr = Buffer_base::getInstance(v); if (vr == NULL) { if (bStrict) return CALL_E_INVALIDARG; std::string str; result_t hr = GetArgumentValue(v, str); if (hr < 0) return hr; vr = new Buffer(str); } return 0; }
void AMXStackFramePrinter::PrintArgumentValue(const AMXStackFrame &frame, const AMXDebugSymbol &arg, int index) { std::string tag_name = debug_info_->GetTagName(arg.GetTag()); cell value = GetArgumentValue(frame.amx(), frame.address(), index); if (arg.IsVariable()) { if (tag_name == "bool") { *stream_ << (value ? "true" : "false"); } else if (tag_name == "Float") { *stream_ << std::fixed << std::setprecision(5) << amx_ctof(value); } else { *stream_ << value; } } else { std::vector<AMXDebugSymbolDim> dims = arg.GetDims(); // For arrays/references we just output their AMX address. char old_fill = stream_->fill('0'); *stream_ << "@0x" << std::hex << std::setw(kCellWidthChars) << value << std::dec; stream_->fill(old_fill); if ((arg.IsArray() || arg.IsArrayRef()) && dims.size() == 1 && tag_name == "_" && debug_info_->GetTagName(dims[0].GetTag()) == "_") { std::string string; bool packed; GetStringContents(frame.amx(), value, dims[0].GetSize(), string, packed); *stream_ << (packed ? " !" : " "); static const std::size_t kMaxString = 30; if (string.length() > kMaxString) { string.replace(kMaxString, string.length() - kMaxString, "..."); } *stream_ << "\"" << string << "\""; } } }
inline result_t GetArray(v8::Local<v8::Value> v, QuickArray<T> &n) { if (v.IsEmpty() || !v->IsArray()) return CALL_E_INVALIDARG; v8::Local<v8::Array> a = v8::Local<v8::Array>::Cast(v); result_t hr; for (int32_t i = 0; i < (int32_t)a->Length(); i ++) { T vr; hr = GetArgumentValue(a->Get(i), vr, true); if (hr < 0) return hr; n.append(vr); } return 0; }
result_t HttpFileHandler::set_mimes(v8::Local<v8::Object> mimes) { v8::Local<v8::Array> keys = mimes->GetPropertyNames(); int32_t len = keys->Length(); int32_t i; result_t hr; for (i = 0; i < len; i++) { v8::Local<v8::Value> ks = keys->Get(i); exlib::string v; hr = GetArgumentValue(mimes->Get(ks), v); if (hr < 0) return CHECK_ERROR(hr); m_mimes.insert(std::pair<exlib::string, exlib::string>(*v8::String::Utf8Value(ks), v)); } return 0; }
result_t Redis::unsub(v8::Local<v8::Array> &channels, int32_t cmd) { int32_t sz = channels->Length(); int32_t i; for (i = 0; i < sz; i ++) { v8::Local<v8::Value> key = channels->Get(i); std::string s; GetArgumentValue(key, s); s = s_cmd[cmd][1] + s; int32_t n = 0; off(s.c_str(), n); m_funcs.erase(s); } Variant v; return doCommand(s_cmd[cmd][0], channels, v); }
result_t Redis::_map(v8::Local<v8::Object> &map, int32_t cmd) { m_subMode = 1; Isolate* isolate = holder(); v8::Local<v8::Array> channels = map->GetPropertyNames(); int32_t sz = channels->Length(); int32_t i; v8::Local<v8::Array> subs = v8::Array::New(isolate->m_isolate); int32_t count = 0; for (i = 0; i < sz; i ++) { v8::Local<v8::Value> channel = channels->Get(i); std::string s; GetArgumentValue(channel, s); s = s_cmd[cmd][1] + s; v8::Local<v8::Value> value = map->Get(channel); if (!value->IsFunction()) return CHECK_ERROR(CALL_E_TYPEMISMATCH); v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(value); if ((cmd & 1) ? unregsub(s, func) : regsub(s, func)) subs->Set(count ++, channel); } if (!count) return 0; Variant v; return doCommand(s_cmd[cmd][0], subs, v); }
void AMXStackFramePrinter::PrintArgumentValue(const AMXStackFrame &frame, int index) { stream_ << GetArgumentValue(frame, index); }
result_t HeapGraphNode::get_name(std::string& retVal) { v8::Local<v8::Value> v = m_graphnode->GetName(); return GetArgumentValue(v, retVal); }
void AsiMS2000::parseXYZArgs(AxisSettingsF *units) { units->x = atof(GetArgumentValue('X')); units->y = atof(GetArgumentValue('Y')); units->z = atof(GetArgumentValue('Z')); }
bool repl_command(std::string &line, v8::Local<v8::Array> cmds) { _parser p(line); std::string cmd_word; result_t hr; int32_t len = cmds->Length(); int32_t i; p.skipSpace(); p.getWord(cmd_word); if (!qstrcmp(cmd_word.c_str(), ".help")) { std::string help_str = ".exit Exit the repl\n" ".help Show repl options\n" ".info Show fibjs build information"; Isolate* isolate = Isolate::current(); for (i = 0; i < len; i ++) { v8::Local<v8::Value> v = cmds->Get(i); v8::Local<v8::Object> o; std::string cmd; std::string help; hr = GetArgumentValue(v, o, true); if (hr >= 0) { hr = GetConfigValue(isolate->m_isolate, o, "cmd", cmd, true); if (hr >= 0) hr = GetConfigValue(isolate->m_isolate, o, "help", help, true); } if (hr < 0) { output(console_base::_ERROR, "Invalid cmds argument."); return false; } cmd.append(10, ' '); help_str = help_str + "\n" + cmd.substr(0, 10) + help; } output(console_base::_INFO, help_str); return true; } if (!qstrcmp(cmd_word.c_str(), ".exit")) return false; if (!qstrcmp(cmd_word.c_str(), ".info")) { v8::Local<v8::Object> o; util_base::buildInfo(o); console_base::dir(o); return true; } Isolate* isolate = Isolate::current(); for (i = 0; i < len; i ++) { v8::Local<v8::Value> v = cmds->Get(i); v8::Local<v8::Object> o; std::string cmd; v8::Local<v8::Function> exec; hr = GetArgumentValue(v, o, true); if (hr >= 0) { hr = GetConfigValue(isolate->m_isolate, o, "cmd", cmd, true); if (hr >= 0) hr = GetConfigValue(isolate->m_isolate, o, "exec", exec, true); } if (hr < 0) { output(console_base::_ERROR, "Invalid cmds argument."); return false; } if (!qstrcmp(cmd_word.c_str(), cmd.c_str())) { v8::Local<v8::Array> argv = v8::Array::New(isolate->m_isolate); int32_t n = 0; while (!cmd_word.empty()) { argv->Set(n ++, GetReturnValue(isolate->m_isolate, cmd_word)); p.skipSpace(); p.getWord(cmd_word); } TryCatch try_catch; v = argv; v = exec->Call(o, 1, &v); if (v.IsEmpty()) ReportException(try_catch, 0); return true; } } output(console_base::_ERROR, cmd_word + ": command not found."); return true; }
static DWORD ParseLeaveArgs( IN int argc, IN const char *argv[], OUT PLEAVE_ARGS pArgs ) { DWORD dwError = 0; PCSTR programName = NULL; PCSTR option = NULL; LW_ARGV_CURSOR cursor; SHOW_USAGE_CALLBACK ShowUsageHelp = ShowLeaveUsageHelp; SHOW_USAGE_CALLBACK ShowUsageError = ShowLeaveUsageError; memset(pArgs, 0, sizeof(*pArgs)); LwArgvCursorInit(&cursor, argc, argv); programName = LwArgvCursorPop(&cursor); // Process options: for (;;) { option = PopNextOption(&cursor); if (!option) { break; } else if (IsHelpOption(option)) { ShowUsageHelp(programName); } else if (!strcmp("--multiple", option)) { SetFlag(pArgs->JoinFlags, LSA_NET_JOIN_DOMAIN_MULTIPLE); dwError = GetOptionValue(programName, ShowUsageError, &cursor, option, &pArgs->pszDomain); GOTO_CLEANUP_ON_WINERROR(dwError); LwStrToUpper(pArgs->pszDomain); } else { fprintf(stderr, "Unrecognized option: %s\n", option); ShowUsageError(programName); } } // Optional arguments dwError = GetArgumentValue(programName, ShowUsageError, &cursor, NULL, &pArgs->pszUsername); assert(!dwError); dwError = GetArgumentValue(programName, ShowUsageError, &cursor, NULL, &pArgs->pszPassword); assert(!dwError); if (LwArgvCursorRemaining(&cursor)) { fprintf(stderr, "Too many arguments.\n"); ShowUsageError(programName); } // Initialize implicit domain argument. if (!pArgs->pszDomain) { dwError = GetCurrentDomain(&pArgs->pszDomain); if (NERR_SetupNotJoined == dwError) { fprintf(stderr, "The computer is not joined to a domain.\n"); exit(1); } GOTO_CLEANUP_ON_WINERROR(dwError); } // If USERNAME was specified, clean it up and get password // as needed. if (pArgs->pszUsername) { dwError = CleanupUsername(pArgs->pszDomain, &pArgs->pszUsername); GOTO_CLEANUP_ON_WINERROR(dwError); if (!pArgs->pszPassword) { dwError = PromptPassword(pArgs->pszUsername, &pArgs->pszPassword); GOTO_CLEANUP_ON_WINERROR(dwError); } } cleanup: if (dwError) { FreeLeaveArgsContents(pArgs); } return dwError; }
static DWORD ParseJoinArgs( IN int argc, IN const char *argv[], OUT PJOIN_ARGS pArgs ) { DWORD dwError = 0; PCSTR programName = NULL; PCSTR option = NULL; LW_ARGV_CURSOR cursor; SHOW_USAGE_CALLBACK ShowUsageHelp = ShowJoinUsageHelp; SHOW_USAGE_CALLBACK ShowUsageError = ShowJoinUsageError; memset(pArgs, 0, sizeof(*pArgs)); LwArgvCursorInit(&cursor, argc, argv); programName = LwArgvCursorPop(&cursor); // Process options: for (;;) { option = PopNextOption(&cursor); if (!option) { break; } else if (IsHelpOption(option)) { ShowUsageHelp(programName); } else if (!strcmp("--name", option)) { dwError = GetOptionValue(programName, ShowUsageError, &cursor, option, &pArgs->pszMachineName); GOTO_CLEANUP_ON_WINERROR(dwError); } else if (!strcmp("--dnssuffix", option)) { dwError = GetOptionValue(programName, ShowUsageError, &cursor, option, &pArgs->pszDnsSuffix); GOTO_CLEANUP_ON_WINERROR(dwError); } else if (!strcmp("--ou", option)) { dwError = GetOptionValue(programName, ShowUsageError, &cursor, option, &pArgs->pszOu); GOTO_CLEANUP_ON_WINERROR(dwError); } else if (!strcmp("--osname", option)) { dwError = GetOptionValue(programName, ShowUsageError, &cursor, option, &pArgs->pszOsName); GOTO_CLEANUP_ON_WINERROR(dwError); } else if (!strcmp("--osversion", option)) { dwError = GetOptionValue(programName, ShowUsageError, &cursor, option, &pArgs->pszOsVersion); GOTO_CLEANUP_ON_WINERROR(dwError); } else if (!strcmp("--osservicepack", option)) { dwError = GetOptionValue(programName, ShowUsageError, &cursor, option, &pArgs->pszOsServicePack); GOTO_CLEANUP_ON_WINERROR(dwError); } else if (!strcmp("--notimesync", option)) { SetFlag(pArgs->JoinFlags, LSA_NET_JOIN_DOMAIN_NOTIMESYNC); } else if (!strcmp("--multiple", option)) { SetFlag(pArgs->JoinFlags, LSA_NET_JOIN_DOMAIN_NOTIMESYNC); SetFlag(pArgs->JoinFlags, LSA_NET_JOIN_DOMAIN_MULTIPLE); } else { fprintf(stderr, "Unrecognized option: %s\n", option); ShowUsageError(programName); } } // Process arguments: dwError = GetArgumentValue(programName, ShowUsageError, &cursor, "DOMAIN", &pArgs->pszDomain); GOTO_CLEANUP_ON_WINERROR(dwError); LwStrToUpper(pArgs->pszDomain); dwError = GetArgumentValue(programName, ShowUsageError, &cursor, "USERNAME", &pArgs->pszUsername); GOTO_CLEANUP_ON_WINERROR(dwError); // Optional argument dwError = GetArgumentValue(programName, ShowUsageError, &cursor, NULL, &pArgs->pszPassword); assert(!dwError); if (LwArgvCursorRemaining(&cursor)) { fprintf(stderr, "Too many arguments.\n"); ShowUsageError(programName); } // Initialize missing options as needed if (!pArgs->pszDnsSuffix) { dwError = LwAllocateString(pArgs->pszDomain, &pArgs->pszDnsSuffix); GOTO_CLEANUP_ON_WINERROR(dwError); } LwStrToLower(pArgs->pszDnsSuffix); if (!pArgs->pszMachineName) { dwError = GetHostname(&pArgs->pszMachineName); GOTO_CLEANUP_ON_WINERROR(dwError); } if (!pArgs->pszOsName || !pArgs->pszOsVersion || !pArgs->pszOsServicePack) { dwError = GetOsInfo( pArgs->pszOsName ? NULL : &pArgs->pszOsName, pArgs->pszOsVersion ? NULL : &pArgs->pszOsVersion, pArgs->pszOsServicePack ? NULL : &pArgs->pszOsServicePack); GOTO_CLEANUP_ON_WINERROR(dwError); } dwError = CleanupUsername(pArgs->pszDomain, &pArgs->pszUsername); GOTO_CLEANUP_ON_WINERROR(dwError); if (!pArgs->pszPassword) { dwError = PromptPassword(pArgs->pszUsername, &pArgs->pszPassword); GOTO_CLEANUP_ON_WINERROR(dwError); } cleanup: if (dwError) { FreeJoinArgsContents(pArgs); } return dwError; }
result_t util_base::omit(v8::Local<v8::Value> v, const v8::FunctionCallbackInfo<v8::Value> &args, v8::Local<v8::Object> &retVal) { Isolate* isolate = Isolate::current(); if (v->IsUndefined() || v->IsNull()) { retVal = v8::Object::New(isolate->m_isolate); return 0; } if (!v->IsObject()) return CHECK_ERROR(CALL_E_TYPEMISMATCH); v8::Local<v8::Object> obj = v->ToObject(); std::map<std::string, bool> _map; int32_t argc = args.Length(); int32_t i, j; result_t hr; for (i = 1; i < argc; i ++) { if (args[i]->IsArray()) { v8::Local<v8::Array> arr = v8::Local<v8::Array>::Cast(args[i]); int32_t len = arr->Length(); for (j = 0; j < len; j ++) { std::string k; hr = GetArgumentValue(arr->Get(j), k); if (hr < 0) return CHECK_ERROR(hr); _map.insert(std::pair<std::string, bool>(k, true)); } } else { std::string k; hr = GetArgumentValue(args[i], k); if (hr < 0) return CHECK_ERROR(hr); _map.insert(std::pair<std::string, bool>(k, true)); } } v8::Local<v8::Array> keys = obj->GetPropertyNames(); int32_t len = keys->Length(); v8::Local<v8::Object> obj1 = v8::Object::New(isolate->m_isolate); for (i = 0; i < len; i ++) { v8::Local<v8::Value> key = keys->Get(i); if (_map.find(*v8::String::Utf8Value(key)) == _map.end()) obj1->Set(key, obj->Get(key)); } retVal = obj1; return 0; }
void FillBakedSummary(BlockSummary *sum) { Variable *name = sum->GetId()->BaseVar(); // primitive memory allocator. Exp *object; Exp *size; if (GetAllocationFunction(name, &object, &size)) { Exp *bound = GetByteUpperBound(object); // the upper bound is greater or equal to zero. bound->IncRef(); Exp *zero = Exp::MakeInt(0); Bit *bound_nonneg = Exp::MakeCompareBit(B_GreaterEqual, bound, zero); sum->AddAssume(bound_nonneg); // the upper bound of the object is exactly equal to size. Bit *bound_equal = Exp::MakeCompareBit(B_Equal, bound, size); sum->AddAssume(bound_equal); // TODO: it would be nice to assert the offset is exactly equal // to zero for the UI; however, this can lead to spurious contradiction // if unaligned pointers are in use. } // return value bears some relation with an argument. ReturnCompareFunctionInfo *cur_return = g_return_compare_functions; while (cur_return->name) { if (TextNameMatch(name, cur_return->name)) { Exp *ret_exp = GetReturnedValue(); Exp *arg_exp = GetArgumentValue(cur_return->compare_arg); Type *type = NULL; if (IsPointerBinop(cur_return->binop)) type = Type::MakeInt(1, true); Bit *bit = Exp::MakeCompareBit(cur_return->binop, ret_exp, arg_exp, type); sum->AddAssume(bit); } cur_return++; } // return value is NULL terminated. const char **cur_ret_term = g_return_terminated_functions; while (*cur_ret_term) { if (TextNameMatch(name, *cur_ret_term)) { Exp *ret_exp = GetReturnedValue(); Exp *terminate = GetNullTerminate(ret_exp); Exp *zero = Exp::MakeInt(0); Bit *bit = Exp::MakeCompareBit(B_GreaterEqual, terminate, zero); sum->AddAssume(bit); } cur_ret_term++; } // an argument is NULL terminated. TerminateFunctionInfo *cur_term = g_terminate_functions; while (cur_term->name) { if (TextNameMatch(name, cur_term->name) && cur_term->terminates) { Exp *arg_exp = GetArgumentValue(cur_term->terminate_arg); Exp *kind = GetNullTerminate(NULL); Exp *exit_term = Exp::MakeExit(arg_exp, kind); Exp *zero = Exp::MakeInt(0); Bit *bit = Exp::MakeCompareBit(B_GreaterEqual, exit_term, zero); sum->AddAssume(bit); } cur_term++; } // strchr constraint: char_arg != 0 => zterm(ret) > 0. StrchrFunctionInfo *cur_strchr = g_strchr_functions; while (cur_strchr->name) { if (TextNameMatch(name, cur_strchr->name)) { Exp *arg_exp = GetArgumentValue(cur_strchr->char_arg); Exp *ret_exp = GetReturnedValue(); Exp *terminate = GetNullTerminate(ret_exp); Exp *zero = Exp::MakeInt(0); zero->IncRef(); Bit *left = Exp::MakeCompareBit(B_NotEqual, arg_exp, zero); Bit *right = Exp::MakeCompareBit(B_GreaterThan, terminate, zero); Bit *bit = Bit::MakeImply(left, right); sum->AddAssume(bit); } cur_strchr++; } // strlen constraint: ret >= 0 && ret == zterm(arg) StrlenFunctionInfo *cur_strlen = g_strlen_functions; while (cur_strlen->name) { if (TextNameMatch(name, cur_strlen->name)) { Exp *arg_exp = GetArgumentValue(cur_strlen->string_arg); Exp *retval = GetReturnedValue(); Exp *terminate = GetNullTerminate(arg_exp); retval->IncRef(); Exp *zero = Exp::MakeInt(0); Bit *ge_zero = Exp::MakeCompareBit(B_GreaterEqual, retval, zero); sum->AddAssume(ge_zero); Bit *eq_term = Exp::MakeCompareBit(B_Equal, retval, terminate); sum->AddAssume(eq_term); } cur_strlen++; } // strcmp constraint: ret == 0 ==> zterm(arg_one) == zterm(arg_two) StrcmpFunctionInfo *cur_strcmp = g_strcmp_functions; while (cur_strcmp->name) { if (TextNameMatch(name, cur_strcmp->name)) { Exp *arg_one_exp = GetArgumentValue(cur_strcmp->string_arg_one); Exp *arg_two_exp = GetArgumentValue(cur_strcmp->string_arg_two); Exp *retval = GetReturnedValue(); Exp *terminate_one = GetNullTerminate(arg_one_exp); Exp *terminate_two = GetNullTerminate(arg_two_exp); Exp *zero = Exp::MakeInt(0); Bit *left = Exp::MakeCompareBit(B_Equal, retval, zero); Bit *right = Exp::MakeCompareBit(B_Equal, terminate_one, terminate_two); Bit *bit = Bit::MakeImply(left, right); sum->AddAssume(bit); } cur_strcmp++; } // strncmp constraint: ret == 0 ==> (zterm(arg_one) == zterm(arg_two) // || (zterm(arg_one) >= length_arg && // zterm(arg_two) >= length_arg)) StrncmpFunctionInfo *cur_strncmp = g_strncmp_functions; while (cur_strncmp->name) { if (TextNameMatch(name, cur_strncmp->name)) { Exp *arg_one_exp = GetArgumentValue(cur_strncmp->string_arg_one); Exp *arg_two_exp = GetArgumentValue(cur_strncmp->string_arg_two); Exp *length_exp = GetArgumentValue(cur_strncmp->length_arg); Exp *retval = GetReturnedValue(); Exp *terminate_one = GetNullTerminate(arg_one_exp); Exp *terminate_two = GetNullTerminate(arg_two_exp); Exp *zero = Exp::MakeInt(0); terminate_one->IncRef(); terminate_two->IncRef(); length_exp->IncRef(); Bit *left = Exp::MakeCompareBit(B_Equal, retval, zero); Bit *term_eq = Exp::MakeCompareBit(B_Equal, terminate_one, terminate_two); Bit *ge_one = Exp::MakeCompareBit(B_GreaterEqual, terminate_one, length_exp); Bit *ge_two = Exp::MakeCompareBit(B_GreaterEqual, terminate_two, length_exp); Bit *ge_both = Bit::MakeAnd(ge_one, ge_two); Bit *right = Bit::MakeOr(term_eq, ge_both); Bit *bit = Bit::MakeImply(left, right); sum->AddAssume(bit); } cur_strncmp++; } }
result_t SubProcess::create(const char* command, v8::Local<v8::Array> args, v8::Local<v8::Object> opts, bool redirect, obj_ptr<SubProcess_base>& retVal) { result_t hr; PROCESS_INFORMATION pi; STARTUPINFOW si; int32_t len = args->Length(); int32_t i; HANDLE cin_pipe[2] = {0}; HANDLE cout_pipe[2] = {0}; wstring wstr(L"cmd /C "); wstr.append(utf8to16String(command)); Isolate* isolate = Isolate::current(); for (i = 0; i < len; i ++) { std::string str; hr = GetArgumentValue(isolate->m_isolate, args->Get(i), str); if (hr < 0) return hr; wstr.append(1, ' '); wstr.append(utf8to16String(str)); } ZeroMemory(&si, sizeof(STARTUPINFO)); si.cb = sizeof(STARTUPINFO); if (redirect) { hr = create_name_pipe(&cin_pipe[0], &cin_pipe[1], true); if (hr < 0) return hr; hr = create_name_pipe(&cout_pipe[0], &cout_pipe[1], false); if (hr < 0) { ::CloseHandle(cin_pipe[0]); ::CloseHandle(cin_pipe[1]); return hr; } si.hStdError = GetStdHandle(STD_ERROR_HANDLE); si.hStdOutput = cout_pipe[1]; si.hStdInput = cin_pipe[1]; si.dwFlags |= STARTF_USESTDHANDLES; } wstring envstr; v8::Local<v8::Object> envs; hr = GetConfigValue(isolate->m_isolate, opts, "env", envs, true); if (hr == CALL_E_PARAMNOTOPTIONAL) hr = process_base::get_env(envs); if (hr < 0) return hr; v8::Local<v8::Array> keys = envs->GetPropertyNames(); len = (int32_t) keys->Length(); for (i = 0; i < len; i++) { v8::Local<v8::Value> k = keys->Get(i); v8::Local<v8::Value> v = envs->Get(k); std::string ks, vs; hr = GetArgumentValue(k, ks); if (hr < 0) return hr; hr = GetArgumentValue(v, vs); if (hr < 0) return hr; ks.append(1, '='); ks.append(vs); envstr.append(utf8to16String(ks)); envstr.append(1, 0); } envstr.append(1, 0); if (!CreateProcessW(NULL, &wstr[0], NULL, NULL, TRUE, CREATE_UNICODE_ENVIRONMENT, &envstr[0], NULL, &si, &pi)) { ::CloseHandle(cin_pipe[0]); ::CloseHandle(cin_pipe[1]); ::CloseHandle(cout_pipe[0]); ::CloseHandle(cout_pipe[1]); return CHECK_ERROR(LastError()); } ::CloseHandle(pi.hThread); obj_ptr<SubProcess> sub = new SubProcess((intptr_t)pi.hProcess); if (redirect) { ::CloseHandle(cin_pipe[1]); ::CloseHandle(cout_pipe[1]); wrap_pipe((intptr_t)cin_pipe[0], sub->m_stdin); wrap_pipe((intptr_t)cout_pipe[0], sub->m_stdout); } retVal = sub; return 0; }