void BrowserFactory::GetExecutableLocation() { std::wstring class_id; if (this->GetRegistryValue(HKEY_LOCAL_MACHINE, IE_CLSID_REGISTRY_KEY, L"", &class_id)) { std::wstring location_key = L"SOFTWARE\\Classes\\CLSID\\" + class_id + L"\\LocalServer32"; std::wstring executable_location; if (this->GetRegistryValue(HKEY_LOCAL_MACHINE, location_key, L"", &executable_location)) { // If the executable location in the registry has an environment // variable in it, expand the environment variable to an absolute // path. size_t start_percent = executable_location.find(L"%"); if (start_percent != std::wstring::npos) { size_t end_percent = executable_location.find(L"%", start_percent + 1); if (end_percent != std::wstring::npos) { std::wstring variable_name = executable_location.substr(start_percent + 1, end_percent - start_percent - 1); DWORD variable_value_size = ::GetEnvironmentVariable(variable_name.c_str(), NULL, 0); vector<WCHAR> variable_value(variable_value_size); ::GetEnvironmentVariable(variable_name.c_str(), &variable_value[0], variable_value_size); executable_location.replace(start_percent, end_percent - start_percent + 1, &variable_value[0]); } } this->ie_executable_location_ = executable_location; if (this->ie_executable_location_.substr(0, 1) == L"\"") { this->ie_executable_location_.erase(0, 1); this->ie_executable_location_.erase(this->ie_executable_location_.size() - 1, 1); } } } }
static struct variable *binary_op_str(struct context *context, enum Opcode op, struct variable *u, struct variable *v) { struct variable *w = NULL; struct byte_array *ustr = u->type == VAR_STR ? u->str : variable_value(context, u); struct byte_array *vstr = v->type == VAR_STR ? v->str : variable_value(context, v); switch (op) { case VM_ADD: w = variable_new_str(context, byte_array_concatenate(2, vstr, ustr)); break; case VM_EQU: w = variable_new_int(context, byte_array_equals(ustr, vstr)); break; default: return (struct variable*)vm_exit_message(context, "unknown string operation"); } return w; }
struct variable *sys_print(struct context *context) { null_check(context); struct variable *args = (struct variable*)stack_pop(context->operand_stack); assert_message(args && args->type==VAR_SRC && args->list.ordered, "bad print arg"); for (int i=1; i<args->list.ordered->length; i++) { struct variable *arg = (struct variable*)array_get(args->list.ordered, i); struct byte_array *str = variable_value(context, arg); if (arg->type == VAR_STR) str = byte_array_part(str, 1, str->length-2); printf("%s\n", byte_array_to_string(str)); } return NULL; }
struct variable *builtin_method(struct context *context, struct variable *indexable, const struct variable *index) { enum VarType it = indexable->type; char *idxstr = byte_array_to_string(index->str); struct variable *result = NULL; if (!strcmp(idxstr, FNC_LENGTH)) { int n; switch (indexable->type) { case VAR_LST: n = indexable->list.ordered->length; break; case VAR_STR: n = indexable->str->length; break; case VAR_NIL: n = 0; break; default: free(idxstr); exit_message("no length for non-indexable"); return NULL; } result = variable_new_int(context, n); } else if (!strcmp(idxstr, FNC_TYPE)) { const char *typestr = var_type_str(it); result = variable_new_str_chars(context, typestr); } else if (!strcmp(idxstr, FNC_STRING)) { switch (indexable->type) { case VAR_STR: case VAR_BYT: case VAR_FNC: result = variable_copy(context, indexable); break; default: { struct byte_array *vv = variable_value(context, indexable); result = variable_new_str(context, vv); byte_array_del(vv); break; } } } else if (!strcmp(idxstr, FNC_LIST)) result = variable_new_list(context, indexable->list.ordered); else if (!strcmp(idxstr, FNC_KEY)) { if (indexable->type == VAR_KVP) result = indexable->kvp.key; else result = variable_new_nil(context); } else if (!strcmp(idxstr, FNC_VAL)) { if (indexable->type == VAR_KVP) result = indexable->kvp.val; else result = variable_new_nil(context); } else if (!strcmp(idxstr, FNC_KEYS)) result = variable_map_list(context, indexable, &map_keys); else if (!strcmp(idxstr, FNC_VALS)) result = variable_map_list(context, indexable, &map_vals); else if (!strcmp(idxstr, FNC_PACK)) result = variable_new_cfnc(context, &cfnc_pack); else if (!strcmp(idxstr, FNC_SERIALIZE)) result = variable_new_cfnc(context, &cfnc_serialize); else if (!strcmp(idxstr, FNC_DESERIALIZE)) result = variable_new_cfnc(context, &cfnc_deserialize); else if (!strcmp(idxstr, FNC_SORT)) { assert_message(indexable->type == VAR_LST, "sorting non-list"); result = variable_new_cfnc(context, &cfnc_sort); } else if (!strcmp(idxstr, FNC_CHAR)) result = variable_new_cfnc(context, &cfnc_char); else if (!strcmp(idxstr, FNC_HAS)) result = variable_new_cfnc(context, &cfnc_has); else if (!strcmp(idxstr, FNC_FIND)) result = variable_new_cfnc(context, &cfnc_find); else if (!strcmp(idxstr, FNC_PART)) result = variable_new_cfnc(context, &cfnc_part); else if (!strcmp(idxstr, FNC_REMOVE)) result = variable_new_cfnc(context, &cfnc_remove); else if (!strcmp(idxstr, FNC_INSERT)) result = variable_new_cfnc(context, &cfnc_insert); else if (!strcmp(idxstr, FNC_REPLACE)) result = variable_new_cfnc(context, &cfnc_replace); free(idxstr); return result; }