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

Function convert_fdata

libcppcryptfs/util/fileutil.cpp:230–289  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

228}
229
230static bool
231convert_fdata(CryptContext *con, BOOL isRoot, const BYTE *dir_iv, const WCHAR *path, WIN32_FIND_DATAW& fdata, string *actual_encrypted, wstring& storage)
232{
233
234 if (!wcscmp(fdata.cFileName, L".") || !wcscmp(fdata.cFileName, L".."))
235 return true;
236
237 bool isReverseConfig = isRoot && con->GetConfig()->m_reverse && !wcscmp(fdata.cFileName, REVERSE_CONFIG_NAME);
238
239 long long size = ((long long)fdata.nFileSizeHigh << 32) | fdata.nFileSizeLow;
240
241 if (size > 0 && !(fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && !isReverseConfig) {
242 LARGE_INTEGER l;
243 l.LowPart = fdata.nFileSizeLow;
244 l.HighPart = fdata.nFileSizeHigh;
245 if (con->GetConfig()->m_reverse) {
246 if (!adjust_file_size_up(l))
247 return false;
248 } else {
249 if (!adjust_file_size_down(l))
250 return false;
251 }
252 fdata.nFileSizeHigh = l.HighPart;
253 fdata.nFileSizeLow = l.LowPart;
254 }
255
256
257
258 if (wcscmp(fdata.cFileName, L".") && wcscmp(fdata.cFileName, L"..")) {
259 storage.clear();
260 const WCHAR *dname;
261
262 if (isReverseConfig) {
263 fdata.dwFileAttributes &= ~FILE_ATTRIBUTE_HIDDEN;
264 dname = CONFIG_NAME;
265 } else {
266 if (con->GetConfig()->m_reverse) {
267 dname = encrypt_filename(con, dir_iv, fdata.cFileName, storage, actual_encrypted);
268 } else {
269 dname = decrypt_filename(con, dir_iv, path, fdata.cFileName, storage);
270 }
271 }
272
273 if (!dname)
274 return false;
275
276 // wcscpy_s throws a weird exception if src is too long so check the length before calling it
277 if (wcslen(dname) >= std::size(fdata.cFileName)) {
278 return false;
279 }
280 if (wcscpy_s(fdata.cFileName, dname)) {
281 return false;
282 }
283 }
284
285 // short name - not really needed
286 fdata.cAlternateFileName[0] = '\0';
287

Callers 1

find_filesFunction · 0.85

Calls 5

adjust_file_size_upFunction · 0.85
adjust_file_size_downFunction · 0.85
encrypt_filenameFunction · 0.85
decrypt_filenameFunction · 0.85
GetConfigMethod · 0.80

Tested by

no test coverage detected