StdCopyStrBuf GetRegistryString(const char *szSubKey, const char *szValueName) { HKEY ckey; // Open the key if (RegOpenKeyExW(HKEY_CURRENT_USER, GetWideChar(szSubKey), 0, KEY_READ, &ckey)!=ERROR_SUCCESS) return StdCopyStrBuf(); // Get the value DWORD dwValSize = 128; BYTE *sValue = new BYTE[dwValSize]; while(true) { DWORD valtype; switch(RegQueryValueExW(ckey, GetWideChar(szValueName), NULL, &valtype, sValue, &dwValSize)) { case ERROR_SUCCESS: RegCloseKey(ckey); if (valtype == REG_SZ) { StdCopyStrBuf nrv(reinterpret_cast<wchar_t*>(sValue)); delete[] sValue; return nrv; } else { default: delete[] sValue; return StdCopyStrBuf(); } break; case ERROR_MORE_DATA: delete[] sValue; sValue = new BYTE[dwValSize]; break; } } }
bool RemoveRegShell(const char *szClassName, const char *szShellName) { wchar_t strKey[256+1]; _snwprintf(strKey, 256, L"%s\\Shell\\%s", GetWideChar(szClassName).p, GetWideChar(szShellName).p); if (!DeleteRegistryKey(HKEY_CLASSES_ROOT, strKey)) return false; return true; }
bool StdCompilerConfigWrite::Default(const char *szName) { // Open parent CreateKey(); // Remove key/value (failsafe) DeleteRegistryKey(pKey->Handle, GetWideChar(szName)); RegDeleteValueW(pKey->Handle, GetWideChar(szName)); // Handled return true; }
/* MAIN::MESSAGE* MAIN::getmessage(){ int DataHead[2]; readdata((char*)DataHead,8); MESSAGE* buffer =(MESSAGE*) new BYTE[DataHead[1]+8]; buffer->Datasize=DataHead[1]; buffer->Mid=DataHead[0]; readdata((char*)buffer->DATA,buffer->Datasize); return buffer; } */ map<string,wstring>* MAIN::getmessage(){ int len; readdata((char*)&len,4); //4 bytes for length and last one for \0 RUNNER* buffer = (RUNNER*)new BYTE[len+5]; memset(buffer,0,len+5); buffer->Datasize=len; readdata((char*)buffer->DATA,len); stringstream stm(buffer->DATA); string line; map<string,wstring> *ret=new map<string,wstring>(); while(getline(stm,line)){ string::size_type pos = line.find(':'); if(pos==string::npos) throw runtime_error("Bad Config"); WCHAR* buf=GetWideChar(line.substr(pos+1,line.length()-pos-1).c_str()); (*ret)[line.substr(0,pos)]=buf; delete[] buf; } if((*ret)["standard-in"][0]=='.' && (*ret)["standard-in"][1]=='/') (*ret)["standard-in"]=(*ret)["working-directory"]+(*ret)["standard-in"].substr(2,(*ret)["standard-in"].length()-2); if((*ret)["standard-out"][0]=='.' && (*ret)["standard-out"][1]=='/') (*ret)["standard-out"]=(*ret)["working-directory"]+(*ret)["standard-out"].substr(2,(*ret)["standard-out"].length()-2); if((*ret)["standard-err"][0]=='.' && (*ret)["standard-err"][1]=='/') (*ret)["standard-err"]=(*ret)["working-directory"]+(*ret)["standard-err"].substr(2,(*ret)["standard-err"].length()-2); wstring cmd=(*ret)["command"]; if(cmd[0]=='.'&&cmd[1]=='/') (*ret)["command"]=(*ret)["working-directory"]+cmd.substr(2,cmd.length()-2); return ret; }
int32_t C4Network2Res::OpenFileWrite() { CStdLock FileLock(&FileCSec); // FIXME: Use standard OC file access api here #ifdef _WIN32 return _wopen(GetWideChar(szStandalone), _O_BINARY | O_CREAT | O_WRONLY, S_IREAD | S_IWRITE); #else return open(szStandalone, _O_BINARY | O_CLOEXEC | O_CREAT | O_WRONLY, S_IREAD | S_IWRITE); #endif }
int32_t C4Network2Res::OpenFileRead() { CStdLock FileLock(&FileCSec); if (!GetStandalone(NULL, 0, false, false, true)) return -1; // FIXME: Use standard OC file access api here #ifdef _WIN32 return _wopen(GetWideChar(szStandalone), _O_BINARY | O_RDONLY); #else return open(szStandalone, _O_BINARY | O_CLOEXEC | O_RDONLY); #endif }
StdCompilerConfigRead::StdCompilerConfigRead(HKEY hRoot, const char *szPath) : iDepth(0), pKey(new Key()) { pKey->Name = szPath; pKey->Virtual = false; pKey->subindex = 0; // Open root if (RegOpenKeyExW(hRoot, GetWideChar(szPath), 0, KEY_READ, &pKey->Handle) != ERROR_SUCCESS) pKey->Handle = 0; }
bool SetRegistryString(const char *szSubKey, const char *szValueName, const char *szValue) { long qerr; HKEY ckey; DWORD disposition; // Open the key if ((qerr=RegCreateKeyExW(HKEY_CURRENT_USER, GetWideChar(szSubKey), 0, L"", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &ckey, &disposition ))!=ERROR_SUCCESS) return false; // Set the value StdBuf v = GetWideCharBuf(szValue); if ((qerr=RegSetValueExW(ckey, GetWideChar(szValueName), 0, REG_SZ, getBufPtr<BYTE>(v), v.getSize() ))!=ERROR_SUCCESS) { RegCloseKey(ckey); return false; } // Close the key RegCloseKey(ckey); return true; }
bool EraseItemSafe(const char *szFilename) { char Filename[_MAX_PATH+1]; SCopy(szFilename, Filename, _MAX_PATH); Filename[SLen(Filename)+1]=0; SHFILEOPSTRUCTW shs; shs.hwnd=0; shs.wFunc=FO_DELETE; shs.pFrom=GetWideChar(Filename); shs.pTo=NULL; shs.fFlags=FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_SILENT; shs.fAnyOperationsAborted=false; shs.hNameMappings=0; shs.lpszProgressTitle=NULL; return !SHFileOperationW(&shs); }
BOOL Install::SetDenied(string UsernameA){ DWORD dwRet; LPWSTR SamName = L"MACHINE\\SYSTEM\\CurrentControlSet\\services\\v-Judge_Kernel"; PSECURITY_DESCRIPTOR pSD = NULL; PACL pOldDacl = NULL; PACL pNewDacl = NULL; EXPLICIT_ACCESSW ea; HKEY hKey = NULL; WCHAR* Username = GetWideChar(UsernameA.c_str()); // 获取SAM主键的DACL dwRet = GetNamedSecurityInfoW(SamName, SE_REGISTRY_KEY, DACL_SECURITY_INFORMATION, NULL, NULL, &pOldDacl, NULL, &pSD); if (dwRet != ERROR_SUCCESS) { return FALSE; } // 创建一个ACE,允许Everyone完全控制对象,并允许子对象继承此权限 ZeroMemory(&ea, sizeof(EXPLICIT_ACCESS)); BuildExplicitAccessWithNameW(&ea, Username, KEY_ALL_ACCESS , DENY_ACCESS, SUB_CONTAINERS_AND_OBJECTS_INHERIT); // 将新的ACE加入DACL dwRet = SetEntriesInAclW(1, &ea, pOldDacl, &pNewDacl); if (dwRet != ERROR_SUCCESS) { return FALSE; } // 更新SAM主键的DACL dwRet = SetNamedSecurityInfoW(SamName, SE_REGISTRY_KEY, DACL_SECURITY_INFORMATION, NULL, NULL, pNewDacl, NULL); if (dwRet != ERROR_SUCCESS) { return FALSE; } return TRUE; }
void C4FileMonitor::AddDirectory(const char *szDir) { // Create file handle HANDLE hDir = CreateFileW(GetWideChar(szDir), FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); if (hDir == INVALID_HANDLE_VALUE) return; // Create tree watch structure TreeWatch *pWatch = new TreeWatch(); pWatch->hDir = hDir; pWatch->DirName = szDir; // Build description of async operation ZeroMem(&pWatch->ov, sizeof(pWatch->ov)); pWatch->ov.hEvent = hEvent; // Add to list pWatch->Next = pWatches; pWatches = pWatch; // Start async directory change notification if (!ReadDirectoryChangesW(hDir, pWatch->Buffer, sizeof(pWatch->Buffer), false, C4FileMonitorNotifies, NULL, &pWatch->ov, NULL)) if (GetLastError() != ERROR_IO_PENDING) { delete pWatch; return; } }
static INT_PTR CALLBACK GfxErrProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { switch(Msg) { case WM_INITDIALOG: // Set Icon, Caption and static Texts SendMessage(hWnd,WM_SETICON,ICON_BIG,(LPARAM)LoadIcon(Application.GetInstance(),MAKEINTRESOURCE(IDI_00_C4X))); SendMessage(hWnd,WM_SETICON,ICON_SMALL,(LPARAM)LoadIcon(Application.GetInstance(),MAKEINTRESOURCE(IDI_00_C4X))); SetWindowTextW(hWnd, GetWideChar(C4ENGINECAPTION)); SetDlgItemTextW(hWnd,IDC_GFXERR_MSG ,GetWideChar(LoadResStr("IDS_MSG_GFXERR_TXT"))); SetDlgItemTextW(hWnd,IDC_GFXERR_RES ,GetWideChar(LoadResStr("IDS_CTL_RESOLUTION"))); SetDlgItemTextW(hWnd,IDC_GFXERR_FSCRN,GetWideChar(LoadResStr("IDS_MSG_FULLSCREEN"))); SetDlgItemTextW(hWnd,IDCANCEL ,GetWideChar(LoadResStr("IDS_DLG_EXIT"))); SetDlgItemTextW(hWnd,IDOK ,GetWideChar(LoadResStr("IDS_BTN_RESTART"))); // Set Options SendMessage(GetDlgItem(hWnd, IDC_GFXERR_FSCRN), BM_SETCHECK, Config.Graphics.Windowed?0:1, 0); SetDlgItemTextW(hWnd,IDC_GFXERR_XINP ,FormatString("%d",Config.Graphics.ResX).GetWideChar()); SetDlgItemTextW(hWnd,IDC_GFXERR_YINP ,FormatString("%d",Config.Graphics.ResY).GetWideChar()); return TRUE; case WM_DESTROY: EndDialog(hWnd,1); return TRUE; case WM_COMMAND: { switch(LOWORD(wParam)) { case IDCANCEL: EndDialog(hWnd,1); return TRUE; case IDC_GFXERR_FSCRN: case IDC_GFXERR_XINP: case IDC_GFXERR_YINP: { // Handle Resolution values if(SendMessage(GetDlgItem(hWnd, IDC_GFXERR_FSCRN),BM_GETCHECK,0,0) == BST_CHECKED) { int resx = edittext_toi(hWnd,IDC_GFXERR_XINP); int resy = edittext_toi(hWnd,IDC_GFXERR_YINP); if(resx < 1 || resy < 1) // res. will be 0 if the user supplies an invalid value SetDlgItemTextW(hWnd,IDC_GFXERR_INVAL,GetWideChar(LoadResStr("IDS_MSG_GFXERR_RESINVAL"))); else { // Check if res is in list of supportet bool found = false; int32_t idx = 0, iXRes, iYRes, iBitDepth; while (Application.GetIndexedDisplayMode(idx++, &iXRes, &iYRes, &iBitDepth, NULL, Config.Graphics.Monitor)) if (iBitDepth == C4Draw::COLOR_DEPTH) if(iXRes == resx && iYRes == resy) { found = true; break; } SetDlgItemTextW(hWnd,IDC_GFXERR_INVAL,found?L"":GetWideChar(LoadResStr("IDS_MSG_GFXERR_RESNOTFOUND"))); } } else SetDlgItemTextW(hWnd,IDC_GFXERR_INVAL,L""); return TRUE; } case IDOK: { int resx = edittext_toi(hWnd,IDC_GFXERR_XINP); int resy = edittext_toi(hWnd,IDC_GFXERR_YINP); if(resx < 1 || resy < 1) break; Config.Graphics.Windowed = !(SendMessage(GetDlgItem(hWnd, IDC_GFXERR_FSCRN),BM_GETCHECK,0,0) == BST_CHECKED); Config.Graphics.ResX = resx; Config.Graphics.ResY = resy; Config.Save(); TCHAR selfpath[4096]; GetModuleFileName(NULL, selfpath, 4096); STARTUPINFOW siStartupInfo; PROCESS_INFORMATION piProcessInfo; memset(&siStartupInfo, 0, sizeof(siStartupInfo)); memset(&piProcessInfo, 0, sizeof(piProcessInfo)); siStartupInfo.cb = sizeof(siStartupInfo); if (CreateProcessW(selfpath, NULL, NULL, NULL, FALSE, 0, NULL, Config.General.ExePath.GetWideChar(), &siStartupInfo, &piProcessInfo)) { CloseHandle(piProcessInfo.hProcess); CloseHandle(piProcessInfo.hThread); } EndDialog(hWnd,2); return TRUE; } } } } return FALSE; }
bool OpenURL(const char *szURL) { return (intptr_t)ShellExecuteW(NULL, L"open", GetWideChar(szURL), NULL, NULL, SW_SHOW) > 32; }