| 423 | |
| 424 | |
| 425 | bool |
| 426 | read_virtual_file(CryptContext *con, LPCWSTR FileName, unsigned char *buf, DWORD buflen, LPDWORD pNread, LONGLONG offset) |
| 427 | { |
| 428 | if (rt_is_dir_iv_file(con, FileName)) { |
| 429 | wstring dirpath; |
| 430 | if (!get_file_directory(FileName, dirpath)) |
| 431 | return false; |
| 432 | BYTE dir_iv[DIR_IV_LEN]; |
| 433 | if (!derive_path_iv(con, &dirpath[0], dir_iv, TYPE_DIRIV)) |
| 434 | return false; |
| 435 | LONGLONG count = min(DIR_IV_LEN - offset, buflen); |
| 436 | if (count <= 0) { |
| 437 | *pNread = 0; |
| 438 | return true; |
| 439 | } |
| 440 | memcpy(buf, dir_iv + offset, static_cast<size_t>(count)); |
| 441 | *pNread = (DWORD)count; |
| 442 | return true; |
| 443 | } else if (rt_is_name_file(con, FileName)) { |
| 444 | string actual_encrypted; |
| 445 | if (!get_actual_encrypted(con, FileName, actual_encrypted)) |
| 446 | return false; |
| 447 | LONGLONG count = min(actual_encrypted.length() - offset, buflen); |
| 448 | if (count <= 0) { |
| 449 | *pNread = 0; |
| 450 | return true; |
| 451 | } |
| 452 | memcpy(buf, &actual_encrypted[0], static_cast<size_t>(count)); |
| 453 | *pNread = (DWORD)count; |
| 454 | return true; |
| 455 | } else { |
| 456 | return false; |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | |
| 461 | #ifdef _WIN32 |
no test coverage detected