MCPcopy Create free account
hub / github.com/bailey27/cppcryptfs / GetStringForLang

Method GetStringForLang

cppcryptfs/cppcryptfs.cpp:118–177  ·  view source on GitHub ↗

Direct reading of a string from a specific language section (bypassing the current thread locale)

Source from the content-addressed store, hash-verified

116
117// Direct reading of a string from a specific language section (bypassing the current thread locale)
118CString CcppcryptfsApp::GetStringForLang(HMODULE hInst, UINT nID, WORD wLang)
119{
120 HRSRC hRes = ::FindResourceExW(
121 hInst,
122 RT_STRING,
123 MAKEINTRESOURCEW((nID >> 4) + 1),
124 wLang);
125
126 if (!hRes)
127 return CString();
128
129 HGLOBAL hGlobal = ::LoadResource(hInst, hRes);
130 if (!hGlobal)
131 return CString();
132
133 DWORD resourceSizeBytes = ::SizeofResource(hInst, hRes);
134 if (resourceSizeBytes < sizeof(WORD) || (resourceSizeBytes % sizeof(WORD)) != 0)
135 return CString();
136
137 const WORD* pWords = static_cast<const WORD*>(::LockResource(hGlobal));
138 if (!pWords)
139 return CString();
140
141 const size_t wordCount = resourceSizeBytes / sizeof(WORD);
142 size_t pos = 0;
143
144 const int index = nID & 0x000F;
145
146 for (int i = 0; i < index; ++i)
147 {
148 if (pos >= wordCount)
149 return CString();
150
151 const size_t len = pWords[pos];
152 ++pos; // skip length word
153
154 if (len > wordCount - pos)
155 return CString();
156
157 pos += len; // skip string data
158 }
159
160 if (pos >= wordCount)
161 return CString();
162
163 const size_t finalLen = pWords[pos];
164 ++pos; // move to first character
165
166 if (finalLen == 0)
167 return CString();
168
169 if (finalLen > wordCount - pos)
170 return CString();
171
172 if (finalLen > static_cast<size_t>(INT_MAX))
173 return CString();
174
175 return CString(reinterpret_cast<const WCHAR*>(pWords + pos),

Callers 1

EnumLangsCallbackFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected