okay I have started my antivirus program and it was working very well until I introduced going into each directory and searching in there so I was wondering if any of you know why it is messing up, I don't want more efficient coding or anything I just want the program to print out all files with dangerous functions defined by the table bad pastebin: pastebin.com/mtvv9da9
My Program Not Working Correctly
Started by jay5476, Jul 26 2013 04:20 AM
6 replies to this topic
#1
Posted 26 July 2013 - 04:20 AM
#2
Posted 26 July 2013 - 05:29 AM
The easiest way to loop over every file in the filesystem is using recursion (a function calling itself from within itself), not using loops.
This code will print out the full path to all files that exist on the computer, excluding any read only folders (such as the rom folder):
This code will print out the full path to all files that exist on the computer, excluding any read only folders (such as the rom folder):
local function check(dir)
for _, v in pairs(fs.list(dir)) do
local path = dir .. "/" .. v
if not fs.isReadOnly(path) then
if fs.isDir(path) then -- is a directory
check(path) -- call this function again to check this directory
else -- is a file
print(path)
-- Do whatever else you want to here
end
end
end
end
check("") -- the empty string (instead of "/") here represents root
#3
Posted 26 July 2013 - 06:45 AM
thanks dude I am going to include this in my code and ill make sure to give you credit
#4
Posted 26 July 2013 - 07:21 AM
:/ sorry to say unsucssefu lagain after trying to figure out what wrong it want test files code
local badFiles = {}
local directories = {}
local bad = {"fs", "io", "os", "delete"}
local function getDirs()
d = fs.list("/")
for i = 1, #d do
if fs.isDir(d[i]) then
table.insert(directories, d[i])
end
end
end
local function test(file)
print("We tested")
f = fs.open(file, "r")
fileContents = f.readAll()
f.close()
for i = 1, #bad do
print("Checking"..file)
if fileContents:find(bad[i]) then
tabel.insert(file, "badFiles")
end
end
end
local function check(dir)
for _, v in pairs(fs.list(dir)) do
local path = dir .. "/" .. v
if not fs.isReadOnly(path) then
if fs.isDir(path) then
check(path)
else
test(path)
end
end
end
end
getDirs()
for i = 1, #directories do
print("Checking "..directories[i])
dir = directories[i]
check(dir)
end
print("Bad Files")
for i = 1, #badFiles do
print(badFile[i])
end
#5
Posted 26 July 2013 - 08:03 AM
local function test(file)
print("We tested")
f = fs.open(file, "r")
fileContents = f.readAll()
f.close()
for i = 1, #bad do
print("Checking"..file)
if fileContents:find(bad[i]) then
tabel.insert(file, "badFiles") -- here
end
end
end
tabel.insert(file, "badFiles")
You spelt table wrong
#6
Posted 26 July 2013 - 05:11 PM
#7
Posted 27 July 2013 - 05:00 AM
local function delete() for i = 1, #badFiles do if fs.exists(badFiles[i]) then if badFiles[i] ~= shell.getRunningProgram() then fs.delete(badFiles[i]) end end end end
I would say the Anti-Virus program is worse than a virus program...
I would make a folder on the Drive, then "mv" all files into that folder that are bad... Llike most good Anti-virus programs do.
or at least do a confirm check for the user first.
local function delete() for i = 1, #badFiles do if fs.exists(badFiles[i]) then if badFiles[i] ~= shell.getRunningProgram() then -- fs.delete(badFiles[i]) fs.move( badFiles[i], "./badfiles/"..tostring(badfiles[i] )) end end end end( not 100% sure that is right as I never used fs.move before )
but the idea is to quarantine the files over deleting them... As just deleting them is virus behavior.
The fine line of virus and anti virus.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











