Windows blocks access to the FAT32 file system

Лев Сахон 20 Баллы репутации
2024-02-27T07:26:16.83+00:00

I need to add a program that is already written in C++ for Windows. The task is to erase the name of a deleted file from the FAT32 system (I do safe deletion, so that recovery programs do not give information that a file with such and such name was on the computer at all). This is easily done using WinHex. I have an algorithm that works, but the problem is the OS, which blocks access in the FAT table. The funny thing is that the system allows you to write anything from zero to, I think, about 10,000th offset, which makes it very easy to put the partition, but it won't let you access the table, despite the fact that I run as administrator.


int main() {     
    LPCSTR partitionU = "\\\\.\\U:"; 
    HANDLE hDisk = CreateFileA(partitionU, 
        GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE  , NULL, OPEN_EXISTING, 0, NULL);

    if (hDisk == INVALID_HANDLE_VALUE) {
        std::cout << GetLastError() << std::endl;
        return 0;
    }
    else std::cout << "Success!" << std::endl;

if (SetFilePointer(hDisk, 4194304, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
            std::cerr << "Set pointer error: ";
            return GetLastError();
        }
   
        byte buffer[1024*1];
        DWORD dwRead;
        int sector_count = 0;
        int row_count = 0;
        int str_count = 0;
        if (ReadFile(hDisk, buffer, sizeof(buffer), &dwRead, NULL)) {
          
            for (DWORD i = 0; i < dwRead; ++i) {
                if (row_count != 15) {
                    std::cout << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(buffer[i]) << " ";
                    row_count++;
                }
                else {
                    std::cout << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(buffer[i]) << " "<<std::endl; 
                    row_count = 0;
                    sector_count++;
                }
                if (sector_count == 32) {
                    std::cout << "-----------------------" << str_count++ << "------------------------" << std::endl;
                    sector_count = 0;
                }
            }
            std::cout << std::endl;
        }
        else {
    
            DWORD error = GetLastError();
            std::cerr << "Error opening disk. Error code: " << error << std::endl;
        }

byte* pointer = reinterpret_cast<byte*>(0);
    LARGE_INTEGER largeInt;
    largeInt.QuadPart = 0x400200;//reinterpret_cast<LONG_PTR>(pointer);
    if (!SetFilePointerEx(hDisk, largeInt, NULL, FILE_BEGIN)) { //file_begin - от начала файла
        std::cerr << "Set pointer error ";
        return GetLastError();
    }
    DWORD dwBytesWritten = 0;
   
    unsigned char byteArray[512*1];
    memset(byteArray, 0xFF, sizeof(byteArray));

    for (int i = 0; i <= 240; i++) {
        byteArray[i] = buffer[i];
    }
    for (int i = 241; i <= 511; i++) {
        byteArray[i] = 0x00;
    }*/
    
    
    if (WriteFile(hDisk, byteArray , sizeof(byteArray), &dwBytesWritten, NULL)) {
        std::cout <<"Success"<< std::endl;
    }
    else {
        std::cerr << "Error" << GetLastError() << std::endl;
    }
Visual Studio
Visual Studio
Семейство интегрированных средств разработки microsoft для создания приложений для Windows, веб-устройств и мобильных устройств.
Вопросы: 5
Комментариев: 0 Без комментариев
Голосов: {count}

Принятый ответ
  1. Maksim Marinov (Convergys Corporation) 240 Баллы репутации Поставщик Майкрософт
    2024-02-27T14:39:24.34+00:00

    Здравствуйте , Посмотрите это обсуждение, возможно подскажет что-то: https://cplusplus.com/forum/windows/21731/

    Пользователи, которые сочли этот ответ полезным: 2.
    Комментариев: 0 Без комментариев

Дополнительные ответы: 0

Сортировать по: Наиболее полезные