| 276 | |
| 277 | |
| 278 | const WCHAR * // returns UNICODE plaintext filename |
| 279 | decrypt_filename(CryptContext *con, const BYTE *dir_iv, const WCHAR *path, const WCHAR *filename, wstring& storage) |
| 280 | { |
| 281 | static ValidFileNameCharChecker char_checker; |
| 282 | |
| 283 | if (con->GetConfig()->m_PlaintextNames) { |
| 284 | storage = filename; |
| 285 | return &storage[0]; |
| 286 | } |
| 287 | |
| 288 | wstring file_without_stream; |
| 289 | wstring stream; |
| 290 | |
| 291 | bool have_stream = get_file_stream(filename, &file_without_stream, &stream); |
| 292 | |
| 293 | vector<unsigned char> ctstorage; |
| 294 | |
| 295 | char longname_buf[4096]; |
| 296 | |
| 297 | wstring longname_storage; |
| 298 | |
| 299 | if (!wcsncmp(file_without_stream.c_str(), longname_prefix, sizeof(longname_prefix)/sizeof(longname_prefix[0])-1)) { |
| 300 | if (con->GetConfig()->m_reverse) { |
| 301 | if (decrypt_reverse_longname(con, file_without_stream.c_str(), path, dir_iv, storage)) |
| 302 | return &storage[0]; |
| 303 | else |
| 304 | return nullptr; |
| 305 | } else { |
| 306 | wstring fullpath = path; |
| 307 | if (fullpath[fullpath.size() - 1] != '\\') |
| 308 | fullpath.push_back('\\'); |
| 309 | |
| 310 | fullpath += file_without_stream.c_str(); |
| 311 | fullpath += longname_suffix; |
| 312 | |
| 313 | HANDLE hFile = CreateFile(&fullpath[0], GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
| 314 | |
| 315 | if (hFile == INVALID_HANDLE_VALUE) |
| 316 | return NULL; |
| 317 | |
| 318 | DWORD nRead; |
| 319 | |
| 320 | if (!ReadFile(hFile, longname_buf, sizeof(longname_buf)-1, &nRead, NULL)) { |
| 321 | CloseHandle(hFile); |
| 322 | return NULL; |
| 323 | } |
| 324 | |
| 325 | CloseHandle(hFile); |
| 326 | |
| 327 | if (nRead < 1) |
| 328 | return NULL; |
| 329 | |
| 330 | longname_buf[nRead] = '\0'; |
| 331 | |
| 332 | if (!utf8_to_unicode(longname_buf, longname_storage)) |
| 333 | return NULL; |
| 334 | |
| 335 | file_without_stream = &longname_storage[0]; |
no test coverage detected