This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Exerro's profile picture

searching for programs/strings in programs

Started by Exerro, 15 July 2012 - 10:00 AM
Exerro #1
Posted 15 July 2012 - 12:00 PM
i made a virus and broke all my computers (its that good) and im trying to make an antivirus now…ive got the gui ready and some simple commands but i want it to be able to search and destroy virus files…any help?
also, is there a way to push you out of the computer terminal like when you press esc?
gamesaucer #2
Posted 16 July 2012 - 11:12 AM
For search&destroy: check names that override ROM functions such as "cd", "startup", "rm", "edit" etc.
Then you can open the files using the Fs API, and read the whole file into a string, which can be scanned for malicious commands such as "os.shutdown()" using the String API, and then removed using the Fs api again.

For pressing keys: Ctrl-T does that, but you would need to have an "os.pullEvent" or "os.pullEventRaw" in your program, since a key press is an event.
The "key" event returns the keycode of the key pressed, and if it's equal to the keycode of the esc key you know it's pressed.
I don't know the Esc keycode, but it's simple to get.

Write a program like this, run it and press any key to get the keycode returned.

local param = nil
while param == nil do
 event, param = os.pullEvent("key")
end
return param

This should work.

If I stated anything incorrectly, feel free to correct me. I'm only getting started as well, after all.
Mtdj2 #3
Posted 16 July 2012 - 11:21 AM
Esc is 1. But im not sure the os.queveEvent("key",1) would help at pushing you out…
Hope this helped.
Exerro #4
Posted 16 July 2012 - 04:33 PM
thanks ill try all this out…but the string api doesnt have anything on the wiki so can someone explain the string.find thing pls?
MysticT #5
Posted 16 July 2012 - 04:52 PM
thanks ill try all this out…but the string api doesnt have anything on the wiki so can someone explain the string.find thing pls?
It's a standard Lua api. It's on the Lua manual and there's a lot of tutorials about it.
gamesaucer #6
Posted 16 July 2012 - 06:40 PM
There's a link to the lua documentation on the wiki as well.
1lann #7
Posted 17 July 2012 - 01:55 AM
There's a link to the lua documentation on the wiki as well.
It's in my bookmarks XD I find it very handy
http://lua-users.org/wiki/StringLibraryTutorial