/* my_gethwaddr - Windows version @brief Retrieve MAC address from network hardware @param[out] to MAC address exactly six bytes @return Operation status @retval 0 OK @retval <>0 FAILED */ my_bool my_gethwaddr(uchar *to) { PIP_ADAPTER_ADDRESSES pAdapterAddresses; PIP_ADAPTER_ADDRESSES pCurrAddresses; IP_ADAPTER_ADDRESSES adapterAddresses; ULONG address_len; my_bool return_val= 1; static pfnGetAdaptersAddresses fnGetAdaptersAddresses= (pfnGetAdaptersAddresses)-1; if (fnGetAdaptersAddresses == (pfnGetAdaptersAddresses)-1) { /* Get the function from the DLL */ fnGetAdaptersAddresses= (pfnGetAdaptersAddresses) GetProcAddress(LoadLibrary("iphlpapi.dll"), "GetAdaptersAddresses"); } if (!fnGetAdaptersAddresses) return 1; /* failed to get function */ address_len= sizeof (IP_ADAPTER_ADDRESSES); /* Get the required size for the address data. */ if (fnGetAdaptersAddresses(AF_UNSPEC, 0, 0, &adapterAddresses, &address_len) == ERROR_BUFFER_OVERFLOW) { pAdapterAddresses= my_malloc(address_len, 0); if (!pAdapterAddresses) return 1; /* error, alloc failed */ } else pAdapterAddresses= &adapterAddresses; /* one is enough don't alloc */ /* Get the hardware info. */ if (fnGetAdaptersAddresses(AF_UNSPEC, 0, 0, pAdapterAddresses, &address_len) == NO_ERROR) { pCurrAddresses= pAdapterAddresses; while (pCurrAddresses) { /* Look for ethernet cards. */ if (pCurrAddresses->IfType == IF_TYPE_ETHERNET_CSMACD) { /* check for a good address */ if (pCurrAddresses->PhysicalAddressLength < 6) continue; /* bad address */ /* save 6 bytes of the address in the 'to' parameter */ memcpy(to, pCurrAddresses->PhysicalAddress, 6); /* Network card found, we're done. */ return_val= 0; break; } pCurrAddresses= pCurrAddresses->Next; } } /* Clean up memory allocation. */ if (pAdapterAddresses != &adapterAddresses) my_free(pAdapterAddresses); return return_val; }
static int xmlModulePlatformSymbol(void *handle, const char *name, void **symbol) { *symbol = GetProcAddress(handle, name); return (NULL == *symbol) ? -1 : 0; }
/* Handler for system messages. The only two we handle are KMSG_SYSTEM_INIT and KMSG_SYSTEM_EXIT. */ khm_int32 KHMAPI handle_kmsg_system(khm_int32 msg_type, khm_int32 msg_subtype, khm_ui_4 uparam, void * vparam) { khm_int32 rv = KHM_ERROR_SUCCESS; switch (msg_subtype) { /* This is the first message that will be received by a plugin. We use it to perform initialization operations such as registering any credential types, data types and attributes. */ case KMSG_SYSTEM_INIT: { kcdb_credtype ct; wchar_t short_desc[KCDB_MAXCCH_SHORT_DESC]; wchar_t long_desc[KCDB_MAXCCH_LONG_DESC]; khui_config_node cnode; khui_config_node_reg creg; kcdb_attrib attr; khm_handle csp_plugin = NULL; khm_handle csp_plugins = NULL; #ifdef BUILD_KRBCOMPAT /* If we don't have a Kerberos backend, then we can't * function. */ if (!DelayLoadHeimdal()) { _reportf("Can't initialize a Kerberos backend. LastError=%d", GetLastError()); return KHM_ERROR_NOT_FOUND; } #endif #if KH_VERSION_API < 12 do { khm_version libver; khm_ui_4 apiver; khm_get_lib_version(&libver, &apiver); if (apiver < 7) break; hm_netidmgr = LoadLibrary(NIMDLLNAME); if (hm_netidmgr == NULL) break; #if KH_VERSION_API < 7 pkhui_action_lock = (void (KHMAPI *)(void)) GetProcAddress(hm_netidmgr, API_khui_action_lock); pkhui_action_unlock = (void (KHMAPI *)(void)) GetProcAddress(hm_netidmgr, API_khui_action_unlock); pkhui_refresh_actions = (void (KHMAPI *)(void)) GetProcAddress(hm_netidmgr, API_khui_refresh_actions); pkhui_request_UI_callback = (khm_int32 (KHMAPI *)(khm_ui_callback, void *)) GetProcAddress(hm_netidmgr, API_khui_request_UI_callback); #endif pkhui_cw_get_primary_id = (khm_int32 (KHMAPI *)(khui_new_creds *, khm_handle *)) GetProcAddress(hm_netidmgr, API_khui_cw_get_primary_id); pkhui_cw_get_result = (khm_int32 (KHMAPI *)(khui_new_creds *)) GetProcAddress(hm_netidmgr, API_khui_cw_get_result); pkhui_cw_get_subtype = (khui_nc_subtype (KHMAPI *)(khui_new_creds *)) GetProcAddress(hm_netidmgr, API_khui_cw_get_subtype); pkhui_cw_get_ctx = (khui_action_context * (KHMAPI *)(khui_new_creds *)) GetProcAddress(hm_netidmgr, API_khui_cw_get_ctx); pkcdb_get_resource = (khm_int32 (KHMAPI *)(khm_handle, kcdb_resource_id, khm_int32, khm_int32 *, void *, void *, khm_size *)) GetProcAddress(hm_netidmgr, API_kcdb_get_resource); } while (FALSE); if (pkhui_cw_get_primary_id == NULL) pkhui_cw_get_primary_id = int_khui_cw_get_primary_id; if (pkhui_cw_get_result == NULL) pkhui_cw_get_result = int_khui_cw_get_result; if (pkhui_cw_get_subtype == NULL) pkhui_cw_get_subtype = int_khui_cw_get_subtype; if (pkhui_cw_get_ctx == NULL) pkhui_cw_get_ctx = int_khui_cw_get_ctx; if (pkcdb_get_resource == NULL) pkcdb_get_resource = int_kcdb_get_resource; #endif /* Add the icon now. On NIM v2.x, doing so after tokens were reported may result in a deadlock as we try to switch to the UI thread and the UI thread is blocked on a resource request to this plug-in. */ kca_icon_set_state(NULL); /* First and foremost, we need to register a credential type. */ ZeroMemory(&ct, sizeof(ct)); ct.id = KCDB_CREDTYPE_AUTO; ct.name = MYCREDTYPE_NAMEW; ct.short_desc = short_desc; ct.long_desc = long_desc; short_desc[0] = L'\0'; LoadString(hResModule, IDS_CT_SHORT_DESC, short_desc, ARRAYLENGTH(short_desc)); long_desc[0] = L'\0'; LoadString(hResModule, IDS_CT_LONG_DESC, long_desc, ARRAYLENGTH(long_desc)); ct.icon = NULL; /* We skip the icon for now, but you can assign a handle to an icon here. The icon will be used to represent the credentials type.*/ kmq_create_subscription(plugin_msg_proc, &ct.sub); ct.is_equal = cred_is_equal; rv = kcdb_credtype_register(&ct, &credtype_id); /* We create a global credential set that we use in the plug-in thread. This alleviates the need to create one everytime we need one. Keep in mind that this should only be used in the plug-in thread and should not be touched from the UI thread or any other thread. */ kcdb_credset_create(&g_credset); /* TODO: Perform additional initialization operations. */ /* Register our attributes */ ZeroMemory(&attr, sizeof(attr)); attr.name = ATTRNAME_KCA_AUTHREALM; attr.id = KCDB_ATTR_INVALID; attr.alt_id = KCDB_ATTR_INVALID; attr.flags = 0; attr.type = KCDB_TYPE_STRING; attr.short_desc = short_desc; attr.long_desc = long_desc; attr.compute_cb = NULL; attr.compute_min_cbsize = 0; attr.compute_max_cbsize = 0; LoadString(hResModule, IDS_ATTR_REALM_SHORT_DESC, short_desc, ARRAYLENGTH(short_desc)); LoadString(hResModule, IDS_ATTR_REALM_LONG_DESC, long_desc, ARRAYLENGTH(long_desc)); rv = kcdb_attrib_register(&attr, &attr_id_auth_realm); if (KHM_FAILED(rv)) break; attr.name = ATTRNAME_SUBJECT_EMAIL; LoadString(hResModule, IDS_ATTR_SUBJECT_EMAIL_SHORT_DESC, short_desc, ARRAYLENGTH(short_desc)); LoadString(hResModule, IDS_ATTR_SUBJECT_EMAIL_LONG_DESC, long_desc, ARRAYLENGTH(long_desc)); rv = kcdb_attrib_register(&attr, &attr_id_subj_email); if (KHM_FAILED(rv)) break; attr.name = ATTRNAME_SUBJECT_DISPLAY; LoadString(hResModule, IDS_ATTR_SUBJECT_SHORT_DESC, short_desc, ARRAYLENGTH(short_desc)); LoadString(hResModule, IDS_ATTR_SUBJECT_LONG_DESC, long_desc, ARRAYLENGTH(long_desc)); rv = kcdb_attrib_register(&attr, &attr_id_subj_display); if (KHM_FAILED(rv)) break; attr.name = ATTRNAME_ISSUER_DISPLAY; LoadString(hResModule, IDS_ATTR_ISSUER_SHORT_DESC, short_desc, ARRAYLENGTH(short_desc)); LoadString(hResModule, IDS_ATTR_ISSUER_LONG_DESC, long_desc, ARRAYLENGTH(long_desc)); rv = kcdb_attrib_register(&attr, &attr_id_issuer_display); if (KHM_FAILED(rv)) break; attr.name = ATTRNAME_ISSUER_NAME; attr.flags = KCDB_ATTR_FLAG_HIDDEN; attr.type = KCDB_TYPE_DATA; attr.short_desc = NULL; attr.long_desc = NULL; rv = kcdb_attrib_register(&attr, &attr_id_issuer_name); if (KHM_FAILED(rv)) break; attr.name = ATTRNAME_SERIAL; rv = kcdb_attrib_register(&attr, &attr_id_serial_number); if (KHM_FAILED(rv)) break; /* List the credentials that are already here */ kca_list_creds(); /* Now we register our configuration panels. */ #ifdef GENERAL_CONFIG_PANEL /* This configuration panel is the one that controls general options. We leave the identity specific and identity defaults for other configuration panels. */ ZeroMemory(&creg, sizeof(creg)); short_desc[0] = L'\0'; LoadString(hResModule, IDS_CFG_SHORT_DESC, short_desc, ARRAYLENGTH(short_desc)); long_desc[0] = L'\0'; LoadString(hResModule, IDS_CFG_LONG_DESC, long_desc, ARRAYLENGTH(long_desc)); creg.name = CONFIGNODE_MAIN; creg.short_desc = short_desc; creg.long_desc = long_desc; creg.h_module = hResModule; creg.dlg_template = MAKEINTRESOURCE(IDD_CONFIG); creg.dlg_proc = config_dlgproc; creg.flags = 0; khui_cfg_register(NULL, &creg); #endif /* Now we do the identity specific and identity default configuration panels. "KhmIdentities" is a predefined configuration node under which all the identity spcific configuration is managed. */ if (KHM_FAILED(khui_cfg_open(NULL, L"KhmIdentities", &cnode))) { /* this should always work */ assert(FALSE); rv = KHM_ERROR_NOT_FOUND; break; } /* First the tab panel for defaults for all identities */ ZeroMemory(&creg, sizeof(creg)); short_desc[0] = L'\0'; LoadString(hResModule, IDS_CFG_IDS_SHORT_DESC, short_desc, ARRAYLENGTH(short_desc)); long_desc[0] = L'\0'; LoadString(hResModule, IDS_CFG_IDS_LONG_DESC, long_desc, ARRAYLENGTH(long_desc)); creg.name = CONFIGNODE_ALL_ID; creg.short_desc = short_desc; creg.long_desc = long_desc; creg.h_module = hResModule; creg.dlg_template = MAKEINTRESOURCE(IDD_CONFIG_IDS); creg.dlg_proc = config_ids_dlgproc; creg.flags = KHUI_CNFLAG_SUBPANEL; khui_cfg_register(cnode, &creg); /* Now the panel for per identity configuration */ ZeroMemory(&creg, sizeof(creg)); short_desc[0] = L'\0'; LoadString(hResModule, IDS_CFG_ID_SHORT_DESC, short_desc, ARRAYLENGTH(short_desc)); long_desc[0] = L'\0'; LoadString(hResModule, IDS_CFG_ID_LONG_DESC, long_desc, ARRAYLENGTH(long_desc)); creg.name = CONFIGNODE_PER_ID; creg.short_desc = short_desc; creg.long_desc = long_desc; creg.h_module = hResModule; creg.dlg_template = MAKEINTRESOURCE(IDD_CONFIG_ID); creg.dlg_proc = config_id_dlgproc; creg.flags = KHUI_CNFLAG_SUBPANEL | KHUI_CNFLAG_INSTANCE; khui_cfg_register(cnode, &creg); khui_cfg_release(cnode); /* load the schema */ if (KHM_SUCCEEDED(kmm_get_plugins_config(0, &csp_plugins))) { khc_load_schema(csp_plugins, plugin_schema); khc_close_space(csp_plugins); } /* open the plug-in and parameter configuration spaces */ if (KHM_SUCCEEDED(kmm_get_plugin_config(MYPLUGIN_NAMEW, KHM_FLAG_CREATE, &csp_plugin))) { khc_open_space(csp_plugin, L"Parameters", KHM_FLAG_CREATE, &csp_params); khc_close_space(csp_plugin); } /* try to install the kpkcs11 plugin now */ install_kpkcs11_plugin(); /* register the "KCA Help" menu item, so that we can add the plug-in menu item to the Help menu. */ { khm_handle h_sub = NULL; #if KH_VERSION_API < 7 if (pkhui_action_lock == NULL || pkhui_action_unlock == NULL || pkhui_refresh_actions == NULL || pkhui_request_UI_callback == NULL) goto no_custom_help; #endif kmq_create_subscription(plugin_msg_proc, &h_sub); LoadString(hResModule, IDS_ACTION_KCA_HELP, short_desc, ARRAYLENGTH(short_desc)); LoadString(hResModule, IDS_ACTION_KCA_HELP_TT, long_desc, ARRAYLENGTH(long_desc)); action_id_kca_help = khui_action_create(NULL, short_desc, long_desc, NULL, KHUI_ACTIONTYPE_TRIGGER, h_sub); if (action_id_kca_help != 0) { khm_size s; khm_size i; khui_menu_def * help_menu; khm_boolean refresh = FALSE; khui_action_lock(); help_menu = khui_find_menu(KHUI_MENU_HELP); if (help_menu) { s = khui_menu_get_size(help_menu); for (i=0; i < s; i++) { khui_action_ref * aref; aref = khui_menu_get_action(help_menu, i); if (aref && !(aref->flags & KHUI_ACTIONREF_PACTION) && aref->action == KHUI_ACTION_HELP_INDEX) { khui_menu_insert_action(help_menu, i + 1, action_id_kca_help, 0); refresh = TRUE; break; } } } khui_action_unlock(); if (refresh) khui_refresh_actions(); } #if KH_VERSION_API < 7 no_custom_help: ; #endif } } break; /* This is the last message that will be received by the plugin. */ case KMSG_SYSTEM_EXIT: { khui_config_node cnode; khui_config_node cn_idents; khm_int32 attr_id; kca_remove_icon(); /* It should not be assumed that initialization of the plugin went well at this point since we receive a KMSG_SYSTEM_EXIT even if the initialization failed. */ /* Try to remove the KCA plug-in action from Help menu if it was successfully registered. Also, delete the action. */ if (action_id_kca_help != 0) { khui_menu_def * help_menu; khm_boolean menu_changed = FALSE; khui_action_lock(); help_menu = khui_find_menu(KHUI_MENU_HELP); if (help_menu) { khm_size s; khm_size i; s = khui_menu_get_size(help_menu); for (i=0; i < s; i++) { khui_action_ref * aref = khui_menu_get_action(help_menu, i); if (aref && !(aref->flags & KHUI_ACTIONREF_PACTION) && aref->action == action_id_kca_help) { khui_menu_remove_action(help_menu, i); menu_changed = TRUE; break; } } } khui_action_delete(action_id_kca_help); khui_action_unlock(); if (menu_changed) khui_refresh_actions(); action_id_kca_help = 0; } if (credtype_id != KCDB_CREDTYPE_INVALID) { kcdb_credtype_unregister(credtype_id); credtype_id = KCDB_CREDTYPE_INVALID; } if (g_credset) { kcdb_credset_delete(g_credset); g_credset = NULL; } /* Now unregister any configuration nodes we registered. */ if (KHM_SUCCEEDED(khui_cfg_open(NULL, CONFIGNODE_MAIN, &cnode))) { khui_cfg_remove(cnode); khui_cfg_release(cnode); } if (KHM_SUCCEEDED(khui_cfg_open(NULL, L"KhmIdentities", &cn_idents))) { if (KHM_SUCCEEDED(khui_cfg_open(cn_idents, CONFIGNODE_ALL_ID, &cnode))) { khui_cfg_remove(cnode); khui_cfg_release(cnode); } if (KHM_SUCCEEDED(khui_cfg_open(cn_idents, CONFIGNODE_PER_ID, &cnode))) { khui_cfg_remove(cnode); khui_cfg_release(cnode); } khui_cfg_release(cn_idents); } if (KHM_SUCCEEDED(kcdb_attrib_get_id(ATTRNAME_KCA_AUTHREALM, &attr_id))) kcdb_attrib_unregister(attr_id); if (KHM_SUCCEEDED(kcdb_attrib_get_id(ATTRNAME_SUBJECT_EMAIL, &attr_id))) kcdb_attrib_unregister(attr_id); if (KHM_SUCCEEDED(kcdb_attrib_get_id(ATTRNAME_SUBJECT_DISPLAY, &attr_id))) kcdb_attrib_unregister(attr_id); if (KHM_SUCCEEDED(kcdb_attrib_get_id(ATTRNAME_ISSUER_DISPLAY, &attr_id))) kcdb_attrib_unregister(attr_id); if (KHM_SUCCEEDED(kcdb_attrib_get_id(ATTRNAME_ISSUER_NAME, &attr_id))) kcdb_attrib_unregister(attr_id); if (KHM_SUCCEEDED(kcdb_attrib_get_id(ATTRNAME_SERIAL, &attr_id))) kcdb_attrib_unregister(attr_id); if (csp_params) { khc_close_space(csp_params); csp_params = NULL; } #if KH_VERSION_API < 12 if (hm_netidmgr) FreeLibrary(hm_netidmgr); pkhui_cw_get_primary_id = NULL; #endif #if KH_VERSION_API < 7 pkhui_action_lock = NULL; pkhui_action_unlock = NULL; pkhui_refresh_actions = NULL; pkhui_request_UI_callback = NULL; #endif /* TODO: Perform additional uninitialization operations. */ } break; } return rv; }
RKT_API Proc getProcAddress(void* moduleHandle, const char* procName) { return reinterpret_cast<Proc>(GetProcAddress((HMODULE)moduleHandle, procName)); }
void init_heap (void) { if (using_dynamic_heap) { unsigned long enable_lfh = 2; /* After dumping, use a new private heap. We explicitly enable the low fragmentation heap (LFH) here, for the sake of pre Vista versions. Note: this will harmlessly fail on Vista and later, where the low-fragmentation heap is enabled by default. It will also fail on pre-Vista versions when Emacs is run under a debugger; set _NO_DEBUG_HEAP=1 in the environment before starting GDB to get low fragmentation heap on XP and older systems, for the price of losing "certain heap debug options"; for the details see http://msdn.microsoft.com/en-us/library/windows/desktop/aa366705%28v=vs.85%29.aspx. */ data_region_end = data_region_base; /* Create the private heap. */ heap = HeapCreate (0, 0, 0); #ifndef MINGW_W64 /* Set the low-fragmentation heap for OS before Vista. */ HMODULE hm_kernel32dll = LoadLibrary ("kernel32.dll"); HeapSetInformation_Proc s_pfn_Heap_Set_Information = (HeapSetInformation_Proc) GetProcAddress (hm_kernel32dll, "HeapSetInformation"); if (s_pfn_Heap_Set_Information != NULL) { if (s_pfn_Heap_Set_Information ((PVOID) heap, HeapCompatibilityInformation, &enable_lfh, sizeof(enable_lfh)) == 0) DebPrint (("Enabling Low Fragmentation Heap failed: error %ld\n", GetLastError ())); } #endif if (os_subtype == OS_9X) { the_malloc_fn = malloc_after_dump_9x; the_realloc_fn = realloc_after_dump_9x; the_free_fn = free_after_dump_9x; } else { the_malloc_fn = malloc_after_dump; the_realloc_fn = realloc_after_dump; the_free_fn = free_after_dump; } } else { /* Find the RtlCreateHeap function. Headers for this function are provided with the w32 DDK, but the function is available in ntdll.dll since XP. */ HMODULE hm_ntdll = LoadLibrary ("ntdll.dll"); RtlCreateHeap_Proc s_pfn_Rtl_Create_Heap = (RtlCreateHeap_Proc) GetProcAddress (hm_ntdll, "RtlCreateHeap"); /* Specific parameters for the private heap. */ RTL_HEAP_PARAMETERS params; ZeroMemory (¶ms, sizeof(params)); params.Length = sizeof(RTL_HEAP_PARAMETERS); data_region_base = (unsigned char *)ROUND_UP (dumped_data, 0x1000); data_region_end = bc_limit = dumped_data + DUMPED_HEAP_SIZE; params.InitialCommit = committed = 0x1000; params.InitialReserve = sizeof(dumped_data); /* Use our own routine to commit memory from the dumped_data array. */ params.CommitRoutine = &dumped_data_commit; /* Create the private heap. */ if (s_pfn_Rtl_Create_Heap == NULL) { fprintf (stderr, "Cannot build Emacs without RtlCreateHeap being available; exiting.\n"); exit (-1); } heap = s_pfn_Rtl_Create_Heap (0, data_region_base, 0, 0, NULL, ¶ms); if (os_subtype == OS_9X) { fprintf (stderr, "Cannot dump Emacs on Windows 9X; exiting.\n"); exit (-1); } else { the_malloc_fn = malloc_before_dump; the_realloc_fn = realloc_before_dump; the_free_fn = free_before_dump; } } /* Update system version information to match current system. */ cache_system_info (); }
/* * Create a restricted token and execute the specified process with it. * * Returns restricted token on success and 0 on failure. * * On NT4, or any other system not containing the required functions, will * NOT execute anything. */ HANDLE CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo, const char *progname) { BOOL b; STARTUPINFO si; HANDLE origToken; HANDLE restrictedToken; SID_IDENTIFIER_AUTHORITY NtAuthority = {SECURITY_NT_AUTHORITY}; SID_AND_ATTRIBUTES dropSids[2]; __CreateRestrictedToken _CreateRestrictedToken = NULL; HANDLE Advapi32Handle; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); Advapi32Handle = LoadLibrary("ADVAPI32.DLL"); if (Advapi32Handle != NULL) { _CreateRestrictedToken = (__CreateRestrictedToken) GetProcAddress(Advapi32Handle, "CreateRestrictedToken"); } if (_CreateRestrictedToken == NULL) { fprintf(stderr, _("%s: WARNING: cannot create restricted tokens on this platform\n"), progname); if (Advapi32Handle != NULL) FreeLibrary(Advapi32Handle); return 0; } /* Open the current token to use as a base for the restricted one */ if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &origToken)) { fprintf(stderr, _("%s: could not open process token: error code %lu\n"), progname, GetLastError()); return 0; } /* Allocate list of SIDs to remove */ ZeroMemory(&dropSids, sizeof(dropSids)); if (!AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &dropSids[0].Sid) || !AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_POWER_USERS, 0, 0, 0, 0, 0, 0, &dropSids[1].Sid)) { fprintf(stderr, _("%s: could not allocate SIDs: error code %lu\n"), progname, GetLastError()); return 0; } b = _CreateRestrictedToken(origToken, DISABLE_MAX_PRIVILEGE, sizeof(dropSids) / sizeof(dropSids[0]), dropSids, 0, NULL, 0, NULL, &restrictedToken); FreeSid(dropSids[1].Sid); FreeSid(dropSids[0].Sid); CloseHandle(origToken); FreeLibrary(Advapi32Handle); if (!b) { fprintf(stderr, _("%s: could not create restricted token: error code %lu\n"), progname, GetLastError()); return 0; } #ifndef __CYGWIN__ AddUserToTokenDacl(restrictedToken); #endif if (!CreateProcessAsUser(restrictedToken, NULL, cmd, NULL, NULL, TRUE, CREATE_SUSPENDED, NULL, NULL, &si, processInfo)) { fprintf(stderr, _("%s: could not start process for command \"%s\": error code %lu\n"), progname, cmd, GetLastError()); return 0; } ResumeThread(processInfo->hThread); return restrictedToken; }
int ms_load_plugins(const char *dir){ int num=0; #if defined(WIN32) && !defined(_WIN32_WCE) WIN32_FIND_DATA FileData; HANDLE hSearch; char szDirPath[1024]; char szPluginFile[1024]; BOOL fFinished = FALSE; const char *tmp=getenv("DEBUG"); BOOL debug=(tmp!=NULL && atoi(tmp)==1); snprintf(szDirPath, sizeof(szDirPath), "%s", dir); // Start searching for .dll files in the current directory. snprintf(szDirPath, sizeof(szDirPath), "%s\\*.dll", dir); hSearch = FindFirstFile(szDirPath, &FileData); if (hSearch == INVALID_HANDLE_VALUE) { ms_message("no plugin (*.dll) found in %s.", szDirPath); return 0; } snprintf(szDirPath, sizeof(szDirPath), "%s", dir); while (!fFinished) { /* load library */ HINSTANCE os_handle; UINT em=0; if (!debug) em = SetErrorMode (SEM_FAILCRITICALERRORS); snprintf(szPluginFile, sizeof(szPluginFile), "%s\\%s", szDirPath, FileData.cFileName); os_handle = LoadLibraryEx (szPluginFile, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); if (os_handle==NULL) { ms_message("Fail to load plugin %s with altered search path: error %i",szPluginFile,(int)GetLastError()); os_handle = LoadLibraryEx (szPluginFile, NULL, 0); } if (!debug) SetErrorMode (em); if (os_handle==NULL) ms_error("Fail to load plugin %s", szPluginFile); else{ init_func_t initroutine; char szPluginName[256]; char szMethodName[256]; char *minus; snprintf(szPluginName, 256, "%s", FileData.cFileName); /*on mingw, dll names might be libsomething-3.dll. We must skip the -X.dll stuff*/ minus=strchr(szPluginName,'-'); if (minus) *minus='\0'; else szPluginName[strlen(szPluginName)-4]='\0'; /*remove .dll*/ snprintf(szMethodName, 256, "%s_init", szPluginName); initroutine = (init_func_t) GetProcAddress (os_handle, szMethodName); if (initroutine!=NULL){ initroutine(); ms_message("Plugin loaded (%s)", szPluginFile); // Add this new loaded plugin to the list (useful for FreeLibrary at the end) ms_plugins_loaded_list=ms_list_append(ms_plugins_loaded_list,os_handle); num++; }else{ ms_warning("Could not locate init routine of plugin %s. Should be %s", szPluginFile, szMethodName); } } if (!FindNextFile(hSearch, &FileData)) { if (GetLastError() == ERROR_NO_MORE_FILES){ fFinished = TRUE; } else { ms_error("couldn't find next plugin dll."); fFinished = TRUE; } } } /* Close the search handle. */ FindClose(hSearch); #elif HAVE_DLOPEN char plugin_name[64]; DIR *ds; MSList *loaded_plugins = NULL; struct dirent *de; char *ext; char *fullpath; ds=opendir(dir); if (ds==NULL){ ms_message("Cannot open directory %s: %s",dir,strerror(errno)); return -1; } while( (de=readdir(ds))!=NULL){ if ( #ifndef __QNX__ (de->d_type==DT_REG || de->d_type==DT_UNKNOWN || de->d_type==DT_LNK) && #endif (ext=strstr(de->d_name,PLUGINS_EXT))!=NULL) { void *handle; snprintf(plugin_name, MIN(sizeof(plugin_name), ext - de->d_name + 1), "%s", de->d_name); if (ms_list_find_custom(loaded_plugins, (MSCompareFunc)strcmp, plugin_name) != NULL) continue; loaded_plugins = ms_list_append(loaded_plugins, ms_strdup(plugin_name)); fullpath=ms_strdup_printf("%s/%s",dir,de->d_name); ms_message("Loading plugin %s...",fullpath); if ( (handle=dlopen(fullpath,RTLD_NOW))==NULL){ ms_warning("Fail to load plugin %s : %s",fullpath,dlerror()); }else { char *initroutine_name=ms_malloc0(strlen(de->d_name)+10); char *p; void *initroutine=NULL; strcpy(initroutine_name,de->d_name); p=strstr(initroutine_name,PLUGINS_EXT); if (p!=NULL){ strcpy(p,"_init"); initroutine=dlsym(handle,initroutine_name); } #ifdef __APPLE__ if (initroutine==NULL){ /* on macosx: library name are libxxxx.1.2.3.dylib */ /* -> MUST remove the .1.2.3 */ p=strstr(initroutine_name,"."); if (p!=NULL) { strcpy(p,"_init"); initroutine=dlsym(handle,initroutine_name); } } #endif if (initroutine!=NULL){ init_func_t func=(init_func_t)initroutine; func(); ms_message("Plugin loaded (%s)", fullpath); num++; }else{ ms_warning("Could not locate init routine of plugin %s",de->d_name); } ms_free(initroutine_name); } ms_free(fullpath); } } ms_list_for_each(loaded_plugins, ms_free); ms_list_free(loaded_plugins); closedir(ds); #else ms_warning("no loadable plugin support: plugins cannot be loaded."); num=-1; #endif return num; }
// Create a VLAN object VLAN *NewVLan(char *instance_name, VLAN_PARAM *param) { VLAN *v; HANDLE h = INVALID_HANDLE_VALUE; HANDLE e = INVALID_HANDLE_VALUE; char tmp[MAX_SIZE]; char name_upper[MAX_SIZE]; // Validate arguments if (instance_name == NULL) { return NULL; } v = ZeroMalloc(sizeof(VLAN)); if (OS_IS_WINDOWS_9X(GetOsInfo()->OsType)) { v->Win9xMode = true; } // Initialize the name Format(name_upper, sizeof(name_upper), "%s", instance_name); StrUpper(name_upper); v->InstanceName = CopyStr(name_upper); Format(tmp, sizeof(tmp), NDIS_NEO_DEVICE_FILE_NAME, v->InstanceName); v->DeviceNameWin32 = CopyStr(tmp); if (v->Win9xMode == false) { Format(tmp, sizeof(tmp), NDIS_NEO_EVENT_NAME_WIN32, v->InstanceName); v->EventNameWin32 = CopyStr(tmp); } // Connect to the device h = CreateFile(v->DeviceNameWin32, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (h == INVALID_HANDLE_VALUE) { // Connection failure goto CLEANUP; } if (v->Win9xMode == false) { // Connect to the event e = OpenEvent(SYNCHRONIZE, FALSE, v->EventNameWin32); if (e == INVALID_HANDLE_VALUE) { // Connection failure goto CLEANUP; } } else { OPENVXDHANDLE OpenVxDHandle; DWORD vxd_handle; UINT bytes_returned; OpenVxDHandle = (OPENVXDHANDLE)GetProcAddress(GetModuleHandle("KERNEL32"), "OpenVxDHandle"); // Deliver to the driver by creating an event e = CreateEvent(NULL, FALSE, FALSE, NULL); vxd_handle = (DWORD)OpenVxDHandle(e); DeviceIoControl(h, NEO_IOCTL_SET_EVENT, &vxd_handle, sizeof(DWORD), NULL, 0, &bytes_returned, NULL); } v->Event = e; v->Handle = h; v->GetBuffer = ZeroMalloc(NEO_EXCHANGE_BUFFER_SIZE); v->PutBuffer = ZeroMalloc(NEO_EXCHANGE_BUFFER_SIZE); return v; CLEANUP: if (h != INVALID_HANDLE_VALUE) { CloseHandle(h); } if (e != INVALID_HANDLE_VALUE) { CloseHandle(e); } Free(v->InstanceName); Free(v->EventNameWin32); Free(v->DeviceNameWin32); Free(v); return NULL; }
int ExecFile(const char *pszFilePath, char *lpFile) { DWORD dwBytes; void *lpImageBase = NULL; // check the image dos header IMAGE_DOS_HEADER *pImageDosHeader = (IMAGE_DOS_HEADER *) lpFile; if(pImageDosHeader->e_magic != IMAGE_DOS_SIGNATURE) { return FALSE; } // check the image nt headers IMAGE_NT_HEADERS *pImageNtHeaders = (IMAGE_NT_HEADERS *)(lpFile + pImageDosHeader->e_lfanew); if(pImageNtHeaders->Signature != IMAGE_NT_SIGNATURE) { return FALSE; } // start the new process which we will overwrite later STARTUPINFOA StartupInfo = {sizeof(STARTUPINFOA)}; PROCESS_INFORMATION ProcessInformation = {0}; if(CreateProcess(pszFilePath, NULL, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &StartupInfo, &ProcessInformation) == FALSE) { return FALSE; } // read the base address of the executable loaded in the // process which we will inject CONTEXT ctx = {CONTEXT_FULL}; DWORD dwImageBase; if(GetThreadContext(ProcessInformation.hThread, &ctx) == FALSE || ReadProcessMemory(ProcessInformation.hProcess, (void *)(ctx.Ebx + 8), &dwImageBase, 4, &dwBytes) == FALSE || dwBytes != 4) { goto cleanup; } // unmap the loaded binary if the base address conflicts // with the binary which we want to load if(dwImageBase == pImageNtHeaders->OptionalHeader.ImageBase) { LP_NtUnmapViewOfSection pNtUnmapViewOfSection = (LP_NtUnmapViewOfSection) GetProcAddress( GetModuleHandleA("ntdll.dll"), "NtUnmapViewOfSection"); pNtUnmapViewOfSection(ProcessInformation.hProcess, dwImageBase); } // allocate memory in the remote process for our binary lpImageBase = VirtualAllocEx(ProcessInformation.hProcess, (void *) pImageNtHeaders->OptionalHeader.ImageBase, pImageNtHeaders->OptionalHeader.SizeOfImage, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); if(lpImageBase == NULL) { goto cleanup; } // write the headers of our binary to the process if(WriteProcessMemory(ProcessInformation.hProcess, lpImageBase, lpFile, pImageNtHeaders->OptionalHeader.SizeOfHeaders, &dwBytes) == FALSE || dwBytes != pImageNtHeaders->OptionalHeader.SizeOfHeaders) { goto cleanup; } // enumerate all the sections in this binary IMAGE_SECTION_HEADER *pImageSectionHeader = (IMAGE_SECTION_HEADER *)( lpFile + pImageDosHeader->e_lfanew + sizeof(IMAGE_FILE_HEADER) + sizeof(DWORD) + pImageNtHeaders->FileHeader.SizeOfOptionalHeader); for (int i = 0; i < pImageNtHeaders->FileHeader.NumberOfSections; i++, pImageSectionHeader++) { // if this section has no size_of_raw_data, then we skip it because // there is nothing to write if(pImageSectionHeader->SizeOfRawData == 0) continue; // and write each section to the correct address in the process if(WriteProcessMemory(ProcessInformation.hProcess, (char *) lpImageBase + pImageSectionHeader->VirtualAddress, lpFile + pImageSectionHeader->PointerToRawData, pImageSectionHeader->SizeOfRawData, &dwBytes) == FALSE || pImageSectionHeader->SizeOfRawData != dwBytes) { goto cleanup; } } // write the new image base address if(WriteProcessMemory(ProcessInformation.hProcess, (void *)(ctx.Ebx + 8), &lpImageBase, 4, &dwBytes) == FALSE || dwBytes != 4) { goto cleanup; } // store the new entry point ctx.Eax = (DWORD) lpImageBase + pImageNtHeaders->OptionalHeader.AddressOfEntryPoint; // write the new context containing the updated entry point to the process SetThreadContext(ProcessInformation.hThread, &ctx); // resume the main thread, start the application ResumeThread(ProcessInformation.hThread); // clean up our resources CloseHandle(ProcessInformation.hThread); CloseHandle(ProcessInformation.hProcess); return TRUE; cleanup: // clean up our resources if(lpImageBase != NULL) { VirtualFreeEx(ProcessInformation.hProcess, lpImageBase, 0, MEM_RELEASE); } CloseHandle(ProcessInformation.hThread); CloseHandle(ProcessInformation.hProcess); return FALSE; }
static inline OSVERSIONINFOEX winOsVersion() { typedef NTSTATUS (NTAPI *RtlGetVersionFunction)(LPOSVERSIONINFO); OSVERSIONINFOEX result = { sizeof(OSVERSIONINFOEX), 0, 0, 0, 0, {'\0'}, 0, 0, 0, 0, 0}; HMODULE ntdll = GetModuleHandleW(L"ntdll.dll"); if (ntdll ) { RtlGetVersionFunction pRtlGetVersion = reinterpret_cast<RtlGetVersionFunction>(GetProcAddress(ntdll, "RtlGetVersion")); if (pRtlGetVersion) { pRtlGetVersion((LPOSVERSIONINFO) &result); } } return result; }
trap_version TRAPENTRY TrapInit( char *parm, char *err, bool remote ) { trap_version ver; OSVERSIONINFO osver; HANDLE dll; osver.dwOSVersionInfoSize = sizeof( osver ); GetVersionEx( &osver ); #if defined( MD_x64 ) #else IsWin32s = FALSE; IsWin95 = FALSE; IsWinNT = FALSE; if( osver.dwPlatformId == VER_PLATFORM_WIN32s ) { IsWin32s = TRUE; } else if( osver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS ) { IsWin95 = TRUE; } else if( osver.dwPlatformId == VER_PLATFORM_WIN32_NT ) { IsWinNT = TRUE; } if( IsWinNT ) { dll = LoadLibrary( "VDMDBG.DLL" ); if( dll != NULL ) { pVDMSetThreadContext = (LPVOID)GetProcAddress( dll, "VDMSetThreadContext" ); pVDMModuleFirst = (LPVOID)GetProcAddress( dll, "VDMModuleFirst" ); pVDMModuleNext = (LPVOID)GetProcAddress( dll, "VDMModuleNext" ); pVDMEnumProcessWOW = (LPVOID)GetProcAddress( dll, "VDMEnumProcessWOW" ); pVDMProcessException = (LPVOID)GetProcAddress( dll, "VDMProcessException" ); pVDMGetModuleSelector = (LPVOID)GetProcAddress( dll, "VDMGetModuleSelector" ); pVDMGetThreadContext = (LPVOID)GetProcAddress( dll, "VDMGetThreadContext" ); pVDMGetThreadSelectorEntry = (LPVOID)GetProcAddress( dll, "VDMGetThreadSelectorEntry" ); } dll = LoadLibrary( "PSAPI.DLL" ); if( dll != NULL ) { pGetMappedFileName = (LPVOID)GetProcAddress( dll, "GetMappedFileNameA" ); } } #endif dll = LoadLibrary( "KERNEL32.DLL" ); if( dll != NULL ) { pOpenThread = (LPVOID)GetProcAddress( dll, "OpenThread" ); pQueryDosDevice = (LPVOID)GetProcAddress( dll, "QueryDosDeviceA" ); pCreateToolhelp32Snapshot = (LPVOID)GetProcAddress( dll, "CreateToolhelp32Snapshot" ); pModule32First = (LPVOID)GetProcAddress( dll, "Module32First" ); pModule32Next = (LPVOID)GetProcAddress( dll, "Module32Next" ); } //say( "base address=%8.8x", ((char*)&GetInPtr)-0x2f ); DLLPath = LocalAlloc( LMEM_FIXED | LMEM_ZEROINIT, strlen( err ) + 1 ); strcpy( DLLPath, err ); StopForDLLs = TRUE; BreakOnKernelMessage = FALSE; if( parm[0] == 'k' ) { BreakOnKernelMessage = TRUE; } remote = remote; parm = parm; err[0] = 0; ver.major = TRAP_MAJOR_VERSION; ver.minor = TRAP_MINOR_VERSION; ver.remote = FALSE; return( ver ); }
int main(int argc, char **argv) { int exfc, infc; char **exfv, **infv; char *x_opt; DWORD dwVerInfoSize; DWORD dwVerHnd; char szFullPath[_MAX_PATH]; int retcode; #ifdef WIN32 char *ptr; #else HFILE hfile; OFSTRUCT ofs; #endif HANDLE hMem; /* handle to mem alloc'ed */ if (argc < 2) /* We must have an archive to unzip */ { printf("usage: %s <zipfile> [entry1 [entry2 [...]]] [-x xentry1 [...]]", "example"); return 0; } hDCL = GlobalAlloc( GPTR, (DWORD)sizeof(DCL)); if (!hDCL) { return 0; } lpDCL = (LPDCL)GlobalLock(hDCL); if (!lpDCL) { GlobalFree(hDCL); return 0; } hUF = GlobalAlloc( GPTR, (DWORD)sizeof(USERFUNCTIONS)); if (!hUF) { GlobalUnlock(hDCL); GlobalFree(hDCL); return 0; } lpUserFunctions = (LPUSERFUNCTIONS)GlobalLock(hUF); if (!lpUserFunctions) { GlobalUnlock(hDCL); GlobalFree(hDCL); GlobalFree(hUF); return 0; } lpUserFunctions->password = password; lpUserFunctions->print = DisplayBuf; lpUserFunctions->sound = NULL; lpUserFunctions->replace = GetReplaceDlgRetVal; lpUserFunctions->SendApplicationMessage = ReceiveDllMessage; /* First we go look for the unzip dll */ #ifdef WIN32 if (SearchPath( NULL, /* address of search path */ UNZ_DLL_NAME, /* address of filename */ NULL, /* address of extension */ _MAX_PATH, /* size, in characters, of buffer */ szFullPath, /* address of buffer for found filename */ &ptr /* address of pointer to file component */ ) == 0) #else hfile = OpenFile(UNZ_DLL_NAME, &ofs, OF_SEARCH); if (hfile == HFILE_ERROR) #endif { char str[256]; wsprintf (str, DLL_WARNING, UNZ_DLL_NAME); printf("%s\n", str); FreeUpMemory(); return 0; } #ifndef WIN32 else lstrcpy(szFullPath, ofs.szPathName); _lclose(hfile); #endif /* Now we'll check the unzip dll version information. Note that this is not the same information as is returned from a call to UzpVersion() */ dwVerInfoSize = GetFileVersionInfoSize(szFullPath, &dwVerHnd); if (dwVerInfoSize) { BOOL fRet, fRetName; char str[256]; LPSTR lpstrVffInfo; /* Pointer to block to hold info */ LPSTR lszVer = NULL; LPSTR lszVerName = NULL; UINT cchVer = 0; /* Get a block big enough to hold the version information */ hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize); lpstrVffInfo = GlobalLock(hMem); /* Get the version information */ if (GetFileVersionInfo(szFullPath, 0L, dwVerInfoSize, lpstrVffInfo)) { fRet = VerQueryValue(lpstrVffInfo, TEXT("\\StringFileInfo\\040904E4\\FileVersion"), (LPVOID)&lszVer, &cchVer); fRetName = VerQueryValue(lpstrVffInfo, TEXT("\\StringFileInfo\\040904E4\\CompanyName"), (LPVOID)&lszVerName, &cchVer); if (!fRet || !fRetName || (lstrcmpi(lszVer, UNZ_DLL_VERSION) != 0) || (lstrcmpi(lszVerName, COMPANY_NAME) != 0)) { wsprintf (str, DLL_VERSION_WARNING, UNZ_DLL_NAME); printf("%s\n", str); FreeUpMemory(); GlobalUnlock(hMem); GlobalFree(hMem); return 0; } } /* free memory */ GlobalUnlock(hMem); GlobalFree(hMem); } else { char str[256]; wsprintf (str, DLL_VERSION_WARNING, UNZ_DLL_NAME); printf("%s\n", str); FreeUpMemory(); return 0; } /* Okay, now we know that the dll exists, and has the proper version * information in it. We can go ahead and load it. */ hUnzipDll = LoadLibrary(UNZ_DLL_NAME); #ifndef WIN32 if (hUnzipDll > HINSTANCE_ERROR) #else if (hUnzipDll != NULL) #endif { Wiz_SingleEntryUnzip = (_DLL_UNZIP)GetProcAddress(hUnzipDll, "Wiz_SingleEntryUnzip"); } else { char str[256]; wsprintf (str, "Could not load %s", UNZ_DLL_NAME); printf("%s\n", str); FreeUpMemory(); return 0; } /* Here is where the actual extraction process begins. First we set up the flags to be passed into the dll. */ lpDCL->ncflag = 0; /* Write to stdout if true */ lpDCL->fQuiet = 0; /* We want all messages. 1 = fewer messages, 2 = no messages */ lpDCL->ntflag = 0; /* test zip file if true */ lpDCL->nvflag = 0; /* give a verbose listing if true */ lpDCL->nzflag = 0; /* display a zip file comment if true */ lpDCL->ndflag = 1; /* Recreate directories if true */ lpDCL->naflag = 0; /* Do not convert CR to CRLF */ lpDCL->nfflag = 0; /* Do not freshen existing files only */ lpDCL->noflag = 1; /* Over-write all files if true */ lpDCL->ExtractOnlyNewer = 0; /* Do not extract only newer */ lpDCL->PromptToOverwrite = 0; /* "Overwrite all" selected -> no query mode */ lpDCL->lpszZipFN = argv[1]; /* The archive name */ lpDCL->lpszExtractDir = NULL; /* The directory to extract to. This is set to NULL if you are extracting to the current directory. */ /* As this is a quite short example, intended primarily to show how to load and call in to the dll, the command-line parameters are only parsed in a very simplistic way: We assume that the command-line parameters after the zip archive make up a list of file patterns: " [file_i1] [file_i2] ... [file_iN] [-x file_x1 [file_x2] ...]". We scan for an argument "-x"; all arguments in front are "include file patterns", all arguments after are "exclude file patterns". If no more arguments are given, we extract ALL files. In summary, the example program should be run like: example <archive.name> [files to include] [-x files to exclude] ("<...> denotes mandatory arguments, "[...]" optional arguments) */ x_opt = NULL; if (argc > 2) { infv = &argv[2]; for (infc = 0; infc < argc-2; infc++) if (!strcmp("-x", infv[infc])) { x_opt = infv[infc]; infv[infc] = NULL; break; } exfc = argc - infc - 3; if (exfc > 0) exfv = &argv[infc+3]; else { exfc = 0; exfv = NULL; } } else { infc = exfc = 0; infv = exfv = NULL; } retcode = (*Wiz_SingleEntryUnzip)(infc, infv, exfc, exfv, lpDCL, lpUserFunctions); if (x_opt) { infv[infc] = x_opt; x_opt = NULL; } if (retcode != 0) printf("Error unzipping...\n"); FreeUpMemory(); FreeLibrary(hUnzipDll); return 1; }
bool PluginPackage::load() { if (m_freeLibraryTimer.isActive()) { ASSERT(m_module); m_freeLibraryTimer.stop(); } else if (m_isLoaded) { if (m_quirks.contains(PluginQuirkDontAllowMultipleInstances)) return false; m_loadCount++; return true; } else { #if OS(WINCE) m_module = ::LoadLibraryW(m_path.charactersWithNullTermination()); #else WCHAR currentPath[MAX_PATH]; if (!::GetCurrentDirectoryW(MAX_PATH, currentPath)) return false; String path = m_path.substring(0, m_path.reverseFind('\\')); if (!::SetCurrentDirectoryW(path.charactersWithNullTermination())) return false; // Load the library m_module = ::LoadLibraryExW(m_path.charactersWithNullTermination(), 0, LOAD_WITH_ALTERED_SEARCH_PATH); if (!::SetCurrentDirectoryW(currentPath)) { if (m_module) ::FreeLibrary(m_module); return false; } #endif } if (!m_module) return false; m_isLoaded = true; NP_GetEntryPointsFuncPtr NP_GetEntryPoints = 0; NP_InitializeFuncPtr NP_Initialize = 0; NPError npErr; #if OS(WINCE) NP_Initialize = (NP_InitializeFuncPtr)GetProcAddress(m_module, L"NP_Initialize"); NP_GetEntryPoints = (NP_GetEntryPointsFuncPtr)GetProcAddress(m_module, L"NP_GetEntryPoints"); m_NPP_Shutdown = (NPP_ShutdownProcPtr)GetProcAddress(m_module, L"NP_Shutdown"); #else NP_Initialize = (NP_InitializeFuncPtr)GetProcAddress(m_module, "NP_Initialize"); NP_GetEntryPoints = (NP_GetEntryPointsFuncPtr)GetProcAddress(m_module, "NP_GetEntryPoints"); m_NPP_Shutdown = (NPP_ShutdownProcPtr)GetProcAddress(m_module, "NP_Shutdown"); #endif if (!NP_Initialize || !NP_GetEntryPoints || !m_NPP_Shutdown) goto abort; memset(&m_pluginFuncs, 0, sizeof(m_pluginFuncs)); m_pluginFuncs.size = sizeof(m_pluginFuncs); npErr = NP_GetEntryPoints(&m_pluginFuncs); LOG_NPERROR(npErr); if (npErr != NPERR_NO_ERROR) goto abort; initializeBrowserFuncs(); npErr = NP_Initialize(&m_browserFuncs); LOG_NPERROR(npErr); if (npErr != NPERR_NO_ERROR) goto abort; m_loadCount++; return true; abort: unloadWithoutShutdown(); return false; }
/////////////////////////////////////////////////////////////////////////// // // GetCurrentProcessorNumber for the current thread. // // Only a guide as it could change after the call has returned // /////////////////////////////////////////////////////////////////////////// DWORD _GetCurrentProcessorNumber ( void ) { DWORD dwProcessorNumber = -1; #ifdef WIN32 typedef DWORD (WINAPI *FUNC_GetCurrentProcessorNumber)( VOID ); // Dynamically load GetCurrentProcessorNumber, as it does not exist on XP static FUNC_GetCurrentProcessorNumber pfn = NULL; static bool bDone = false; if ( !bDone ) { HMODULE hModule = LoadLibraryA ( "Kernel32" ); pfn = static_cast < FUNC_GetCurrentProcessorNumber > ( static_cast < PVOID > ( GetProcAddress ( hModule, "GetCurrentProcessorNumber" ) ) ); bDone = true; } if ( pfn ) dwProcessorNumber = pfn (); #endif return dwProcessorNumber; }
/************************************************************************** * DRIVER_TryOpenDriver32 [internal] * * Tries to load a 32 bit driver whose DLL's (module) name is fn */ LPWINE_DRIVER DRIVER_TryOpenDriver32(LPCWSTR fn, LPARAM lParam2) { LPWINE_DRIVER lpDrv = NULL; HMODULE hModule = 0; LPWSTR ptr; LPCSTR cause = 0; TRACE("(%s, %08lX);\n", debugstr_w(fn), lParam2); if ((ptr = strchrW(fn, ' ')) != NULL) { *ptr++ = '\0'; while (*ptr == ' ') ptr++; if (*ptr == '\0') ptr = NULL; } lpDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_DRIVER)); if (lpDrv == NULL) {cause = "OOM"; goto exit;} if ((hModule = LoadLibraryW(fn)) == 0) {cause = "Not a 32 bit lib"; goto exit;} lpDrv->lpDrvProc = (DRIVERPROC)GetProcAddress(hModule, "DriverProc"); if (lpDrv->lpDrvProc == NULL) {cause = "no DriverProc"; goto exit;} lpDrv->dwFlags = 0; lpDrv->hModule = hModule; lpDrv->dwDriverID = 0; /* Win32 installable drivers must support a two phase opening scheme: * + first open with NULL as lParam2 (session instance), * + then do a second open with the real non null lParam2) */ if (DRIVER_GetNumberOfModuleRefs(lpDrv->hModule, NULL) == 0 && lParam2) { LPWINE_DRIVER ret; if (!DRIVER_AddToList(lpDrv, (LPARAM)ptr, 0L)) { cause = "load0 failed"; goto exit; } ret = DRIVER_TryOpenDriver32(fn, lParam2); if (!ret) { CloseDriver((HDRVR)lpDrv, 0L, 0L); cause = "load1 failed"; goto exit; } lpDrv->dwFlags |= WINE_GDF_SESSION; return ret; } if (!DRIVER_AddToList(lpDrv, (LPARAM)ptr, lParam2)) {cause = "load failed"; goto exit;} TRACE("=> %p\n", lpDrv); return lpDrv; exit: FreeLibrary(hModule); HeapFree(GetProcessHeap(), 0, lpDrv); TRACE("Unable to load 32 bit module %s: %s\n", debugstr_w(fn), cause); return NULL; }
void SSLManager::loadSecurityLibrary() { if (_hSecurityModule) return; OSVERSIONINFO VerInfo; std::wstring dllPath; // Find out which security DLL to use, depending on // whether we are on Win2k, NT or Win9x VerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); if (!GetVersionEx(&VerInfo)) throw Poco::SystemException("Cannot determine OS version"); #if defined(_WIN32_WCE) dllPath = L"Secur32.dll"; #else if (VerInfo.dwPlatformId == VER_PLATFORM_WIN32_NT && VerInfo.dwMajorVersion == 4) { dllPath = L"Security.dll"; } else if (VerInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS || VerInfo.dwPlatformId == VER_PLATFORM_WIN32_NT ) { dllPath = L"Secur32.dll"; } else { throw Poco::SystemException("Cannot determine which security DLL to use"); } #endif // // Load Security DLL // _hSecurityModule = LoadLibraryW(dllPath.c_str()); if(_hSecurityModule == 0) { throw Poco::SystemException("Failed to load security DLL"); } #if defined(_WIN32_WCE) INIT_SECURITY_INTERFACE pInitSecurityInterface = (INIT_SECURITY_INTERFACE)GetProcAddressW( _hSecurityModule, L"InitSecurityInterfaceW"); #else INIT_SECURITY_INTERFACE pInitSecurityInterface = (INIT_SECURITY_INTERFACE)GetProcAddress( _hSecurityModule, "InitSecurityInterfaceW"); #endif if (!pInitSecurityInterface) { FreeLibrary(_hSecurityModule); _hSecurityModule = 0; throw Poco::SystemException("Failed to initialize security DLL (no init function)"); } PSecurityFunctionTable pSecurityFunc = pInitSecurityInterface(); if (!pSecurityFunc) { FreeLibrary(_hSecurityModule); _hSecurityModule = 0; throw Poco::SystemException("Failed to initialize security DLL (no function table)"); } CopyMemory(&_securityFunctions, pSecurityFunc, sizeof(_securityFunctions)); }
void InitOutput (ScreenInfo *screenInfo, int argc, char *argv[]) { int i; /* Log the command line */ winLogCommandLine (argc, argv); #if CYGDEBUG winDebug ("InitOutput\n"); #endif /* Validate command-line arguments */ if (serverGeneration == 1 && !winValidateArgs ()) { FatalError ("InitOutput - Invalid command-line arguments found. " "Exiting.\n"); } /* Check for duplicate invocation on same display number.*/ if (serverGeneration == 1 && !winCheckDisplayNumber ()) { if (g_fSilentDupError) g_fSilentFatalError = TRUE; FatalError ("InitOutput - Duplicate invocation on display " "number: %s. Exiting.\n", display); } #ifdef XWIN_XF86CONFIG /* Try to read the xorg.conf-style configuration file */ if (!winReadConfigfile ()) winErrorFVerb (1, "InitOutput - Error reading config file\n"); #else winMsg(X_INFO, "xorg.conf is not supported\n"); winMsg(X_INFO, "See http://x.cygwin.com/docs/faq/cygwin-x-faq.html " "for more information\n"); winConfigFiles (); #endif /* Load preferences from XWinrc file */ LoadPreferences(); /* Setup global screen info parameters */ screenInfo->imageByteOrder = IMAGE_BYTE_ORDER; screenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD; screenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT; screenInfo->bitmapBitOrder = BITMAP_BIT_ORDER; screenInfo->numPixmapFormats = NUMFORMATS; /* Describe how we want common pixmap formats padded */ for (i = 0; i < NUMFORMATS; i++) { screenInfo->formats[i] = g_PixmapFormats[i]; } /* Load pointers to DirectDraw functions */ winGetDDProcAddresses (); /* Detect supported engines */ winDetectSupportedEngines (); /* Load common controls library */ g_hmodCommonControls = LoadLibraryEx ("comctl32.dll", NULL, 0); /* Load TrackMouseEvent function pointer */ g_fpTrackMouseEvent = GetProcAddress (g_hmodCommonControls, "_TrackMouseEvent"); if (g_fpTrackMouseEvent == NULL) { winErrorFVerb (1, "InitOutput - Could not get pointer to function\n" "\t_TrackMouseEvent in comctl32.dll. Try installing\n" "\tInternet Explorer 3.0 or greater if you have not\n" "\talready.\n"); /* Free the library since we won't need it */ FreeLibrary (g_hmodCommonControls); g_hmodCommonControls = NULL; /* Set function pointer to point to no operation function */ g_fpTrackMouseEvent = (FARPROC) (void (*)(void))NoopDDA; } /* Store the instance handle */ g_hInstance = GetModuleHandle (NULL); /* Initialize each screen */ for (i = 0; i < g_iNumScreens; ++i) { /* Initialize the screen */ if (-1 == AddScreen (winScreenInit, argc, argv)) { FatalError ("InitOutput - Couldn't add screen %d", i); } } #if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW) /* Generate a cookie used by internal clients for authorization */ if (g_fXdmcpEnabled || g_fAuthEnabled) winGenerateAuthorization (); /* Perform some one time initialization */ if (1 == serverGeneration) { /* * setlocale applies to all threads in the current process. * Apply locale specified in LANG environment variable. */ setlocale (LC_ALL, ""); } #endif #if CYGDEBUG || YES winDebug ("InitOutput - Returning.\n"); #endif }
/*-----------------------------------------------------------------------------------*/ IMPORT_EXPORT_GETWINDOWSVERSION_DLL int GetWindowsVersion(void) { OSVERSIONINFOEX osvi; BOOL bOsVersionInfoEx; ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); if ( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) ) { osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) { return OS_ERROR; } } switch (osvi.dwPlatformId) { case VER_PLATFORM_WIN32_NT: if (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 2) { if ( osvi.wProductType == VER_NT_WORKSTATION ) { #ifdef _WIN64 return OS_WIN32_WINDOWS_EIGHT_64; #else if (IsWow64()) { return OS_WIN32_WINDOWS_EIGHT_64; } else { return OS_WIN32_WINDOWS_EIGHT; } #endif } else { #ifdef _WIN64 return OS_WIN32_WINDOWS_EIGHT_SERVER_64; #else if (IsWow64()) { return OS_WIN32_WINDOWS_EIGHT_SERVER_64; } else { return OS_WIN32_WINDOWS_EIGHT_SERVER; } #endif } } if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 1 ) { if ( osvi.wProductType == VER_NT_WORKSTATION ) { #ifdef _WIN64 return OS_WIN32_WINDOWS_SEVEN_64; #else if (IsWow64()) { return OS_WIN32_WINDOWS_SEVEN_64; } else { return OS_WIN32_WINDOWS_SEVEN; } #endif } else { #ifdef _WIN64 return OS_WIN32_WINDOWS_SEVEN_SERVER_64; #else if (IsWow64()) { return OS_WIN32_WINDOWS_SEVEN_SERVER_64; } else { return OS_WIN32_WINDOWS_SEVEN_SERVER; } #endif } } if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0 ) { if ( osvi.wProductType == VER_NT_WORKSTATION ) { #ifdef _WIN64 return OS_WIN32_WINDOWS_VISTA_64; #else if (IsWow64()) { return OS_WIN32_WINDOWS_VISTA_64; } else { return OS_WIN32_WINDOWS_VISTA; } #endif } else { #ifdef _WIN64 return OS_WIN32_WINDOWS_SERVER_2008_64; #else if (IsWow64()) { return OS_WIN32_WINDOWS_SERVER_2008_64; } else { return OS_WIN32_WINDOWS_SERVER_2008; } #endif } } if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 ) { SYSTEM_INFO si; PGNSI pGNSI; pGNSI = (PGNSI) GetProcAddress(GetModuleHandle("kernel32.dll"), "GetNativeSystemInfo"); if (NULL != pGNSI) { pGNSI(&si); } if ( GetSystemMetrics(SM_SERVERR2) ) { return OS_WIN32_WINDOWS_SERVER_2003_R2; } else if ( osvi.wProductType == VER_NT_WORKSTATION && si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) { return OS_WIN32_WINDOWS_XP_64; } else { return OS_WIN32_WINDOWS_SERVER_2003; } } if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 ) { return OS_WIN32_WINDOWS_XP; } if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 ) { return OS_WIN32_WINDOWS_2000; } if ( osvi.dwMajorVersion == 4 ) { return OS_WIN32_WINDOWS_NT_4_0; } if ( osvi.dwMajorVersion == 3 && osvi.dwMinorVersion == 51 ) { return OS_WIN32_WINDOWS_NT_3_51; } break; case VER_PLATFORM_WIN32_WINDOWS: if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0) { return OS_WIN32_WINDOWS_95; } if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10) { return OS_WIN32_WINDOWS_98; } if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90) { return OS_WIN32_WINDOWS_Me; } break; } return OS_ERROR; }
bool InitDirectInput( HWND hWnd ) { if( g_hDirectInputDLL == NULL ) g_hDirectInputDLL = LoadLibrary( _T( "dinput8.dll" )); if( g_hDirectInputDLL == NULL ) { ErrorMessage(IDS_ERR_DINOTFOUND, 0, false); } else if( !g_pDIHandle ) // is NULL if not yet initialized { HRESULT (WINAPI *lpGetDIHandle)( HINSTANCE, DWORD, REFIID, LPVOID*, LPUNKNOWN ) = NULL; lpGetDIHandle = (HRESULT (WINAPI *)( HINSTANCE, DWORD, REFIID, LPVOID*, LPUNKNOWN ))GetProcAddress( g_hDirectInputDLL, "DirectInput8Create" ); if( lpGetDIHandle != NULL ) { HRESULT hr; hr = lpGetDIHandle( g_strEmuInfo.hinst, DIRECTINPUT_VERSION, IID_IDirectInput8, (LPVOID*)&g_pDIHandle, NULL ); if( FAILED( hr )) { ErrorMessage(IDS_ERR_DICREATE, 0, false); g_pDIHandle = NULL; FreeLibrary( g_hDirectInputDLL ); g_hDirectInputDLL = NULL; } } } return (g_pDIHandle != NULL); }
static lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) { lua_CFunction f = (lua_CFunction)GetProcAddress((HMODULE)lib, sym); if (f == NULL) pusherror(L); return f; }
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { int argc; /* VLC does not change the thread locale, so gettext/libintil will use the * user default locale as reference. */ /* gettext versions 0.18-0.18.1 will use the Windows Vista locale name * if the GETTEXT_MUI environment variable is set. If not set or if running * on Windows 2000/XP/2003 an hard-coded language ID list is used. This * putenv() call may become redundant with later versions of gettext. */ putenv("GETTEXT_MUI=1"); #ifdef TOP_BUILDDIR putenv("VLC_PLUGIN_PATH=Z:"TOP_BUILDDIR"/modules"); putenv("VLC_DATA_PATH=Z:"TOP_SRCDIR"/share"); #endif SetErrorMode(SEM_FAILCRITICALERRORS); HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0); /* SetProcessDEPPolicy */ HINSTANCE h_Kernel32 = LoadLibraryW(L"kernel32.dll"); if(h_Kernel32) { BOOL (WINAPI * mySetProcessDEPPolicy)( DWORD dwFlags); BOOL (WINAPI * mySetDllDirectoryA)(const char* lpPathName); # define PROCESS_DEP_ENABLE 1 mySetProcessDEPPolicy = (BOOL (WINAPI *)(DWORD)) // sunqueen modify GetProcAddress(h_Kernel32, "SetProcessDEPPolicy"); if(mySetProcessDEPPolicy) mySetProcessDEPPolicy(PROCESS_DEP_ENABLE); /* Do NOT load any library from cwd. */ mySetDllDirectoryA = (BOOL (WINAPI *)(const char *)) // sunqueen modify GetProcAddress(h_Kernel32, "SetDllDirectoryA"); if(mySetDllDirectoryA) mySetDllDirectoryA(""); FreeLibrary(h_Kernel32); } /* Args */ wchar_t **wargv = CommandLineToArgvW (GetCommandLine (), &argc); if (wargv == NULL) return 1; // char *argv[argc + 3]; char **argv = (char **)malloc((argc + 3) * sizeof(char *)); // sunqueen modify BOOL crash_handling = TRUE; int j = 0; char *lang = NULL; argv[j++] = FromWide( L"--media-library" ); argv[j++] = FromWide( L"--no-ignore-config" ); for (int i = 1; i < argc; i++) { if(!wcscmp(wargv[i], L"--no-crashdump")) { crash_handling = FALSE; continue; /* don't give argument to libvlc */ } if (!wcsncmp(wargv[i], L"--language", 10) ) { if (i < argc - 1 && wcsncmp( wargv[i + 1], L"--", 2 )) lang = FromWide (wargv[++i]); continue; } argv[j++] = FromWide (wargv[i]); } argc = j; argv[argc] = NULL; LocalFree (wargv); if(crash_handling) { static wchar_t path[MAX_PATH]; if( S_OK != SHGetFolderPathW( NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, path ) ) fprintf( stderr, "Can't open the vlc conf PATH\n" ); _snwprintf( path+wcslen( path ), MAX_PATH, L"%s", L"\\vlc\\crashdump" ); crashdump_path = &path[0]; check_crashdump(); SetUnhandledExceptionFilter(vlc_exception_filter); } _setmode( STDIN_FILENO, _O_BINARY ); /* Needed for pipes */ /* */ if (!lang) { HKEY h_key; if( RegOpenKeyEx( HKEY_CURRENT_USER, TEXT("Software\\VideoLAN\\VLC\\"), 0, KEY_READ, &h_key ) == ERROR_SUCCESS ) { TCHAR szData[256]; DWORD len = 256; if( RegQueryValueEx( h_key, TEXT("Lang"), NULL, NULL, (LPBYTE) &szData, &len ) == ERROR_SUCCESS ) lang = FromWide( szData ); } } if (lang && strncmp( lang, "auto", 4 ) ) { char tmp[11]; snprintf(tmp, 11, "LANG=%s", lang); putenv(tmp); } free(lang); /* Initialize libvlc */ libvlc_instance_t *vlc; vlc = libvlc_new (argc, (const char **)argv); if (vlc != NULL) { libvlc_set_app_id (vlc, "org.VideoLAN.VLC", PACKAGE_VERSION, PACKAGE_NAME); libvlc_set_user_agent (vlc, "VLC media player", "VLC/"PACKAGE_VERSION); libvlc_add_intf (vlc, "hotkeys,none"); libvlc_add_intf (vlc, "globalhotkeys,none"); libvlc_add_intf (vlc, NULL); libvlc_playlist_play (vlc, -1, 0, NULL); libvlc_wait (vlc); libvlc_release (vlc); } else MessageBox (NULL, TEXT("VLC media player could not start.\nEither the command line options were invalid or no plugins were found.\n"), TEXT("VLC media player"), MB_OK|MB_ICONERROR); for (int i = 0; i < argc; i++) free (argv[i]); free(argv); // sunqueen add (void)hInstance; (void)hPrevInstance; (void)lpCmdLine; (void)nCmdShow; return 0; }
//----------------------------------------------------------------// void MOAIEnvironment::DetectEnvironment () { RTTI_SINGLE ( MOAIGlobalEventSource ) #if defined( MOAI_OS_WINDOWS ) this->SetValue ( MOAI_ENV_osBrand, "Windows" ); UUID uuid; UuidCreateSequential ( &uuid ); // For now, we'll just use the MAC address which is the last 6 bytes of the uuid. char buf[13]; sprintf ( buf, "%02X%02X%02X%02X%02X%02X", uuid.Data4[2], uuid.Data4[3], uuid.Data4[4], uuid.Data4[5], uuid.Data4[6], uuid.Data4[7]); this->SetValue ( MOAI_ENV_udid, buf ); char path[MAX_PATH]; //HRESULT hr = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, path); SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, path); this->SetValue ( MOAI_ENV_documentDirectory, path ); const int BUFSIZE = 256; TCHAR pszOS[BUFSIZE]; OSVERSIONINFOEX osvi; SYSTEM_INFO si; PGNSI pGNSI; ZeroMemory(&si, sizeof(SYSTEM_INFO)); ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); GetVersionEx((OSVERSIONINFO*) &osvi); pGNSI = (PGNSI) GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo"); if(NULL != pGNSI) { pGNSI(&si); } else { GetSystemInfo(&si); } if ( VER_PLATFORM_WIN32_NT==osvi.dwPlatformId && osvi.dwMajorVersion > 4 ) { strcpy ( pszOS, TEXT ( "Win" )); if ( osvi.dwMajorVersion == 6 ) { if ( osvi.dwMinorVersion == 1 ) { if( osvi.wProductType == VER_NT_WORKSTATION ) strcat(pszOS, TEXT("7")); else strcat(pszOS, TEXT("2008R2" )); } else if( osvi.dwMinorVersion == 0 ) { if( osvi.wProductType == VER_NT_WORKSTATION ) strcat(pszOS, TEXT("Vista")); else strcat(pszOS, TEXT("Server2008" )); } } else if ( osvi.dwMajorVersion == 5 ) { if (osvi.dwMinorVersion == 2) { if( osvi.wProductType == VER_NT_WORKSTATION && si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64) { strcat(pszOS, TEXT( "XPx64")); } else { strcat(pszOS, TEXT("Server2003")); } } else if ( osvi.dwMinorVersion == 1 ) { strcat(pszOS, TEXT("XP")); } else if ( osvi.dwMinorVersion == 0 ) { strcat(pszOS, TEXT("2000")); } } this->SetValue ( MOAI_ENV_osVersion, pszOS ); } else { this->SetValue ( MOAI_ENV_osVersion, "WinUnknown" ); } #elif defined( MOAI_OS_LINUX ) this->SetValue ( MOAI_ENV_osBrand, "Linux" ); #elif defined ( MOAI_OS_OSX ) this->SetValue ( MOAI_ENV_osBrand, "OSX" ); #if 0 /* doesn't compile yet */ // OS Version SInt32 majorVersion,minorVersion,bugFixVersion; Gestalt(gestaltSystemVersionMajor, &majorVersion); Gestalt(gestaltSystemVersionMinor, &minorVersion); Gestalt(gestaltSystemVersionBugFix, &bugFixVersion); char buffer[256]; sprintf(buffer, "%d.%d.%d",majorVersion,minorVersion,bugFixVersion); this->SetValue ( MOAI_ENV_osVersion, buffer ); #endif #endif }
/************* * DESCRIPTION: do initializations for an instance * INPUT: - * OUTPUT: - *************/ BOOL CTheApp::InitInstance() { KEYGETINFO keyGetInfo; HMODULE hKeyFile; OSVERSIONINFO OSVersionInfo; char szBuf[15]; OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); if (!GetVersionEx(&OSVersionInfo)) return FALSE; if (OSVersionInfo.dwMajorVersion < 4) { AfxMessageBox(IDS_ERR_PLATFORM); return FALSE; } // This is just for setting the current working directory in rsi.dll rsiInit(); // Standard initialization // 3d controls and grey background Enable3dControls(); SetDialogBkColor(); // Drag and drop support AfxOleInit(); strcpy(szBuf, "ke"); // Load standard INI file options (including MRU) LoadStdProfileSettings(); getcwd(szWorkingDirectory, 256); // get user name and serial number out of keyfile strcpy(szUserName, ""); strcat(szBuf, "yfil"); nUserSernum = 0; strcat(szBuf, "e.dll"); hKeyFile = LoadLibrary(szBuf); if (hKeyFile) { keyGetInfo = (KEYGETINFO)GetProcAddress(hKeyFile, (LPCSTR)2); keyGetInfo(szUserName, &nUserSernum); FreeLibrary(hKeyFile); } // Register document templates CSingleDocTemplate *pDocTemplate; pDocTemplate = new CSingleDocTemplate(IDR_MAINFRAME, RUNTIME_CLASS(CDoc), RUNTIME_CLASS(CMainFrame), // main SDI frame window RUNTIME_CLASS(CCamView)); AddDocTemplate(pDocTemplate); OnFileNew(); return TRUE; }
void DwmSetIconicLivePreviewBitmap(HWND hwnd, HBITMAP hbmp, POINT *pptClient, DWORD dwSITFlags) { HMODULE dwmapi = LoadLibrary(TEXT("dwmapi.dll")); if (dwmapi) { t_DwmSetIconicLivePreviewBitmap set_live_preview = reinterpret_cast<t_DwmSetIconicLivePreviewBitmap>(GetProcAddress(dwmapi, "DwmSetIconicLivePreviewBitmap")); set_live_preview(hwnd, hbmp, pptClient, dwSITFlags); FreeLibrary(dwmapi); } }
//------------------------------------------------------------------ // get CPU usage on NT-style operating systems //------------------------------------------------------------------ DWORD cpuUsageNT() { static SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo; static SYSTEM_TIME_INFORMATION SysTimeInfo; static SYSTEM_BASIC_INFORMATION SysBaseInfo; static double dbIdleTime; static double dbSystemTime; static LONG status; static LARGE_INTEGER liOldIdleTime = {0,0}; static LARGE_INTEGER liOldSystemTime = {0,0}; static BOOL init = FALSE; static PROCNTQSI NtQuerySystemInformation = NULL; DWORD retVal = 0xffffffff; if( !init ) { NtQuerySystemInformation = (PROCNTQSI)GetProcAddress( GetModuleHandle(_T("ntdll")), "NtQuerySystemInformation" ); if( !NtQuerySystemInformation ) return 0xffffffff; // get number of processors in the system status = NtQuerySystemInformation( SystemBasicInformation, &SysBaseInfo, sizeof(SysBaseInfo), NULL ); if( status != NO_ERROR ) return 0xffffffff; init = TRUE; } // get new system time status = NtQuerySystemInformation( SystemTimeInformation, &SysTimeInfo, sizeof(SysTimeInfo), 0 ); if( status != NO_ERROR ) return 0xffffffff; // get new CPU's idle time status = NtQuerySystemInformation( SystemPerformanceInformation, &SysPerfInfo, sizeof(SysPerfInfo), NULL ); if( status != NO_ERROR ) return 0xffffffff; // if it's a first call - skip it if( liOldIdleTime.QuadPart != 0 ) { // CurrentValue = NewValue - OldValue dbIdleTime = Li2Double( SysPerfInfo.liIdleTime ) - Li2Double( liOldIdleTime ); dbSystemTime = Li2Double( SysTimeInfo.liKeSystemTime ) - Li2Double( liOldSystemTime ); // CurrentCpuIdle = IdleTime / SystemTime dbIdleTime = dbIdleTime / dbSystemTime; // CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors dbIdleTime = 100.0 - dbIdleTime * 100.0 / (double)SysBaseInfo.bKeNumberProcessors + 0.5; retVal = (DWORD)dbIdleTime; } // store new CPU's idle and system time liOldIdleTime = SysPerfInfo.liIdleTime; liOldSystemTime = SysTimeInfo.liKeSystemTime; return retVal; }
void DwmSetWindowAttribute(HWND hwnd, DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute) { HMODULE dwmapi = LoadLibrary(TEXT("dwmapi.dll")); if (dwmapi) { t_DwmSetWindowAttribute set_window_attribute = reinterpret_cast<t_DwmSetWindowAttribute>(GetProcAddress(dwmapi, "DwmSetWindowAttribute")); set_window_attribute(hwnd, dwAttribute, pvAttribute, cbAttribute); FreeLibrary(dwmapi); } }
void DwmSetIconicThumbnail(HWND hwnd, HBITMAP hbmp, DWORD dwSITFlags) { HMODULE dwmapi = LoadLibrary(TEXT("dwmapi.dll")); if (dwmapi) { t_DwmSetIconicThumbnail set_iconic_thumbnail = reinterpret_cast<t_DwmSetIconicThumbnail>(GetProcAddress(dwmapi, "DwmSetIconicThumbnail")); set_iconic_thumbnail(hwnd, hbmp, dwSITFlags); FreeLibrary(dwmapi); } }
void DwmInvalidateIconicBitmaps(HWND hwnd) { HMODULE dwmapi = LoadLibrary(TEXT("dwmapi.dll")); if (dwmapi) { t_DwmInvalidateIconicBitmaps invalidate_icon_bitmap = reinterpret_cast<t_DwmInvalidateIconicBitmaps>(GetProcAddress(dwmapi, "DwmInvalidateIconicBitmaps")); invalidate_icon_bitmap(hwnd); FreeLibrary(dwmapi); } }
ALboolean LoadOAL10Library(char *szOALFullPathName, LPOPENALFNTABLE lpOALFnTable) { if (!lpOALFnTable) return AL_FALSE; if (szOALFullPathName) g_hOpenALDLL = LoadLibrary(szOALFullPathName); else g_hOpenALDLL = LoadLibrary("openal32.dll"); if (!g_hOpenALDLL) return AL_FALSE; memset(lpOALFnTable, 0, sizeof(OPENALFNTABLE)); // Get function pointers lpOALFnTable->alEnable = (LPALENABLE)GetProcAddress(g_hOpenALDLL, "alEnable"); if (lpOALFnTable->alEnable == NULL) { OutputDebugString("Failed to retrieve 'alEnable' function address\n"); return AL_FALSE; } lpOALFnTable->alDisable = (LPALDISABLE)GetProcAddress(g_hOpenALDLL, "alDisable"); if (lpOALFnTable->alDisable == NULL) { OutputDebugString("Failed to retrieve 'alDisable' function address\n"); return AL_FALSE; } lpOALFnTable->alIsEnabled = (LPALISENABLED)GetProcAddress(g_hOpenALDLL, "alIsEnabled"); if (lpOALFnTable->alIsEnabled == NULL) { OutputDebugString("Failed to retrieve 'alIsEnabled' function address\n"); return AL_FALSE; } lpOALFnTable->alGetBoolean = (LPALGETBOOLEAN)GetProcAddress(g_hOpenALDLL, "alGetBoolean"); if (lpOALFnTable->alGetBoolean == NULL) { OutputDebugString("Failed to retrieve 'alGetBoolean' function address\n"); return AL_FALSE; } lpOALFnTable->alGetInteger = (LPALGETINTEGER)GetProcAddress(g_hOpenALDLL, "alGetInteger"); if (lpOALFnTable->alGetInteger == NULL) { OutputDebugString("Failed to retrieve 'alGetInteger' function address\n"); return AL_FALSE; } lpOALFnTable->alGetFloat = (LPALGETFLOAT)GetProcAddress(g_hOpenALDLL, "alGetFloat"); if (lpOALFnTable->alGetFloat == NULL) { OutputDebugString("Failed to retrieve 'alGetFloat' function address\n"); return AL_FALSE; } lpOALFnTable->alGetDouble = (LPALGETDOUBLE)GetProcAddress(g_hOpenALDLL, "alGetDouble"); if (lpOALFnTable->alGetDouble == NULL) { OutputDebugString("Failed to retrieve 'alGetDouble' function address\n"); return AL_FALSE; } lpOALFnTable->alGetBooleanv = (LPALGETBOOLEANV)GetProcAddress(g_hOpenALDLL, "alGetBooleanv"); if (lpOALFnTable->alGetBooleanv == NULL) { OutputDebugString("Failed to retrieve 'alGetBooleanv' function address\n"); return AL_FALSE; } lpOALFnTable->alGetIntegerv = (LPALGETINTEGERV)GetProcAddress(g_hOpenALDLL, "alGetIntegerv"); if (lpOALFnTable->alGetIntegerv == NULL) { OutputDebugString("Failed to retrieve 'alGetIntegerv' function address\n"); return AL_FALSE; } lpOALFnTable->alGetFloatv = (LPALGETFLOATV)GetProcAddress(g_hOpenALDLL, "alGetFloatv"); if (lpOALFnTable->alGetFloatv == NULL) { OutputDebugString("Failed to retrieve 'alGetFloatv' function address\n"); return AL_FALSE; } lpOALFnTable->alGetDoublev = (LPALGETDOUBLEV)GetProcAddress(g_hOpenALDLL, "alGetDoublev"); if (lpOALFnTable->alGetDoublev == NULL) { OutputDebugString("Failed to retrieve 'alGetDoublev' function address\n"); return AL_FALSE; } lpOALFnTable->alGetString = (LPALGETSTRING)GetProcAddress(g_hOpenALDLL, "alGetString"); if (lpOALFnTable->alGetString == NULL) { OutputDebugString("Failed to retrieve 'alGetString' function address\n"); return AL_FALSE; } lpOALFnTable->alGetError = (LPALGETERROR)GetProcAddress(g_hOpenALDLL, "alGetError"); if (lpOALFnTable->alGetError == NULL) { OutputDebugString("Failed to retrieve 'alGetError' function address\n"); return AL_FALSE; } lpOALFnTable->alIsExtensionPresent = (LPALISEXTENSIONPRESENT)GetProcAddress(g_hOpenALDLL, "alIsExtensionPresent"); if (lpOALFnTable->alIsExtensionPresent == NULL) { OutputDebugString("Failed to retrieve 'alIsExtensionPresent' function address\n"); return AL_FALSE; } lpOALFnTable->alGetProcAddress = (LPALGETPROCADDRESS)GetProcAddress(g_hOpenALDLL, "alGetProcAddress"); if (lpOALFnTable->alGetProcAddress == NULL) { OutputDebugString("Failed to retrieve 'alGetProcAddress' function address\n"); return AL_FALSE; } lpOALFnTable->alGetEnumValue = (LPALGETENUMVALUE)GetProcAddress(g_hOpenALDLL, "alGetEnumValue"); if (lpOALFnTable->alGetEnumValue == NULL) { OutputDebugString("Failed to retrieve 'alGetEnumValue' function address\n"); return AL_FALSE; } lpOALFnTable->alListeneri = (LPALLISTENERI)GetProcAddress(g_hOpenALDLL, "alListeneri"); if (lpOALFnTable->alListeneri == NULL) { OutputDebugString("Failed to retrieve 'alListeneri' function address\n"); return AL_FALSE; } lpOALFnTable->alListenerf = (LPALLISTENERF)GetProcAddress(g_hOpenALDLL, "alListenerf"); if (lpOALFnTable->alListenerf == NULL) { OutputDebugString("Failed to retrieve 'alListenerf' function address\n"); return AL_FALSE; } lpOALFnTable->alListener3f = (LPALLISTENER3F)GetProcAddress(g_hOpenALDLL, "alListener3f"); if (lpOALFnTable->alListener3f == NULL) { OutputDebugString("Failed to retrieve 'alListener3f' function address\n"); return AL_FALSE; } lpOALFnTable->alListenerfv = (LPALLISTENERFV)GetProcAddress(g_hOpenALDLL, "alListenerfv"); if (lpOALFnTable->alListenerfv == NULL) { OutputDebugString("Failed to retrieve 'alListenerfv' function address\n"); return AL_FALSE; } lpOALFnTable->alGetListeneri = (LPALGETLISTENERI)GetProcAddress(g_hOpenALDLL, "alGetListeneri"); if (lpOALFnTable->alGetListeneri == NULL) { OutputDebugString("Failed to retrieve 'alGetListeneri' function address\n"); return AL_FALSE; } lpOALFnTable->alGetListenerf =(LPALGETLISTENERF)GetProcAddress(g_hOpenALDLL, "alGetListenerf"); if (lpOALFnTable->alGetListenerf == NULL) { OutputDebugString("Failed to retrieve 'alGetListenerf' function address\n"); return AL_FALSE; } lpOALFnTable->alGetListener3f = (LPALGETLISTENER3F)GetProcAddress(g_hOpenALDLL, "alGetListener3f"); if (lpOALFnTable->alGetListener3f == NULL) { OutputDebugString("Failed to retrieve 'alGetListener3f' function address\n"); return AL_FALSE; } lpOALFnTable->alGetListenerfv = (LPALGETLISTENERFV)GetProcAddress(g_hOpenALDLL, "alGetListenerfv"); if (lpOALFnTable->alGetListenerfv == NULL) { OutputDebugString("Failed to retrieve 'alGetListenerfv' function address\n"); return AL_FALSE; } lpOALFnTable->alGenSources = (LPALGENSOURCES)GetProcAddress(g_hOpenALDLL, "alGenSources"); if (lpOALFnTable->alGenSources == NULL) { OutputDebugString("Failed to retrieve 'alGenSources' function address\n"); return AL_FALSE; } lpOALFnTable->alDeleteSources = (LPALDELETESOURCES)GetProcAddress(g_hOpenALDLL, "alDeleteSources"); if (lpOALFnTable->alDeleteSources == NULL) { OutputDebugString("Failed to retrieve 'alDeleteSources' function address\n"); return AL_FALSE; } lpOALFnTable->alIsSource = (LPALISSOURCE)GetProcAddress(g_hOpenALDLL, "alIsSource"); if (lpOALFnTable->alIsSource == NULL) { OutputDebugString("Failed to retrieve 'alIsSource' function address\n"); return AL_FALSE; } lpOALFnTable->alSourcei = (LPALSOURCEI)GetProcAddress(g_hOpenALDLL, "alSourcei"); if (lpOALFnTable->alSourcei == NULL) { OutputDebugString("Failed to retrieve 'alSourcei' function address\n"); return AL_FALSE; } lpOALFnTable->alSourcef = (LPALSOURCEF)GetProcAddress(g_hOpenALDLL, "alSourcef"); if (lpOALFnTable->alSourcef == NULL) { OutputDebugString("Failed to retrieve 'alSourcef' function address\n"); return AL_FALSE; } lpOALFnTable->alSource3f = (LPALSOURCE3F)GetProcAddress(g_hOpenALDLL, "alSource3f"); if (lpOALFnTable->alSource3f == NULL) { OutputDebugString("Failed to retrieve 'alSource3f' function address\n"); return AL_FALSE; } lpOALFnTable->alSourcefv = (LPALSOURCEFV)GetProcAddress(g_hOpenALDLL, "alSourcefv"); if (lpOALFnTable->alSourcefv == NULL) { OutputDebugString("Failed to retrieve 'alSourcefv' function address\n"); return AL_FALSE; } lpOALFnTable->alGetSourcei = (LPALGETSOURCEI)GetProcAddress(g_hOpenALDLL, "alGetSourcei"); if (lpOALFnTable->alGetSourcei == NULL) { OutputDebugString("Failed to retrieve 'alGetSourcei' function address\n"); return AL_FALSE; } lpOALFnTable->alGetSourcef = (LPALGETSOURCEF)GetProcAddress(g_hOpenALDLL, "alGetSourcef"); if (lpOALFnTable->alGetSourcef == NULL) { OutputDebugString("Failed to retrieve 'alGetSourcef' function address\n"); return AL_FALSE; } lpOALFnTable->alGetSourcefv = (LPALGETSOURCEFV)GetProcAddress(g_hOpenALDLL, "alGetSourcefv"); if (lpOALFnTable->alGetSourcefv == NULL) { OutputDebugString("Failed to retrieve 'alGetSourcefv' function address\n"); return AL_FALSE; } lpOALFnTable->alSourcePlayv = (LPALSOURCEPLAYV)GetProcAddress(g_hOpenALDLL, "alSourcePlayv"); if (lpOALFnTable->alSourcePlayv == NULL) { OutputDebugString("Failed to retrieve 'alSourcePlayv' function address\n"); return AL_FALSE; } lpOALFnTable->alSourceStopv = (LPALSOURCESTOPV)GetProcAddress(g_hOpenALDLL, "alSourceStopv"); if (lpOALFnTable->alSourceStopv == NULL) { OutputDebugString("Failed to retrieve 'alSourceStopv' function address\n"); return AL_FALSE; } lpOALFnTable->alSourcePlay = (LPALSOURCEPLAY)GetProcAddress(g_hOpenALDLL, "alSourcePlay"); if (lpOALFnTable->alSourcePlay == NULL) { OutputDebugString("Failed to retrieve 'alSourcePlay' function address\n"); return AL_FALSE; } lpOALFnTable->alSourcePause = (LPALSOURCEPAUSE)GetProcAddress(g_hOpenALDLL, "alSourcePause"); if (lpOALFnTable->alSourcePause == NULL) { OutputDebugString("Failed to retrieve 'alSourcePause' function address\n"); return AL_FALSE; } lpOALFnTable->alSourceStop = (LPALSOURCESTOP)GetProcAddress(g_hOpenALDLL, "alSourceStop"); if (lpOALFnTable->alSourceStop == NULL) { OutputDebugString("Failed to retrieve 'alSourceStop' function address\n"); return AL_FALSE; } lpOALFnTable->alGenBuffers = (LPALGENBUFFERS)GetProcAddress(g_hOpenALDLL, "alGenBuffers"); if (lpOALFnTable->alGenBuffers == NULL) { OutputDebugString("Failed to retrieve 'alGenBuffers' function address\n"); return AL_FALSE; } lpOALFnTable->alDeleteBuffers = (LPALDELETEBUFFERS)GetProcAddress(g_hOpenALDLL, "alDeleteBuffers"); if (lpOALFnTable->alDeleteBuffers == NULL) { OutputDebugString("Failed to retrieve 'alDeleteBuffers' function address\n"); return AL_FALSE; } lpOALFnTable->alIsBuffer = (LPALISBUFFER)GetProcAddress(g_hOpenALDLL, "alIsBuffer"); if (lpOALFnTable->alIsBuffer == NULL) { OutputDebugString("Failed to retrieve 'alIsBuffer' function address\n"); return AL_FALSE; } lpOALFnTable->alBufferData = (LPALBUFFERDATA)GetProcAddress(g_hOpenALDLL, "alBufferData"); if (lpOALFnTable->alBufferData == NULL) { OutputDebugString("Failed to retrieve 'alBufferData' function address\n"); return AL_FALSE; } lpOALFnTable->alGetBufferi = (LPALGETBUFFERI)GetProcAddress(g_hOpenALDLL, "alGetBufferi"); if (lpOALFnTable->alGetBufferi == NULL) { OutputDebugString("Failed to retrieve 'alGetBufferi' function address\n"); return AL_FALSE; } lpOALFnTable->alGetBufferf = (LPALGETBUFFERF)GetProcAddress(g_hOpenALDLL, "alGetBufferf"); if (lpOALFnTable->alGetBufferf == NULL) { OutputDebugString("Failed to retrieve 'alGetBufferf' function address\n"); return AL_FALSE; } lpOALFnTable->alSourceQueueBuffers = (LPALSOURCEQUEUEBUFFERS)GetProcAddress(g_hOpenALDLL, "alSourceQueueBuffers"); if (lpOALFnTable->alSourceQueueBuffers == NULL) { OutputDebugString("Failed to retrieve 'alSourceQueueBuffers' function address\n"); return AL_FALSE; } lpOALFnTable->alSourceUnqueueBuffers = (LPALSOURCEUNQUEUEBUFFERS)GetProcAddress(g_hOpenALDLL, "alSourceUnqueueBuffers"); if (lpOALFnTable->alSourceUnqueueBuffers == NULL) { OutputDebugString("Failed to retrieve 'alSourceUnqueueBuffers' function address\n"); return AL_FALSE; } lpOALFnTable->alDistanceModel = (LPALDISTANCEMODEL)GetProcAddress(g_hOpenALDLL, "alDistanceModel"); if (lpOALFnTable->alDistanceModel == NULL) { OutputDebugString("Failed to retrieve 'alDistanceModel' function address\n"); return AL_FALSE; } lpOALFnTable->alDopplerFactor = (LPALDOPPLERFACTOR)GetProcAddress(g_hOpenALDLL, "alDopplerFactor"); if (lpOALFnTable->alDopplerFactor == NULL) { OutputDebugString("Failed to retrieve 'alDopplerFactor' function address\n"); return AL_FALSE; } lpOALFnTable->alDopplerVelocity = (LPALDOPPLERVELOCITY)GetProcAddress(g_hOpenALDLL, "alDopplerVelocity"); if (lpOALFnTable->alDopplerVelocity == NULL) { OutputDebugString("Failed to retrieve 'alDopplerVelocity' function address\n"); return AL_FALSE; } lpOALFnTable->alcGetString = (LPALCGETSTRING)GetProcAddress(g_hOpenALDLL, "alcGetString"); if (lpOALFnTable->alcGetString == NULL) { OutputDebugString("Failed to retrieve 'alcGetString' function address\n"); return AL_FALSE; } lpOALFnTable->alcGetIntegerv = (LPALCGETINTEGERV)GetProcAddress(g_hOpenALDLL, "alcGetIntegerv"); if (lpOALFnTable->alcGetIntegerv == NULL) { OutputDebugString("Failed to retrieve 'alcGetIntegerv' function address\n"); return AL_FALSE; } lpOALFnTable->alcOpenDevice = (LPALCOPENDEVICE)GetProcAddress(g_hOpenALDLL, "alcOpenDevice"); if (lpOALFnTable->alcOpenDevice == NULL) { OutputDebugString("Failed to retrieve 'alcOpenDevice' function address\n"); return AL_FALSE; } lpOALFnTable->alcCloseDevice = (LPALCCLOSEDEVICE)GetProcAddress(g_hOpenALDLL, "alcCloseDevice"); if (lpOALFnTable->alcCloseDevice == NULL) { OutputDebugString("Failed to retrieve 'alcCloseDevice' function address\n"); return AL_FALSE; } lpOALFnTable->alcCreateContext = (LPALCCREATECONTEXT)GetProcAddress(g_hOpenALDLL, "alcCreateContext"); if (lpOALFnTable->alcCreateContext == NULL) { OutputDebugString("Failed to retrieve 'alcCreateContext' function address\n"); return AL_FALSE; } lpOALFnTable->alcMakeContextCurrent = (LPALCMAKECONTEXTCURRENT)GetProcAddress(g_hOpenALDLL, "alcMakeContextCurrent"); if (lpOALFnTable->alcMakeContextCurrent == NULL) { OutputDebugString("Failed to retrieve 'alcMakeContextCurrent' function address\n"); return AL_FALSE; } lpOALFnTable->alcProcessContext = (LPALCPROCESSCONTEXT)GetProcAddress(g_hOpenALDLL, "alcProcessContext"); if (lpOALFnTable->alcProcessContext == NULL) { OutputDebugString("Failed to retrieve 'alcProcessContext' function address\n"); return AL_FALSE; } lpOALFnTable->alcGetCurrentContext = (LPALCGETCURRENTCONTEXT)GetProcAddress(g_hOpenALDLL, "alcGetCurrentContext"); if (lpOALFnTable->alcGetCurrentContext == NULL) { OutputDebugString("Failed to retrieve 'alcGetCurrentContext' function address\n"); return AL_FALSE; } lpOALFnTable->alcGetContextsDevice = (LPALCGETCONTEXTSDEVICE)GetProcAddress(g_hOpenALDLL, "alcGetContextsDevice"); if (lpOALFnTable->alcGetContextsDevice == NULL) { OutputDebugString("Failed to retrieve 'alcGetContextsDevice' function address\n"); return AL_FALSE; } lpOALFnTable->alcSuspendContext = (LPALCSUSPENDCONTEXT)GetProcAddress(g_hOpenALDLL, "alcSuspendContext"); if (lpOALFnTable->alcSuspendContext == NULL) { OutputDebugString("Failed to retrieve 'alcSuspendContext' function address\n"); return AL_FALSE; } lpOALFnTable->alcDestroyContext = (LPALCDESTROYCONTEXT)GetProcAddress(g_hOpenALDLL, "alcDestroyContext"); if (lpOALFnTable->alcDestroyContext == NULL) { OutputDebugString("Failed to retrieve 'alcDestroyContext' function address\n"); return AL_FALSE; } lpOALFnTable->alcGetError = (LPALCGETERROR)GetProcAddress(g_hOpenALDLL, "alcGetError"); if (lpOALFnTable->alcGetError == NULL) { OutputDebugString("Failed to retrieve 'alcGetError' function address\n"); return AL_FALSE; } lpOALFnTable->alcIsExtensionPresent = (LPALCISEXTENSIONPRESENT)GetProcAddress(g_hOpenALDLL, "alcIsExtensionPresent"); if (lpOALFnTable->alcIsExtensionPresent == NULL) { OutputDebugString("Failed to retrieve 'alcIsExtensionPresent' function address\n"); return AL_FALSE; } lpOALFnTable->alcGetProcAddress = (LPALCGETPROCADDRESS)GetProcAddress(g_hOpenALDLL, "alcGetProcAddress"); if (lpOALFnTable->alcGetProcAddress == NULL) { OutputDebugString("Failed to retrieve 'alcGetProcAddress' function address\n"); return AL_FALSE; } lpOALFnTable->alcGetEnumValue = (LPALCGETENUMVALUE)GetProcAddress(g_hOpenALDLL, "alcGetEnumValue"); if (lpOALFnTable->alcGetEnumValue == NULL) { OutputDebugString("Failed to retrieve 'alcGetEnumValue' function address\n"); return AL_FALSE; } return AL_TRUE; }
int bsc_platform_init(int features) { #if defined(_WIN32) if (features & LIBBSC_FEATURE_LARGEPAGES) { HANDLE hToken = 0; if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken)) { LUID luid; if (LookupPrivilegeValue(NULL, TEXT("SeLockMemoryPrivilege"), &luid)) { TOKEN_PRIVILEGES tp; tp.PrivilegeCount = 1; tp.Privileges[0].Luid = luid; tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), 0, 0); } CloseHandle(hToken); } { typedef SIZE_T (WINAPI * GetLargePageMinimumProcT)(); GetLargePageMinimumProcT largePageMinimumProc = (GetLargePageMinimumProcT)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetLargePageMinimum"); if (largePageMinimumProc != NULL) { SIZE_T largePageSize = largePageMinimumProc(); if ((largePageSize & (largePageSize - 1)) != 0) largePageSize = 0; g_LargePageSize = largePageSize; } } } #endif return LIBBSC_NO_ERROR; }