using System;
using ;
using ;
using ;
using ;
using ;
namespace *Scanning
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
delegate void SetTextCallback(string text);
delegate void SetTextCallback2(bool b);
delegate void SetTextCallback3(ListViewItem item);
private string fname, code;
private Thread thr;
private string[] sArray;
private void button1_Click(object sender, EventArgs e)
{
if (() == )
{
= ;
}
}
private void startbtn_Click(object sender, EventArgs e)
{
();
fname = ;
thr = new Thread(new ThreadStart(scan));
= true;
();
}
private void scan(){
FileSystemInfo s = GetFileSystemInfo(fname);
if (s != null) { scanbtn(false); ListFiles(s); scantext("Scan complete"); scanbtn(true); } else { ("Please select the directory to scan first"); }
}
public FileSystemInfo GetFileSystemInfo(string path){
if ((path))
return new FileInfo(path);
else if ((path))
return new DirectoryInfo(path);
else
return null;
}
private void ListFiles(FileSystemInfo info){
if (){
DirectoryInfo dir = info as DirectoryInfo;
if (dir == null) return;
try{
FileSystemInfo[] files = ();
for (int i = 0; i < ; i++){
FileInfo file = files[i] as FileInfo;
if (file != null && (() == ".asp" || () == ".php" || () == ".aspx" || () == ".master"))
{
scantext("scan " + );
chkfile(,);
}else{
ListFiles(files[i]);
}
}
}
catch{}
}
}
private void chkfile(string filepath,long filesize)
{
try{
if (IsFileInUse(filepath)) { (2000); chkfile(filepath,filesize); }
StreamReader sr = new StreamReader(filepath);
string content = ();
();
string chkr=chkcontent(content);
if (chkr!=""){
ListViewItem item = new ListViewItem("Suspicious");
((filepath).ToString());
(chkr);
(filepath);
((filesize/1024).ToString() + " kb");
addtiem(item);
}
}
catch { }
}
private string downurl(string url)
{
WebClient client = new WebClient();
string result = (url);
return result;
}
private void addtiem(ListViewItem item)
{
if (){
SetTextCallback3 d = new SetTextCallback3(addtiem);
(d, new object[] { item });
}else{
(item);
}
}
private void scantext(string text)
{
if ()
{
SetTextCallback d = new SetTextCallback(scantext);
(d, new object[] { text });
}else{
=text;
}
}
private void scanbtn(bool b){
if (){
SetTextCallback2 d = new SetTextCallback2(scanbtn);
(d, new object[] { b });
}else{
= b;
= b;
this. = b;
}
}
private string chkcontent(string content){
string returnval = "";
content = ();
foreach (string i in sArray)
{
if ((i)> -1){ returnval+=i+","; }
}
if (returnval != "") { returnval=(0, - 1); }
return returnval;
}
bool IsFileInUse(string fileName)
{
bool inUse = true;
if ((fileName))
{
FileStream fs = null;
try { fs = new FileStream(fileName, , , ); inUse = false; }
catch { }
finally { if (fs != null)(); }
return inUse;
}
else { return false; }
}
private void Form1_Load(object sender, EventArgs e)
{
try{
code = downurl("/txt/");
sArray = ().Split('|');
}
catch (Exception ex)
{
("Error:" + , "Cannot start the program!", ); ();
}
}
private void list_DoubleClick(object sender, EventArgs e)
{
("", [0].SubItems[3].Text);
}
}
}