bool MyGetVolumeInformation( LPCWSTR rootPathName, UString &volumeName, LPDWORD volumeSerialNumber, LPDWORD maximumComponentLength, LPDWORD fileSystemFlags, UString &fileSystemName) { if (g_IsNT) { bool result = BOOLToBool(GetVolumeInformationW( rootPathName, volumeName.GetBuffer(MAX_PATH), MAX_PATH, volumeSerialNumber, maximumComponentLength, fileSystemFlags, fileSystemName.GetBuffer(MAX_PATH), MAX_PATH)); volumeName.ReleaseBuffer(); fileSystemName.ReleaseBuffer(); return result; } AString volumeNameA, fileSystemNameA; bool result = MyGetVolumeInformation(GetSystemString(rootPathName), volumeNameA, volumeSerialNumber, maximumComponentLength, fileSystemFlags,fileSystemNameA); if (result) { volumeName = GetUnicodeString(volumeNameA); fileSystemName = GetUnicodeString(fileSystemNameA); } return result; }
static void ConvertResourceToResourceW(const CResource &resource, CResourceW &resourceW) { *(CResourceBase *)&resourceW = *(CResourceBase *)&resource; resourceW.LocalName = GetUnicodeString(resource.LocalName); resourceW.RemoteName = GetUnicodeString(resource.RemoteName); resourceW.Comment = GetUnicodeString(resource.Comment); resourceW.Provider = GetUnicodeString(resource.Provider); }
void dumpSmbNtlmAuthResponse(FILE *fp, tSmbNtlmAuthResponse *response) { fprintf(fp,"NTLM Response:\n"); fprintf(fp," Ident = %s\n",response->ident); fprintf(fp," mType = %d\n",IVAL(&response->msgType,0)); fprintf(fp," LmResp = "); DumpBuffer(fp,response,lmResponse); fprintf(fp," NTResp = "); DumpBuffer(fp,response,ntResponse); fprintf(fp," Domain = %s\n",GetUnicodeString(response,uDomain)); fprintf(fp," User = %s\n",GetUnicodeString(response,uUser)); fprintf(fp," Wks = %s\n",GetUnicodeString(response,uWks)); fprintf(fp," sKey = "); DumpBuffer(fp, response,sessionKey); fprintf(fp," Flags = %08x\n",IVAL(&response->flags,0)); }
void buildSmbNtlmAuthResponse(tSmbNtlmAuthChallenge *challenge, tSmbNtlmAuthResponse *response, char *user, char *password) { uint8 lmRespData[24]; uint8 ntRespData[24]; char *d = strdup(GetUnicodeString(challenge,uDomain)); char *domain = d; char *u = strdup(user); char *p = strchr(u,'@'); if (p) { domain = p+1; *p = '\0'; } SMBencrypt(password, challenge->challengeData, lmRespData); SMBNTencrypt(password, challenge->challengeData, ntRespData); response->bufIndex = 0; memcpy(response->ident,"NTLMSSP\0\0\0",8); SIVAL(&response->msgType,0,3); AddBytes(response,lmResponse,lmRespData,24); AddBytes(response,ntResponse,ntRespData,24); AddUnicodeString(response,uDomain,domain); AddUnicodeString(response,uUser,u); AddUnicodeString(response,uWks,u); AddString(response,sessionKey,NULL); response->flags = challenge->flags; free(d); free(u); }
bool MyGetLogicalDriveStrings(UStringVector &driveStrings) { driveStrings.Clear(); if (g_IsNT) { UINT32 size = GetLogicalDriveStringsW(0, NULL); if (size == 0) return false; UString buffer; UINT32 newSize = GetLogicalDriveStringsW(size, buffer.GetBuffer(size)); if (newSize == 0) return false; if (newSize > size) return false; UString string; for (UINT32 i = 0; i < newSize; i++) { WCHAR c = buffer[i]; if (c == L'\0') { driveStrings.Add(string); string.Empty(); } else string += c; } return string.IsEmpty(); } CSysStringVector driveStringsA; bool res = MyGetLogicalDriveStrings(driveStringsA); for (int i = 0; i < driveStringsA.Size(); i++) driveStrings.Add(GetUnicodeString(driveStringsA[i])); return res; }
void ReadInternalAssociations(CObjectVector<CExtInfo> &items) { items.Clear(); NSynchronization::CCriticalSectionLock lock(g_CriticalSection); CKey associationsKey; if (associationsKey.Open(HKEY_CURRENT_USER, kAssociationsPath, KEY_READ) != ERROR_SUCCESS) return; CSysStringVector extNames; associationsKey.EnumKeys(extNames); for(int i = 0; i < extNames.Size(); i++) { const CSysString extName = extNames[i]; CExtInfo extInfo; // extInfo.Enabled = false; extInfo.Ext = GetUnicodeString(extName); CKey key; if (key.Open(associationsKey, extName, KEY_READ) != ERROR_SUCCESS) return; UString pluginsString; key.QueryValue(kExtPlugins, pluginsString); SplitString(pluginsString, extInfo.Plugins); /* if (key.QueryValue(kExtEnabled, extInfo.Enabled) != ERROR_SUCCESS) extInfo.Enabled = false; */ items.Add(extInfo); } }
DWORD GetResourceInformation(const CResourceW &resource, CResourceW &destResource, UString &systemPathPart) { if (g_IsNT) { CByteBuffer byteBuffer; const DWORD kBufferSize = 16384; byteBuffer.SetCapacity(kBufferSize); LPNETRESOURCEW lpnrLocal = (LPNETRESOURCEW) (BYTE *)(byteBuffer); ZeroMemory(lpnrLocal, kBufferSize); DWORD bufferSize = kBufferSize; NETRESOURCEW netResource; ConvertCResourceToNETRESOURCE(resource, netResource); LPWSTR lplpSystem; DWORD result = ::WNetGetResourceInformationW(&netResource, lpnrLocal, &bufferSize, &lplpSystem); if (result != NO_ERROR) return result; if (lplpSystem != 0) systemPathPart = lplpSystem; ConvertNETRESOURCEToCResource(lpnrLocal[0], destResource); return result; } CResource resourceA, destResourceA; ConvertResourceWToResource(resource, resourceA); AString systemPathPartA; DWORD result = GetResourceInformation(resourceA, destResourceA, systemPathPartA); ConvertResourceToResourceW(destResourceA, destResource); systemPathPart = GetUnicodeString(systemPathPartA); return result; }
bool MyFormatMessage(DWORD messageID, UString &message) { CSysString messageSys; bool result = MyFormatMessage(messageID, messageSys); message = GetUnicodeString(messageSys); return result; }
STDMETHODIMP CArchiveFolderManager::GetIconPath(const wchar_t *ext, BSTR *iconPath, Int32 *iconIndex) { LoadFormats(); *iconPath = 0; *iconIndex = 0; for (int i = 0; i < _codecs->Libs.Size(); i++) { const CCodecLib &lib = _codecs->Libs[i]; int ii; if (lib.FindIconIndex(ext, ii)) { *iconIndex = ii; return StringToBstr(GetUnicodeString(lib.Path, GetCurrentFileCodePage()), iconPath); } } int ii; if (_codecs->InternalIcons.FindIconIndex(ext, ii)) { *iconIndex = ii; UString path; NWindows::NDLL::MyGetModuleFileName(g_hInstance, path); return StringToBstr(path, iconPath); } return S_OK; }
void dumpSmbNtlmAuthChallenge(FILE *fp, tSmbNtlmAuthChallenge *challenge) { fprintf(fp,"NTLM Challenge:\n"); fprintf(fp," Ident = %s\n",challenge->ident); fprintf(fp," mType = %d\n",IVAL(&challenge->msgType,0)); fprintf(fp," Domain = %s\n",GetUnicodeString(challenge,uDomain)); fprintf(fp," Flags = %08x\n",IVAL(&challenge->flags,0)); fprintf(fp," Challenge = "); dumpRaw(fp, challenge->challengeData,8); }
void dumpSmbNtlmAuthResponse (FILE * fp, tSmbNtlmAuthResponse * response) { unsigned char buf1[NTLM_BUFSIZE], buf2[NTLM_BUFSIZE], buf3[NTLM_BUFSIZE]; fprintf (fp, "NTLM Response:\n" " Ident = %.8s\n" " mType = %d\n" " LmResp = ", response->ident, UI32LE (response->msgType)); DumpBuffer (fp, response, lmResponse); fprintf (fp, " Domain = %s\n" " User = %s\n" " Wks = %s\n" " sKey = ", GetUnicodeString (response, uDomain, buf1), GetUnicodeString (response, uUser, buf2), GetUnicodeString (response, uWks, buf3)); DumpBuffer (fp, response, sessionKey); fprintf (fp, " Flags = %08x\n", UI32LE (response->flags)); }
void buildSmbNtlmAuthResponse_noatsplit (tSmbNtlmAuthChallenge * challenge, tSmbNtlmAuthResponse * response, const char *user, const char *password) { unsigned char buf[NTLM_BUFSIZE]; const char *domain = GetUnicodeString (challenge, uDomain, buf); buildSmbNtlmAuthResponse_userlen (challenge, response, user, strlen (user), domain, password); }
static void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATA &fd, CFileInfoW &fi) { fi.Attrib = fd.dwFileAttributes; fi.CTime = fd.ftCreationTime; fi.ATime = fd.ftLastAccessTime; fi.MTime = fd.ftLastWriteTime; fi.Size = (((UInt64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow; fi.Name = GetUnicodeString(fd.cFileName, GetCurrentCodePage()); #ifndef _WIN32_WCE fi.ReparseTag = fd.dwReserved0; #else fi.ObjectID = fd.dwOID; #endif }
static bool CheckShellExtensionInfo2(const CSysString &extension, UString &iconPath, int &iconIndex) { iconIndex = -1; iconPath.Empty(); NSynchronization::CCriticalSectionLock lock(g_CriticalSection); CKey extKey; if (extKey.Open(HKEY_CLASSES_ROOT, GetExtensionKeyName(extension), KEY_READ) != ERROR_SUCCESS) return false; CSysString programNameValue; if (extKey.QueryValue(NULL, programNameValue) != ERROR_SUCCESS) return false; CSysString extProgramKeyName = GetExtProgramKeyName(extension); UString programNameValueU = GetUnicodeString(programNameValue); if (programNameValueU.CompareNoCase(GetUnicodeString(extProgramKeyName)) != 0) return false; CKey iconKey; if (extKey.Open(HKEY_CLASSES_ROOT, extProgramKeyName + CSysString(TEXT(CHAR_PATH_SEPARATOR)) + kDefaultIconKeyName, KEY_READ) != ERROR_SUCCESS) return false; UString value; if (extKey.QueryValue(NULL, value) == ERROR_SUCCESS) { int pos = value.ReverseFind(L','); iconPath = value; if (pos >= 0) { const wchar_t *end; UInt64 index = ConvertStringToUInt64((const wchar_t *)value + pos + 1, &end); if (*end == 0) { iconIndex = (int)index; iconPath = value.Left(pos); } } } return true; }
void dumpSmbNtlmAuthChallenge (FILE * fp, tSmbNtlmAuthChallenge * challenge) { unsigned char buf[NTLM_BUFSIZE]; fprintf (fp, "NTLM Challenge:\n" " Ident = %.8s\n" " mType = %d\n" " Domain = %s\n" " Flags = %08x\n" " Challenge = ", challenge->ident, UI32LE (challenge->msgType), GetUnicodeString (challenge, uDomain, buf), UI32LE (challenge->flags)); dumpRaw (fp, challenge->challengeData, 8); }
bool CFindFile::FindNext(CFileInfoW &fileInfo) { CFileInfo fileInfo0; bool bret = FindNext(fileInfo0); if (bret) { fileInfo.Attrib = fileInfo0.Attrib; fileInfo.CTime = fileInfo0.CTime; fileInfo.ATime = fileInfo0.ATime; fileInfo.MTime = fileInfo0.MTime; fileInfo.Size = fileInfo0.Size; fileInfo.IsDevice = fileInfo0.IsDevice; fileInfo.Name = GetUnicodeString(fileInfo0.Name, CP_ACP); } return bret; }
bool BrowseForFolder(HWND owner, LPCWSTR title, LPCWSTR initialFolder, UString &resultPath) { if (g_IsNT) return BrowseForFolder(owner, title, BIF_NEWDIALOGSTYLE | BIF_RETURNONLYFSDIRS // | BIF_STATUSTEXT // This flag is not supported when BIF_NEWDIALOGSTYLE is specified. , initialFolder, resultPath); // BIF_STATUSTEXT; BIF_USENEWUI (Version 5.0) CSysString s; bool res = BrowseForFolder(owner, GetSystemString(title), BIF_NEWDIALOGSTYLE | BIF_RETURNONLYFSDIRS // | BIF_STATUSTEXT // This flag is not supported when BIF_NEWDIALOGSTYLE is specified. , GetSystemString(initialFolder), s); resultPath = GetUnicodeString(s); return res; }
STDMETHODIMP CArchiveFolderManager::GetIconPath(const wchar_t *ext, BSTR *iconPath, Int32 *iconIndex) { LoadFormats(); *iconPath = 0; *iconIndex = 0; for (int i = 0; i < _codecs->Libs.Size(); i++) { const CCodecLib &lib = _codecs->Libs[i]; int ii = lib.FindIconIndex(ext); if (ii >= 0) { *iconIndex = ii; return StringToBstr(GetUnicodeString(lib.Path, GetCurrentFileCodePage()), iconPath); } } return S_OK; }
UString MyLoadStringW(HINSTANCE hInstance, UINT resourceID) { if (g_IsNT) { UString s; int size = 256; int len; do { size += 256; len = ::LoadStringW(hInstance, resourceID, s.GetBuffer(size - 1), size); } while (size - len <= 1); s.ReleaseBuffer(); return s; } return GetUnicodeString(MyLoadString(hInstance, resourceID)); }
bool MyFormatMessage(DWORD messageID, UString &message) { if (g_IsNT) { LPVOID msgBuf; if(::FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, messageID, 0, (LPWSTR) &msgBuf, 0, NULL) == 0) return false; message = (LPCWSTR)msgBuf; ::LocalFree(msgBuf); return true; } CSysString messageSys; bool result = MyFormatMessage(messageID, messageSys); message = GetUnicodeString(messageSys); return result; }
static bool GetCurDir(UString &path) { path.Empty(); char begin[MAX_PATHNAME_LEN]; begin[0]='c'; begin[1]=':'; char * cret = getcwd(begin+2, MAX_PATHNAME_LEN - 3); if (cret) { #ifdef _UNICODE path = GetUnicodeString(begin); #else path = begin; #endif return true; } return false; }
LRESULT CComboBox::GetLBText(int index, UString &s) { s.Empty(); if (g_IsNT) { LRESULT len = SendMessageW(CB_GETLBTEXTLEN, index, 0); if (len == CB_ERR) return len; len = SendMessageW(CB_GETLBTEXT, index, (LPARAM)s.GetBuffer((int)len + 1)); s.ReleaseBuffer(); return len; } AString sa; LRESULT len = GetLBText(index, sa); if (len == CB_ERR) return len; s = GetUnicodeString(sa); return s.Len(); }
bool CFindFile::FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo) { if (!Close()) return false; CFileInfo fileInfo0; AString Awildcard = UnicodeStringToMultiByte(wildcard, CP_ACP); bool bret = FindFirst((LPCSTR)Awildcard, fileInfo0); if (bret) { fileInfo.Attrib = fileInfo0.Attrib; fileInfo.CTime = fileInfo0.CTime; fileInfo.ATime = fileInfo0.ATime; fileInfo.MTime = fileInfo0.MTime; fileInfo.Size = fileInfo0.Size; fileInfo.IsDevice = fileInfo0.IsDevice; fileInfo.Name = GetUnicodeString(fileInfo0.Name, CP_ACP); } return bret; }
bool CWindow::GetText(UString &s) { if (g_IsNT) { s.Empty(); int length = GetWindowTextLengthW(_window); if (length == 0) return (::GetLastError() == ERROR_SUCCESS); length = GetWindowTextW(_window, s.GetBuffer(length), length + 1); s.ReleaseBuffer(); if (length == 0) return (::GetLastError() == ERROR_SUCCESS); return true; } CSysString sysString; bool result = GetText(sysString); s = GetUnicodeString(sysString); return result; }
bool CMenu::GetItem(UINT itemIndex, bool byPosition, CMenuItem &item) { const UINT kMaxSize = 512; #ifndef _UNICODE if (!g_IsNT) { CHAR s[kMaxSize + 1]; MENUITEMINFOA si; ConvertItemToSysForm(item, si); if (item.IsString()) { si.cch = kMaxSize; si.dwTypeData = s; } if (GetItemInfo(itemIndex, byPosition, &si)) { ConvertItemToMyForm(si, item); if (item.IsString()) item.StringValue = GetUnicodeString(s); return true; } } else #endif { wchar_t s[kMaxSize + 1]; MENUITEMINFOW si; ConvertItemToSysForm(item, si); if (item.IsString()) { si.cch = kMaxSize; si.dwTypeData = s; } if (GetItemInfo(itemIndex, byPosition, &si)) { ConvertItemToMyForm(si, item); if (item.IsString()) item.StringValue = s; return true; } } return false; }
void buildSmbNtlmAuthResponse (tSmbNtlmAuthChallenge * challenge, tSmbNtlmAuthResponse * response, const char *user, const char *password) { const char *p = strchr (user, '@'); size_t user_len = strlen (user); unsigned char buf[NTLM_BUFSIZE]; const char *domain = GetUnicodeString (challenge, uDomain, buf); if (p) { domain = p + 1; user_len = p - user; } buildSmbNtlmAuthResponse_userlen (challenge, response, user, user_len, domain, password); }
UString GetNsisString(const UString &s) { UString res; for (int i = 0; i < s.Length();) { wchar_t nVarIdx = s[i++]; if (nVarIdx > NS_UN_CODES_START && nVarIdx <= NS_UN_CODES_END) { if (i == s.Length()) break; int nData = s[i++] & 0x7FFF; if (nVarIdx == NS_UN_SHELL_CODE) res += GetUnicodeString(GetShellString(nData >> 8)); else if (nVarIdx == NS_UN_VAR_CODE) res += GetUnicodeString(GetVar(nData)); else if (nVarIdx == NS_UN_LANG_CODE) res += L"NS_LANG_CODE"; } else if (nVarIdx == NS_UN_SKIP_CODE)
UString MyLoadString(UINT resourceID) { #ifndef _UNICODE if (!g_IsNT) return GetUnicodeString(MyLoadStringA(g_hInstance, resourceID)); else #endif { { wchar_t s[kStartSize]; s[0] = 0; int len = ::LoadStringW(g_hInstance, resourceID, s, kStartSize); if (kStartSize - len > 1) return s; } UString dest; MyLoadString2(g_hInstance, resourceID, dest); return dest; } }
UString CDrop::QueryFileName(UINT fileIndex) { UString fileName; #ifndef _UNICODE if (!g_IsNT) { AString fileNameA; UINT bufferSize = QueryFile(fileIndex, (LPTSTR)NULL, 0); QueryFile(fileIndex, fileNameA.GetBuffer(bufferSize + 2), bufferSize + 1); fileNameA.ReleaseBuffer(); fileName = GetUnicodeString(fileNameA); } else #endif { UINT bufferSize = QueryFile(fileIndex, (LPWSTR)NULL, 0); QueryFile(fileIndex, fileName.GetBuffer(bufferSize + 2), bufferSize + 1); fileName.ReleaseBuffer(); } return fileName; }
LRESULT CComboBox::GetLBText(int index, UString &s) { s.Empty(); if (g_IsNT) { LRESULT len = SendMsgW(CB_GETLBTEXTLEN, index, 0); if (len == CB_ERR) return len; LRESULT len2 = SendMsgW(CB_GETLBTEXT, index, (LPARAM)s.GetBuf((unsigned)len)); if (len2 == CB_ERR) return len; if (len > len2) len = len2; s.ReleaseBuf_CalcLen((unsigned)len); return len; } AString sa; LRESULT len = GetLBText(index, sa); if (len == CB_ERR) return len; s = GetUnicodeString(sa); return s.Len(); }