Created
November 19, 2013 02:22
-
-
Save Announcement/7539215 to your computer and use it in GitHub Desktop.
Snail Antivirus Source Code On Progress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var readline = require('readline'); | |
var colors = require('colors'); | |
var rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
var fs = require('fs'); | |
rl.setPrompt('>> '); | |
var path = "C:\\Users\\Admin\\Documents";//*/process.cwd(); | |
function LMono(len,str,fill) | |
{ if (str.length>len) return str.substring(0,len); else return str + (new Array(len-str.length+1)).join((fill||" ")); } | |
function RMono(len,str,fill) | |
{ return LMono(len,str.split("").reverse().join(""),fill).split("").reverse().join(""); } | |
var fileCount = 0; | |
var fileQuery = []; | |
var fileIndex = 0; | |
var folderOffset = 0; | |
var init = fs.readdirSync(path); | |
fileCount+=init.length; | |
fileQuery = fileQuery.concat(init.map(function(val){val=path+"\\"+val;return val;})); | |
var dotx = 1; | |
var virusDatabase = []; | |
var virusDetected = []; | |
function addVirus(type, xpath, name, removal, description){//int,array,string,array,string | |
virusDatabase.push({"type":type,"path":xpath,"name":name,"rem":removal,"desc":description,"index":virusDatabase.length}); | |
} | |
function chkVirus(testPath){ | |
var vi = virusDatabase.length; | |
while (vi-->0){ | |
var virus = virusDatabase[vi]; | |
var detected = false; | |
virus.path.forEach(function(key, value){ if (testPath.match(value)) detected = true; }); | |
if (!virus.path) detected = true; | |
if (detected) {return virus;} | |
} | |
} | |
var RemovalProcess = { | |
"Kill in task manager": ["Swatting flies","Closing the program","Ending the process tree"], | |
"Remove from auto run": ["Applying bug spray","Canceling application restart","Removing from registry and autorun"], | |
"Delete the file": ["Throw away carcass","Deleting the infected file", "Clearing file system from infestation"], | |
"Uninstall from client":["Remove your wire","Restore the application","Return application to original state"], | |
"Reboot your computer": ["Good nights rest","Shutdown and turn on", "Random Access Memory clears with loss of power"], | |
}; | |
//add some common viruses by default because no servers yet. | |
addVirus("Webroot", | |
[ | |
new RegExp("/(free|smile|weather|bug|channel|\s|\S)+\.(exe)","gi"), | |
], | |
"WEBROOT.BUDG3TC02R41N", | |
[ | |
"Kill in task manager", | |
"Remove from autorun", | |
"Delete the file" | |
], | |
"Nothing is free, the cost is your keystrokes and person information." | |
); | |
addVirus("TROJAN", | |
[ | |
new RegExp("(gen|crack|fix|patch|hack|mod|aim|bot|adventure|quest|club|penguin|game|habro|loader|\s|\S)+\.(exe|dll|msi)","gi") | |
], | |
"TROJAN.B4TTL3CR1", | |
[ | |
"Kill in task manager", | |
"Remove from client", | |
"Delete the file" | |
], | |
"You could be banned and the creator has full access to your computer" | |
); | |
addVirus("OVERFLOW", | |
[ | |
new RegExp("([aeiou]{0,2}[^aeiou\W_\d]{1,3}[\s]){2,}.(pdf|doc|docx)","gi"), | |
], | |
"EXPLOIT.EXC3551VEFPBC", | |
[ | |
"Kill in taskmanager", | |
"Reboot your computer" | |
], | |
"Documents exploit the way your computer handles memory and executes its code" | |
); | |
var start = new Date(); | |
var timeTable = [ | |
["days", "hours","minutes","seconds","milliseconds"], | |
[1000*60*60*24,1000*60*60,1000*60,1000,1], | |
["day", "hrs", "min", "sec", "ms"] | |
]; | |
function calcTimes(time, useString){ | |
//var time = (new Date())-start; | |
var tbrk = timeTable[1]; | |
var times = new Array(tbrk.length); | |
var offset = 0; | |
for (var i = 0; i < times.length; i++){ | |
times[i]=Math.floor((time-offset)/tbrk[i]); | |
offset+=times[i]*tbrk[i]; | |
} | |
if (!useString){ | |
return times; | |
}else{ | |
var str = ""; | |
for (var i=0;i<times.length;i++) | |
if (times[i]>0) | |
str+=times[i]+" "+timeTable[0][i]+((i!=times.length-1)?", ":"."); | |
return str; | |
} | |
} | |
var messages = []; | |
function Scan(testPath){ | |
//var result = chkVirus(testPath); | |
//if (!!result) messages.push(result.name); | |
} | |
function Advance(){ | |
var organizeIndex = fileQuery.length, | |
folders = [], | |
fileHolder = []; | |
if (organizeIndex-folderOffset<Math.pow(10,3)){ | |
while (organizeIndex-->folderOffset){ | |
var skip2=false; | |
var curFile = fileQuery[organizeIndex]; | |
try{ | |
if (fs.statSync(curFile).isDirectory()) fs.readdirSync(curFile); | |
}catch (e){ | |
skip2 = true; | |
} | |
if (!skip2){ | |
if (fs.statSync(curFile).isDirectory()) folders.push(curFile); | |
else fileHolder.push(curFile); | |
} | |
} | |
fileQuery = folders.concat(fileHolder); | |
folderOffset = fileQuery.length; | |
} | |
var file = fileQuery.shift(); | |
var type = "File"; | |
var skip = false; | |
try{ | |
if (fs.statSync(file).isDirectory()) fs.readdirSync(file); | |
}catch (e){ | |
skip = true; | |
} | |
if (skip||!fs.existsSync(file)){ | |
messages.push("(?) File permission errors, skipped "+file); | |
fileCount--; | |
fileQuery.splice(0,1); | |
finish(); | |
return false; | |
} | |
if (fs.statSync(file).isDirectory()){ | |
type="Folder"; | |
var files = fs.readdirSync(file); | |
fileCount+= files.length; | |
fileQuery = fileQuery.concat(files.map(function(val){val=file+"\\"+val;return val;})); | |
}else{ | |
Scan(file); | |
} | |
fileIndex++; | |
if (folderOffset>0) folderOffset--; | |
process.stdout.clearLine(); | |
process.stdout.cursorTo(0); | |
var fip = Math.floor(fileIndex/fileCount*100); | |
var fio = Math.floor(fip/5); | |
var fcp = 20-fio; | |
var fios = ((fio>0)?(new Array(fio+1)).join("="):""); | |
var fcps = ((fcp>0)?(new Array(fcp+1)).join("-"):""); | |
var fccs = ((fip<100)?fios.green:fios)+((fcp>0)?">".green+fcps.substring(1):""); | |
//process.stdout.write(fip+"%"); | |
dotx = dotx%3+1; | |
dots = (new Array(dotx+1)).join("."); | |
var etas = "?????"; | |
if (fileIndex>0){ | |
var time = ((new Date())-start)/fileIndex; | |
var est = Math.floor(time*(fileCount-fileIndex)); | |
var times = calcTimes(est); | |
var maxIx = times.length; | |
while (maxIx-->0) if (times[maxIx]==0) {maxIx++;break} | |
if (maxIx<timeTable[0].length) | |
etas = times[maxIx]+" "+timeTable[2][maxIx]; | |
} | |
if (fip==100) etas = "DONE" | |
process.stdout.write("Scanning"+LMono(3,dots," ")+"["+fccs+"] "+RMono(3,fip+""," ")+"% "+LMono(7,etas," ").red+RMono(6,fileQuery.length.toString()," ")+((type=="Folder")?"=":"-")+"> "+RMono(24,file," ")); | |
function finish(){ | |
if (fileQuery.length>0) call(); | |
else{ | |
var times = calcTimes((new Date())-start,true); | |
console.log("\n"+times); | |
console.log("\n"+LMono(44,"YOU HAVE "+messages.length+" NEW MESSAGE(S)"," ")+RMono(35,"PRESS ENTER TO VIEW"," ")); | |
rl.on("line",function(input){ | |
if (messages.length>0){ | |
console.log(messages.shift()); | |
console.log((messages.length>0)?(LMono(39,messages.length+" MORE"," ")+RMono(39,"NEXT"," ")):RMono(79,"FINISHED"," ")); | |
} | |
if (messages.length<1){ | |
rl.pause(); | |
process.exit(1); | |
} | |
}); | |
} | |
} | |
finish(); | |
} | |
function call(){ | |
setTimeout(Advance,1000/20); | |
}; | |
console.log(fs.readFileSync("snail.txt","ASCII")); | |
console.log(fs.readFileSync("slime.txt","ASCII")); | |
setTimeout(function(){ | |
console.log("\n\n\n"); | |
},1000*4.9); | |
setTimeout(call,1000*5); | |
//call(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment