int do_attribute_value(void *context, long state_index, unsigned char tag, const void *value, long vlen) { CHAR16 *ptr; ptr = ASCII_to_UCS2(value, (int)vlen); StrCat(tmpbuf, ptr); FreePool(ptr); return 0; }
// Convert a hexadecimal string to a binary data BUF *StrToBin(char *str) { BUF *b; UINT len, i; char tmp[3]; // Validate arguments if (str == NULL) { return NULL; } len = StrLen(str); tmp[0] = 0; b = NewBuf(); for (i = 0;i < len;i++) { char c = str[i]; c = ToUpper(c); if (('0' <= c && c <= '9') || ('A' <= c && c <= 'F')) { if (tmp[0] == 0) { tmp[0] = c; tmp[1] = 0; } else if (tmp[1] == 0) { UCHAR data; char tmp2[64]; tmp[1] = c; tmp[2] = 0; StrCpy(tmp2, sizeof(tmp2), "0x"); StrCat(tmp2, sizeof(tmp2), tmp); data = (UCHAR)strtoul(tmp2, NULL, 0); WriteBuf(b, &data, 1); Zero(tmp, sizeof(tmp)); } } else if (c == ' ' || c == ',' || c == '-' || c == ':') { // Do Nothing } else { break; } } return b; }
int next_int(C& c, I& it, std::set<char> stop) { string s; while (it != std::end(c) && !contains(stop, *it)) { if (!std::isdigit(*it)) { throw bad_fidonet_address(StrCat("Missing Unexpected nondigit. address: ", c)); } s.push_back(*it++); } if (it != std::end(c) && contains(stop, *it)) { // skip over last it++; } return StringToInt(s); }
EFI_STATUS make_full_path(CHAR16 *dirname, CHAR16 *filename, CHAR16 **out, UINT64 *outlen) { UINT64 len; len = StrLen(L"\\EFI\\") + StrLen(dirname) + StrLen(L"\\") + StrLen(filename) + 2; CHAR16 *fullpath = AllocateZeroPool(len*sizeof(CHAR16)); if (!fullpath) { Print(L"Could not allocate memory\n"); return EFI_OUT_OF_RESOURCES; } StrCat(fullpath, L"\\EFI\\"); StrCat(fullpath, dirname); StrCat(fullpath, L"\\"); StrCat(fullpath, filename); *out = fullpath; *outlen = len; return EFI_SUCCESS; }
/** Compute md5 of a buffer. * @param data unsigned chat pointer to data buffer. * @param len size of buffer. */ void MD5Utils::md5Buffer(unsigned char *data , int len) { MD5_CTX context; memset(digest , 0 , sizeof(digest)); MD5_Init(&context); MD5_Update(&context , data , len); MD5_Final(digest , &context); memset(digestStr , 0 , sizeof(digestStr)); char digit[6]; for (int i = 0 ; i < 16 ; i++) { snprintf(digit, sizeof(digit), "%.2x" , digest[i]); digit[2] = 0; StrCat(digestStr , digit); } }
HRESULT CreateAssemblyDirPath( LPCTSTR pszCustomPath, DWORD dwInstaller, DWORD dwCacheFlags, BOOL bUser, LPTSTR pszPath, DWORD *pcchSize) { HRESULT hr = S_OK; LPWSTR pszCacheLoc = NULL; if (dwCacheFlags & ASM_CACHE_GAC) { hr = GetGACDir(&pszCacheLoc); if(hr != S_OK) goto exit; StrCpy(pszPath, pszCacheLoc); } else if(dwCacheFlags & ASM_CACHE_ZAP) { hr = GetZapDir(&pszCacheLoc); if(hr != S_OK) goto exit; StrCpy(pszPath, pszCacheLoc); } else if (dwCacheFlags & ASM_CACHE_DOWNLOAD) { if (pszCustomPath != NULL) { // Use custom path as the base StrCpy(pszPath, pszCustomPath); StrCat(pszPath, FUSION_CACHE_DIR_DOWNLOADED_SZ); } else { // Else use the default hr = GetDownloadDir(&pszCacheLoc); if(hr != S_OK) goto exit; StrCpy(pszPath, pszCacheLoc); } } else { // Assert; } exit : return hr; }
UINT StrCatLeft(char *dst, UINT size, char *src) { char *s; // Validate arguments if (dst == NULL || src == NULL) { return 0; } s = CopyStr(dst); StrCpy(dst, size, src); StrCat(dst, size, s); Free(s); return StrLen(dst); }
static PackFile *PackOpen(char *name) { FILE *fp; char tmp[MAX_PATH]; RemoveExt(tmp, name); StrCat(tmp, MAX_PATH, ".txt"); fp = FOpen(tmp, "r"); if (fp) { fgets(tmp, MAX_PATH, fp); FClose(fp); packFile = FOpen(tmp, "rb"); return PackOpenFromFile(tmp); } packFile = FOpen(name, "rb"); return PackOpenFromFile(name); }
/** Convert Memory Size to a string. @param MemorySize The size of the memory to process @param String The string that is created **/ VOID ConvertMemorySizeToString ( IN UINT32 MemorySize, OUT CHAR16 **String ) { CHAR16 *StringBuffer; StringBuffer = AllocateZeroPool (0x20); ASSERT (StringBuffer != NULL); UnicodeValueToString (StringBuffer, LEFT_JUSTIFY, MemorySize, 6); StrCat (StringBuffer, L" MB RAM"); *String = (CHAR16 *) StringBuffer; return ; }
// ************************************************************************* // Draw an item on the screen // ************************************************************************* static void DrawItem( char* Name, int y, long Price ) { int j; FntSetFont( stdFont ); DrawChars( Name, 30, y ); EraseRectangle( 110, y, 56, 9 ); StrIToA( SBuf, Price ); StrCat( SBuf, " cr." ); j = MAXDIGITS - StrLen( SBuf ); if (Price > 0) DrawChars( SBuf, 124+j*5, y ); else DrawChars( "not sold", 122, y ); }
HRESULT GetRandomFileName(LPTSTR pszPath, DWORD dwFileName) { HRESULT hr=S_OK; LPTSTR pszFileName=NULL; DWORD dwPathLen = 0; DWORD dwErr=0; ASSERT(pszPath); //ASSERT(IsPathRelative(pszPath)) StrCat (pszPath, TEXT("\\") ); dwPathLen = lstrlen(pszPath); ASSERT( (dwPathLen + dwFileName) < MAX_PATH); pszFileName = pszPath + dwPathLen; // Loop until we get a unique file name. while (1) { GetRandomName (pszFileName, dwFileName); if (GetFileAttributes(pszPath) != (DWORD) -1) continue; dwErr = GetLastError(); if (dwErr == ERROR_FILE_NOT_FOUND) { hr = S_OK; break; } if (dwErr == ERROR_PATH_NOT_FOUND) { if(FAILED(hr = CreateFilePathHierarchy(pszPath))) break; else continue; } hr = HRESULT_FROM_WIN32(dwErr); break; } return hr; }
static bool ParseCalloutFile(std::map<uint16_t, net_call_out_rec>* node_config_map, const string network_dir) { TextFile node_config_file(network_dir, CALLOUT_NET, "rt"); if (!node_config_file.IsOpen()) { return false; } // A line will be of the format @node host:port [password]. string line; while (node_config_file.ReadLine(&line)) { StringTrim(&line); net_call_out_rec node_config{}; if (ParseCalloutNetLine(line, &node_config)) { // Parsed a line correctly. node_config.ftn_address = StrCat("20000:20000/", node_config.sysnum); node_config_map->emplace(node_config.sysnum, node_config); } } return true; }
/* * fonction permettant d'afficher le manuel d'aide des commandes */ void afficherManuel(char* element){ char quit; char *extension = ".txt"; int fileDescripteur; element = realloc(element, StrLengh(element) + StrLengh(extension)); StrCat(extension,element); //ouverture du fichier fileDescripteur = OpenFile(element, SEEK_SET, O_RDONLY); // on ouvre les pages du manuel en lecture seule // copie du texte du fichier dans la variable texte while((quit = GetChar()) != 'q'){ // temps qu'on ne tape pas Q on affiche le manuel //affichage du texte //Printf("%s",getContent(fileDescripteur); } //liberation de la mémoire free(element); return; }
CFlashControl::~CFlashControl() { #if 0 if (1 == InterlockedExchangeAdd((volatile long *)&s_lCount, -1)) { TCHAR szWorkDirectory[MAX_PATH]={0}; UIRenderEngine->GetWorkDirectory(szWorkDirectory,MAX_PATH); StrCat(szWorkDirectory,TEXT("\\Flash8.ocx")); HMODULE hmod=LoadLibrary (szWorkDirectory); ASSERT(hmod); if (hmod) { FARPROC pReg =GetProcAddress (hmod,"DllUnregisterServer"); (*pReg)(); } } #endif }
/** * Returns a string justified and padded with "bg". * @param pszString The text to justify * @param nLength the length of the text * @param bg the character to use as the background * @param nJustificationType one of the following: * LEFT * RIGHT * @return the justified text. */ void StringJustify(string* s, string::size_type length, char bg, JustificationType just_type) { if (s->size() > length) { *s = s->substr(0, length); return; } else if (s->size() == length) { return; } string::size_type delta = length - s->size(); switch (just_type) { case JustificationType::LEFT: { s->resize(length, bg); } break; case JustificationType::RIGHT: { string tmp(*s); *s = StrCat(string(delta, bg), tmp); } break; } }
void TestArchive::Run() { Compile(official_source); if (is_interactive) { Compile(checker); } stable_sort(testcases.begin(), testcases.end()); int test_number = 0; os.RunBashCommand("mkdir -p " + tests_location); for (auto itr : testcases) { if (itr.Type() == DEBUG_TEST) { continue; } std::cerr << GetBloatware() << "\t" << Colored(4, 2, 3, "Generating") << " input for test " << Colored(5, 1, 1, Allign(StrCat("#", test_number), 3)) << '\n'; std::string input = itr.Input(); // write input before generating so in case something goes wrong // the user has the input that triggered that bug / crash os.WriteFile(tests_location + test_prefix + std::to_string(test_number) + ".in", input); // Info("Computed .in file and wrote it to\t", test_prefix + std::to_string(test_number)); if (not is_interactive) { EggResult test_result = deploy_eggecutor.Run(official_source, input); std::cerr << '\n'; auto stdok = test_result.stdout; if (itr.has_output) { stdok = itr.output; } os.WriteFile(tests_location + test_prefix + std::to_string(test_number) + ".ok", stdok); } else { auto all_results = deploy_eggecutor.RunInteractive(official_source, checker, input); if (itr.Type() == EXAMPLE) { os.WriteFile(tests_location + test_prefix + std::to_string(test_number) + ".json", all_results.second.logger); } std::cerr << "Checker: " << (all_results.second.passed ? Colored(Color::green, "Passed!") : Colored(Color::red, "Not passed")) << "\t" << Colored(Color::light_magenta, all_results.second.message) << '\n'; } test_number += 1; } }
bool CConfigIni::LoadConfig(LPCTSTR strIni) { if(strIni == NULL) { TCHAR l_szIniPath[MAX_PATH] = {0}; GetModuleFileName(AfxGetInstanceHandle(), l_szIniPath, MAX_PATH); PathRemoveFileSpec(l_szIniPath); PathAddBackslash(l_szIniPath); m_szPath = l_szIniPath; StrCat(l_szIniPath, l_szIniFilename); m_szIni = l_szIniPath; } else m_szIni = strIni; //节点名 LoadString(l_szIniKey_Sys, l_szIniItem_Sys, m_szName); return LoadCurrentSystem(); }
// static void Logger::Init(int argc, char** argv) { string filename(argv[0]); if (ends_with(filename, ".exe") || ends_with(filename, ".EXE")) { filename = filename.substr(0, filename.size() - 4); } int last_slash = filename.rfind(File::pathSeparatorChar); if (last_slash != string::npos) { filename = filename.substr(last_slash + 1); } set_filename("I", StrCat(filename, ".log")); time_t t = time(nullptr); string l(asctime(localtime(&t))); StringTrim(&l); Logger() << filename << " version " << wwiv_version << beta_version << " (" << wwiv_date << ")"; Logger() << filename << " starting at " << l; exit_filename = filename; }
CPipeServer::CPipeServer(TCHAR *name) { processhandle=0; CorDebugProcess5=NULL; CorDebugProcess=NULL; CLRDebugging=NULL; libprovider=NULL; datacallback=NULL; StrCpy(pipename, L"\\\\.\\pipe\\"); StrCat(pipename, name); pipe=CreateNamedPipeW(pipename, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, 255,256*1024, 16, INFINITE, NULL); ConnectNamedPipe(pipe, NULL); }
HRESULT CModuleHashNode::RectifyFileName(LPCTSTR pszPath, DWORD cbPath) { HRESULT hr = S_OK; TCHAR szBuf[MAX_PATH+1], *pszTemp; StrCpy(szBuf, _szPath); pszTemp = PathFindFileName (szBuf); if (pszTemp <= szBuf) { hr = HRESULT_FROM_WIN32(ERROR_BAD_PATHNAME); goto exit; } *(pszTemp) = TEXT('\0'); if( (lstrlen(szBuf) + cbPath) > MAX_PATH ) { hr = HRESULT_FROM_WIN32(FUSION_E_INVALID_NAME ); goto exit; } StrCat(szBuf, pszPath); if ( !MoveFile(_szPath, szBuf) ) { hr = FusionpHresultFromLastError(); if( GetFileAttributes(szBuf) != (DWORD) -1 ) { // someone else already downloaded this file. DeleteFile(_szPath); hr = S_OK; } } exit : return hr; }
EFIAPI CatPrint ( IN OUT POOL_PRINT *Str, IN CHAR16 *Fmt, ... ) { UINT16 *AppendStr; VA_LIST Args; UINTN StringSize; AppendStr = AllocateZeroPool (0x1000); if (AppendStr == NULL) { ASSERT(FALSE); return Str->Str; } VA_START (Args, Fmt); UnicodeVSPrint (AppendStr, 0x1000, Fmt, Args); VA_END (Args); if (NULL == Str->Str) { StringSize = StrSize (AppendStr); Str->Str = AllocateZeroPool (StringSize); ASSERT (Str->Str != NULL); } else { StringSize = StrSize (AppendStr); StringSize += (StrSize (Str->Str) - sizeof (UINT16)); Str->Str = ReallocatePool ( StrSize (Str->Str), StringSize, Str->Str ); ASSERT (Str->Str != NULL); } StrCat (Str->Str, AppendStr); Str->Len = StringSize; FreePool (AppendStr); return Str->Str; }
Err vfsFileRename (UInt16 volRefNum, Char *pathNameP, Char *newNameP) { Int32 ret; Char newName[256]; Int16 i; Int16 srclen; i = srclen = StrLen(pathNameP); /* in the AxxPac the Rename function can change the path. The new name must contain the original path */ while ((1 < i) && (pathNameP[i - 1] != '/')) i--; StrNCopy(newName, pathNameP, i); newName[i] = chrNull; StrCat(newName, newNameP); ret = axxPacRename(LibRef, pathNameP, newName); if (ret < 0) return expErrNotOpen; else return errNone; }
void DecodeCDTag(PLAYERINFO* playerinfo, const wchar_t* letter, UCHAR index) { PLAYERTAG* playertag = &playerinfo->tag; if (playertag->read) return; DWORD length = 8; playertag->artist = new wchar_t[length + 1]; wmemset(playertag->artist, 0, length + 1); StrCat(playertag->artist, letter); length = 16; playertag->title = new wchar_t[length + 1]; wmemset(playertag->title, 0, length + 1); wsprintf(playertag->title, L"CD音轨%02d", index); long minute = playerinfo->duration / 60; long second = playerinfo->duration % 60; wsprintf(playertag->timer, L"%d:%02d", minute, second); playertag->read = TRUE; }
void GetBgmName(char *bgmName, char *name) { int i = 0, j = 0, n; char tmp[MAX_PATH]; char *buf; RemoveExt(tmp, name); StrCat(tmp, MAX_PATH, ".txt"); buf = LoadFile(tmp, &n); while (buf[j] != '\0') { if (buf[j] == ';') { break; } tmp[i] = buf[j]; tmp[i + 1] = '\0'; i++; j++; } StrCpy(bgmName, MAX_PATH, tmp); free(buf); }
/* ** Add the Linker link to the plugin text. The calling ** function must free the returned pointer. */ static Char* GetLink(Char* orig_text) { UInt16 length = 0; Char* linked_text = NULL; LinkerCPB command_block; UInt32 result; /* Bail if there is no text */ if (!orig_text) return 0; length = StrLen(orig_text) + 1; if (p.flags & PFLAGS_XFER_BACKLINK && d.linker_available) length += 5; linked_text = MemPtrNew(length); ASSERT(linked_text); StrCopy(linked_text, orig_text); if (!(p.flags & PFLAGS_XFER_BACKLINK && d.linker_available)) return linked_text; MemSet(&command_block, sizeof(LinkerCPB), 0); command_block.creator = 'Linx'; /* maybe this is overkill, but .... */ command_block.message = LinkerNewLinkMessage; /* command_block.linkTag is empty and to be filled by Linker */ command_block.gotoTargetAppCreator = AppType; /* DiddleBug is the target */ DmOpenDatabaseInfo(d.dbR, &(command_block.gotoLinkParams.dbID), NULL, NULL, &(command_block.gotoLinkParams.dbCardNo), NULL); command_block.gotoLinkParams.recordNum = p.dbI; /* Signal Linker */ SysAppLaunch(d.cardNo, d.dbID, 0, linkerAppLaunchCmdSignalLinker, &command_block, &result); /* Add the link text */ command_block.linkTag[5] = 0x00; /* just to be sure */ StrCat(linked_text, command_block.linkTag); return linked_text; }
HRESULT GetAssemblyStagingPath(LPCTSTR pszCustomPath, DWORD dwCacheFlags, BOOL bUser, LPTSTR pszPath, DWORD *pcchSize) { HRESULT hr = S_OK; LPTSTR pszCacheLoc = NULL; ASSERT(pcchSize); if (pszCustomPath != NULL) { // Use custom path as the base StrCpy(pszPath, pszCustomPath); } else { if(FAILED(hr = GetCacheLoc(dwCacheFlags, &pszCacheLoc))) goto exit; // Else use the default StrCpy(pszPath, pszCacheLoc); } // check for buffer overflow if( ((DWORD)(lstrlenW(pszPath) + lstrlenW(FUSION_CACHE_STAGING_DIR_SZ) + 10)) > (*pcchSize)) { hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); goto exit; } PathRemoveBackslash(pszPath); StrCat(pszPath, FUSION_CACHE_STAGING_DIR_SZ); PathAddBackslash(pszPath); hr = CreateDirectoryForAssembly(8, pszPath, pcchSize); exit : return hr; }
bool MenuInstanceData::LoadMenuRecord(const std::string& command, MenuRec* pMenu) { // If we have 'numbers set the sub #' turned on then create a command to do so if a # is entered. if (IsNumber(command)) { if (header.nNumbers == MENU_NUMFLAG_SUBNUMBER) { memset(pMenu, 0, sizeof(MenuRec)); sprintf(pMenu->szExecute, "SetSubNumber %d", atoi(command.c_str())); return true; } else if (header.nNumbers == MENU_NUMFLAG_DIRNUMBER) { memset(pMenu, 0, sizeof(MenuRec)); sprintf(pMenu->szExecute, "SetDirNumber %d", atoi(command.c_str())); return true; } } if (contains(menu_command_map_, command)) { *pMenu = menu_command_map_.at(command); if (CheckMenuItemSecurity(pMenu, true)) { return true; } MenuSysopLog(StrCat("|06< item security : ", command)); } return false; }
CFlashControl::CFlashControl() { #if 0 if (0 == InterlockedExchangeAdd((volatile long *)&s_lCount, 1)) { TCHAR szWorkDirectory[MAX_PATH]={0}; UIRenderEngine->GetWorkDirectory(szWorkDirectory,MAX_PATH); StrCat(szWorkDirectory,TEXT("\\Flash8.ocx")); HMODULE hmod=LoadLibrary (szWorkDirectory); ASSERT(hmod); if (hmod) { FARPROC pReg =GetProcAddress (hmod,"DllRegisterServer"); (*pReg)(); } } #endif m_bHasInit = FALSE; m_lOldProc = 0; m_pIFlashContrlSink = NULL; }
// Shift treatment of text input void EmLicenseAddDlgShiftTextItem(HWND hWnd, UINT id1, UINT id2, UINT *next_focus) { char *s; // Validate arguments if (hWnd == NULL || next_focus == NULL) { return; } s = GetTextA(hWnd, id1); if (StrLen(s) >= 6) { char *s2 = CopyStr(s); char tmp[MAX_SIZE]; s2[6] = 0; SetTextA(hWnd, id1, s2); Free(s2); if (id2 != 0) { GetTxtA(hWnd, id2, tmp, sizeof(tmp)); StrCat(tmp, sizeof(tmp), s + 6); ReplaceStrEx(tmp, sizeof(tmp), tmp, "-", "", false); SetTextA(hWnd, id2, tmp); *next_focus = id2; } else { *next_focus = IDOK; } } Free(s); }
wchar_t* WideCharToHex(const wchar_t* buffer, DWORD length) { if (length == 0) return NULL; DWORD len = length * 4; wchar_t* content = new wchar_t[len + 1]; wmemset(content, 0, len + 1); DWORD i = 0; wchar_t tmp[5] = {0}; wchar_t rev[2] = {0}; while (i < length) { wsprintf(tmp, L"%02X", buffer[i]); if (buffer[i] > 0x7F) { rev[0] = tmp[0]; rev[1] = tmp[1]; tmp[0] = tmp[2]; tmp[1] = tmp[3]; tmp[2] = rev[0]; tmp[3] = rev[1]; } else { tmp[2] = '0'; tmp[3] = '0'; } StrCat(content, tmp); i++; } return content; }