| 228 | } |
| 229 | |
| 230 | static bool |
| 231 | convert_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 |
no test coverage detected